Tests: Add test to check shared-memory FD leaks after relayd dies
[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
dceffc9e 26plan_tests 22
b61776fb
SM
27
28FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
29
8d5a3312
MJ
30tmp_stdout=$(mktemp -t test_remove_triggers_cli_stdout.XXXXXX)
31tmp_stderr=$(mktemp -t test_remove_triggers_cli_stderr.XXXXXX)
32tmp_expected_stdout=$(mktemp -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
dceffc9e
JR
67function test_mi ()
68{
69 local tmp_stdout_raw
70 local tmp_expected_stdout
71
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.
75
8d5a3312
MJ
76 tmp_stdout_raw=$(mktemp -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
77 tmp_expected_stdout=$(mktemp -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX")
dceffc9e
JR
78
79 diag "${FULL_LTTNG_BIN} --mi=xml remove-trigger"
80
81 cat > "${tmp_expected_stdout}" <<- EOF
82 <?xml version="1.0" encoding="UTF-8"?>
dcd975d1 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}">
dceffc9e
JR
84 <name>remove-trigger</name>
85 <output>
86 <trigger>
87 <name>mi</name>
88 <owner_uid>${UID}</owner_uid>
89 <condition>
90 <condition_event_rule_matches>
91 <event_rule>
92 <event_rule_user_tracepoint>
93 <name_pattern>mi_aa</name_pattern>
94 <filter_expression>p == 2</filter_expression>
95 </event_rule_user_tracepoint>
96 </event_rule>
97 <capture_descriptors/>
98 </condition_event_rule_matches>
99 </condition>
100 <action>
101 <action_list>
102 <action>
103 <action_notify>
104 <rate_policy>
105 <rate_policy_every_n>
106 <interval>1</interval>
107 </rate_policy_every_n>
108 </rate_policy>
109 </action_notify>
110 </action>
111 </action_list>
112 </action>
113 </trigger>
114 </output>
115 <success>true</success>
116 </command>
117 EOF
118
119 # Add a trigger
120 lttng_add_trigger_ok "mi" --condition event-rule-matches --name=mi_aa --type=user --filter 'p == 2' --action notify
121
122 # Remove it
123 "${FULL_LTTNG_BIN}" --mi xml remove-trigger mi > "${tmp_stdout_raw}" 2> "${tmp_stderr}"
124 ok $? "remove-trigger mi: exit code is 0"
125
126 # Pretty-fy xml before further test.
fa182fe0 127 $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
dceffc9e 128
fa182fe0 129 $MI_VALIDATE "${tmp_stdout}"
dceffc9e
JR
130 ok $? "remove-trigger mi is valid"
131
132 diff -u "${tmp_expected_stdout}" "${tmp_stdout}"
133 ok $? "mi: expected stdout"
134
135 diff -u "${tmp_stderr}" /dev/null
136 ok $? "mi: expected stderr"
137
138 rm -f "${tmp_stdout_raw}"
139}
140
b61776fb
SM
141# shellcheck disable=SC2119
142start_lttng_sessiond_notap
143
144# Add a few triggers
695f7044
JR
145lttng_add_trigger_ok "ABC" --condition event-rule-matches --name=aaa --type=user --filter 'p == 2' --action notify
146lttng_add_trigger_ok "DEF" --condition event-rule-matches --type=user --action notify
b61776fb
SM
147
148cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 149- name: ABC
481c5310 150 owner uid: ${uid}
8c1d25ff 151 condition: event rule matches
695f7044 152 rule: aaa (type: user tracepoint, filter: p == 2)
63dd3d7b 153 errors: none
b61776fb
SM
154 actions:
155 notify
709fb83f
JG
156 errors: none
157 errors: none
1d4b59f2 158- name: DEF
481c5310 159 owner uid: ${uid}
8c1d25ff 160 condition: event rule matches
695f7044 161 rule: * (type: user tracepoint)
63dd3d7b 162 errors: none
b61776fb
SM
163 actions:
164 notify
709fb83f
JG
165 errors: none
166 errors: none
b61776fb
SM
167EOF
168list_triggers "two triggers left" "${tmp_expected_stdout}"
169
170remove_trigger "ABC"
171
172cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 173- name: DEF
481c5310 174 owner uid: ${uid}
8c1d25ff 175 condition: event rule matches
695f7044 176 rule: * (type: user tracepoint)
63dd3d7b 177 errors: none
b61776fb
SM
178 actions:
179 notify
709fb83f
JG
180 errors: none
181 errors: none
b61776fb
SM
182EOF
183list_triggers "one trigger left" "${tmp_expected_stdout}"
184
70c766ac 185remove_trigger "DEF"
b61776fb
SM
186
187list_triggers "no triggers left" "/dev/null"
188
dceffc9e
JR
189test_mi
190
b61776fb
SM
191# Cleanup
192stop_lttng_sessiond_notap
193rm -f "${tmp_stdout}"
194rm -f "${tmp_stderr}"
195rm -f "${tmp_expected_stdout}"
This page took 0.054285 seconds and 4 git commands to generate.