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

TEST_DESC="Kernel tracer - System calls"

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

# `gen-syscall-event` starts and waits for the creation a file passed by
# arguments to start executing 3 syscalls (open,read,close) and returning.
TESTCMD="$TESTDIR/utils/testapp/gen-syscall-events/gen-syscall-events"

source $TESTDIR/utils/utils.sh

function trace_testapp()
{
	local start_file_sync=$(mktemp --tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_start.XXXXXX")

	# Clear all entries from the resource tracker
	lttng_untrack_kernel_all_ok

	# Launch the testapp and save its Process ID
	./"$TESTCMD" "$start_file_sync" "/proc/cpuinfo" "/proc/cmdline" &
	PID=$!

	# Set LTTng to track this PID and start the tracing
	lttng_track_pid_ok $PID

	start_lttng_tracing_ok

	# Create start file to launch the execution of the workload by the
	# test app
	touch "$start_file_sync"

	wait $PID

	stop_lttng_tracing_ok

	# Clean up the synchronization file
	rm -f "$start_file_sync"
}

function validate_list()
{
	local session_name=$1
	local event_name=$2
	local opt=$3

	out=$($TESTDIR/../src/bin/lttng/$LTTNG_BIN list $session_name $opt | grep $event_name)
	if [ -z "$out" ]; then
		fail "Validate syscall listing"
		diag "$event_name not found when listing $session_name (opt $opt)"
	else
		pass "Validate syscall listing. Found $event_name."
	fi
}

function test_syscall_event_list()
{
	local EVENT_NAME="getpid"

	diag "Syscall event listing"

	validate_list "" $EVENT_NAME "-k --syscall"
}

function test_syscall_simple_list()
{
	local TRACE_PATH=$(mktemp --tmpdir -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
	SESSION_NAME="kernel_syscall_simple_list"
	local EVENT_NAME="close"

	diag "Syscall simple listing"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME

	validate_list $SESSION_NAME $EVENT_NAME

	trace_testapp

	# ensure all events are in the trace.
	validate_trace_exp "-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH

	# ensure trace only contains those.
	validate_trace_only_exp "-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME: -e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

function test_syscall_simple_list_two()
{
	local TRACE_PATH=$(mktemp --tmpdir -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
	SESSION_NAME="kernel_syscall_simple_list_two"
	local EVENT_NAME="close"
	local EVENT_NAME2="read"

	diag "Syscall simple listing"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME
	lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME2

	validate_list $SESSION_NAME $EVENT_NAME
	validate_list $SESSION_NAME $EVENT_NAME2

	trace_testapp

	# ensure all events are in the trace.
	validate_trace_exp "-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH

	validate_trace_exp "-e syscall_entry_$EVENT_NAME2: -e compat_syscall_entry_$EVENT_NAME2:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_$EVENT_NAME2: -e compat_syscall_exit_$EVENT_NAME2:" $TRACE_PATH

	# ensure trace only contains those.
	validate_trace_only_exp "-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME: -e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME: -e syscall_entry_$EVENT_NAME2: -e compat_syscall_entry_$EVENT_NAME2: -e syscall_exit_$EVENT_NAME2: -e compat_syscall_exit_$EVENT_NAME2:" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace single"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"

	trace_testapp

	# ensure all events are in the trace.
	validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH

	# ensure trace only contains those.
	validate_trace_only_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace two events"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
	lttng_enable_kernel_syscall_ok $SESSION_NAME "close"

	trace_testapp

	# ensure all events are in the trace.
	validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH

	# ensure trace only contains those.
	validate_trace_only_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat: -e syscall_entry_close: -e compat_syscall_entry_close: -e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace all events"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable all syscalls
	lttng_enable_kernel_syscall_ok $SESSION_NAME

	trace_testapp

	# ensure at least open and close are there.
	validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
	# trace may contain other syscalls.

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace all events and disable one"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable all syscalls
	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# try to disable open system call: fails because enabler semantic of
	# "all syscalls" is not "the open" system call.
	lttng_disable_kernel_syscall_fail $SESSION_NAME "openat"

	trace_testapp

	# ensure "openat" syscall is there.
	validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH

	# ensure "close" syscall is there.
	validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace all events and disable two"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable all syscalls
	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# try to disable open and close system calls: fails because enabler
	# semantic of "all syscalls" is not "the open" system call.
	lttng_disable_kernel_syscall_fail $SESSION_NAME "openat"
	lttng_disable_kernel_syscall_fail $SESSION_NAME "close"

	trace_testapp

	# ensure "openat" syscall is there.
	validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH

	# ensure "close" syscall is there.
	validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH

	# ensure "read" syscall is there.
	validate_trace_exp "-e syscall_entry_read: -e compat_syscall_entry_read:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_read: -e compat_syscall_exit_read:" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace all events and disable all"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable all system calls
	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# disable all system calls
	lttng_disable_kernel_syscall_ok $SESSION_NAME

	trace_testapp

	# ensure nothing has been traced.
	validate_trace_empty $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace all events and enable/disable all"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable all system calls
	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# disable all system calls
	lttng_disable_kernel_syscall_ok $SESSION_NAME
	# enable all system calls
	lttng_enable_kernel_syscall_ok $SESSION_NAME

	trace_testapp

	# ensure at least open and close are there.
	validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
	# trace may contain other syscalls.

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace all events, enable one and disable all"

	create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"

	# enable all syscalls
	lttng_enable_kernel_syscall_ok $SESSION_NAME

	# enable one specific syscall, "openat"
	lttng_enable_kernel_syscall_ok $SESSION_NAME openat

	# disable all syscalls
	lttng_disable_kernel_syscall_ok $SESSION_NAME

	trace_testapp

	# The trace shouldn't contain any syscalls, disable-all should disable
	# even individually specified syscalls
	trace_match_only openat 0 "$TRACE_PATH"

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf "$TRACE_PATH"
}

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

	diag "Syscall trace all events and enable/disable one"

	create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"

	# enable one specific syscall, "openat"
	lttng_enable_kernel_syscall_ok $SESSION_NAME openat

	# enable all syscalls
	lttng_enable_kernel_syscall_ok $SESSION_NAME

	# disable one specific syscall, "openat"
	lttng_disable_kernel_syscall_ok $SESSION_NAME openat

	trace_testapp

	# The trace should contain all syscalls, including 'openat' because
	# enable-all overrides individually disabled syscalls.
	validate_trace openat "$TRACE_PATH"

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf "$TRACE_PATH"
}

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

	diag "Syscall trace all events and enable/disable one"

	create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"

	# enable one specific syscall, "openat"
	lttng_enable_kernel_syscall_ok $SESSION_NAME openat

	# enable all syscalls
	lttng_enable_kernel_syscall_ok $SESSION_NAME

	# disable all syscalls
	lttng_disable_kernel_syscall_ok $SESSION_NAME

	# disable one specific syscall, "openat"
	lttng_disable_kernel_syscall_ok $SESSION_NAME openat

	trace_testapp

	# The trace shouldn't contain any syscalls, disable-all should disable
	# even individually specified syscalls
	trace_match_only openat 0 "$TRACE_PATH"

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf "$TRACE_PATH"
}

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

	diag "Syscall trace all events and enable/disable all twice"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable all system calls
	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# disable all system calls
	lttng_disable_kernel_syscall_ok $SESSION_NAME
	# enable all system calls
	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# disable all system calls
	lttng_disable_kernel_syscall_ok $SESSION_NAME

	trace_testapp

	# ensure nothing has been traced.
	validate_trace_empty $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace one event and disable one"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable open system call
	lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
	# disable open system call
	lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"

	trace_testapp

	# ensure nothing has been traced.
	validate_trace_empty $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace two events and disable two"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable open and close system calls
	lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
	lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
	# disable open and close system calls
	lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"
	lttng_disable_kernel_syscall_ok $SESSION_NAME "close"

	trace_testapp

	# ensure nothing has been traced.
	validate_trace_empty $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace two events and disable one"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# enable open and close system calls
	lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
	lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
	# disable close system call
	lttng_disable_kernel_syscall_ok $SESSION_NAME "close"

	trace_testapp

	# ensure open is there.
	validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
	validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH

	# ensure trace only contains those.
	validate_trace_only_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace one event and disable twice"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
	# First disable will succeed
	lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"
	# Second disable succeeds too, due to enabler semantic.
	lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall trace all events and disable all twice"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# First disable will succeed
	lttng_disable_kernel_syscall_ok $SESSION_NAME
	# Second disable succeeds too, due to enabler semantic.
	lttng_disable_kernel_syscall_ok $SESSION_NAME

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}


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

	diag "Syscall enable an unknown event"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	# Enabling a syscall that does not exist succeeds, due to enabler
	# semantic.
	lttng_enable_kernel_syscall_ok $SESSION_NAME "thissyscallcannotexist"

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall enable all and enable one"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME
	# Enabling an event already enabled succeeds, due to enabler semantic.
	lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

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

	diag "Syscall disable all and disable one"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_syscall_ok $SESSION_NAME
	lttng_disable_kernel_syscall_ok $SESSION_NAME
	# Disabling an event already disabled fails.
	lttng_disable_kernel_syscall_fail $SESSION_NAME "openat"

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

function test_syscall_enable_channel_disable_all()
{
	local TRACE_PATH=$(mktemp --tmpdir -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
	SESSION_NAME="kernel_syscall_enable_channel_disable_all"
	CHANNEL_NAME="channel"

	diag "Syscall enable channel and disable all"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_channel_ok $SESSION_NAME $CHANNEL_NAME
	# sessiond semantic for "disable all" is to try to match all enalers
	# it knowns about. Disable all succeeds if it finds no match.
	lttng_disable_kernel_syscall_ok $SESSION_NAME "-a" $CHANNEL_NAME

	destroy_lttng_session_ok $SESSION_NAME

	rm -rf $TRACE_PATH
}

function test_syscall_enable_channel_disable_one()
{
	local TRACE_PATH=$(mktemp --tmpdir -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
	SESSION_NAME="kernel_syscall_enable_channel_disable_all"
	CHANNEL_NAME="channel"

	diag "Syscall enable channel and disable one"

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH

	lttng_enable_kernel_channel_ok $SESSION_NAME $CHANNEL_NAME
	lttng_disable_kernel_syscall_fail $SESSION_NAME "openat" $CHANNEL_NAME

	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_syscall_event_list
	test_syscall_simple_list
	test_syscall_simple_list_two
	test_syscall_single
	test_syscall_two
	test_syscall_all
	test_syscall_all_disable_one
	test_syscall_all_disable_two
	test_syscall_enable_all_disable_all
	test_syscall_enable_all_disable_all_enable_all
	test_syscall_enable_all_disable_all_twice
	test_syscall_enable_all_enable_one_disable_all
	test_syscall_enable_one_enable_all_disable_one
	test_syscall_enable_one_enable_all_disable_all_disable_one
	test_syscall_enable_one_disable_one
	test_syscall_enable_two_disable_two
	test_syscall_enable_two_disable_one
	test_syscall_disable_twice
	test_syscall_disable_all_twice
	test_syscall_enable_unknown
	test_syscall_enable_all_enable_one
	test_syscall_disable_all_disable_one
	test_syscall_enable_channel_disable_all
	test_syscall_enable_channel_disable_one

	stop_lttng_sessiond
}
