File: test_kernel

package info (click to toggle)
ltt-control 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,860 kB
  • sloc: cpp: 192,012; sh: 28,777; ansic: 10,960; python: 7,108; makefile: 3,520; java: 109; xml: 46
file content (127 lines) | stat: -rwxr-xr-x 3,683 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
#
# SPDX-FileCopyrightText: 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
#
# SPDX-License-Identifier: LGPL-2.1-only

TEST_DESC="Metadata env - Kernel space tracing"

CURDIR=$(dirname "$0")/
TESTDIR=$CURDIR/../../..
EVENT_NAME="lttng_test_filter_event"

TRACE_PATH=$(mktemp -d -t tmp.test_metadata_env_kernel_trace_path.XXXXXX)

NUM_TESTS=15

source "$TESTDIR/utils/utils.sh"

# Fetch utils functions common to ust and kernel tests.
source "$CURDIR/utils.sh"

function test_kernel ()
{
	local metadata_path
	local metadata
	local metadata_env

	local expected_path="${TRACE_PATH}/lttng-traces"
	local session_name="kernel"

	metadata=$(mktemp -t "tmp.test_kernel_metadata.XXXXXX")
	metadata_env=$(mktemp -t "tmp.test_kernel_metadata_env.XXXXXX")

	diag "Test Kernel metadata env field"
	create_lttng_session_ok "$session_name"
	enable_kernel_lttng_event_ok "$session_name" "$EVENT_NAME"
	start_lttng_tracing_ok "$session_name"

	echo -n "10" > /proc/lttng-test-filter-event

	stop_lttng_tracing_ok "$session_name"
	destroy_lttng_session_ok "$session_name"

	# bt1 accepts only a directory while bt2 accepts either the metadata
	# file directly or a directory with an immediate metadata file.
	# Settle for the common denominator.
	metadata_path=$(find "${expected_path}/${session_name}"* -name "metadata")
	metadata_path=$(dirname "$metadata_path")

	_run_babeltrace_cmd --output-format=ctf-metadata "${metadata_path}" > "$metadata"

	# Extract "env" scope
	awk '/env {/,/};/' < "$metadata" > "$metadata_env"

	# Construct the expected path from the env metadata and use it to
	# validate that all information make sense. This information is present
	# to allow trace viewer to recreate the same directory hierarchy.

	# Trace name
	local trace_name
	trace_name=$(get_env_value "$metadata_env" trace_name)
	ok $? "Extracting trace_name from env metadata: \`$trace_name\`"
	expected_path="${expected_path}/${trace_name}"

	# Session creation time
	local trace_creation_datetime
	trace_creation_datetime=$(get_env_value "$metadata_env" trace_creation_datetime)
	ok $? "Extracting trace_creation_datetime from env metadata: \`$trace_creation_datetime\`"
	trace_creation_datetime=$(iso8601_to_lttng_dir_datetime "$trace_creation_datetime")
	expected_path="${expected_path}-${trace_creation_datetime}"

	# Domain
	local domain
	domain=$(get_env_value "$metadata_env" domain)
	ok $? "Extracting domain from env metadata: \`$domain\`"
	expected_path="${expected_path}/${domain}"

	# Append "metadata" and test that we find the file.
	expected_path="${expected_path}/metadata"

	test -f "$expected_path"
	ok $? "Reconstructed path from metadata is an existing file: \`$expected_path\`"

	# Hostname
	# The hostname is not part of the lttng hierarchy still we can test for
	# its validity here.
	local hostname
	hostname=$(get_env_value "$metadata_env" hostname)
	ok $? "Extracting hostname from env metadata: \`$hostname\`"
	is "$hostname" "$(hostname)" "Extracted hostname matches current hostname"

	rm -f "$metadata"
	rm -f "$metadata_env"
}

plan_tests $NUM_TESTS
print_test_banner "$TEST_DESC"

bail_out_if_no_babeltrace

check_skip_kernel_test "$NUM_TESTS" "Skipping kernel metadata tests." ||
{
	lttng_modules_loaded_fail
	validate_lttng_modules_present
	modprobe lttng-test

	# Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
	# with "<session_name>-<datetime>/...".
	export LTTNG_HOME="$TRACE_PATH"

	start_lttng_sessiond

	tests=( test_kernel )

	for fct_test in "${tests[@]}";
	do
		${fct_test}
	done

	modprobe --remove lttng-test

	stop_lttng_sessiond
	lttng_modules_loaded_fail
	unset LTTNG_HOME
}

rm -rf "$TRACE_PATH"