Cleanup: tests: name all temporary files to better identify leakage
[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
33e55711 13TRACE_PATH=$(mktemp --tmpdir -d 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"
33e55711
FD
29 local metadata=$(mktemp --tmpdir "tmp.${FUNCNAME[0]}_metadata.XXXXXX")
30 local metadata_env=$(mktemp --tmpdir "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
93
94if [ "$(id -u)" == "0" ]; then
95 isroot=1
96else
97 isroot=0
98fi
99
100skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
101{
102 validate_lttng_modules_present
103 modprobe lttng-test
104
105 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
106 # with "<session_name>-<datetime>/...".
107 LTTNG_HOME="$TRACE_PATH"
108
109 export LTTNG_HOME
110 start_lttng_sessiond
111
112 tests=( test_kernel )
113
114 for fct_test in "${tests[@]}";
115 do
116 ${fct_test}
117 done
118
d0e263e7 119 modprobe --remove lttng-test
01654d69
JR
120
121 stop_lttng_sessiond
122 unset LTTNG_HOME
123}
124
125rm -rf "$TRACE_PATH"
This page took 0.031887 seconds and 4 git commands to generate.