diff options
| -rw-r--r-- | tests/ChangeLog | 6 | ||||
| -rw-r--r-- | tests/Template.c | 68 | ||||
| -rw-r--r-- | tests/tsd1.c | 116 | 
3 files changed, 164 insertions, 26 deletions
| diff --git a/tests/ChangeLog b/tests/ChangeLog index a634f87..54cccef 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +Wed Dec 30 11:22:44 1998  Ross Johnson  <rpj@ixobrychus.canberra.edu.au> + +	* tsd1.c: Re-written. See comments at start of file. +	* Template.c: New. Contains skeleton code and comment template +	intended to fully document the test. +  Fri Oct 16 17:59:49 1998  Ross Johnson  <rpj@swan.canberra.edu.au>  	* tsd1.c (destroy_key): Add function. Change diagnostics. diff --git a/tests/Template.c b/tests/Template.c new file mode 100644 index 0000000..50a81bf --- /dev/null +++ b/tests/Template.c @@ -0,0 +1,68 @@ +/* + * File:  + * + * Test Synopsis: + * -  + * + * Test Method (Validation or Falsification): + * -  + * + * Requirements Tested: + * -  + * + * Features Tested: + * -  + * + * Cases Tested: + * -  + * + * Description: + * -  + * + * Environment: + * -  + * + * Input: + * -  + * + * Output: + * -  + * + * Assumptions: + * -  + * + * Pass Criteria: + * -  + * + * Fail Criteria: + * -  + */ + +#include <pthread.h> +#include <stdio.h> + +pthread_key_t key; +pthread_once_t key_once = PTHREAD_ONCE_INIT; + +void * +mythread(void * arg) +{ +  return 0; +} + +int +main() +{ +  int rc; +  pthread_t t1, t2; +   +  rc = pthread_create(&t1, NULL, mythread, (void *) 1); +  printf("pthread_create returned %d\n", rc); + +  rc = pthread_create(&t2, NULL, mythread, (void *) 2); +  printf("pthread_create returned %d\n", rc); + +  /* Give threads time to run. */ +  Sleep(2000); +  return 0; +} diff --git a/tests/tsd1.c b/tests/tsd1.c index aa2d3da..5236fe7 100644 --- a/tests/tsd1.c +++ b/tests/tsd1.c @@ -1,7 +1,53 @@ +/* + * File: tsd1.c + * + * Test Synopsis: + * - Thread Specific Data (TSD) key creation and destruction. + * + * Description: + * -  + * + * Test Method (validation or falsification): + * - validation + * + * Requirements Tested: + * - keys are created for each existing thread including the main thread + * - keys are created for newly created threads + * - keys are thread specific + * - destroy routine is called on each thread exit including the main thread + * + * Features Tested: + * -  + * + * Cases Tested: + * -  + * + * Environment: + * -  + * + * Input: + * - none + * + * Output: + * - text to stdout + * + * Assumptions: + * - already validated:     pthread_create() + *                          pthread_once() + * - main thread also has a POSIX thread identity + * + * Pass Criteria: + * - stdout matches file reference/tsd1.out + * + * Fail Criteria: + * - fails to match file reference/tsd1.out + * - output identifies failed component + */ +  #include <pthread.h>  #include <stdio.h> -pthread_key_t key; +pthread_key_t key = NULL;  pthread_once_t key_once = PTHREAD_ONCE_INIT;  void @@ -11,9 +57,6 @@ destroy_key(void * arg)    printf("SUCCESS: %s: destroying key.\n", (char *) arg);    free((char *) arg); - -  /* Is it our responsibility to do this? */ -  arg = NULL;  }  void @@ -26,44 +69,50 @@ make_key(void)      }  } -void * -mythread(void * arg) +void +setkey(void * arg)  {    void * ptr; -  (void) pthread_once(&key_once, make_key); -    if ((ptr = pthread_getspecific(key)) != NULL)      { -      printf("ERROR: Thread %d, Key 0x%x not initialised to NULL\n", -	     (int) arg, -	     (int) key); +      printf("ERROR: Thread %d, Key not initialised to NULL\n", +	     (int) arg);        exit(1);      }    else      {        ptr = (void *) malloc(80); -      sprintf((char *) ptr, "Thread %d Key 0x%x", -	      (int) arg, -	      (int) key); +      sprintf((char *) ptr, "Thread %d Key", +	      (int) arg);        (void) pthread_setspecific(key, ptr);      }    if ((ptr = pthread_getspecific(key)) == NULL)      { -      printf("FAILED: Thread %d Key 0x%x: key value set or get failed.\n", -	     (int) arg, -	     (int) key); +      printf("FAILED: Thread %d Key value set or get failed.\n", +	     (int) arg);        exit(1);      }    else      { -      printf("SUCCESS: Thread %d Key 0x%x: key value set and get succeeded.\n", -	     (int) arg, -	     (int) key); +      printf("SUCCESS: Thread %d Key value set and get succeeded.\n", +	     (int) arg);        printf("SUCCESS: %s: exiting thread.\n", (char *) ptr);      } +} + +void * +mythread(void * arg) +{ +  while (key == NULL) +    { +    } + +  printf("Thread %d, Key created\n", (int) arg); + +  setkey(arg);    return 0; @@ -74,14 +123,29 @@ int  main()  {    int rc; -  pthread_t t1, t2; -   -  rc = pthread_create(&t1, NULL, mythread, (void *) 1); -  printf("pthread_create returned %d\n", rc); +  int t; +  pthread_t thread[10]; -  rc = pthread_create(&t2, NULL, mythread, (void *) 2); -  printf("pthread_create returned %d\n", rc); +  for (t = 0; t < 5; t++) +    { +      rc = pthread_create(&thread[t], NULL, mythread, (void *) (t + 1)); +      printf("pthread_create returned %d\n", rc); +    } + +  (void) pthread_once(&key_once, make_key); + +  /* Test main thread key. */ +  setkey((void *) 0); + +  Sleep(500); + +  for (t = 5; t < 10; t++) +    { +      rc = pthread_create(&thread[t], NULL, mythread, (void *) (t + 1)); +      printf("pthread_create returned %d\n", rc); +    }    Sleep(2000);    return 0;  } + | 
