aboutsummaryrefslogtreecommitdiffstats
path: root/tests/sender-receiver.c
diff options
context:
space:
mode:
authorGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2021-07-02 16:33:26 +0300
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2021-07-28 13:19:02 +0300
commit90ac6734fc164efb3f25e7cd1fdcf91502edbd2d (patch)
tree7fca9903d394c4b430e6d78eb24832532549ea37 /tests/sender-receiver.c
parentfb530b4f92126cbf1802fb711f945c3f34c11fbb (diff)
tests: create wpipc tests sockets also in /tmp with a random name
See #39, #16 Signed-off-by: George Kiagiadakis <george.kiagiadakis@collabora.com>
Diffstat (limited to 'tests/sender-receiver.c')
-rw-r--r--tests/sender-receiver.c39
1 files changed, 26 insertions, 13 deletions
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]));