Debian Codegraph @

tests/regression/ust/before-after/test_before_after

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # SPDX-FileCopyrightText: 2012 David Goulet <[email protected]>
4 # SPDX-FileCopyrightText: 2025 Michael Jeanson <[email protected]>
5 #
6 # SPDX-License-Identifier: LGPL-2.1-only
7
8 TEST_DESC="UST tracer - Start tracing before and after execution"
9
10 CURDIR=$(dirnamescip-shell system . . dirname. "$0")/
11 TESTDIR=$CURDIR/../../..
12
13 NR_ITER=100
14
15 TESTAPP_PATH="$TESTDIR/utils/testapp"
16 TESTAPP_NAME="gen-ust-events"
17 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME"
18 TESTAPP_TIMEOUT_SEC=10
19
20 EVENT_NAME="tp:tptest"
21
22 NUM_TESTS=17
23
24 # shellcheck source-path=SCRIPTDIR/../../..
25 source "$TESTDIR/utils/utils.sh"
26
27 if [scip-shell system . . `[`. ! -x "$TESTAPP_BIN" ]; then
28 BAIL_OUT "No UST nevents binary detected."
29 fi
30
31 # MUST set TESTDIR before calling those functions
32
33 function test_before_appsscip-shell shell shell-project 0.0.0 test_before_apps().()
34 {
35 local session_name="before-app"
36 local trace_path
37 local file_testapp_output
38
39 diag "Start tracing BEFORE application is started"
40
41 trace_path=$(mktempscip-shell system . . mktemp. -d -t tmp.test_before_after_ust_trace_path.XXXXXX)
42 file_testapp_output=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_testapp_output.XXXXXX")
43
44 # BEFORE application is started
45 create_lttng_session_ok $session_name "$trace_path"
46 enable_ust_lttng_event_ok $session_name $EVENT_NAME
47 start_lttng_tracing_ok $session_name
48
49 run_testapp_ok "$file_testapp_output" "$TESTAPP_BIN" -i "$NR_ITER"
50
51 stop_lttng_tracing_ok $session_name
52 destroy_lttng_session_ok $session_name
53
54 trace_match_only $EVENT_NAME $NR_ITER "$trace_path"
55
56 rmscip-shell system . . rm. -rf "$trace_path"
57 rmscip-shell system . . rm. -f "$file_testapp_output"
58 }
59
60 function test_after_appsscip-shell shell shell-project 0.0.0 test_after_apps().()
61 {
62 local session_name="after-app"
63 local testapp_pid
64 local trace_path
65 local file_testapp_output
66 local file_sync_after_first
67 local file_sync_before_last
68 local file_sync_before_exit_touch
69
70 diag "Start tracing AFTER application is started"
71
72 trace_path=$(mktempscip-shell system . . mktemp. -d -t tmp.test_before_after_ust_trace_path.XXXXXX)
73 file_testapp_output=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_testapp_output.XXXXXX")
74 file_sync_after_first=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
75 file_sync_before_last=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
76 file_sync_before_exit_touch=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_sync_before_exit_touch.XXXXXX")
77
78 create_lttng_session_ok $session_name "$trace_path"
79 enable_ust_lttng_event_ok $session_name $EVENT_NAME
80
81 "$TESTAPP_BIN" -i $NR_ITER \
82 --sync-after-first-event "${file_sync_after_first}" \
83 --sync-before-last-event "${file_sync_before_last}" \
84 --sync-before-exit-touch "${file_sync_before_exit_touch}" >"${file_testapp_output}" 2>&1 &
85 testapp_pid=$!
86 diag "Launched testapp '$TESTAPP_NAME' (pid: $testapp_pid) to generate $NR_ITER events"
87
88 # Wait for the testapp first event
89 app_alive_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_after_first"
90
91 # AFTER application is started
92 start_lttng_tracing_ok $session_name
93
94 # Tell the testapp to continue
95 touchscip-shell system . . touch. "${file_sync_before_last}"
96
97 app_exit_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_before_exit_touch"
98
99 stop_lttng_tracing_ok $session_name
100 destroy_lttng_session_ok $session_name
101
102 validate_trace $EVENT_NAME "$trace_path"
103
104 rmscip-shell system . . rm. -rf "$trace_path"
105 rmscip-shell system . . rm. -f "$file_testapp_output"
106 rmscip-shell system . . rm. -f "$file_sync_after_first"
107 rmscip-shell system . . rm. -f "$file_sync_before_last"
108 rmscip-shell system . . rm. -f "$file_sync_before_exit_touch"
109 }
110
111 # MUST set TESTDIR before calling those functions
112 plan_tests $NUM_TESTS
113
114 print_test_banner "$TEST_DESC"
115
116 bail_out_if_no_babeltrace
117
118 start_lttng_sessiond
119
120 test_before_appsscip-shell shell shell-project 0.0.0 test_before_apps().
121 test_after_appsscip-shell shell shell-project 0.0.0 test_after_apps().
122
123 stop_lttng_sessiond
124