vscode: Add configurations to run the executables under the debugger
[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 -d -t 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 metadata
26 local metadata_env
27
28 local expected_path="${TRACE_PATH}/lttng-traces"
29 local session_name="kernel"
30
31 metadata=$(mktemp -t "tmp.test_kernel_metadata.XXXXXX")
32 metadata_env=$(mktemp -t "tmp.test_kernel_metadata_env.XXXXXX")
33
34 diag "Test Kernel metadata env field"
35 create_lttng_session_ok "$session_name"
36 enable_kernel_lttng_event_ok "$session_name" "$EVENT_NAME"
37 start_lttng_tracing_ok "$session_name"
38
39 echo -n "10" > /proc/lttng-test-filter-event
40
41 stop_lttng_tracing_ok "$session_name"
42 destroy_lttng_session_ok "$session_name"
43
44 # bt1 accepts only a directory while bt2 accepts either the metadata
45 # file directly or a directory with an immediate metadata file.
46 # Settle for the common denominator.
47 metadata_path=$(find "${expected_path}/${session_name}"* -name "metadata")
48 metadata_path=$(dirname "$metadata_path")
49
50 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata"
51
52 # Extract "env" scope
53 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
54
55 # Construct the expected path from the env metadata and use it to
56 # validate that all information make sense. This information is present
57 # to allow trace viewer to recreate the same directory hierarchy.
58
59 # Trace name
60 local trace_name
61 trace_name=$(get_env_value "$metadata_env" trace_name)
62 ok $? "Extracting trace_name from env metadata: \`$trace_name\`"
63 expected_path="${expected_path}/${trace_name}"
64
65 # Session creation time
66 local trace_creation_datetime
67 trace_creation_datetime=$(get_env_value "$metadata_env" trace_creation_datetime)
68 ok $? "Extracting trace_creation_datetime from env metadata: \`$trace_creation_datetime\`"
69 trace_creation_datetime=$(iso8601_to_lttng_dir_datetime "$trace_creation_datetime")
70 expected_path="${expected_path}-${trace_creation_datetime}"
71
72 # Domain
73 local domain
74 domain=$(get_env_value "$metadata_env" domain)
75 ok $? "Extracting domain from env metadata: \`$domain\`"
76 expected_path="${expected_path}/${domain}"
77
78 # Append "metadata" and test that we find the file.
79 expected_path="${expected_path}/metadata"
80
81 test -f "$expected_path"
82 ok $? "Reconstructed path from metadata is an existing file: \`$expected_path\`"
83
84 # Hostname
85 # The hostname is not part of the lttng hierarchy still we can test for
86 # its validity here.
87 local hostname
88 hostname=$(get_env_value "$metadata_env" hostname)
89 ok $? "Extracting hostname from env metadata: \`$hostname\`"
90 is "$hostname" "$(hostname)" "Extracted hostname matches current hostname"
91
92 rm -f "$metadata"
93 rm -f "$metadata_env"
94 }
95
96 plan_tests $NUM_TESTS
97 print_test_banner "$TEST_DESC"
98
99 bail_out_if_no_babeltrace
100
101 check_skip_kernel_test "$NUM_TESTS" "Skipping kernel metadata 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 export LTTNG_HOME="$TRACE_PATH"
109
110 start_lttng_sessiond
111
112 tests=( test_kernel )
113
114 for fct_test in "${tests[@]}";
115 do
116 ${fct_test}
117 done
118
119 modprobe --remove lttng-test
120
121 stop_lttng_sessiond
122 unset LTTNG_HOME
123 }
124
125 rm -rf "$TRACE_PATH"
This page took 0.03303 seconds and 5 git commands to generate.