From: Jonathan Rajotte Date: Tue, 30 Mar 2021 01:38:54 +0000 (-0400) Subject: Fix: test: start-stop trigger: test execution is invalid X-Git-Tag: v2.13.0-rc1~103 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=7d59def241ece2d8d1c77ecce46431019b51a494;hp=db786d4499cdc45cb071ab96c5b63c7d8b3206c1 Fix: test: start-stop trigger: test execution is invalid Observed issue ============== The test expects the notification client to be a background process but `&` is not used. The notification client is expected to sync with its launcher via the sync file but the invocation of mktemp already creates the file. Solution ======= Use `&` and `mktemp -u`. While there a little cleanup in notification_client for error code path was done. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: Iba80413d6ca36989cd967895d3330860cb4ef614 --- diff --git a/tests/regression/tools/trigger/start-stop/test_start_stop b/tests/regression/tools/trigger/start-stop/test_start_stop index a6fc7bd02..a09279eee 100755 --- a/tests/regression/tools/trigger/start-stop/test_start_stop +++ b/tests/regression/tools/trigger/start-stop/test_start_stop @@ -43,7 +43,7 @@ function test_start_session_action() local SESSION_NAME="my_triggered_session" local TRIGGER_NAME="trigger1" local TRACE_PATH=$(mktemp -d test-start-action-trace.XXXXXX) - local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp test-notif-register.XXXXXX) + local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX) diag "Start session action" @@ -64,7 +64,7 @@ function test_start_session_action() # Launch notification listener. $NOTIFICATION_CLIENT_BIN \ --trigger $TRIGGER_NAME \ - --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" + --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" & notif_client_pid=$! while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do @@ -96,7 +96,7 @@ function test_stop_session_action() local SESSION_NAME="my_triggered_session" local TRIGGER_NAME="trigger1" local TRACE_PATH=$(mktemp -d test-stop-action-trace.XXXXXX) - local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp test-notif-register.XXXXXX) + local SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX) diag "Stop session action" create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" @@ -118,7 +118,7 @@ function test_stop_session_action() # Launch notification listener. $NOTIFICATION_CLIENT_BIN \ --trigger $TRIGGER_NAME \ - --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" + --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" & notif_client_pid=$! while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do diff --git a/tests/regression/tools/trigger/utils/notification-client.c b/tests/regression/tools/trigger/utils/notification-client.c index 688775a6e..7803fd51d 100644 --- a/tests/regression/tools/trigger/utils/notification-client.c +++ b/tests/regression/tools/trigger/utils/notification-client.c @@ -22,7 +22,7 @@ static struct option long_options[] = { /* These options set a flag. */ - {"trigger", required_argument, 0, 'i'}, + {"trigger", required_argument, 0, 't'}, {"sync-after-notif-register", required_argument, 0, 'a'}, {0, 0, 0, 0} }; @@ -53,7 +53,7 @@ static bool action_group_contains_notify( return false; } -static bool is_expected_trigger_name(const char *expected_trigger_name, +static bool is_trigger_name(const char *expected_trigger_name, struct lttng_notification *notification) { const char *trigger_name = NULL; @@ -76,6 +76,10 @@ static bool is_expected_trigger_name(const char *expected_trigger_name, } names_match = strcmp(expected_trigger_name, trigger_name) == 0; + if (!names_match) { + fprintf(stderr, "Got an unexpected trigger name: name = '%s', expected name = '%s'\n", + trigger_name, expected_trigger_name); + } end: return names_match; } @@ -126,6 +130,7 @@ int main(int argc, char **argv) ret = lttng_list_triggers(&triggers); if (ret != LTTNG_OK) { fprintf(stderr, "Failed to list triggers\n"); + ret = -1; goto end; } @@ -136,6 +141,7 @@ int main(int argc, char **argv) goto end; } + /* Look for the trigger we want to subscribe to. */ for (i = 0; i < count; i++) { const struct lttng_trigger *trigger = lttng_triggers_get_at_index(triggers, i); @@ -199,14 +205,16 @@ int main(int argc, char **argv) switch (channel_status) { case LTTNG_NOTIFICATION_CHANNEL_STATUS_NOTIFICATIONS_DROPPED: printf("Dropped notification\n"); - break; + ret = -1; + goto end; case LTTNG_NOTIFICATION_CHANNEL_STATUS_INTERRUPTED: - ret = 0; + ret = -1; goto end; case LTTNG_NOTIFICATION_CHANNEL_STATUS_OK: break; case LTTNG_NOTIFICATION_CHANNEL_STATUS_CLOSED: printf("Notification channel was closed by peer.\n"); + ret = -1; break; default: fprintf(stderr, "A communication error occurred on the notification channel.\n"); @@ -214,10 +222,12 @@ int main(int argc, char **argv) goto end; } - ret = is_expected_trigger_name(expected_trigger_name, - notification); + ret = is_trigger_name(expected_trigger_name, notification); lttng_notification_destroy(notification); - if (ret) { + if (!ret) { + ret = -1; + goto end; + } else { ret = 0; goto end; }