From: Francis Deslauriers Date: Thu, 4 Mar 2021 22:12:57 +0000 (-0500) Subject: Tests: Cleanup: add `lttng_{add, remove}_trigger_ok()` bash functions X-Git-Tag: v2.13.0-rc1~199 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=70c766ac8dfa25ccb07dfdf1b1835e9c6a98807b Tests: Cleanup: add `lttng_{add, remove}_trigger_ok()` bash functions Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: I63b1f4d2a72b291f93df4548114014a116824864 --- diff --git a/tests/regression/tools/trigger/start-stop/test_start_stop b/tests/regression/tools/trigger/start-stop/test_start_stop index cecea3b19..a6fc7bd02 100755 --- a/tests/regression/tools/trigger/start-stop/test_start_stop +++ b/tests/regression/tools/trigger/start-stop/test_start_stop @@ -22,47 +22,6 @@ NUM_TESTS=18 NR_ITER=5 NR_USEC_WAIT=5 -function lttng_add_trigger_ust() -{ - local expected_to_fail="$1" - local trigger_name="$2" - shift 2 - - "$FULL_LTTNG_BIN" add-trigger --id "$trigger_name" "$@" 1> /dev/null 2> /dev/null - ret=$? - if [[ $expected_to_fail -eq "1" ]]; then - test "$ret" -ne "0" - ok $? "Add trigger $trigger_name failed as expected" - else - ok $ret "Add trigger $trigger_name" - fi -} - -function lttng_remove_trigger_ust() -{ - local expected_to_fail="$1" - local trigger_name="$2" - - "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" 1> /dev/null 2> /dev/null - ret=$? - if [[ $expected_to_fail -eq "1" ]]; then - test "$ret" -ne "0" - ok $? "Remove trigger $trigger_name failed as expected" - else - ok $ret "Remove trigger $trigger_name" - fi -} - -function lttng_add_trigger_ust_ok() -{ - lttng_add_trigger_ust 0 "$@" -} - -function lttng_remove_trigger_ust_ok() -{ - lttng_remove_trigger_ust 0 "$@" -} - function lttng_session_is_active() { local SESSION_NAME="$1" @@ -96,7 +55,7 @@ function test_start_session_action() # Add `start-session` action to an event-rule condition _followed_ by # a `notify` action. - lttng_add_trigger_ust_ok \ + lttng_add_trigger_ok \ $TRIGGER_NAME \ --condition on-event -u "tp:tptest" \ --action start-session $SESSION_NAME \ @@ -124,7 +83,7 @@ function test_start_session_action() lttng_session_is_active $SESSION_NAME # Tearing down. - lttng_remove_trigger_ust_ok $TRIGGER_NAME + lttng_remove_trigger_ok $TRIGGER_NAME stop_lttng_tracing_ok $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME @@ -150,7 +109,7 @@ function test_stop_session_action() # Add `stop-session` action to an event-rule condition _followed_ by # a `notify` action. - lttng_add_trigger_ust_ok \ + lttng_add_trigger_ok \ $TRIGGER_NAME \ --condition on-event -u "tp:tptest" \ --action stop-session $SESSION_NAME \ @@ -178,7 +137,7 @@ function test_stop_session_action() lttng_session_is_inactive $SESSION_NAME # Tearing down. - lttng_remove_trigger_ust_ok $TRIGGER_NAME + lttng_remove_trigger_ok $TRIGGER_NAME destroy_lttng_session_ok $SESSION_NAME rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH" diff --git a/tests/regression/tools/trigger/test_list_triggers_cli b/tests/regression/tools/trigger/test_list_triggers_cli index fb7ce2c49..6a189231a 100755 --- a/tests/regression/tools/trigger/test_list_triggers_cli +++ b/tests/regression/tools/trigger/test_list_triggers_cli @@ -41,12 +41,6 @@ else ist_root=0 fi -function add_trigger () -{ - "${FULL_LTTNG_BIN}" add-trigger "$@" - ok $? "add trigger \`$*\`: exit code is 0" -} - function list_triggers () { local test_name="$1" @@ -68,9 +62,9 @@ test_top_level_options () start_lttng_sessiond_notap - add_trigger --id hello --condition on-event -u test-id --action notify - add_trigger --fire-once-after 123 --condition on-event -u test-fire-once-after --action notify - add_trigger --fire-every 124 --condition on-event -u test-fire-every --action notify + lttng_add_trigger_ok "hello" --condition on-event -u test-id --action notify + lttng_add_trigger_ok "T0" --fire-once-after 123 --condition on-event -u test-fire-once-after --action notify + lttng_add_trigger_ok "T1" --fire-every 124 --condition on-event -u test-fire-every --action notify cat > "${tmp_expected_stdout}" <<- EOF - id: T0 @@ -105,49 +99,49 @@ test_on_event_tracepoint () # shellcheck disable=SC2119 start_lttng_sessiond_notap - add_trigger --condition on-event -u -a --action notify - add_trigger --id ABC --condition on-event aaa -u --filter 'p == 2' --action notify - add_trigger --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify - add_trigger --id BCD --condition on-event -u gerboise --loglevel INFO --action notify - add_trigger --condition on-event -u lemming --loglevel-only WARNING --action notify - add_trigger --condition on-event -u capture-payload-field --capture a --action notify - add_trigger --condition on-event -u capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify - add_trigger --condition on-event -u capture-chan-ctx --capture '$ctx.vpid' --action notify - add_trigger --condition on-event -u capture-app-ctx --capture '$app.iga:active_clients' --action notify + lttng_add_trigger_ok "C" --condition on-event -u -a --action notify + lttng_add_trigger_ok "A" --condition on-event aaa -u --filter 'p == 2' --action notify + lttng_add_trigger_ok "D" --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify + lttng_add_trigger_ok "B" --condition on-event -u gerboise --loglevel INFO --action notify + lttng_add_trigger_ok "E" --condition on-event -u lemming --loglevel-only WARNING --action notify + lttng_add_trigger_ok "F" --condition on-event -u capture-payload-field --capture a --action notify + lttng_add_trigger_ok "G" --condition on-event -u capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify + lttng_add_trigger_ok "H" --condition on-event -u capture-chan-ctx --capture '$ctx.vpid' --action notify + lttng_add_trigger_ok "I" --condition on-event -u capture-app-ctx --capture '$app.iga:active_clients' --action notify cat > "${tmp_expected_stdout}" <<- EOF - - id: ABC + - id: A user id: ${uid} condition: event rule hit rule: aaa (type: tracepoint, domain: ust, filter: p == 2) actions: notify - - id: BCD + - id: B user id: ${uid} condition: event rule hit rule: gerboise (type: tracepoint, domain: ust, log level at least INFO) actions: notify - - id: T0 + - id: C user id: ${uid} condition: event rule hit rule: * (type: tracepoint, domain: ust) actions: notify - - id: T1 + - id: D user id: ${uid} condition: event rule hit rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4) actions: notify - - id: T2 + - id: E user id: ${uid} condition: event rule hit rule: lemming (type: tracepoint, domain: ust, log level is WARNING) actions: notify - - id: T3 + - id: F user id: ${uid} condition: event rule hit rule: capture-payload-field (type: tracepoint, domain: ust) @@ -155,7 +149,7 @@ test_on_event_tracepoint () - a actions: notify - - id: T4 + - id: G user id: ${uid} condition: event rule hit rule: capture-array (type: tracepoint, domain: ust) @@ -164,7 +158,7 @@ test_on_event_tracepoint () - \$ctx.tourlou[18] actions: notify - - id: T5 + - id: H user id: ${uid} condition: event rule hit rule: capture-chan-ctx (type: tracepoint, domain: ust) @@ -172,7 +166,7 @@ test_on_event_tracepoint () - \$ctx.vpid actions: notify - - id: T6 + - id: I user id: ${uid} condition: event rule hit rule: capture-app-ctx (type: tracepoint, domain: ust) @@ -211,9 +205,9 @@ test_on_event_probe () offset_hex="0x$(printf '%x' $offset)" - add_trigger --condition on-event -k --probe=lttng_channel_enable my_channel_enable --action notify - add_trigger --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_channel_enable --action notify - add_trigger --condition on-event -k --probe="0x${channel_enable_addr}" my_channel_enable --action notify + lttng_add_trigger_ok "T0" --condition on-event -k --probe=lttng_channel_enable my_channel_enable --action notify + lttng_add_trigger_ok "T1" --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_channel_enable --action notify + lttng_add_trigger_ok "T2" --condition on-event -k --probe="0x${channel_enable_addr}" my_channel_enable --action notify cat > "${tmp_expected_stdout}" <<- EOF - id: T0 @@ -246,7 +240,7 @@ test_on_event_userspace_probe () # shellcheck disable=SC2119 start_lttng_sessiond_notap - add_trigger --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify + lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify cat > "${tmp_expected_stdout}" <<- EOF - id: T0 @@ -267,8 +261,8 @@ test_on_event_syscall () # shellcheck disable=SC2119 start_lttng_sessiond_notap - add_trigger --condition on-event -k --syscall open --action notify - add_trigger --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify + lttng_add_trigger_ok "T0" --condition on-event -k --syscall open --action notify + lttng_add_trigger_ok "T1" --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify cat > "${tmp_expected_stdout}" <<- EOF - id: T0 @@ -294,14 +288,14 @@ test_snapshot_action () { start_lttng_sessiond_notap - add_trigger --condition on-event -u some-event --action snapshot-session ze-session - add_trigger --condition on-event -u some-event --action snapshot-session ze-session --path /some/path - add_trigger --condition on-event -u some-event --action snapshot-session ze-session --url file:///some/other/path - add_trigger --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4 - add_trigger --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4:1234:1235 - add_trigger --condition on-event -u some-event --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1111 --data-url=tcp://1.2.3.4:1112 - add_trigger --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --max-size=1234 - add_trigger --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --name=meh + lttng_add_trigger_ok "T0" --condition on-event -u some-event --action snapshot-session ze-session + lttng_add_trigger_ok "T1" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path + lttng_add_trigger_ok "T2" --condition on-event -u some-event --action snapshot-session ze-session --url file:///some/other/path + lttng_add_trigger_ok "T3" --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4 + lttng_add_trigger_ok "T4" --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4:1234:1235 + lttng_add_trigger_ok "T5" --condition on-event -u some-event --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1111 --data-url=tcp://1.2.3.4:1112 + lttng_add_trigger_ok "T6" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --max-size=1234 + lttng_add_trigger_ok "T7" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --name=meh cat > "${tmp_expected_stdout}" <<- EOF diff --git a/tests/regression/tools/trigger/test_remove_trigger_cli b/tests/regression/tools/trigger/test_remove_trigger_cli index 168227a4a..ffaefbb44 100755 --- a/tests/regression/tools/trigger/test_remove_trigger_cli +++ b/tests/regression/tools/trigger/test_remove_trigger_cli @@ -34,12 +34,6 @@ tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX) uid=$(id --user) gid=$(id --group) -function add_trigger () -{ - "${FULL_LTTNG_BIN}" add-trigger "$@" - ok $? "add trigger \`$*\`: exit code is 0" -} - function list_triggers () { local test_name="$1" @@ -74,8 +68,8 @@ function remove_trigger () start_lttng_sessiond_notap # Add a few triggers -add_trigger --condition on-event -u -a --action notify -add_trigger --id ABC --condition on-event aaa -u --filter 'p == 2' --action notify +lttng_add_trigger_ok "ABC" --condition on-event aaa -u --filter 'p == 2' --action notify +lttng_add_trigger_ok "DEF" --condition on-event -u -a --action notify cat > "${tmp_expected_stdout}" <<- EOF - id: ABC @@ -84,7 +78,7 @@ cat > "${tmp_expected_stdout}" <<- EOF rule: aaa (type: tracepoint, domain: ust, filter: p == 2) actions: notify -- id: T0 +- id: DEF user id: ${uid} condition: event rule hit rule: * (type: tracepoint, domain: ust) @@ -96,7 +90,7 @@ list_triggers "two triggers left" "${tmp_expected_stdout}" remove_trigger "ABC" cat > "${tmp_expected_stdout}" <<- EOF -- id: T0 +- id: DEF user id: ${uid} condition: event rule hit rule: * (type: tracepoint, domain: ust) @@ -105,7 +99,7 @@ cat > "${tmp_expected_stdout}" <<- EOF EOF list_triggers "one trigger left" "${tmp_expected_stdout}" -remove_trigger "T0" +remove_trigger "DEF" list_triggers "no triggers left" "/dev/null" diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 8e76ce497..7e8100f00 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -2126,3 +2126,44 @@ function lttng_clear_all () $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ok $? "Clear all lttng sessions" } + +function lttng_add_trigger() +{ + local expected_to_fail="$1" + local trigger_name="$2" + shift 2 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --id "$trigger_name" "$@" 1> /dev/null 2> /dev/null + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Add trigger $trigger_name failed as expected" + else + ok $ret "Add trigger $trigger_name" + fi +} + +function lttng_remove_trigger() +{ + local expected_to_fail="$1" + local trigger_name="$2" + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger "$trigger_name" 1> /dev/null 2> /dev/null + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Remove trigger $trigger_name failed as expected" + else + ok $ret "Remove trigger $trigger_name" + fi +} + +function lttng_add_trigger_ok() +{ + lttng_add_trigger 0 "$@" +} + +function lttng_remove_trigger_ok() +{ + lttng_remove_trigger 0 "$@" +}