Fix: test: start-stop trigger: test execution is invalid
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 30 Mar 2021 01:38:54 +0000 (21:38 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 16 Apr 2021 22:33:32 +0000 (18:33 -0400)
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 <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iba80413d6ca36989cd967895d3330860cb4ef614

tests/regression/tools/trigger/start-stop/test_start_stop
tests/regression/tools/trigger/utils/notification-client.c

index a6fc7bd028e3f3ff2e818d4a1cbb5c816f74413d..a09279eeed51a8986a630242ebff4bb42fb8b050 100755 (executable)
@@ -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
index 688775a6e72b2ab97c4419efac7726fb201281dc..7803fd51dac96eca02d4b05a9f56bc3c6f152ae0 100644 (file)
@@ -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;
                }
This page took 0.029155 seconds and 4 git commands to generate.