1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#!/bin/bash
#
# Copyright (C) - 2020 EfficiOS, inc
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; version 2.1 of the License.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Test the `lttng remove-trigger` command line interface.
CURDIR="$(dirname "$0")"
TESTDIR="$CURDIR/../../.."
# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"
plan_tests 22
FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
tmp_stdout=$(mktemp -t test_remove_triggers_cli_stdout.XXXXXX)
tmp_stderr=$(mktemp -t test_remove_triggers_cli_stderr.XXXXXX)
tmp_expected_stdout=$(mktemp -t test_remove_triggers_cli_expected_stdout.XXXXXX)
uid=$(id --user)
gid=$(id --group)
function list_triggers ()
{
local test_name="$1"
local expected_stdout_file="$2"
"${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
ok $? "${test_name}: exit code is 0"
diff -u "${expected_stdout_file}" "${tmp_stdout}"
ok $? "${test_name}: expected stdout"
diff -u /dev/null "${tmp_stderr}"
ok $? "${test_name}: expected stderr"
}
function remove_trigger ()
{
local name="$1"
local test_name="remove trigger ${name}"
"${FULL_LTTNG_BIN}" remove-trigger "${name}" > "${tmp_stdout}" 2> "${tmp_stderr}"
ok $? "${test_name}: exit code is 0"
diff -u <(echo "Removed trigger \`${name}\`.") "${tmp_stdout}"
ok $? "${test_name}: expected stdout"
diff -u /dev/null "${tmp_stderr}"
ok $? "${test_name}: expected stderr"
}
function test_mi ()
{
local tmp_stdout_raw
local tmp_expected_stdout
# Concretely the code used to serialize a trigger object is the same as
# the one used by the list command. Here we simply validate that a
# simple trigger is correctly generated on removal for MI.
tmp_stdout_raw=$(mktemp -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
tmp_expected_stdout=$(mktemp -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX")
diag "${FULL_LTTNG_BIN} --mi=xml remove-trigger"
cat > "${tmp_expected_stdout}" <<- EOF
<?xml version="1.0" encoding="UTF-8"?>
<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}">
<name>remove-trigger</name>
<output>
<trigger>
<name>mi</name>
<owner_uid>${UID}</owner_uid>
<condition>
<condition_event_rule_matches>
<event_rule>
<event_rule_user_tracepoint>
<name_pattern>mi_aa</name_pattern>
<filter_expression>p == 2</filter_expression>
</event_rule_user_tracepoint>
</event_rule>
<capture_descriptors/>
</condition_event_rule_matches>
</condition>
<action>
<action_list>
<action>
<action_notify>
<rate_policy>
<rate_policy_every_n>
<interval>1</interval>
</rate_policy_every_n>
</rate_policy>
</action_notify>
</action>
</action_list>
</action>
</trigger>
</output>
<success>true</success>
</command>
EOF
# Add a trigger
lttng_add_trigger_ok "mi" --condition event-rule-matches --name=mi_aa --type=user --filter 'p == 2' --action notify
# Remove it
"${FULL_LTTNG_BIN}" --mi xml remove-trigger mi > "${tmp_stdout_raw}" 2> "${tmp_stderr}"
ok $? "remove-trigger mi: exit code is 0"
# Pretty-fy xml before further test.
$XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"
$MI_VALIDATE "${tmp_stdout}"
ok $? "remove-trigger mi is valid"
diff -u "${tmp_expected_stdout}" "${tmp_stdout}"
ok $? "mi: expected stdout"
diff -u "${tmp_stderr}" /dev/null
ok $? "mi: expected stderr"
rm -f "${tmp_stdout_raw}"
}
# shellcheck disable=SC2119
start_lttng_sessiond_notap
# Add a few triggers
lttng_add_trigger_ok "ABC" --condition event-rule-matches --name=aaa --type=user --filter 'p == 2' --action notify
lttng_add_trigger_ok "DEF" --condition event-rule-matches --type=user --action notify
cat > "${tmp_expected_stdout}" <<- EOF
- name: ABC
owner uid: ${uid}
condition: event rule matches
rule: aaa (type: user tracepoint, filter: p == 2)
errors: none
actions:
notify
errors: none
errors: none
- name: DEF
owner uid: ${uid}
condition: event rule matches
rule: * (type: user tracepoint)
errors: none
actions:
notify
errors: none
errors: none
EOF
list_triggers "two triggers left" "${tmp_expected_stdout}"
remove_trigger "ABC"
cat > "${tmp_expected_stdout}" <<- EOF
- name: DEF
owner uid: ${uid}
condition: event rule matches
rule: * (type: user tracepoint)
errors: none
actions:
notify
errors: none
errors: none
EOF
list_triggers "one trigger left" "${tmp_expected_stdout}"
remove_trigger "DEF"
list_triggers "no triggers left" "/dev/null"
test_mi
# Cleanup
stop_lttng_sessiond_notap
rm -f "${tmp_stdout}"
rm -f "${tmp_stderr}"
rm -f "${tmp_expected_stdout}"
|