From a416ab17ecf9f2cb0f1e3f7bd645a8d1ce690ca2 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 18 Feb 2002 03:16:52 +0000 Subject: Major reorganisation of source code; new routine and tests added. --- tests/ChangeLog | 5 +++ tests/GNUmakefile | 7 ++- tests/Makefile | 4 +- tests/condvar1_1.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/condvar1_2.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/condvar3_1.c | 2 + tests/exit4.c | 13 +++++- 7 files changed, 266 insertions(+), 4 deletions(-) create mode 100644 tests/condvar1_1.c create mode 100644 tests/condvar1_2.c (limited to 'tests') diff --git a/tests/ChangeLog b/tests/ChangeLog index 4a4883e..944961d 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2002-02-17 Ross Johnson + + * condvar1_1.c: New test. + * condvar1_2.c: New test. + 2002-02-07 Ross Johnson * delay1.c: New test. diff --git a/tests/GNUmakefile b/tests/GNUmakefile index fc0a7e3..74bd6b3 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -67,9 +67,10 @@ COPYFILES = $(HDR) $(LIB) $(DLL) TESTS = loadfree \ self1 mutex5 mutex1 mutex1e mutex1n mutex1r \ - condvar1 condvar2 condvar2_1 exit1 create1 equal1 \ + condvar1 condvar1_1 condvar1_2 condvar2 condvar2_1 exit1 create1 equal1 \ exit2 exit3 \ - join0 join1 join2 mutex2 mutex3 mutex4 mutex6 mutex6n mutex6e mutex6r \ + join0 join1 join2 \ + mutex2 mutex3 mutex4 mutex6 mutex6n mutex6e mutex6r \ mutex7 mutex7n mutex7e mutex7r mutex8 mutex8n mutex8e mutex8r \ count1 once1 tsd1 self2 cancel1 cancel2 \ delay1 delay2 eyal1 \ @@ -148,6 +149,8 @@ cleanup1.pass: cleanup0.pass cleanup2.pass: cleanup1.pass cleanup3.pass: cleanup2.pass condvar1.pass: +condvar1_1.pass: condvar1.pass +condvar1_2.pass: join2.pass condvar2.pass: condvar1.pass condvar2_1.pass: condvar2.pass join2.pass condvar3.pass: create1.pass condvar2.pass diff --git a/tests/Makefile b/tests/Makefile index ad2a055..9532b41 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -73,7 +73,7 @@ EHFLAGS = PASSES= loadfree.pass \ self1.pass mutex5.pass \ mutex1.pass mutex1n.pass mutex1e.pass mutex1r.pass mutex2.pass mutex3.pass \ - condvar1.pass condvar2.pass condvar2_1.pass \ + condvar1.pass condvar1_1.pass condvar1_2.pass condvar2.pass condvar2_1.pass \ exit1.pass create1.pass equal1.pass \ exit2.pass exit3.pass \ join0.pass join1.pass join2.pass \ @@ -213,6 +213,8 @@ cleanup1.pass: cleanup0.pass cleanup2.pass: cleanup1.pass cleanup3.pass: cleanup2.pass condvar1.pass: +condvar1_1.pass: condvar1.pass +condvar1_2.pass: join2.pass condvar2.pass: condvar1.pass condvar2_1.pass: condvar2.pass join2.pass condvar3.pass: create1.pass condvar2.pass diff --git a/tests/condvar1_1.c b/tests/condvar1_1.c new file mode 100644 index 0000000..465c9df --- /dev/null +++ b/tests/condvar1_1.c @@ -0,0 +1,117 @@ +/* + * File: condvar1_1.c + * + * + * -------------------------------------------------------------------------- + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2002 Pthreads-win32 contributors + * + * Contact Email: rpj@ise.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test CV linked list management. + * + * Test Method (Validation or Falsification): + * - Validation: + * Initiate and destry several CVs in random order. + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Creates and then imediately destroys a CV. Does not + * test the CV. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - All initialised CVs destroyed without segfault. + * - Successfully broadcasts all remaining CVs after + * each CV is removed. + * + * Fail Criteria: + */ + +#include +#include "test.h" + +enum { + NUM_CV = 100 +}; + +static pthread_cond_t cv[NUM_CV]; + +int +main() +{ + int i, j; + + for (i = 0; i < NUM_CV; i++) + { + /* Traverse the list before every init of a CV. */ + assert(pthread_timechange_handler_np(NULL) == (void *) 0); + assert(pthread_cond_init(&cv[i], NULL) == 0); + } + + j = NUM_CV; + (void) srand((unsigned)time(NULL)); + + do + { + i = (NUM_CV - 1) * rand() / RAND_MAX; + if (cv[i] != NULL) + { + j--; + assert(pthread_cond_destroy(&cv[i]) == 0); + /* Traverse the list every time we remove a CV. */ + assert(pthread_timechange_handler_np(NULL) == (void *) 0); + } + } + while (j > 0); + + return 0; +} diff --git a/tests/condvar1_2.c b/tests/condvar1_2.c new file mode 100644 index 0000000..66237ba --- /dev/null +++ b/tests/condvar1_2.c @@ -0,0 +1,122 @@ +/* + * File: condvar1_2.c + * + * + * -------------------------------------------------------------------------- + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2002 Pthreads-win32 contributors + * + * Contact Email: rpj@ise.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test CV linked list management and serialisation. + * + * Test Method (Validation or Falsification): + * - Validation: + * Initiate and destroy several CVs in random order. + * Asynchronously traverse the CV list and broadcast. + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Creates and then imediately destroys a CV. Does not + * test the CV. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - All initialised CVs destroyed without segfault. + * - Successfully broadcasts all remaining CVs after + * each CV is removed. + * + * Fail Criteria: + */ + +#include +#include "test.h" + +enum { + NUM_CV = 100 +}; + +static pthread_cond_t cv[NUM_CV]; + +int +main() +{ + int i, j; + int result = -1; + pthread_t t; + + for (i = 0; i < NUM_CV; i++) + { + assert(pthread_cond_init(&cv[i], NULL) == 0); + } + + j = NUM_CV; + (void) srand((unsigned)time(NULL)); + + /* Traverse the list asynchronously. */ + assert(pthread_create(&t, NULL, pthread_timechange_handler_np, NULL) == 0); + + do + { + i = (NUM_CV - 1) * rand() / RAND_MAX; + if (cv[i] != NULL) + { + j--; + assert(pthread_cond_destroy(&cv[i]) == 0); + } + } + while (j > 0); + + assert(pthread_join(t, (void **) &result) == 0); + assert (result == 0); + + return 0; +} diff --git a/tests/condvar3_1.c b/tests/condvar3_1.c index e181c58..9c4e25b 100644 --- a/tests/condvar3_1.c +++ b/tests/condvar3_1.c @@ -161,6 +161,8 @@ main() signaled++; } + assert(pthread_cond_destroy(&cv1) == 0); + for (i = 1; i <= NUMTHREADS; i++) { assert(pthread_join(t[i], (void **) &result) == 0); diff --git a/tests/exit4.c b/tests/exit4.c index 3c0c8b1..480fc2e 100644 --- a/tests/exit4.c +++ b/tests/exit4.c @@ -64,21 +64,29 @@ void * func(void * arg) { Guard g("func", counter); + #ifdef USE_PTHREAD_EXIT + pthread_exit(arg); assert(0); //Never reached with pthread_exit + #endif //USE_PTHREAD_EXIT + return ret_value; } #endif /*__CLEANUP_CXX */ -int main(int, char **) +int +main() { #ifndef __CLEANUP_CXX + printf("Test requires C++ cleanup enabled. Skipped.\n"); + #else + { void *ret = 0; Guard g("main", counter); @@ -87,7 +95,10 @@ int main(int, char **) assert(0 == pthread_join(id, &ret)); assert(ret == ret_value); } + assert(counter == init_counter_value); + #endif /*__CLEANUP_CXX */ + return 0; } -- cgit v1.2.3