From 34a2c5822fd95fb51720c11c8d9813482f51bed0 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 20 Feb 2014 15:48:52 +0100 Subject: [PATCH] Add test-pthread-basic. --- regress/Makefile | 1 + regress/test-pthread-basic.c++ | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 regress/test-pthread-basic.c++ diff --git a/regress/Makefile b/regress/Makefile index dbcdac87..ae36faef 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -14,6 +14,7 @@ BINARIES:=\ regress \ TESTS:=\ +test-pthread-basic \ all: $(BINARIES) $(TESTS) diff --git a/regress/test-pthread-basic.c++ b/regress/test-pthread-basic.c++ new file mode 100644 index 00000000..e8df0685 --- /dev/null +++ b/regress/test-pthread-basic.c++ @@ -0,0 +1,52 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2014. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + test-pthread-basic.c++ + Tests whether basic pthread support works. + +*******************************************************************************/ + +#include + +#include "test.h" + +void* thread_routine(void* cookie) +{ + int* test_failure_ptr = (int*) cookie; + *test_failure_ptr = 0; + return cookie; +} + +int main(void) +{ + int errnum; + + int test_failure = 1; + + pthread_t thread; + if ( (errnum = pthread_create(&thread, NULL, &thread_routine, &test_failure)) ) + test_error(errnum, "pthread_create"); + + void* thread_result; + if ( (errnum = pthread_join(thread, &thread_result)) ) + test_error(errnum, "pthread_join"); + + test_assert(test_failure == 0); + test_assert(thread_result == &test_failure); + + return 0; +}