123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #include "test.h"
- #ifdef __GNUC__
- #include <stdlib.h>
- #endif
- #include "benchtest.h"
- #define ITERATIONS 1000000L
- sem_t sema;
- struct _timeb currSysTimeStart;
- struct _timeb currSysTimeStop;
- long durationMilliSecs;
- long overHeadMilliSecs = 0;
- int one = 1;
- int zero = 0;
- #define GetDurationMilliSecs(_TStart, _TStop) ((_TStop.time*1000+_TStop.millitm) \
- - (_TStart.time*1000+_TStart.millitm))
- #define TESTSTART \
- { int i, j = 0, k = 0; _ftime(&currSysTimeStart); for (i = 0; i < ITERATIONS; i++) { j++;
- #define TESTSTOP \
- }; _ftime(&currSysTimeStop); if (j + k == i) j++; }
- void
- reportTest (char * testNameString)
- {
- durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
- printf( "%-45s %15ld %15.3f\n",
- testNameString,
- durationMilliSecs,
- (float) durationMilliSecs * 1E3 / ITERATIONS);
- }
- int
- main (int argc, char *argv[])
- {
- printf( "=============================================================================\n");
- printf( "\nOperations on a semaphore.\n%ld iterations\n\n",
- ITERATIONS);
- printf( "%-45s %15s %15s\n",
- "Test",
- "Total(msec)",
- "average(usec)");
- <<<<<<< .mine
- <<<<<<< .mine
- * --------------------------------------------------------------------------
- =======
- * --------------------------------------------------------------------------
- *
- * Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
- * Copyright(C) 2008 Jason Schmidlapp
- *
- * Contact Email: jschmidlapp@users.sourceforge.net
- *
- =======
- * --------------------------------------------------------------------------
- >>>>>>> .r47
- >>>>>>> .r51
-
- TESTSTART
- assert(1 == one);
- TESTSTOP
- durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
- overHeadMilliSecs = durationMilliSecs;
-
- assert((w32sema = CreateSemaphore(NULL, (long) 0, (long) ITERATIONS, NULL)) != 0);
- TESTSTART
- assert(ReleaseSemaphore(w32sema, 1, NULL) != zero);
- TESTSTOP
- assert(CloseHandle(w32sema) != 0);
- reportTest("W32 Post with no waiters");
- assert((w32sema = CreateSemaphore(NULL, (long) ITERATIONS, (long) ITERATIONS, NULL)) != 0);
- TESTSTART
- assert(WaitForSingleObject(w32sema, INFINITE) == WAIT_OBJECT_0);
- TESTSTOP
- assert(CloseHandle(w32sema) != 0);
- reportTest("W32 Wait without blocking");
- assert(sem_init(&sema, 0, 0) == 0);
- TESTSTART
- assert(sem_post(&sema) == zero);
- TESTSTOP
- assert(sem_destroy(&sema) == 0);
- reportTest("POSIX Post with no waiters");
- assert(sem_init(&sema, 0, ITERATIONS) == 0);
- TESTSTART
- assert(sem_wait(&sema) == zero);
- TESTSTOP
- assert(sem_destroy(&sema) == 0);
- reportTest("POSIX Wait without blocking");
- printf( "=============================================================================\n");
-
- return 0;
- }
|