Clean-up: consumer.hpp: coding style indentation fix
[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
8d5a3312 13TRACE_PATH=$(mktemp -d -t 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 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
96plan_tests $NUM_TESTS
97print_test_banner "$TEST_DESC"
98
c125de8f 99bail_out_if_no_babeltrace
01654d69 100
3a174400 101check_skip_kernel_test "$NUM_TESTS" "Skipping kernel metadata tests." ||
01654d69
JR
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>/...".
b7a2f86d 108 export LTTNG_HOME="$TRACE_PATH"
01654d69 109
01654d69
JR
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.053182 seconds and 4 git commands to generate.