diff options
author | dzwdz | 2022-07-06 19:46:35 +0200 |
---|---|---|
committer | dzwdz | 2022-07-06 19:46:35 +0200 |
commit | caec20e9886fd6d0437b59a9de48a7b686a2cc09 (patch) | |
tree | 2b2e06d90876168a81fdcda15029cd1a2eaffd0a /src/init/tests/pipe.c | |
parent | a89984d7200381d7b8035c48124d93105d59cf24 (diff) |
kernel/pipes: read & write support
Diffstat (limited to 'src/init/tests/pipe.c')
-rw-r--r-- | src/init/tests/pipe.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/init/tests/pipe.c b/src/init/tests/pipe.c new file mode 100644 index 0000000..bbfe79a --- /dev/null +++ b/src/init/tests/pipe.c @@ -0,0 +1,41 @@ +#define TEST_MACROS +#include <init/stdlib.h> +#include <init/tests/main.h> +#include <shared/flags.h> +#include <shared/syscalls.h> + +static const char *pipe_msgs[2] = {"hello", "world"}; + +static void test_pipe_child(handle_t pipe) { + int ret = _syscall_write(pipe, pipe_msgs[0], 5, -1); + assert(ret == 5); + + ret = _syscall_write(pipe, pipe_msgs[1], 5, -1); + assert(ret == 5); +} + +static void test_pipe_parent(handle_t pipe) { + char buf[16]; + int ret = _syscall_read(pipe, buf, 16, 0); + assert(ret == 5); + assert(!memcmp(buf, pipe_msgs[0], 5)); + + _syscall_read(pipe, buf, 16, 0); + assert(ret == 5); + assert(!memcmp(buf, pipe_msgs[1], 5)); // wrong compare for test +} + +void test_pipe(void) { + handle_t pipe = _syscall_pipe(0); + assert(pipe > 0); + + if (!_syscall_fork(0, NULL)) { + test_pipe_child(pipe); + _syscall_exit(0); + } else { + test_pipe_parent(pipe); + _syscall_await(); + } + + // TODO kill process that's waiting on a pipe +} |