source: rtems/testsuites/psxtests/psx06/init.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16#include <errno.h>
17
18const char rtems_test_name[] = "PSX 6";
19
20extern void Key_destructor( void *key_data );
21
22void Key_destructor(
23 void *key_data
24)
25{
26  Destructor_invoked++;
27
28  /*
29   *  This checks out that we only run the destructor multiple times
30   *  when the key data is non null.
31   */
32
33  if ( Destructor_invoked == 5 )
34     (void) pthread_setspecific( Key_id, NULL );
35}
36
37void *POSIX_Init(
38  void *argument
39)
40{
41  int               status;
42  unsigned int      remaining;
43  uint32_t   *key_data;
44
45  TEST_BEGIN();
46
47  /* set the time of day, and print our buffer in multiple ways */
48
49  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
50
51  /* get id of this thread */
52
53  Init_id = pthread_self();
54  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
55
56  /* create a couple of threads */
57
58  status = pthread_create( &Task_id, NULL, Task_1, NULL );
59  rtems_test_assert( !status );
60
61  status = pthread_create( &Task2_id, NULL, Task_2, NULL );
62  rtems_test_assert( !status );
63
64  /* create a key */
65
66  empty_line();
67
68  Destructor_invoked = 0;
69  puts( "Init: pthread_key_create - SUCCESSFUL" );
70  status = pthread_key_create( &Key_id, Key_destructor );
71  if ( status )
72    printf( "status = %d\n", status );
73  rtems_test_assert( !status );
74
75  printf( "Destructor invoked %d times\n", Destructor_invoked );
76
77  puts( "Init: pthread_key_create - EAGAIN (too many keys)" );
78  status = pthread_key_create( &Key_id, Key_destructor );
79  rtems_test_assert( status == EAGAIN );
80
81  puts( "Init: pthread_setspecific - EINVAL (invalid key)" );
82  status = pthread_setspecific( (pthread_t) -1, &Data_array[ 0 ] );
83  rtems_test_assert( status == EINVAL );
84
85  puts( "Init: pthread_getspecific - EINVAL (invalid key)" );
86  key_data = pthread_getspecific( (pthread_t) -1 );
87  rtems_test_assert( !key_data );
88
89  puts( "Init: pthread_key_delete - EINVAL (invalid key)" );
90  status = pthread_key_delete( (pthread_t) -1 );
91  rtems_test_assert( status == EINVAL );
92
93  printf( "Init: Setting the key to %d\n", 0 );
94  status = pthread_setspecific( Key_id, &Data_array[ 0 ] );
95  if ( status )
96    printf( "status = %d\n", status );
97  rtems_test_assert( !status );
98
99     /* switch to task 1 */
100
101  key_data = pthread_getspecific( Key_id );
102  printf( "Init: Got the key value of %ld\n",
103          (unsigned long) ((uint32_t   *)key_data - Data_array) );
104
105  remaining = sleep( 3 );
106  if ( remaining )
107     printf( "seconds remaining = %d\n", remaining );
108  rtems_test_assert( !remaining );
109
110     /* switch to task 1 */
111
112  /* delete the key */
113
114  puts( "Init: pthread_key_delete - SUCCESSFUL" );
115  status = pthread_key_delete( Key_id );
116  if ( status )
117    printf( "status = %d\n", status );
118  rtems_test_assert( !status );
119
120  printf( "Destructor invoked %d times\n", Destructor_invoked );
121
122  TEST_END();
123  rtems_test_exit( 0 );
124
125  return NULL; /* just so the compiler thinks we returned something */
126}
Note: See TracBrowser for help on using the repository browser.