Skip to content

Commit

Permalink
Tests: Perform I/O testing using socketpair.
Browse files Browse the repository at this point in the history
  • Loading branch information
heiher committed Feb 11, 2025
1 parent cfdd130 commit 8d7df67
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
17 changes: 11 additions & 6 deletions tests/cio-fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : cio-fd.c
Author : hev <[email protected]>
Copyright : Copyright (c) 2024 hev.
Copyright : Copyright (c) 2024 - 2025 hev.
Description : CIO Fd Test
============================================================================
*/
Expand All @@ -12,7 +12,7 @@

#include <hev-task.h>
#include <hev-task-io.h>
#include <hev-task-io-pipe.h>
#include <hev-task-io-socket.h>
#include <hev-task-cio-fd.h>
#include <hev-task-system.h>

Expand Down Expand Up @@ -57,13 +57,13 @@ task_entry (void *data)
ssize_t size;
int res;

res = hev_task_io_pipe_pipe (&fds1[0]);
res = hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, &fds1[0]);
assert (res == 0);
res = hev_task_io_pipe_pipe (&fds1[2]);
res = hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, &fds1[2]);
assert (res == 0);
res = hev_task_io_pipe_pipe (&fds2[0]);
res = hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, &fds2[0]);
assert (res == 0);
res = hev_task_io_pipe_pipe (&fds2[2]);
res = hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, &fds2[2]);
assert (res == 0);

assert (hev_task_add_fd (task, fds1[3], POLLOUT) == 0);
Expand Down Expand Up @@ -105,6 +105,11 @@ task_entry (void *data)
assert (hev_task_cio_write_dgram (a, buf1, 64, NULL, NULL, NULL) == -1);
assert (hev_task_cio_writev_dgram (a, &iov, 1, NULL, NULL, NULL) == -1);

assert (hev_task_del_fd (task, fds1[3]) == 0);
assert (hev_task_del_fd (task, fds2[3]) == 0);
assert (hev_task_del_fd (task, fds1[0]) == 0);
assert (hev_task_del_fd (task, fds2[0]) == 0);

hev_object_unref (HEV_OBJECT (a));
hev_object_unref (HEV_OBJECT (b));
}
Expand Down
7 changes: 4 additions & 3 deletions tests/io-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : io-poll.c
Author : Heiher <[email protected]>
Copyright : Copyright (c) 2018 everyone.
Copyright : Copyright (c) 2018 - 2025 everyone.
Description : IO Poll Test
============================================================================
*/
Expand All @@ -14,8 +14,9 @@

#include <hev-task.h>
#include <hev-task-system.h>
#include <hev-task-io-pipe.h>
#include <hev-task-io.h>
#include <hev-task-io-poll.h>
#include <hev-task-io-socket.h>

static int fds[2];

Expand Down Expand Up @@ -62,7 +63,7 @@ main (int argc, char *argv[])

assert (hev_task_system_init () == 0);

assert (hev_task_io_pipe_pipe (fds) == 0);
assert (hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, fds) == 0);
assert (fds[0] >= 0);
assert (fds[1] >= 0);

Expand Down
7 changes: 4 additions & 3 deletions tests/io-read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : io-read.c
Author : Heiher <[email protected]>
Copyright : Copyright (c) 2018 everyone.
Copyright : Copyright (c) 2018 - 2025 everyone.
Description : IO Read Test
============================================================================
*/
Expand All @@ -14,7 +14,7 @@
#include <hev-task.h>
#include <hev-task-system.h>
#include <hev-task-io.h>
#include <hev-task-io-pipe.h>
#include <hev-task-io-socket.h>

static void
task_entry (void *data)
Expand All @@ -25,7 +25,7 @@ task_entry (void *data)
char buf[4];
ssize_t size;

assert (hev_task_io_pipe_pipe (fds) == 0);
assert (hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, fds) == 0);

flags = fcntl (fds[1], F_GETFL);
assert (flags >= 0);
Expand All @@ -37,6 +37,7 @@ task_entry (void *data)
size = hev_task_io_read (fds[0], buf, 4, NULL, NULL);
assert (size >= 0);

assert (hev_task_del_fd (task, fds[0]) == 0);
close (fds[0]);
close (fds[1]);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/io-readv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : io-readv.c
Author : Heiher <[email protected]>
Copyright : Copyright (c) 2018 everyone.
Copyright : Copyright (c) 2018 - 2025 everyone.
Description : IO ReadV Test
============================================================================
*/
Expand All @@ -14,7 +14,7 @@
#include <hev-task.h>
#include <hev-task-system.h>
#include <hev-task-io.h>
#include <hev-task-io-pipe.h>
#include <hev-task-io-socket.h>

static void
task_entry (void *data)
Expand All @@ -27,7 +27,7 @@ task_entry (void *data)
ssize_t size;
struct iovec iov[2];

