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