sewardj | b411202 | 2007-11-09 22:49:28 +0000 | [diff] [blame^] | 1 | |
| 2 | /* Do stupid things with semaphores, and check that Thrcheck doesn't |
| 3 | fall over and does report errors appropriately. If nothing else |
| 4 | this just checks that the relevant functions are getting |
| 5 | intercepted. */ |
| 6 | |
| 7 | /* This is pretty lame, because making the sem_ functions fail is |
| 8 | difficult. Not sure it's really worth having. */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <assert.h> |
| 13 | #include <pthread.h> |
| 14 | #include <semaphore.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | int main ( void ) |
| 18 | { |
| 19 | int r; |
| 20 | sem_t s1; |
| 21 | |
| 22 | /* Do sem_init with huge initial count */ |
| 23 | r= sem_init(&s1, 0, ~0); |
| 24 | |
| 25 | /* initialise properly */ |
| 26 | r= sem_init(&s1, 0, 0); |
| 27 | |
| 28 | /* in glibc, sem_destroy is a no-op; making it fail is |
| 29 | impossible. */ |
| 30 | |
| 31 | /* Do 'wait' on a bogus semaphore. This should fail, but on glibc |
| 32 | it succeeds. */ |
| 33 | memset(&s1, 0x55, sizeof(s1)); |
| 34 | r= sem_wait(&s1); /* assert(r != 0); */ |
| 35 | |
| 36 | /* this really ought to fail, but it doesn't. */ |
| 37 | r= sem_post(&s1); assert(!r); |
| 38 | |
| 39 | sem_destroy(&s1); |
| 40 | |
| 41 | return 0; |
| 42 | } |