Gen-ust-events: use options instead of arguments
[lttng-tools.git] / tests / regression / ust / before-after / test_before_after
CommitLineData
b19155c0
DG
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
c38b5107 17TEST_DESC="UST tracer - Start tracing before and after execution"
b19155c0
DG
18
19CURDIR=$(dirname $0)/
9ac429ef 20TESTDIR=$CURDIR/../../..
b19155c0 21NR_ITER=100
6cb45b17
CB
22NR_USEC_WAIT=100000
23TESTAPP_PATH="$TESTDIR/utils/testapp"
24TESTAPP_NAME="gen-ust-events"
25TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
b19155c0 26SESSION_NAME="per-session"
6cb45b17 27EVENT_NAME="tp:tptest"
f8ccb5c8 28NUM_TESTS=16
b19155c0 29
9ac429ef 30source $TESTDIR/utils/utils.sh
b19155c0 31
6cb45b17 32if [ ! -x "$TESTAPP_BIN" ]; then
f38839af 33 BAIL_OUT "No UST nevents binary detected."
b19155c0
DG
34fi
35
36# MUST set TESTDIR before calling those functions
37
4986e6a6
DG
38function test_before_apps()
39{
b19155c0 40 # BEFORE application is spawned
bf6ae429 41 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
c4926bb5 42 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
e563bbdb 43 start_lttng_tracing_ok $SESSION_NAME
f38839af 44
a4c30524 45 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
c7613334 46 wait
4986e6a6 47 ok $? "Traced application stopped."
f38839af 48
96340a01 49 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 50 destroy_lttng_session_ok $SESSION_NAME
b19155c0 51
d53addeb 52 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
b19155c0
DG
53
54 return $?
55}
56
4986e6a6
DG
57function test_after_apps()
58{
b19155c0 59 local out
5fcaccbc
MD
60 local file_sync_after_first=$(mktemp -u)
61 local file_sync_before_last=$(mktemp -u)
b19155c0 62
bf6ae429 63 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
c4926bb5 64 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
f8ccb5c8 65
a4c30524
JR
66 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
67 --sync-after-first-event ${file_sync_after_first} \
68 --sync-before-last-event ${file_sync_before_last} &
4986e6a6 69 ok $? "Application started in background."
b19155c0 70
e563bbdb 71 start_lttng_tracing_ok $SESSION_NAME
b19155c0 72
5fcaccbc
MD
73 touch ${file_sync_before_last}
74
c7613334 75 wait
b19155c0 76
96340a01 77 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 78 destroy_lttng_session_ok $SESSION_NAME
b19155c0 79
5fcaccbc
MD
80 rm -f ${file_sync_after_first}
81 rm -f ${file_sync_before_last}
82
4986e6a6
DG
83 validate_trace $EVENT_NAME $TRACE_PATH
84 out=$?
b19155c0
DG
85
86 return $out
87}
88
89# MUST set TESTDIR before calling those functions
f38839af 90plan_tests $NUM_TESTS
b19155c0 91
e3bef725
CB
92print_test_banner "$TEST_DESC"
93
fb3268e3 94start_lttng_sessiond
b19155c0 95
4986e6a6 96diag "Start tracing BEFORE application is started"
b19155c0
DG
97
98TRACE_PATH=$(mktemp -d)
99
100test_before_apps
101out=$?
102if [ $out -ne 0 ]; then
fb3268e3 103 stop_lttng_sessiond
b19155c0
DG
104 exit $out
105fi
106
107rm -rf $TRACE_PATH
108
4986e6a6 109diag "Start tracing AFTER application is started"
b19155c0
DG
110
111TRACE_PATH=$(mktemp -d)
112
113test_after_apps
114out=$?
115if [ $out -ne 0 ]; then
fb3268e3 116 stop_lttng_sessiond
b19155c0
DG
117 exit $out
118fi
119
fb3268e3 120stop_lttng_sessiond
b19155c0
DG
121
122rm -rf $TRACE_PATH
This page took 0.0866479999999999 seconds and 5 git commands to generate.