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