Tests: Fix first line of output to follow TAP guidelines
[lttng-tools.git] / tests / regression / ust / before-after / test_before_after
1 #!/bin/bash
2 #
3 # Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
4 #
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 TEST_DESC="UST tracer - Start tracing before and after execution"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 NR_ITER=100
22 SESSION_NAME="per-session"
23 EVENT_NAME="ust_gen_nevents:tptest"
24 NUM_TESTS=16
25
26 source $TESTDIR/utils/utils.sh
27
28 if [ ! -x "$CURDIR/gen-nevents" ]; then
29 BAIL_OUT "No UST nevents binary detected."
30 fi
31
32 # MUST set TESTDIR before calling those functions
33
34 test_before_apps() {
35 local out
36
37 # BEFORE application is spawned
38 create_lttng_session $SESSION_NAME $TRACE_PATH
39 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
40 start_lttng_tracing $SESSION_NAME
41
42 ./$CURDIR/gen-nevents $NR_ITER
43 ok $? "Start application to trace"
44
45 stop_lttng_tracing $SESSION_NAME
46 destroy_lttng_session $SESSION_NAME
47
48 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
49
50 return $?
51 }
52
53 test_after_apps() {
54 local out
55
56 ./$CURDIR/gen-nevents 100 &
57 ok $? "Start application to trace"
58
59 # BEFORE application is spawned
60 create_lttng_session $SESSION_NAME $TRACE_PATH
61 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
62 start_lttng_tracing $SESSION_NAME
63
64 # At least hit one event
65 sleep 2
66
67 stop_lttng_tracing $SESSION_NAME
68 destroy_lttng_session $SESSION_NAME
69
70 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
71 if [ $out -eq 0 ]; then
72 fail "Trace validation"
73 diag "No event(s) found. We are supposed to have at least one."
74 out=1
75 else
76 pass "Trace validation"
77 diag "Found $out event(s). Coherent."
78 out=0
79 fi
80
81 return $out
82 }
83
84 # MUST set TESTDIR before calling those functions
85 plan_tests $NUM_TESTS
86
87 print_test_banner "$TEST_DESC"
88
89 start_lttng_sessiond
90
91 diag "Start application BEFORE tracing was started"
92
93 TRACE_PATH=$(mktemp -d)
94
95 test_before_apps
96 out=$?
97 if [ $out -ne 0 ]; then
98 stop_lttng_sessiond
99 exit $out
100 fi
101
102 rm -rf $TRACE_PATH
103
104 diag "Start application AFTER tracing was started"
105
106 TRACE_PATH=$(mktemp -d)
107
108 test_after_apps
109 out=$?
110 if [ $out -ne 0 ]; then
111 stop_lttng_sessiond
112 exit $out
113 fi
114
115 stop_lttng_sessiond
116
117 rm -rf $TRACE_PATH
This page took 0.031792 seconds and 4 git commands to generate.