Add condition-targeting error query
[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
695f7044
JR
30tmp_stdout=$(mktemp --tmpdir -t test_remove_triggers_cli_stdout.XXXXXX)
31tmp_stderr=$(mktemp --tmpdir -t test_remove_triggers_cli_stderr.XXXXXX)
32tmp_expected_stdout=$(mktemp --tmpdir -t test_remove_triggers_cli_expected_stdout.XXXXXX)
b61776fb
SM
33
34uid=$(id --user)
35gid=$(id --group)
36
b61776fb
SM
37function list_triggers ()
38{
39 local test_name="$1"
40 local expected_stdout_file="$2"
41
42 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
43 ok $? "${test_name}: exit code is 0"
44
45 diff -u "${expected_stdout_file}" "${tmp_stdout}"
46 ok $? "${test_name}: expected stdout"
47
48 diff -u /dev/null "${tmp_stderr}"
49 ok $? "${test_name}: expected stderr"
50}
51
52function remove_trigger ()
53{
1d4b59f2
SM
54 local name="$1"
55 local test_name="remove trigger ${name}"
b61776fb 56
1d4b59f2 57 "${FULL_LTTNG_BIN}" remove-trigger "${name}" > "${tmp_stdout}" 2> "${tmp_stderr}"
b61776fb
SM
58 ok $? "${test_name}: exit code is 0"
59
1d4b59f2 60 diff -u <(echo "Removed trigger \`${name}\`.") "${tmp_stdout}"
b61776fb
SM
61 ok $? "${test_name}: expected stdout"
62
63 diff -u /dev/null "${tmp_stderr}"
64 ok $? "${test_name}: expected stderr"
65}
66
67# shellcheck disable=SC2119
68start_lttng_sessiond_notap
69
70# Add a few triggers
695f7044
JR
71lttng_add_trigger_ok "ABC" --condition event-rule-matches --name=aaa --type=user --filter 'p == 2' --action notify
72lttng_add_trigger_ok "DEF" --condition event-rule-matches --type=user --action notify
b61776fb
SM
73
74cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 75- name: ABC
481c5310 76 owner uid: ${uid}
8c1d25ff 77 condition: event rule matches
695f7044 78 rule: aaa (type: user tracepoint, filter: p == 2)
63dd3d7b 79 errors: none
b61776fb
SM
80 actions:
81 notify
709fb83f
JG
82 errors: none
83 errors: none
1d4b59f2 84- name: DEF
481c5310 85 owner uid: ${uid}
8c1d25ff 86 condition: event rule matches
695f7044 87 rule: * (type: user tracepoint)
63dd3d7b 88 errors: none
b61776fb
SM
89 actions:
90 notify
709fb83f
JG
91 errors: none
92 errors: none
b61776fb
SM
93EOF
94list_triggers "two triggers left" "${tmp_expected_stdout}"
95
96remove_trigger "ABC"
97
98cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 99- name: DEF
481c5310 100 owner uid: ${uid}
8c1d25ff 101 condition: event rule matches
695f7044 102 rule: * (type: user tracepoint)
63dd3d7b 103 errors: none
b61776fb
SM
104 actions:
105 notify
709fb83f
JG
106 errors: none
107 errors: none
b61776fb
SM
108EOF
109list_triggers "one trigger left" "${tmp_expected_stdout}"
110
70c766ac 111remove_trigger "DEF"
b61776fb
SM
112
113list_triggers "no triggers left" "/dev/null"
114
115# Cleanup
116stop_lttng_sessiond_notap
117rm -f "${tmp_stdout}"
118rm -f "${tmp_stderr}"
119rm -f "${tmp_expected_stdout}"
This page took 0.029693 seconds and 4 git commands to generate.