lttng add-trigger: replace --exclude-names with --exclude-name
[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)
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
25 local metadata_env
26 local metadata_path
27 local value
28
29 local expected_path="${TRACE_PATH}/lttng-traces"
30 local session_name="kernel"
31
32 metadata=$(mktemp)
33 metadata_env=$(mktemp)
34
35 diag "Test Kernel metadata env field"
36 create_lttng_session_ok "$session_name"
37 enable_kernel_lttng_event_ok "$session_name" "$EVENT_NAME"
38 start_lttng_tracing_ok "$session_name"
39
40 echo -n "10" > /proc/lttng-test-filter-event
41
42 stop_lttng_tracing_ok "$session_name"
43 destroy_lttng_session_ok "$session_name"
44
45 # bt1 accepts only a directory while bt2 accepts either the metadata
46 # file directly or a directory with an immediate metadata file.
47 # Settle for the common denominator.
48 metadata_path=$(find "${expected_path}/${session_name}"* | grep metadata)
49 metadata_path=$(dirname "$metadata_path")
50
51 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata"
52
53 # Extract "env" scope
54 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
55
56 # Construct the expected path from the env metadata and use it to
57 # validate that all information make sense. This information is present
58 # to allow trace viewer to recreate the same directory hierarchy.
59
60 # Trace name
61 value=$(get_env_value "$metadata_env" trace_name)
62 ok $? "Extracting trace_name from env metadata"
63 expected_path="${expected_path}/${value}"
64
65 # Session creation time
66 value=$(get_env_value "$metadata_env" trace_creation_datetime)
67 ok $? "Extracting trace_creation_datetime from env metadata"
68 value=$(iso8601_to_lttng_dir_datetime "$value")
69 expected_path="${expected_path}-${value}"
70
71 # Domain
72 value=$(get_env_value "$metadata_env" domain)
73 ok $? "Extracting domain from env metadata"
74 expected_path="${expected_path}/${value}"
75
76 # Append "metadata" and test that we find the file.
77 expected_path="${expected_path}/metadata"
78
79 test -e "$expected_path"
80 ok $? "Reconstructed path from metadata is valid"
81
82 # Hostname
83 # The hostname is not part of the lttng hierarchy still we can test for
84 # its validity here.
85 value=$(get_env_value "$metadata_env" hostname)
86 ok $? "Extracting hostname from env metadata"
87 is "$value" "$(hostname)" "Hostname is valid"
88
89 rm -f "$metadata"
90 rm -f "$metadata_env"
91 }
92
93 plan_tests $NUM_TESTS
94 print_test_banner "$TEST_DESC"
95
96
97 if [ "$(id -u)" == "0" ]; then
98 isroot=1
99 else
100 isroot=0
101 fi
102
103 skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
104 {
105 validate_lttng_modules_present
106 modprobe lttng-test
107
108 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
109 # with "<session_name>-<datetime>/...".
110 LTTNG_HOME="$TRACE_PATH"
111
112 export LTTNG_HOME
113 start_lttng_sessiond
114
115 tests=( test_kernel )
116
117 for fct_test in "${tests[@]}";
118 do
119 ${fct_test}
120 done
121
122 modprobe --remove lttng-test
123
124 stop_lttng_sessiond
125 unset LTTNG_HOME
126 }
127
128 rm -rf "$TRACE_PATH"
This page took 0.037262 seconds and 4 git commands to generate.