diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/client-server.c | 9 | ||||
-rw-r--r-- | tests/sender-receiver.c | 39 |
2 files changed, 31 insertions, 17 deletions
diff --git a/tests/client-server.c b/tests/client-server.c index 24f8cc1..da42aaf 100644 --- a/tests/client-server.c +++ b/tests/client-server.c @@ -10,8 +10,7 @@ #include <spa/pod/builder.h> #include <spa/pod/parser.h> #include <icipc/icipc.h> - -#define TEST_ADDRESS "icipc-client-server" +#include <unistd.h> static bool increment_request_handler (struct icipc_server *self, int client_fd, @@ -70,9 +69,11 @@ reply_handler (struct icipc_sender *self, const uint8_t *buffer, size_t size, vo static void test_icipc_server_client () { - struct icipc_server *s = icipc_server_new (TEST_ADDRESS, true); + g_autofree gchar *address = g_strdup_printf ("%s/icipc-test-%d-%d", + g_get_tmp_dir(), getpid(), g_random_int ()); + struct icipc_server *s = icipc_server_new (address, true); g_assert_nonnull (s); - struct icipc_client *c = icipc_client_new (TEST_ADDRESS, true); + struct icipc_client *c = icipc_client_new (address, true); g_assert_nonnull (c); struct reply_data data; g_mutex_init (&data.mutex); diff --git a/tests/sender-receiver.c b/tests/sender-receiver.c index ca6e816..8424074 100644 --- a/tests/sender-receiver.c +++ b/tests/sender-receiver.c @@ -8,8 +8,7 @@ #include <glib.h> #include <icipc/icipc.h> - -#define TEST_ADDRESS "icipc-sender-receiver" +#include <unistd.h> struct event_data { const uint8_t * expected_data; @@ -70,7 +69,9 @@ reply_callback (struct icipc_sender *self, const uint8_t *buffer, size_t size, v static void test_icipc_receiver_basic () { - struct icipc_receiver *r = icipc_receiver_new (TEST_ADDRESS, 16, NULL, NULL, 0); + g_autofree gchar *address = g_strdup_printf ("%s/icipc-test-%d-%d", + g_get_tmp_dir(), getpid(), g_random_int ()); + struct icipc_receiver *r = icipc_receiver_new (address, 16, NULL, NULL, 0); g_assert_nonnull (r); /* start and stop */ @@ -87,7 +88,9 @@ test_icipc_receiver_basic () static void test_icipc_sender_basic () { - struct icipc_sender *s = icipc_sender_new (TEST_ADDRESS, 16, NULL, NULL, 0); + g_autofree gchar *address = g_strdup_printf ("%s/icipc-test-%d-%d", + g_get_tmp_dir(), getpid(), g_random_int ()); + struct icipc_sender *s = icipc_sender_new (address, 16, NULL, NULL, 0); g_assert_nonnull (s); /* clean up */ @@ -106,9 +109,12 @@ test_icipc_sender_connect () g_cond_init (&data.cond); data.n_events = 0; data.connections = 0; - struct icipc_receiver *r = icipc_receiver_new (TEST_ADDRESS, 16, &events, &data, 0); + + g_autofree gchar *address = g_strdup_printf ("%s/icipc-test-%d-%d", + g_get_tmp_dir(), getpid(), g_random_int ()); + struct icipc_receiver *r = icipc_receiver_new (address, 16, &events, &data, 0); g_assert_nonnull (r); - struct icipc_sender *s = icipc_sender_new (TEST_ADDRESS, 16, NULL, NULL, 0); + struct icipc_sender *s = icipc_sender_new (address, 16, NULL, NULL, 0); g_assert_nonnull (s); /* start receiver */ @@ -154,9 +160,12 @@ test_icipc_sender_lost_connection () struct event_data data; g_mutex_init (&data.mutex); g_cond_init (&data.cond); - struct icipc_receiver *r = icipc_receiver_new (TEST_ADDRESS, 16, NULL, NULL, 0); + + g_autofree gchar *address = g_strdup_printf ("%s/icipc-test-%d-%d", + g_get_tmp_dir(), getpid(), g_random_int ()); + struct icipc_receiver *r = icipc_receiver_new (address, 16, NULL, NULL, 0); g_assert_nonnull (r); - struct icipc_sender *s = icipc_sender_new (TEST_ADDRESS, 16, lost_connection_handler, &data, 0); + struct icipc_sender *s = icipc_sender_new (address, 16, lost_connection_handler, &data, 0); g_assert_nonnull (s); /* connect sender */ @@ -172,7 +181,7 @@ test_icipc_sender_lost_connection () g_assert_false (icipc_sender_is_connected (s)); /* create a new receiver */ - struct icipc_receiver *r2 = icipc_receiver_new (TEST_ADDRESS, 16, NULL, NULL, 0); + struct icipc_receiver *r2 = icipc_receiver_new (address, 16, NULL, NULL, 0); g_assert_nonnull (r2); /* re-connect sender with new receiver */ @@ -189,9 +198,11 @@ test_icipc_sender_lost_connection () static void test_icipc_sender_send () { - struct icipc_receiver *r = icipc_receiver_new (TEST_ADDRESS, 2, NULL, NULL, 0); + g_autofree gchar *address = g_strdup_printf ("%s/icipc-test-%d-%d", + g_get_tmp_dir(), getpid(), g_random_int ()); + struct icipc_receiver *r = icipc_receiver_new (address, 2, NULL, NULL, 0); g_assert_nonnull (r); - struct icipc_sender *s = icipc_sender_new (TEST_ADDRESS, 2, NULL, NULL, 0); + struct icipc_sender *s = icipc_sender_new (address, 2, NULL, NULL, 0); g_assert_nonnull (s); struct event_data data; g_mutex_init (&data.mutex); @@ -250,7 +261,9 @@ test_icipc_sender_send () static void test_icipc_multiple_senders_send () { - struct icipc_receiver *r = icipc_receiver_new (TEST_ADDRESS, 16, NULL, NULL, 0); + g_autofree gchar *address = g_strdup_printf ("%s/icipc-test-%d-%d", + g_get_tmp_dir(), getpid(), g_random_int ()); + struct icipc_receiver *r = icipc_receiver_new (address, 16, NULL, NULL, 0); g_assert_nonnull (r); struct icipc_sender *senders[50]; struct event_data data; @@ -263,7 +276,7 @@ test_icipc_multiple_senders_send () /* create and connect 50 senders */ for (int i = 0; i < 50; i++) { - senders[i] = icipc_sender_new (TEST_ADDRESS, 16, NULL, NULL, 0); + senders[i] = icipc_sender_new (address, 16, NULL, NULL, 0); g_assert_nonnull (senders[i]); g_assert_true (icipc_sender_connect (senders[i])); g_assert_true (icipc_sender_is_connected (senders[i])); |