Run clang-format on the whole tree
[lttng-tools.git] / tests / regression / tools / metadata / test_kernel
CommitLineData
01654d69
JR
1#!/bin/bash
2#
4942c256 3# Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
01654d69 4#
9d16b343
MJ
5# SPDX-License-Identifier: LGPL-2.1-only
6
01654d69
JR
7TEST_DESC="Metadata env - Kernel space tracing"
8
9CURDIR=$(dirname "$0")/
10TESTDIR=$CURDIR/../../..
11EVENT_NAME="lttng_test_filter_event"
12
8d5a3312 13TRACE_PATH=$(mktemp -d -t tmp.test_metadata_env_kernel_trace_path.XXXXXX)
01654d69
JR
14
15NUM_TESTS=13
16
17source "$TESTDIR/utils/utils.sh"
18
19# Fetch utils functions common to ust and kernel tests.
20source "$CURDIR/utils.sh"
21
22function test_kernel ()
23{
01654d69
JR
24 local metadata_path
25 local value
26
27 local expected_path="${TRACE_PATH}/lttng-traces"
28 local session_name="kernel"
8d5a3312
MJ
29 local metadata=$(mktemp -t "tmp.${FUNCNAME[0]}_metadata.XXXXXX")
30 local metadata_env=$(mktemp -t "tmp.${FUNCNAME[0]}_metadata_env.XXXXXX")
01654d69
JR
31
32 diag "Test Kernel metadata env field"
33 create_lttng_session_ok "$session_name"
34 enable_kernel_lttng_event_ok "$session_name" "$EVENT_NAME"
35 start_lttng_tracing_ok "$session_name"
36
37 echo -n "10" > /proc/lttng-test-filter-event
38
39 stop_lttng_tracing_ok "$session_name"
40 destroy_lttng_session_ok "$session_name"
41
42 # bt1 accepts only a directory while bt2 accepts either the metadata
43 # file directly or a directory with an immediate metadata file.
44 # Settle for the common denominator.
fc2dd19e 45 metadata_path=$(find "${expected_path}/${session_name}"* -name "metadata")
01654d69
JR
46 metadata_path=$(dirname "$metadata_path")
47
48 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata"
49
50 # Extract "env" scope
51 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
52
53 # Construct the expected path from the env metadata and use it to
54 # validate that all information make sense. This information is present
55 # to allow trace viewer to recreate the same directory hierarchy.
56
57 # Trace name
58 value=$(get_env_value "$metadata_env" trace_name)
59 ok $? "Extracting trace_name from env metadata"
60 expected_path="${expected_path}/${value}"
61
62 # Session creation time
63 value=$(get_env_value "$metadata_env" trace_creation_datetime)
64 ok $? "Extracting trace_creation_datetime from env metadata"
65 value=$(iso8601_to_lttng_dir_datetime "$value")
66 expected_path="${expected_path}-${value}"
67
68 # Domain
69 value=$(get_env_value "$metadata_env" domain)
70 ok $? "Extracting domain from env metadata"
71 expected_path="${expected_path}/${value}"
72
73 # Append "metadata" and test that we find the file.
74 expected_path="${expected_path}/metadata"
75
76 test -e "$expected_path"
77 ok $? "Reconstructed path from metadata is valid"
78
79 # Hostname
80 # The hostname is not part of the lttng hierarchy still we can test for
81 # its validity here.
82 value=$(get_env_value "$metadata_env" hostname)
83 ok $? "Extracting hostname from env metadata"
84 is "$value" "$(hostname)" "Hostname is valid"
85
86 rm -f "$metadata"
87 rm -f "$metadata_env"
88}
89
90plan_tests $NUM_TESTS
91print_test_banner "$TEST_DESC"
92
c125de8f 93bail_out_if_no_babeltrace
01654d69
JR
94
95if [ "$(id -u)" == "0" ]; then
96 isroot=1
97else
98 isroot=0
99fi
100
101skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
102{
103 validate_lttng_modules_present
104 modprobe lttng-test
105
106 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
107 # with "<session_name>-<datetime>/...".
108 LTTNG_HOME="$TRACE_PATH"
109
110 export LTTNG_HOME
111 start_lttng_sessiond
112
113 tests=( test_kernel )
114
115 for fct_test in "${tests[@]}";
116 do
117 ${fct_test}
118 done
119
d0e263e7 120 modprobe --remove lttng-test
01654d69
JR
121
122 stop_lttng_sessiond
123 unset LTTNG_HOME
124}
125
126rm -rf "$TRACE_PATH"
This page took 0.042266 seconds and 4 git commands to generate.