Commit | Line | Data |
---|---|---|
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 |
7 | TEST_DESC="Metadata env - Kernel space tracing" |
8 | ||
9 | CURDIR=$(dirname "$0")/ | |
10 | TESTDIR=$CURDIR/../../.. | |
11 | EVENT_NAME="lttng_test_filter_event" | |
12 | ||
8d5a3312 | 13 | TRACE_PATH=$(mktemp -d -t tmp.test_metadata_env_kernel_trace_path.XXXXXX) |
01654d69 JR |
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 | { | |
01654d69 | 24 | local metadata_path |
b7a2f86d MJ |
25 | local metadata |
26 | local metadata_env | |
01654d69 JR |
27 | |
28 | local expected_path="${TRACE_PATH}/lttng-traces" | |
29 | local session_name="kernel" | |
b7a2f86d MJ |
30 | |
31 | metadata=$(mktemp -t "tmp.test_kernel_metadata.XXXXXX") | |
32 | metadata_env=$(mktemp -t "tmp.test_kernel_metadata_env.XXXXXX") | |
01654d69 JR |
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. | |
fc2dd19e | 47 | metadata_path=$(find "${expected_path}/${session_name}"* -name "metadata") |
01654d69 JR |
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 | |
b7a2f86d MJ |
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}" | |
01654d69 JR |
64 | |
65 | # Session creation time | |
b7a2f86d MJ |
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}" | |
01654d69 JR |
71 | |
72 | # Domain | |
b7a2f86d MJ |
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}" | |
01654d69 JR |
77 | |
78 | # Append "metadata" and test that we find the file. | |
79 | expected_path="${expected_path}/metadata" | |
80 | ||
b7a2f86d MJ |
81 | test -f "$expected_path" |
82 | ok $? "Reconstructed path from metadata is an existing file: \`$expected_path\`" | |
01654d69 JR |
83 | |
84 | # Hostname | |
85 | # The hostname is not part of the lttng hierarchy still we can test for | |
86 | # its validity here. | |
b7a2f86d MJ |
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" | |
01654d69 JR |
91 | |
92 | rm -f "$metadata" | |
93 | rm -f "$metadata_env" | |
94 | } | |
95 | ||
96 | plan_tests $NUM_TESTS | |
97 | print_test_banner "$TEST_DESC" | |
98 | ||
c125de8f | 99 | bail_out_if_no_babeltrace |
01654d69 JR |
100 | |
101 | if [ "$(id -u)" == "0" ]; then | |
102 | isroot=1 | |
103 | else | |
104 | isroot=0 | |
105 | fi | |
106 | ||
107 | skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS || | |
108 | { | |
109 | validate_lttng_modules_present | |
110 | modprobe lttng-test | |
111 | ||
112 | # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy | |
113 | # with "<session_name>-<datetime>/...". | |
b7a2f86d | 114 | export LTTNG_HOME="$TRACE_PATH" |
01654d69 | 115 | |
01654d69 JR |
116 | start_lttng_sessiond |
117 | ||
118 | tests=( test_kernel ) | |
119 | ||
120 | for fct_test in "${tests[@]}"; | |
121 | do | |
122 | ${fct_test} | |
123 | done | |
124 | ||
d0e263e7 | 125 | modprobe --remove lttng-test |
01654d69 JR |
126 | |
127 | stop_lttng_sessiond | |
128 | unset LTTNG_HOME | |
129 | } | |
130 | ||
131 | rm -rf "$TRACE_PATH" |