lttng: Add remove-trigger command
[lttng-tools.git] / tests / regression / tools / trigger / test_remove_trigger_cli
CommitLineData
b61776fb
SM
1#!/bin/bash
2#
3# Copyright (C) - 2020 EfficiOS, inc
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
17
18# Test the `lttng remove-trigger` command line interface.
19
20CURDIR="$(dirname "$0")"
21TESTDIR="$CURDIR/../../.."
22
23# shellcheck source=../../../utils/utils.sh
24source "$TESTDIR/utils/utils.sh"
25
26plan_tests 17
27
28FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
29
30tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
31tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
32tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
33
34uid=$(id --user)
35gid=$(id --group)
36
37function add_trigger ()
38{
39 "${FULL_LTTNG_BIN}" add-trigger "$@"
40 ok $? "add trigger \`$*\`: exit code is 0"
41}
42
43function list_triggers ()
44{
45 local test_name="$1"
46 local expected_stdout_file="$2"
47
48 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
49 ok $? "${test_name}: exit code is 0"
50
51 diff -u "${expected_stdout_file}" "${tmp_stdout}"
52 ok $? "${test_name}: expected stdout"
53
54 diff -u /dev/null "${tmp_stderr}"
55 ok $? "${test_name}: expected stderr"
56}
57
58function remove_trigger ()
59{
60 local id="$1"
61 local test_name="remove trigger ${id}"
62
63 "${FULL_LTTNG_BIN}" remove-trigger "${id}" > "${tmp_stdout}" 2> "${tmp_stderr}"
64 ok $? "${test_name}: exit code is 0"
65
66 diff -u <(echo "Removed trigger \`${id}\`.") "${tmp_stdout}"
67 ok $? "${test_name}: expected stdout"
68
69 diff -u /dev/null "${tmp_stderr}"
70 ok $? "${test_name}: expected stderr"
71}
72
73# shellcheck disable=SC2119
74start_lttng_sessiond_notap
75
76# Add a few triggers
77add_trigger --condition on-event -u -a --action notify
78add_trigger --id ABC --condition on-event aaa -u --filter 'p == 2' --action notify
79
80cat > "${tmp_expected_stdout}" <<- EOF
81- id: ABC
82 user id: ${uid}
83 condition: event rule hit
84 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
85 actions:
86 notify
87- id: T0
88 user id: ${uid}
89 condition: event rule hit
90 rule: * (type: tracepoint, domain: ust)
91 actions:
92 notify
93EOF
94list_triggers "two triggers left" "${tmp_expected_stdout}"
95
96remove_trigger "ABC"
97
98cat > "${tmp_expected_stdout}" <<- EOF
99- id: T0
100 user id: ${uid}
101 condition: event rule hit
102 rule: * (type: tracepoint, domain: ust)
103 actions:
104 notify
105EOF
106list_triggers "one trigger left" "${tmp_expected_stdout}"
107
108remove_trigger "T0"
109
110list_triggers "no triggers left" "/dev/null"
111
112# Cleanup
113stop_lttng_sessiond_notap
114rm -f "${tmp_stdout}"
115rm -f "${tmp_stderr}"
116rm -f "${tmp_expected_stdout}"
This page took 0.026554 seconds and 4 git commands to generate.