From 8c8bcc5d1737002a9d153105c16b262d2e201efa Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 19 Oct 2004 13:24:40 +0000 Subject: Semaphore speedups - alpha, but passes testsuite --- tests/ChangeLog | 12 ++++-- tests/GNUmakefile | 4 +- tests/Makefile | 8 ++-- tests/semaphore2.c | 2 +- tests/semaphore3.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 tests/semaphore3.c (limited to 'tests') diff --git a/tests/ChangeLog b/tests/ChangeLog index f55b2b6..65d52f1 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,8 +1,12 @@ -2004-10-14 Ross Johnson +2004-10-19 Ross Johnson - * rwlock7.c (main): Tidy up statistics reporting; randomise - update accesses. - * rwlock8.c: New test. + * semaphore3.c: New test. + +2004-10-14 Ross Johnson + + * rwlock7.c (main): Tidy up statistics reporting; randomise + update accesses. + * rwlock8.c: New test. 2004-09-08 Alexandre Girao diff --git a/tests/GNUmakefile b/tests/GNUmakefile index 0979fda..aecd718 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -70,7 +70,8 @@ COPYFILES = $(HDR) $(LIB) $(DLL) $(QAPC) # stop. TESTS = sizes loadfree \ - self1 mutex5 mutex1 mutex1e mutex1n mutex1r semaphore1 semaphore2 \ + self1 mutex5 mutex1 mutex1e mutex1n mutex1r \ + semaphore1 semaphore2 semaphore3 \ condvar1 condvar1_1 condvar1_2 condvar2 condvar2_1 exit1 \ create1 create2 reuse1 reuse2 equal1 \ kill1 valid1 valid2 \ @@ -251,6 +252,7 @@ self1.pass: self2.pass: create1.pass semaphore1.pass: semaphore2.pass: +semaphore3.pass: semaphore2.pass sizes.pass: spin1.pass: spin2.pass: spin1.pass diff --git a/tests/Makefile b/tests/Makefile index 535347f..71154b3 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -80,8 +80,10 @@ EHFLAGS = # stop. PASSES= sizes.pass loadfree.pass \ - semaphore1.pass semaphore2.pass self1.pass mutex5.pass \ - mutex1.pass mutex1n.pass mutex1e.pass mutex1r.pass mutex2.pass mutex3.pass \ + self1.pass mutex5.pass \ + mutex1.pass mutex1n.pass mutex1e.pass mutex1r.pass \ + semaphore1.pass semaphore2.pass semaphore3.pass \ + mutex2.pass mutex3.pass \ mutex2r.pass mutex2e.pass mutex3r.pass mutex3e.pass \ condvar1.pass condvar1_1.pass condvar1_2.pass condvar2.pass condvar2_1.pass \ exit1.pass create1.pass create2.pass reuse1.pass reuse2.pass equal1.pass \ @@ -100,7 +102,7 @@ PASSES= sizes.pass loadfree.pass \ condvar4.pass condvar5.pass condvar6.pass \ condvar7.pass condvar8.pass condvar9.pass \ errno1.pass \ - rwlock1.pass rwlock2.pass rwlock3.pass rwlock4.pass \ + rwlock1.pass rwlock2.pass rwlock3.pass rwlock4.pass \ rwlock5.pass rwlock6.pass rwlock7.pass rwlock8.pass \ rwlock2_t.pass rwlock3_t.pass rwlock4_t.pass rwlock5_t.pass rwlock6_t.pass rwlock6_t2.pass \ context1.pass \ diff --git a/tests/semaphore2.c b/tests/semaphore2.c index 8e264ea..e3663d9 100644 --- a/tests/semaphore2.c +++ b/tests/semaphore2.c @@ -73,7 +73,7 @@ #include "test.h" -#define MAX_COUNT 100000 +#define MAX_COUNT 100 int main() diff --git a/tests/semaphore3.c b/tests/semaphore3.c new file mode 100644 index 0000000..c6570f8 --- /dev/null +++ b/tests/semaphore3.c @@ -0,0 +1,120 @@ +/* + * File: semaphore3.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2003 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.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: Verify sem_getvalue returns the correct number of waiters. + * - + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + +#include "test.h" + +#define MAX_COUNT 100 + +sem_t s; + +void * +thr (void * arg) +{ + assert(pthread_detach(pthread_self()) == 0); + assert(sem_wait(&s) == 0); + + return NULL; +} + +int +main() +{ + int value = 0; + int i; + pthread_t t[MAX_COUNT]; + + assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0); + assert(sem_getvalue(&s, &value) == 0); + assert(value == 0); +// printf("Value = %ld\n", value); + + for (i = 1; i <= MAX_COUNT; i++) + { + assert(pthread_create(&t[i-1], NULL, thr, NULL) == 0); + sched_yield(); + assert(sem_getvalue(&s, &value) == 0); +// printf("Value = %ld\n", value); + assert(-value == i); + } + + for (i = MAX_COUNT - 1; i >= 0; i--) + { + assert(sem_post(&s) == 0); + assert(sem_getvalue(&s, &value) == 0); +// printf("Value = %ld\n", value); + assert(-value == i); + } + + return 0; +} + -- cgit v1.2.3