Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
45ce77e1 JR |
30 | tmp_stdout=$(mktemp --tmpdir -t test_remove_triggers_cli_stdout.XXXXXX) |
31 | tmp_stderr=$(mktemp --tmpdir -t test_remove_triggers_cli_stderr.XXXXXX) | |
32 | tmp_expected_stdout=$(mktemp --tmpdir -t test_remove_triggers_cli_expected_stdout.XXXXXX) | |
b61776fb SM |
33 | |
34 | uid=$(id --user) | |
35 | gid=$(id --group) | |
36 | ||
b61776fb SM |
37 | function 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 | ||
52 | function 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 | |
68 | start_lttng_sessiond_notap | |
69 | ||
70 | # Add a few triggers | |
45ce77e1 JR |
71 | lttng_add_trigger_ok "ABC" --condition event-rule-matches --name=aaa --type=user --filter 'p == 2' --action notify |
72 | lttng_add_trigger_ok "DEF" --condition event-rule-matches --type=user --action notify | |
b61776fb SM |
73 | |
74 | cat > "${tmp_expected_stdout}" <<- EOF | |
1d4b59f2 | 75 | - name: ABC |
481c5310 | 76 | owner uid: ${uid} |
e1e94513 | 77 | condition: event rule matches |
45ce77e1 | 78 | rule: aaa (type: user tracepoint, filter: p == 2) |
8ce7c93a | 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} |
e1e94513 | 86 | condition: event rule matches |
45ce77e1 | 87 | rule: * (type: user tracepoint) |
8ce7c93a | 88 | errors: none |
b61776fb SM |
89 | actions: |
90 | notify | |
709fb83f JG |
91 | errors: none |
92 | errors: none | |
b61776fb SM |
93 | EOF |
94 | list_triggers "two triggers left" "${tmp_expected_stdout}" | |
95 | ||
96 | remove_trigger "ABC" | |
97 | ||
98 | cat > "${tmp_expected_stdout}" <<- EOF | |
1d4b59f2 | 99 | - name: DEF |
481c5310 | 100 | owner uid: ${uid} |
e1e94513 | 101 | condition: event rule matches |
45ce77e1 | 102 | rule: * (type: user tracepoint) |
8ce7c93a | 103 | errors: none |
b61776fb SM |
104 | actions: |
105 | notify | |
709fb83f JG |
106 | errors: none |
107 | errors: none | |
b61776fb SM |
108 | EOF |
109 | list_triggers "one trigger left" "${tmp_expected_stdout}" | |
110 | ||
70c766ac | 111 | remove_trigger "DEF" |
b61776fb SM |
112 | |
113 | list_triggers "no triggers left" "/dev/null" | |
114 | ||
115 | # Cleanup | |
116 | stop_lttng_sessiond_notap | |
117 | rm -f "${tmp_stdout}" | |
118 | rm -f "${tmp_stderr}" | |
119 | rm -f "${tmp_expected_stdout}" |