3 # Copyright (C) - 2020 EfficiOS, inc
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.
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
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
18 # Test the `lttng remove-trigger` command line interface.
20 CURDIR
="$(dirname "$0")"
21 TESTDIR
="$CURDIR/../../.."
23 # shellcheck source=../../../utils/utils.sh
24 source "$TESTDIR/utils/utils.sh"
28 FULL_LTTNG_BIN
="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
30 tmp_stdout
=$
(mktemp
-t test_remove_triggers_cli_stdout.XXXXXX
)
31 tmp_stderr
=$
(mktemp
-t test_remove_triggers_cli_stderr.XXXXXX
)
32 tmp_expected_stdout
=$
(mktemp
-t test_remove_triggers_cli_expected_stdout.XXXXXX
)
37 function list_triggers
()
40 local expected_stdout_file
="$2"
42 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
43 ok $?
"${test_name}: exit code is 0"
45 diff -u "${expected_stdout_file}" "${tmp_stdout}"
46 ok $?
"${test_name}: expected stdout"
48 diff -u /dev
/null
"${tmp_stderr}"
49 ok $?
"${test_name}: expected stderr"
52 function remove_trigger
()
55 local test_name
="remove trigger ${name}"
57 "${FULL_LTTNG_BIN}" remove-trigger "${name}" > "${tmp_stdout}" 2> "${tmp_stderr}"
58 ok $?
"${test_name}: exit code is 0"
60 diff -u <(echo "Removed trigger \`${name}\`.") "${tmp_stdout}"
61 ok $?
"${test_name}: expected stdout"
63 diff -u /dev
/null
"${tmp_stderr}"
64 ok $?
"${test_name}: expected stderr"
70 local tmp_expected_stdout
72 # Concretely the code used to serialize a trigger object is the same as
73 # the one used by the list command. Here we simply validate that a
74 # simple trigger is correctly generated on removal for MI.
76 tmp_stdout_raw
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
77 tmp_expected_stdout
=$
(mktemp
-t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX")
79 diag
"${FULL_LTTNG_BIN} --mi=xml remove-trigger"
81 cat > "${tmp_expected_stdout}" <<- EOF
82 <?xml version="1.0" encoding="UTF-8"?>
83 <command xmlns="https://lttng.org/xml/ns/lttng-mi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://lttng.org/xml/ns/lttng-mi https://lttng.org/xml/schemas/lttng-mi/${MI_XSD_MAJOR_VERSION}/lttng-mi-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd" schemaVersion="${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}">
84 <name>remove-trigger</name>
88 <owner_uid>${UID}</owner_uid>
90 <condition_event_rule_matches>
92 <event_rule_user_tracepoint>
93 <name_pattern>mi_aa</name_pattern>
94 <filter_expression>p == 2</filter_expression>
95 </event_rule_user_tracepoint>
97 <capture_descriptors/>
98 </condition_event_rule_matches>
105 <rate_policy_every_n>
106 <interval>1</interval>
107 </rate_policy_every_n>
115 <success>true</success>
120 lttng_add_trigger_ok
"mi" --condition event-rule-matches
--name=mi_aa
--type=user
--filter 'p == 2' --action notify
123 "${FULL_LTTNG_BIN}" --mi xml remove-trigger mi > "${tmp_stdout_raw}" 2> "${tmp_stderr}"
124 ok $?
"remove-trigger mi: exit code is 0"
126 # Pretty-fy xml before further test.
127 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
129 $MI_VALIDATE "${tmp_stdout}"
130 ok $?
"remove-trigger mi is valid"
132 diff -u "${tmp_expected_stdout}" "${tmp_stdout}"
133 ok $?
"mi: expected stdout"
135 diff -u "${tmp_stderr}" /dev
/null
136 ok $?
"mi: expected stderr"
138 rm -f "${tmp_stdout_raw}"
141 # shellcheck disable=SC2119
142 start_lttng_sessiond_notap
145 lttng_add_trigger_ok
"ABC" --condition event-rule-matches
--name=aaa
--type=user
--filter 'p == 2' --action notify
146 lttng_add_trigger_ok
"DEF" --condition event-rule-matches
--type=user
--action notify
148 cat > "${tmp_expected_stdout}" <<- EOF
151 condition: event rule matches
152 rule: aaa (type: user tracepoint, filter: p == 2)
160 condition: event rule matches
161 rule: * (type: user tracepoint)
168 list_triggers
"two triggers left" "${tmp_expected_stdout}"
172 cat > "${tmp_expected_stdout}" <<- EOF
175 condition: event rule matches
176 rule: * (type: user tracepoint)
183 list_triggers
"one trigger left" "${tmp_expected_stdout}"
187 list_triggers
"no triggers left" "/dev/null"
192 stop_lttng_sessiond_notap
193 rm -f "${tmp_stdout}"
194 rm -f "${tmp_stderr}"
195 rm -f "${tmp_expected_stdout}"