assert (hev_task_io_pipe_pipe (fds) == 0);
assert (hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, fds) == 0);

flags = fcntl (fds[1], F_GETFL);
assert (flags >= 0);
Expand All @@ -43,6 +43,7 @@ task_entry (void *data)
size = hev_task_io_readv (fds[0], iov, 2, NULL, NULL);
assert (size >= 0);

assert (hev_task_del_fd (task, fds[0]) == 0);
close (fds[0]);
close (fds[1]);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/io-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : io-write.c
Author : Heiher <[email protected]>
Copyright : Copyright (c) 2018 everyone.
Copyright : Copyright (c) 2018 - 2025 everyone.
Description : IO Write Test
============================================================================
*/
Expand All @@ -13,7 +13,7 @@
#include <hev-task.h>
#include <hev-task-system.h>
#include <hev-task-io.h>
#include <hev-task-io-pipe.h>
#include <hev-task-io-socket.h>

static void
task_entry (void *data)
Expand All @@ -23,13 +23,14 @@ task_entry (void *data)
char buf[4];
ssize_t size;

assert (hev_task_io_pipe_pipe (fds) == 0);
assert (hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, fds) == 0);

assert (hev_task_add_fd (task, fds[1], POLLOUT) == 0);

size = hev_task_io_write (fds[1], buf, 4, NULL, NULL);
assert (size >= 0);

assert (hev_task_del_fd (task, fds[1]) == 0);
close (fds[0]);
close (fds[1]);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/io-writev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : io-writev.c
Author : Heiher <[email protected]>
Copyright : Copyright (c) 2018 everyone.
Copyright : Copyright (c) 2018 - 2025 everyone.
Description : IO WriteV Test
============================================================================
*/
Expand All @@ -13,7 +13,7 @@
#include <hev-task.h>
#include <hev-task-system.h>
#include <hev-task-io.h>
#include <hev-task-io-pipe.h>
#include <hev-task-io-socket.h>

static void
task_entry (void *data)
Expand All @@ -24,7 +24,7 @@ task_entry (void *data)
ssize_t size;
struct iovec iov[2];

assert (hev_task_io_pipe_pipe (fds) == 0);
assert (hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, fds) == 0);

assert (hev_task_add_fd (task, fds[1], POLLOUT) == 0);

Expand All @@ -35,6 +35,7 @@ task_entry (void *data)
size = hev_task_io_writev (fds[1], iov, 2, NULL, NULL);
assert (size == 4);

assert (hev_task_del_fd (task, fds[1]) == 0);
close (fds[0]);
close (fds[1]);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/io-yielder.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : io-yielder.c
Author : Heiher <[email protected]>
Copyright : Copyright (c) 2018 everyone.
Copyright : Copyright (c) 2018 - 2025 everyone.
Description : IO Yielder Test
============================================================================
*/
Expand All @@ -18,7 +18,7 @@
#include <hev-task.h>
#include <hev-task-system.h>
#include <hev-task-io.h>
#include <hev-task-io-pipe.h>
#include <hev-task-io-socket.h>

static int
task_io_yielder (HevTaskYieldType type, void *data)
Expand All @@ -36,7 +36,7 @@ task_entry (void *data)
char buf[16];
ssize_t size;

assert (hev_task_io_pipe_pipe (fds) == 0);
assert (hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, fds) == 0);
assert (fds[0] >= 0);
assert (fds[1] >= 0);

Expand All @@ -45,6 +45,7 @@ task_entry (void *data)
size = hev_task_io_read (fds[0], buf, 16, task_io_yielder, NULL);
assert (size == -2);

assert (hev_task_del_fd (task, fds[0]) == 0);
close (fds[0]);
close (fds[1]);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/task-fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
============================================================================
Name : task-fd.c
Author : Heiher <[email protected]>
Copyright : Copyright (c) 2018 everyone.
Copyright : Copyright (c) 2018 - 2025 everyone.
Description : Task FD Test
============================================================================
*/
Expand All @@ -13,9 +13,9 @@
#include <assert.h>

#include <hev-task.h>
#include <hev-task-io.h>
#include <hev-task-io-pipe.h>
#include <hev-task-system.h>
#include <hev-task-io.h>
#include <hev-task-io-socket.h>

static int fds[2];

Expand Down Expand Up @@ -55,7 +55,7 @@ main (int argc, char *argv[])

assert (hev_task_system_init () == 0);

assert (hev_task_io_pipe_pipe (fds) == 0);
assert (hev_task_io_socket_socketpair (PF_LOCAL, SOCK_STREAM, 0, fds) == 0);

task = hev_task_new (-1);
assert (task);
Expand Down

0 comments on commit 8d7df67

Please sign in to comment.