From 831f8599fc06d6f60a953c3dedcaee56d0c04871 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 26 May 2021 18:08:14 -0400 Subject: [PATCH] Tests: MI: {add, list, remove}-trigger MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: Ica66a759d961cc122c1a1b81ce69fa54b0e78c78 --- .../tools/trigger/test_add_trigger_cli | 78 +- .../tools/trigger/test_list_triggers_cli | 2041 ++++++++++++++++- .../tools/trigger/test_remove_trigger_cli | 78 +- tests/utils/utils.sh | 38 + 4 files changed, 2227 insertions(+), 8 deletions(-) diff --git a/tests/regression/tools/trigger/test_add_trigger_cli b/tests/regression/tools/trigger/test_add_trigger_cli index a55406c1a..cc873bef3 100755 --- a/tests/regression/tools/trigger/test_add_trigger_cli +++ b/tests/regression/tools/trigger/test_add_trigger_cli @@ -23,7 +23,7 @@ TESTDIR="$CURDIR/../../.." # shellcheck source=../../../utils/utils.sh source "$TESTDIR/utils/utils.sh" -plan_tests 282 +plan_tests 286 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" @@ -48,8 +48,8 @@ function test_success () diag "${FULL_LTTNG_BIN} add-trigger $*" set -x "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}" - set +x ok $? "${test_name}: exit code is 0" + set +x diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.") ok $? "${test_name}: expected stdout" @@ -76,6 +76,78 @@ function test_failure () 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. + + tmp_stdout_raw=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") + tmp_expected_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX") + + diag "${FULL_LTTNG_BIN} --mi=xml add-trigger" + + cat > "${tmp_expected_stdout}" <<- EOF + + + add-trigger + + + mi_hohoho + ${UID} + + + + + some-event-id + + + + + + + + + + + + 1 + + + + + + + + + true + + EOF + + "${FULL_LTTNG_BIN}" --mi xml add-trigger --name mi_hohoho \ + --condition event-rule-matches --name=some-event-id --type=user \ + --action notify > "${tmp_stdout_raw}" 2> "${tmp_stderr}" + + ok $? "add-trigger mi: exit code is 0" + + # Pretty-fy xml before further test. + $XML_PRETTY_BIN < "${tmp_stdout_raw}" > "${tmp_stdout}" + + $XML_VALIDATE_BIN "${MI_XSD_PATH}" "${tmp_stdout}" + ok $? "add-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}" +} + # top-level options test_success "explicit name" \ --name hohoho \ @@ -501,6 +573,8 @@ test_failure "snapshot-session action, --name with-net-url-instead-of-path" \ --condition event-rule-matches --type=user \ --action snapshot-session ze-session --name hallo --path net://8.8.8.8/ +test_mi + # Cleanup stop_lttng_sessiond_notap rm -f "${tmp_stdout}" diff --git a/tests/regression/tools/trigger/test_list_triggers_cli b/tests/regression/tools/trigger/test_list_triggers_cli index dcc634438..d03329547 100755 --- a/tests/regression/tools/trigger/test_list_triggers_cli +++ b/tests/regression/tools/trigger/test_list_triggers_cli @@ -23,13 +23,14 @@ TESTDIR="$CURDIR/../../.." # shellcheck source=../../../utils/utils.sh source "$TESTDIR/utils/utils.sh" -NUM_TESTS=106 +NUM_TESTS=150 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" tmp_stdout=$(mktemp --tmpdir -t test_list_triggers_cli_stdout.XXXXXX) tmp_stderr=$(mktemp --tmpdir -t test_list_triggers_cli_stderr.XXXXXX) tmp_expected_stdout=$(mktemp --tmpdir -t test_list_triggers_cli_expected_stdout.XXXXXX) +tmp_expected_stdout_mi=$(mktemp --tmpdir -t test_list_triggers_cli_expected_stdout.mi.XXXXXX) uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary") uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binary/.libs/userspace-probe-sdt-binary") register_some_triggers_bin=$(realpath "${CURDIR}/utils/register-some-triggers") @@ -69,7 +70,65 @@ test_top_level_options () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + hello + ${uid} + + + + + test-name + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "top level options" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI top level options" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "hello" } @@ -191,7 +250,535 @@ test_event_rule_matches_tracepoint () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + A + ${uid} + + + + + aaa + p == 2 + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + B + ${uid} + + + + + gerboise + + + 6 + + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + C + ${uid} + + + + + * + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + D + ${uid} + + + + + hello* + + hello2 + hello3 + hello4 + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + E + ${uid} + + + + + lemming + + + 4 + + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + F + ${uid} + + + + + capture-payload-field + + + + + + a + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + G + ${uid} + + + + + capture-array + + + + + + 2 + + + a + + + + + + + 18 + + + tourlou + + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + H + ${uid} + + + + + capture-chan-ctx + + + + + + vpid + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + I + ${uid} + + + + + capture-app-ctx + + + + + + iga + active_clients + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + J + ${uid} + + + + + lemming + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI event-rule-matches, tracepoint event rule" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "A" lttng_remove_trigger_ok "B" @@ -227,6 +814,7 @@ test_event_rule_matches_probe () fi offset_hex="0x$(printf '%x' $offset)" + channel_enable_addr_decimal=$(echo "ibase=16; ${channel_enable_addr^^} " | bc) lttng_add_trigger_ok "T0" --condition event-rule-matches --type=kprobe --location=lttng_channel_enable --event-name=my_channel_enable --action notify lttng_add_trigger_ok "T1" --condition event-rule-matches --type=kprobe --location="${base_symbol}+${offset_hex}" --event-name=my_channel_enable --action notify @@ -262,7 +850,174 @@ test_event_rule_matches_probe () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + T0 + ${uid} + + + + + my_channel_enable + + + lttng_channel_enable + 0 + + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T1 + ${uid} + + + + + my_channel_enable + + + ${base_symbol} + ${offset} + + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T2 + ${uid} + + + + + my_channel_enable + + +
${channel_enable_addr_decimal}
+
+
+
+
+ +
+ + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + +
+ + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + +
+
+
+
+ EOF + list_triggers_matches_ok "event-rule-matches, probe event rule" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI event-rule-matches, probe event rule" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "T0" lttng_remove_trigger_ok "T1" @@ -289,7 +1044,75 @@ test_event_rule_matches_userspace_probe_elf () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + T0 + ${uid} + + + + + ma-probe-elf + + + ${elf_function_name} + ${uprobe_elf_binary} + ENTRY + + + + + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "T0" } @@ -315,7 +1138,75 @@ test_event_rule_matches_userspace_probe_sdt () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + T0 + ${uid} + + + + + ma-probe-sdt + + + ${sdt_probe_name} + ${sdt_provider_name} + ${uprobe_sdt_binary} + + + + + + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "event-rule-matches, userspace-probe event rule SDT" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI event-rule-matches, userspace-probe event rule SDT" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "T0" } @@ -378,7 +1269,256 @@ test_event_rule_matches_syscall () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + T0 + ${uid} + + + + + entry+exit + open + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T1 + ${uid} + + + + + entry + open + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T2 + ${uid} + + + + + exit + open + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T3 + ${uid} + + + + + entry+exit + open + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T4 + ${uid} + + + + + entry+exit + ptrace + a > 2 + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + + list_triggers_matches_ok "event-rule-matches, syscall event rule" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI event-rule-matches, syscall event rule" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "T0" lttng_remove_trigger_ok "T1" @@ -404,7 +1544,54 @@ test_session_consumed_size_condition () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + trigger-with-session-consumed-size-condition + ${uid} + + + the-session-name + 1234 + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + + list_triggers_matches_ok "session consumed size condition" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI session consumed size condition" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "trigger-with-session-consumed-size-condition" } @@ -464,7 +1651,163 @@ test_buffer_usage_conditions () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + trigger-with-buffer-usage-high-bytes-condition + ${uid} + + + the-session-name + the-channel-name + UST + 1234 + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + trigger-with-buffer-usage-high-ratio-condition + ${uid} + + + the-session-name + the-channel-name + UST + 0.250000 + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + trigger-with-buffer-usage-low-bytes-condition + ${uid} + + + the-session-name + the-channel-name + UST + 2345 + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + trigger-with-buffer-usage-low-ratio-condition + ${uid} + + + the-session-name + the-channel-name + UST + 0.400000 + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "buffer usage condition" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI buffer usage condition" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "trigger-with-buffer-usage-high-bytes-condition" lttng_remove_trigger_ok "trigger-with-buffer-usage-high-ratio-condition" @@ -497,7 +1840,85 @@ test_session_rotation_conditions () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + trigger-with-session-rotation-completed-condition + ${uid} + + + the-session-name + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + trigger-with-session-rotation-ongoing-condition + ${uid} + + + the-session-name + + + + + + + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "session rotation conditions" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI session rotation conditions" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "trigger-with-session-rotation-completed-condition" lttng_remove_trigger_ok "trigger-with-session-rotation-ongoing-condition" @@ -611,7 +2032,513 @@ test_snapshot_action () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + T0 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T1 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + /some/path + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T2 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + /some/other/path + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T3 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + net://1.2.3.4 + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T4 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + net://1.2.3.4:1234:1235 + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T5 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + tcp://1.2.3.4:1111 + tcp://1.2.3.4:1112 + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T6 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + /some/path + 1234 + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T7 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + meh + /some/path + + + + 1 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T8 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + + 10 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T9 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + ze-session + + + 10 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI snapshot action" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "T0" lttng_remove_trigger_ok "T1" @@ -651,7 +2578,111 @@ test_notify_action () errors: none EOF + cat > "${tmp_expected_stdout_mi}" <<- EOF + + + list-trigger + + + + T0 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 5 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + T1 + ${uid} + + + + + some-event + + + + + + + discarded tracer messages + Count of messages discarded by the tracer due to a communication error with the session daemon + + 0 + + + + + + + + + + + 10 + + + + + + total execution failures + Aggregated count of errors encountered when executing the action + + 0 + + + + + + + + + + + + EOF + list_triggers_matches_ok "notify action" "${tmp_expected_stdout}" + list_triggers_matches_mi_ok "MI notify action" "${tmp_expected_stdout_mi}" lttng_remove_trigger_ok "T0" lttng_remove_trigger_ok "T1" @@ -664,10 +2695,10 @@ start_lttng_sessiond_notap test_top_level_options test_event_rule_matches_tracepoint -skip $ist_root "non-root user: skipping kprobe tests" 9 || test_event_rule_matches_probe -skip $ist_root "non-root user: skipping uprobe tests" 5 || test_event_rule_matches_userspace_probe_elf -skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_event_rule_matches_userspace_probe_sdt -skip $ist_root "non-root user: skipping syscall tests" 13 || test_event_rule_matches_syscall +skip $ist_root "non-root user: skipping kprobe tests" 13 || test_event_rule_matches_probe +skip $ist_root "non-root user: skipping uprobe tests" 9 || test_event_rule_matches_userspace_probe_elf +skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 9 || test_event_rule_matches_userspace_probe_sdt +skip $ist_root "non-root user: skipping syscall tests" 17 || test_event_rule_matches_syscall test_session_consumed_size_condition test_buffer_usage_conditions test_session_rotation_conditions diff --git a/tests/regression/tools/trigger/test_remove_trigger_cli b/tests/regression/tools/trigger/test_remove_trigger_cli index 9e342d9b5..f306f114f 100755 --- a/tests/regression/tools/trigger/test_remove_trigger_cli +++ b/tests/regression/tools/trigger/test_remove_trigger_cli @@ -23,7 +23,7 @@ TESTDIR="$CURDIR/../../.." # shellcheck source=../../../utils/utils.sh source "$TESTDIR/utils/utils.sh" -plan_tests 17 +plan_tests 22 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" @@ -64,6 +64,80 @@ function remove_trigger () 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 --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") + tmp_expected_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX") + + diag "${FULL_LTTNG_BIN} --mi=xml remove-trigger" + + cat > "${tmp_expected_stdout}" <<- EOF + + + remove-trigger + + + mi + ${UID} + + + + + mi_aa + p == 2 + + + + + + + + + + + + 1 + + + + + + + + + true + + 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_BIN < "${tmp_stdout_raw}" > "${tmp_stdout}" + + $XML_VALIDATE_BIN "${MI_XSD_PATH}" "${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 @@ -112,6 +186,8 @@ remove_trigger "DEF" list_triggers "no triggers left" "/dev/null" +test_mi + # Cleanup stop_lttng_sessiond_notap rm -f "${tmp_stdout}" diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index b2991207a..6a25aec47 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -15,6 +15,9 @@ LTTNG_BIN="lttng" BABELTRACE_BIN="babeltrace" OUTPUT_DEST=/dev/null ERROR_OUTPUT_DEST=/dev/null +MI_XSD_PATH=$TESTDIR/../src/common/mi-lttng-4.0.xsd +XML_PRETTY_BIN="$TESTDIR/utils/xml-utils/pretty_xml" +XML_VALIDATE_BIN="$TESTDIR/utils/xml-utils/validate_xml" # To match 20201127-175802 date_time_pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]" @@ -2270,6 +2273,41 @@ function list_triggers_matches_ok () rm -f "${tmp_stderr}" } +function list_triggers_matches_mi_ok () +{ + local tmp_stdout + local tmp_stdout_raw + local tmp_stderr + + local test_name="$1" + local expected_stdout_file="$2" + + tmp_stdout_raw=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") + tmp_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") + tmp_stderr=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX") + + diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers" + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers > "${tmp_stdout_raw}" 2> "${tmp_stderr}" + ok $? "${test_name}: exit code is 0" + + # Pretty-fy xml before further test. + $XML_PRETTY_BIN < "${tmp_stdout_raw}" > "${tmp_stdout}" + + $XML_VALIDATE_BIN "${MI_XSD_PATH}" "${tmp_stdout}" + ok $? "list-trigger mi is valid" + + diff -u "${expected_stdout_file}" "${tmp_stdout}" + ok $? "${test_name}: expected stdout" + + diff -u /dev/null "${tmp_stderr}" + ok $? "${test_name}: expected stderr" + + rm -f "${tmp_stdout}" + rm -f "${tmp_stdout_raw}" + rm -f "${tmp_stderr}" +} + function validate_path_pattern () { local message=$1 -- 2.34.1