Commit | Line | Data |
---|---|---|
345121ec DG |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com> |
345121ec | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
345121ec | 6 | # |
345121ec DG |
7 | |
8 | TEST_DESC="Event exclusion" | |
9 | ||
10 | CURDIR=$(dirname $0)/ | |
11 | TESTDIR=$CURDIR/../../.. | |
345121ec DG |
12 | STATS_BIN="$TESTDIR/utils/babelstats.pl" |
13 | SESSION_NAME="test-exclusion" | |
345121ec DG |
14 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
15 | TESTAPP_NAME="gen-ust-nevents" | |
16 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
17 | NR_ITER=100 | |
18 | NR_USEC_WAIT=1 | |
737403de | 19 | NUM_TESTS=178 |
345121ec DG |
20 | |
21 | source $TESTDIR/utils/utils.sh | |
22 | ||
23 | function enable_ust_lttng_all_event_exclusion() | |
24 | { | |
25 | sess_name="$1" | |
26 | exclusion="$2" | |
27 | ||
737403de | 28 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $sess_name -x "$exclusion" |
345121ec DG |
29 | } |
30 | ||
31 | function run_apps | |
32 | { | |
737403de FD |
33 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 |
34 | ok $? "Running test application" | |
35 | } | |
36 | ||
37 | # Testing for the absence of an event when testing exclusion is tricky. An | |
38 | # event could be absent because our exclusion mechanism works but also because | |
39 | # the event was not generate in the first place. This function test the ability | |
40 | # of our test suite to generate events. | |
41 | function dry_run | |
42 | { | |
43 | trace_path=$(mktemp -d) | |
44 | ||
45 | # Create session | |
46 | create_lttng_session_ok $SESSION_NAME $trace_path | |
47 | ||
48 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $SESSION_NAME > /dev/null | |
49 | ok $? "Enabling events without exclusion" | |
50 | ||
51 | # Trace apps | |
52 | start_lttng_tracing_ok $SESSION_NAME | |
53 | run_apps | |
54 | stop_lttng_tracing_ok $SESSION_NAME | |
55 | ||
56 | nb_events=$(babeltrace $trace_path | wc -l) | |
57 | if [ "$nb_events" -ne "0" ]; then | |
58 | ok 0 "Events were found during the dry run without exclusion" | |
59 | else | |
60 | fail "No events were found during the dry run without exclusion" | |
61 | fi | |
62 | ||
63 | rm -rf $trace_path | |
64 | ||
65 | # Destroy session | |
66 | destroy_lttng_session_ok $SESSION_NAME | |
345121ec DG |
67 | } |
68 | ||
69 | function test_exclusion | |
70 | { | |
062f6132 PP |
71 | exclusions="$1" |
72 | event_name_expected_to_be_missing="$2" | |
345121ec DG |
73 | trace_path=$(mktemp -d) |
74 | ||
75 | # Create session | |
bf6ae429 | 76 | create_lttng_session_ok $SESSION_NAME $trace_path |
345121ec | 77 | |
062f6132 PP |
78 | enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions" |
79 | ok $? "Enable lttng event with event \"$exclusions\" excluded" | |
345121ec DG |
80 | |
81 | # Trace apps | |
e563bbdb | 82 | start_lttng_tracing_ok $SESSION_NAME |
345121ec | 83 | run_apps |
96340a01 | 84 | stop_lttng_tracing_ok $SESSION_NAME |
345121ec DG |
85 | |
86 | # Destroy session | |
67b4c664 | 87 | destroy_lttng_session_ok $SESSION_NAME |
345121ec | 88 | |
737403de | 89 | stats=`babeltrace $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index 2> /dev/null` |
345121ec | 90 | if [ ! -z "$stats" ]; then |
062f6132 | 91 | fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!" |
345121ec DG |
92 | else |
93 | ok 0 "Validate trace exclusion output" | |
94 | rm -rf $trace_path | |
95 | fi | |
96 | } | |
97 | ||
062f6132 PP |
98 | function test_exclusion_fail |
99 | { | |
100 | event_name="$1" | |
101 | exclusions="$2" | |
102 | ||
103 | create_lttng_session_ok $SESSION_NAME $trace_path | |
6efba076 | 104 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "$event_name" -s $sess_name -x "$exclusions" >/dev/null 2>&1 |
062f6132 PP |
105 | res=$? |
106 | destroy_lttng_session_ok $SESSION_NAME | |
107 | ||
108 | if [ $res -eq 0 ]; then | |
109 | fail "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes" | |
110 | return 1 | |
111 | else | |
112 | pass "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails" | |
113 | return 0 | |
114 | fi | |
115 | } | |
116 | ||
345121ec DG |
117 | plan_tests $NUM_TESTS |
118 | ||
119 | print_test_banner $TEST_DESC | |
120 | ||
121 | start_lttng_sessiond | |
122 | ||
737403de FD |
123 | dry_run |
124 | ||
062f6132 PP |
125 | test_exclusion 'tp:tptest2' 'tp:tptest2' |
126 | test_exclusion 'tp:tptest3' 'tp:tptest3' | |
127 | test_exclusion 'tp:tptest*' 'tp:tptest1' | |
128 | test_exclusion 'tp:tptest*' 'tp:tptest2' | |
129 | test_exclusion 'tp:tptest*' 'tp:tptest3' | |
130 | test_exclusion 'tp:tptest*' 'tp:tptest4' | |
131 | test_exclusion 'tp:tptest*' 'tp:tptest5' | |
132 | test_exclusion 'tp*tptest*' 'tp:tptest1' | |
133 | test_exclusion 'tp*tptest*' 'tp:tptest2' | |
134 | test_exclusion 'tp*tptest*' 'tp:tptest3' | |
135 | test_exclusion 'tp*tptest*' 'tp:tptest4' | |
136 | test_exclusion 'tp*tptest*' 'tp:tptest5' | |
137 | test_exclusion '*test2' 'tp:tptest2' | |
138 | test_exclusion '*test5' 'tp:tptest5' | |
139 | test_exclusion '*p*test*' 'tp:tptest1' | |
140 | test_exclusion '*p*test*' 'tp:tptest2' | |
141 | test_exclusion '*p*test*' 'tp:tptest3' | |
142 | test_exclusion '*p***test*' 'tp:tptest4' | |
143 | test_exclusion '*p*test*' 'tp:tptest5' | |
144 | test_exclusion '*3' 'tp:tptest3' | |
145 | test_exclusion 'tp*test3,*2' 'tp:tptest2' | |
146 | test_exclusion '**tp*test3,*2' 'tp:tptest3' | |
147 | ||
148 | # Cannot use exclusions with non-globbing event name | |
149 | test_exclusion_fail "allo" "lol" | |
150 | test_exclusion_fail "allo" "meow,lol" | |
151 | test_exclusion_fail "allo" "z*em" | |
152 | ||
153 | # Exclusion name excludes all possible event names | |
154 | test_exclusion_fail "allo*" "all*" | |
155 | test_exclusion_fail "allo*" "ze,all*,yes" | |
345121ec DG |
156 | |
157 | stop_lttng_sessiond |