diff options
author | David Robillard <d@drobilla.net> | 2022-08-18 18:47:57 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-08-18 19:23:41 -0400 |
commit | 93eb717f520d68d27bfe110d48057cdd54a4a2bc (patch) | |
tree | 39be097ac1cb678e1b2df3087f6d83d78c382e52 /test | |
parent | 35c7e80281ff6079b6e89dd421addd0a5f6b8b2c (diff) | |
download | zix-93eb717f520d68d27bfe110d48057cdd54a4a2bc.tar.gz zix-93eb717f520d68d27bfe110d48057cdd54a4a2bc.tar.bz2 zix-93eb717f520d68d27bfe110d48057cdd54a4a2bc.zip |
Fix semaphore error handling
Note that existing code which uses zix_sem_try_wait() may still compile against
this change, but be incorrect!
Diffstat (limited to 'test')
-rw-r--r-- | test/test_sem.c | 19 | ||||
-rw-r--r-- | test/test_status.c | 2 |
2 files changed, 17 insertions, 4 deletions
diff --git a/test/test_sem.c b/test/test_sem.c index 023b8ee..d43dac8 100644 --- a/test/test_sem.c +++ b/test/test_sem.c @@ -4,6 +4,7 @@ #undef NDEBUG #include "zix/attributes.h" +#include "zix/common.h" #include "zix/sem.h" #include "zix/thread.h" @@ -33,13 +34,24 @@ writer(void* ZIX_UNUSED(arg)) printf("Writer starting\n"); for (unsigned i = 0; i < n_signals; ++i) { - zix_sem_post(&sem); + assert(!zix_sem_post(&sem)); } printf("Writer finished\n"); return ZIX_THREAD_RESULT; } +static void +test_try_wait(void) +{ + assert(!zix_sem_init(&sem, 0)); + assert(zix_sem_try_wait(&sem) == ZIX_STATUS_TIMEOUT); + assert(!zix_sem_post(&sem)); + assert(!zix_sem_try_wait(&sem)); + assert(zix_sem_try_wait(&sem) == ZIX_STATUS_TIMEOUT); + assert(!zix_sem_destroy(&sem)); +} + int main(int argc, char** argv) { @@ -52,6 +64,8 @@ main(int argc, char** argv) n_signals = (unsigned)strtol(argv[1], NULL, 10); } + test_try_wait(); + printf("Testing %u signals...\n", n_signals); assert(!zix_sem_init(&sem, 0)); @@ -64,7 +78,6 @@ main(int argc, char** argv) assert(!zix_thread_join(reader_thread)); assert(!zix_thread_join(writer_thread)); - - zix_sem_destroy(&sem); + assert(!zix_sem_destroy(&sem)); return 0; } diff --git a/test/test_status.c b/test/test_status.c index eb11bc1..486c210 100644 --- a/test/test_status.c +++ b/test/test_status.c @@ -37,7 +37,7 @@ test_strerror(void) const char* msg = zix_strerror(ZIX_STATUS_SUCCESS); assert(!strcmp(msg, "Success")); - for (int i = ZIX_STATUS_ERROR; i <= ZIX_STATUS_REACHED_END; ++i) { + for (int i = ZIX_STATUS_ERROR; i <= ZIX_STATUS_OVERFLOW; ++i) { msg = zix_strerror((ZixStatus)i); assert(strcmp(msg, "Success")); } |