diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ChangeLog | 12 | ||||
-rw-r--r-- | tests/Makefile | 51 | ||||
-rw-r--r-- | tests/equal1.c | 51 | ||||
-rw-r--r-- | tests/exit1.c | 5 | ||||
-rw-r--r-- | tests/test.h | 28 |
5 files changed, 107 insertions, 40 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 962f922..2d57206 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,15 @@ +1999-02-23 Ross Johnson <rpj@ise.canberra.edu.au> + + * Makefile: Now actually runs the tests. + + * tests.h: Define our own assert macro. The Mingw32 + version pops up a dialog but we want to run non-interactively. + + * equal1.c: use assert a little more directly so that it + prints the actual call statement. + + * exit1.c: Modify to return 0 on success, 1 on failure. + 1999-02-22 Ross Johnson <rpj@ise.canberra.edu.au> * self2.c: Bring up to date. diff --git a/tests/Makefile b/tests/Makefile index 82c1d44..56968e5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,14 +1,55 @@ # Makefile for the pthreads test suite. # If all of the .pass files can be created, the test suite has passed. + +CP = copy +RM = erase +TOUCH = echo Passed > + +# +# Mingw32 +# +CC = gcc +CFLAGS = -g -O2 -UNDEBUG -Wall -o $@ $^ +BUILD_DIR = ../build +RELEASE_DIR = ../release +INCLUDES = -I$(BUILD_DIR)/include +LIBS = $(BUILD_DIR)/lib/libpthread32.a + +## +## MSVC +## +#CC = cl +#CFLAGS = /W3 /MT /nologo /Yd /Zi /Fe$@ $^ +#BUILD_DIR = ..\build +#RELEASE_DIR = ..\release +#INCLUDES = -I$(BUILD_DIR)\include +#LIBS = $(BUILD_DIR)\lib\pthread.lib + +DLL = pthread.dll + # If a test case returns a non-zero exit code to the shell, make will # stop. -PASSES = count1.pass create1.pass equal1.pass exit1.pass exit2.pass \ - exit3.pass eyal1.pass mutex1.pass mutex2.pass mutex3.pass \ - once1.pass self1.pass self2.pass self3.pass tsd1.pass +TESTS = count1 create1 equal1 exit1 exit2 \ + exit3 eyal1 mutex1 mutex2 mutex3 \ + once1 self1 self2 self3 tsd1 + +PASSES = $(TESTS:%=%.pass) all: $(PASSES) -%.pass: %.exe - touch $@ +%.pass: %.exe $(DLL) + $* + $(TOUCH) $@ + +%.exe: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(LIBS) + +$(DLL): + $(CP) ..\build\bin\$@ . + +clean: + - $(RM) *.exe + - $(RM) *.pass + diff --git a/tests/equal1.c b/tests/equal1.c index d882adc..617a956 100644 --- a/tests/equal1.c +++ b/tests/equal1.c @@ -4,44 +4,31 @@ * Depends on functions: pthread_create(). */ -#include <pthread.h> -#include <stdio.h> -#include <windows.h> +#include "test.h" void * func(void * arg) { Sleep(2000); return 0; } - + +int main() { - int rc; - pthread_t t1, t2; - if (pthread_create(&t1, NULL, func, (void *) 1) != 0) - { - return 1; - } - - if (pthread_create(&t2, NULL, func, (void *) 2) != 0) - { - return 1; - } - - if (pthread_equal(t1, t2)) - { - return 1; - } - - if (pthread_equal(t1,t1) == 0) - { - return 1; - } - - /* This is a hack. We don't want to rely on pthread_join - yet if we can help it. */ - Sleep(8000); - - /* Success. */ - return 0; + pthread_t t1, t2; + + assert(pthread_create(&t1, NULL, func, (void *) 1) == 0); + + assert(pthread_create(&t2, NULL, func, (void *) 2) == 0); + + assert(pthread_equal(t1, t2) == 0); + + assert(pthread_equal(t1,t1) != 0); + + /* This is a hack. We don't want to rely on pthread_join + yet if we can help it. */ + Sleep(4000); + + /* Success. */ + return 0; } diff --git a/tests/exit1.c b/tests/exit1.c index 2f31383..758852a 100644 --- a/tests/exit1.c +++ b/tests/exit1.c @@ -10,5 +10,8 @@ int main(int argc, char * argv[]) { /* A simple test firstly. */ - pthread_exit((void *) 2); + pthread_exit((void *) 0); + + /* Not reached */ + return 1; } diff --git a/tests/test.h b/tests/test.h index 0beeaab..23bcd48 100644 --- a/tests/test.h +++ b/tests/test.h @@ -4,11 +4,12 @@ * Useful definitions and declarations for tests. */ -#include <pthread.h> - #ifndef _PTHREAD_TEST_H_ #define _PTHREAD_TEST_H_ +#include <pthread.h> +#include <stdio.h> + char * error_string[] = { "ZERO", "EPERM", @@ -55,4 +56,27 @@ char * error_string[] = { "EILSEQ", }; +/* + * The Mingw32 assert macro calls the CRTDLL _assert function + * which pops up a dialog. We want to run in batch mode so + * we define our own assert macro. + */ +#ifdef NDEBUG + +#define assert(e) ((void)0) + +#else /* NDEBUG */ + +#ifdef assert +# undef assert +#endif + +#define assert(e) \ + ((e) ? (void) 0 : \ + (fprintf(stderr, "Assertion failed: (%s), file %s, line %d\n", \ + #e, __FILE__, (int) __LINE__), exit(1))) + +#endif /* NDEBUG */ + + #endif |