#!/bin/bash
#
# Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
#
# SPDX-License-Identifier: GPL-2.0-only
#

TEST_DESC="Kernel tracer - All events"

CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/../..
NUM_TESTS=8

TESTCMD="/bin/true"

source $TESTDIR/utils/utils.sh

function test_all_event()
{
	local TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
	SESSION_NAME="kernel_all_events_basic"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_event $SESSION_NAME

	start_lttng_tracing_ok

	# Running a process and waiting for its completion forces the triggering of a
	# sched_switch event
	eval ${TESTCMD}
	stop_lttng_tracing_ok

	validate_trace "sched_switch" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

# MUST set TESTDIR before calling those functions
plan_tests $NUM_TESTS

print_test_banner "$TEST_DESC"

check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
{
	validate_lttng_modules_present
	start_lttng_sessiond

	test_all_event

	stop_lttng_sessiond
}
