tests: Move to kernel style SPDX license identifiers
[lttng-tools.git] / tests / regression / ust / namespaces / test_ns_contexts
CommitLineData
bbf15743
MJ
1#!/bin/bash
2#
3# Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
4#
9d16b343 5# SPDX-License-Identifier: LGPL-2.1-only
bbf15743
MJ
6
7TEST_DESC="UST - Namespace contexts"
8
9CURDIR=$(dirname "$0")/
10TESTDIR=$CURDIR/../../..
11
12TESTAPP_PATH="$TESTDIR/utils/testapp"
13TESTAPP_NAME="gen-ust-events"
14TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
15NUM_EVENT=10000
16EVENT_NAME="tp:tptest"
17
18TESTS_PER_NS=13
19
20NUM_TESTS=$((TESTS_PER_NS * 7))
21
22source "$TESTDIR/utils/utils.sh"
23
24# MUST set TESTDIR before calling those functions
25function run_app()
26{
6c4a91d6 27 $TESTAPP_BIN -i $NUM_EVENT
bbf15743
MJ
28 ok $? "Application done"
29}
30
31function test_ns()
32{
33 local ns=$1
34
35 local session_name="${ns}_ns"
36 local chan_name="${ns}_ns"
37 local context_name="${ns}_ns"
38
39 local trace_path
40 local ns_inode
41
42 # Check if the kernel has support for this ns type
43 if [ ! -f "/proc/$$/ns/$ns" ]; then
44 skip 0 "System has no $ns namespace support" $TESTS_PER_NS
45 return
46 fi
47
48 # Get the current ns inode number
49 ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns")
50 ok $? "Get current $ns namespace inode: $ns_inode"
51
52 trace_path=$(mktemp -d)
53
54 start_lttng_sessiond
55
56 create_lttng_session_ok "$session_name" "$trace_path"
57 enable_ust_lttng_channel_ok "$session_name" "$chan_name"
58 add_context_ust_ok "$session_name" "$chan_name" "$context_name"
59 enable_ust_lttng_event_ok "$session_name" "$EVENT_NAME" "$chan_name"
60 start_lttng_tracing_ok "$session_name"
61
62 run_app
63
64 # stop and destroy
65 stop_lttng_tracing_ok "$session_name"
66 destroy_lttng_session_ok "$session_name"
67 stop_lttng_sessiond
68
69 # Check that the events contain the right namespace inode number
70 validate_trace_count "${ns}_ns = $ns_inode" "$trace_path" $NUM_EVENT
71
72 rm -rf "$trace_path"
73}
74
75
76plan_tests $NUM_TESTS
77
78print_test_banner "$TEST_DESC"
79
80system_has_ns=0
81if [ -d "/proc/$$/ns" ]; then
82 system_has_ns=1
83fi
84
85skip $system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
86
87test_ns cgroup
88test_ns ipc
89test_ns mnt
90test_ns net
91test_ns pid
92test_ns user
93test_ns uts
This page took 0.030188 seconds and 5 git commands to generate.