| 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 | uid=$(id --user) |
| 35 | gid=$(id --group) |
| 36 | |
| 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 | { |
| 54 | local name="$1" |
| 55 | local test_name="remove trigger ${name}" |
| 56 | |
| 57 | "${FULL_LTTNG_BIN}" remove-trigger "${name}" > "${tmp_stdout}" 2> "${tmp_stderr}" |
| 58 | ok $? "${test_name}: exit code is 0" |
| 59 | |
| 60 | diff -u <(echo "Removed trigger \`${name}\`.") "${tmp_stdout}" |
| 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 |
| 71 | lttng_add_trigger_ok "ABC" --condition event-rule-matches --name=aaa --domain=user --filter 'p == 2' --action notify |
| 72 | lttng_add_trigger_ok "DEF" --condition event-rule-matches --domain=user --action notify |
| 73 | |
| 74 | cat > "${tmp_expected_stdout}" <<- EOF |
| 75 | - name: ABC |
| 76 | owner uid: ${uid} |
| 77 | condition: event rule hit |
| 78 | rule: aaa (type: tracepoint, domain: ust, filter: p == 2) |
| 79 | actions: |
| 80 | notify |
| 81 | errors: none |
| 82 | errors: none |
| 83 | - name: DEF |
| 84 | owner uid: ${uid} |
| 85 | condition: event rule hit |
| 86 | rule: * (type: tracepoint, domain: ust) |
| 87 | actions: |
| 88 | notify |
| 89 | errors: none |
| 90 | errors: none |
| 91 | EOF |
| 92 | list_triggers "two triggers left" "${tmp_expected_stdout}" |
| 93 | |
| 94 | remove_trigger "ABC" |
| 95 | |
| 96 | cat > "${tmp_expected_stdout}" <<- EOF |
| 97 | - name: DEF |
| 98 | owner uid: ${uid} |
| 99 | condition: event rule hit |
| 100 | rule: * (type: tracepoint, domain: ust) |
| 101 | actions: |
| 102 | notify |
| 103 | errors: none |
| 104 | errors: none |
| 105 | EOF |
| 106 | list_triggers "one trigger left" "${tmp_expected_stdout}" |
| 107 | |
| 108 | remove_trigger "DEF" |
| 109 | |
| 110 | list_triggers "no triggers left" "/dev/null" |
| 111 | |
| 112 | # Cleanup |
| 113 | stop_lttng_sessiond_notap |
| 114 | rm -f "${tmp_stdout}" |
| 115 | rm -f "${tmp_stderr}" |
| 116 | rm -f "${tmp_expected_stdout}" |