diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ChangeLog | 7 | ||||
-rw-r--r-- | tests/mutex2.c | 23 | ||||
-rw-r--r-- | tests/test.h | 58 |
3 files changed, 83 insertions, 5 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index c5ac1ce..27834cb 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +1999-02-20 Ross Johnson <rpj@ise.canberra.edu.au> + + * mutex2.c: Test static mutex initialisation. + + * test.h: New. Declares a table mapping error numbers to + error names. + 1999-01-17 Ross Johnson <rpj@ise.canberra.edu.au> * runtest: New script to build and run a test in the tests directory. diff --git a/tests/mutex2.c b/tests/mutex2.c index 224b7ea..d0885fc 100644 --- a/tests/mutex2.c +++ b/tests/mutex2.c @@ -1,12 +1,25 @@ +/* + * mutex1.c + * + * Declare a static mutex object, lock it, and then unlock it again. + */ + #include <pthread.h> +#include "test.h" -pthread_mutex_t mutex1; - +pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; + main() { - pthread_mutex_init(&mutex1, NULL); - pthread_mutex_trylock(&mutex1); - pthread_mutex_unlock(&mutex1); + int result; + + result = pthread_mutex_trylock(&mutex1); + printf("pthread_mutex_trylock returned %s\n", error_string[result]); + + if (result == 0) + { + pthread_mutex_unlock(&mutex1); + } return 0; } diff --git a/tests/test.h b/tests/test.h new file mode 100644 index 0000000..0beeaab --- /dev/null +++ b/tests/test.h @@ -0,0 +1,58 @@ +/* + * test.h + * + * Useful definitions and declarations for tests. + */ + +#include <pthread.h> + +#ifndef _PTHREAD_TEST_H_ +#define _PTHREAD_TEST_H_ + +char * error_string[] = { + "ZERO", + "EPERM", + "ENOFILE_or_ENOENT", + "ESRCH", + "EINTR", + "EIO", + "ENXIO", + "E2BIG", + "ENOEXEC", + "EBADF", + "ECHILD", + "EAGAIN", + "ENOMEM", + "EACCES", + "EFAULT", + "UNKNOWN_15", + "EBUSY", + "EEXIST", + "EXDEV", + "ENODEV", + "ENOTDIR", + "EISDIR", + "EINVAL", + "ENFILE", + "EMFILE", + "ENOTTY", + "UNKNOWN_26", + "EFBIG", + "ENOSPC", + "ESPIPE", + "EROFS", + "EMLINK", + "EPIPE", + "EDOM", + "ERANGE", + "UNKNOWN_35", + "EDEADLOCK_or_EDEADLK", + "UNKNOWN_37", + "ENAMETOOLONG", + "ENOLCK", + "ENOSYS", + "ENOTEMPTY", + "EILSEQ", +}; + +#endif |