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

TEST_DESC="UST tracer - Basic events"

CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/../..
BIN_NAME="gen-ust-events"
SESSION_NAME="valid_filter"
EVENT_NAME="tp:tptest"


NUM_TESTS=25

source $TESTDIR/utils/utils.sh

function test_event_basic()
{
	TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
	SESSION_NAME="ust_event_basic"
	SESSION_NAME2="ust_event_basic2"
	CHAN_NAME="mychan"
	CHAN_NAME2="mychan2"
	EVENT_NAME="tp1"
	EVENT_NAME2="ev2"
	EVENT_NAME3="ev3"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
	create_lttng_session_ok $SESSION_NAME2 $TRACE_PATH

	enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
	enable_ust_lttng_channel_ok $SESSION_NAME2 $CHAN_NAME2

	enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
	enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME2 $CHAN_NAME
	enable_ust_lttng_event_ok $SESSION_NAME2 $EVENT_NAME3 $CHAN_NAME2

	add_context_ust_ok $SESSION_NAME $CHAN_NAME "vpid"
	add_context_ust_ok $SESSION_NAME $CHAN_NAME "vtid"
	add_context_ust_ok $SESSION_NAME $CHAN_NAME "pthread_id"
	add_context_ust_ok $SESSION_NAME $CHAN_NAME "procname"
	add_context_ust_ok $SESSION_NAME2 $CHAN_NAME2 "procname"

	disable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHAN_NAME
	disable_ust_lttng_event $SESSION_NAME2 $EVENT_NAME3 $CHAN_NAME2

	enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
	enable_ust_lttng_event_ok $SESSION_NAME2 $EVENT_NAME3 $CHAN_NAME2

	start_lttng_tracing_ok
	stop_lttng_tracing_ok

	start_lttng_tracing_ok
	stop_lttng_tracing_ok

	# TODO: Validate trace output is coherent"
	ok 0 "Validate trace"

	destroy_lttng_session_ok $SESSION_NAME2
	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"

start_lttng_sessiond

test_event_basic

stop_lttng_sessiond
