+function test_exclusion_tracing_started
+{
+ local exclusions="$1"
+ local event_name_expected_to_be_missing="$2"
+ local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
+ local file_wait_before_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX")
+ local file_create_in_main=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_create_in_main.XXXXXX")
+
+ # Create session
+ create_lttng_session_ok $SESSION_NAME $trace_path
+
+ # Enable a dummy event so that the session is active after we start the
+ # session.
+ enable_ust_lttng_event_ok $SESSION_NAME "non-existent-event"
+
+ # Start the tracing
+ start_lttng_tracing_ok $SESSION_NAME
+
+ # Launch the test app and make it create a sync file once it's in the
+ # main function.
+ $TESTAPP_BIN -i 1 -w 10000 \
+ --create-in-main ${file_create_in_main} \
+ --wait-before-first-event ${file_wait_before_first} 2>&1 &
+
+ while [ ! -f "${file_create_in_main}" ]; do
+ sleep 0.5
+ done
+
+ # Enable an event with an exclusion once the tracing is active in the
+ # UST app.
+ enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
+ ok $? "Enable lttng event with event \"$exclusions\" excluded"
+
+ # Create the sync file so that the test app starts generating events.
+ touch ${file_wait_before_first}
+
+ # Wait for the testapp to finish.
+ wait
+
+ stop_lttng_tracing_ok $SESSION_NAME
+
+ # Destroy session
+ destroy_lttng_session_ok $SESSION_NAME
+
+ stats=$("$BABELTRACE_BIN" $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index 2> /dev/null)
+ if [ ! -z "$stats" ]; then
+ fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
+ else
+ ok 0 "Validate trace exclusion output"
+ rm -rf $trace_path
+ fi
+
+ rm -f $file_wait_before_first
+ rm -f $file_create_in_main
+}
+
+function test_exclusion_fail
+{
+ event_name="$1"
+ exclusions="$2"
+
+ create_lttng_session_ok $SESSION_NAME $trace_path
+ $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "$event_name" -s $sess_name -x "$exclusions" >/dev/null 2>&1
+ res=$?
+ destroy_lttng_session_ok $SESSION_NAME
+
+ if [ $res -eq 0 ]; then
+ fail "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes"
+ return 1
+ else
+ pass "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails"
+ return 0
+ fi
+}
+