source: rtems/testsuites/psxtests/psxkey03/init.c @ ea7d86b

4.104.115
Last change on this file since ea7d86b was ea7d86b, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 12, 2009 at 12:21:51 AM

2009-11-11 Joel Sherrill <joel.sherrill@…>

PR 1466/tests

  • Makefile.am, configure.ac, psxclock/init.c, psxclock/psxclock.doc, psxclock/psxclock.scn, psxkey03/init.c, psxsignal02/init.c, psxsignal03/init.c, psxstack01/init.c: Remove usleep() from tests. Add test specifically to test it since it is deprecated as of POSIX.1-2008.
  • psxusleep/.cvsignore, psxusleep/Makefile.am, psxusleep/init.c, psxusleep/psxusleep.doc, psxusleep/psxusleep.scn: New files.
  • Property mode set to 100644
File size: 2.4 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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <pthread.h>
13#include <errno.h>
14#include "tmacros.h"
15#include "pmacros.h"
16
17pthread_key_t Key;
18volatile bool destructor_ran;
19
20void destructor(void *value)
21{
22  destructor_ran = true;
23}
24
25void *Test_Thread(
26  void *key_value
27)
28{
29  int sc;
30
31  puts( "Test_Thread - pthread_setspecific - OK" );
32  sc = pthread_setspecific( Key, key_value );
33  assert( !sc );
34 
35  puts( "Test_Thread - pthread_exit to run key destructors - OK" );
36  return NULL;
37}
38
39void *POSIX_Init(
40  void *ignored
41)
42{
43  pthread_t        thread;
44  int              sc;
45  struct timespec  delay_request;
46
47  puts( "\n\n*** TEST KEY 03 ***" );
48 
49  /*
50   *  Key with NULL destructor
51   */
52  puts( "Init - pthread_key_create with NULL destructor - OK" );
53  sc = pthread_key_create( &Key, NULL );
54  assert( !sc ); 
55
56  puts( "Init - pthread_create - OK" );
57  sc = pthread_create( &thread, NULL, Test_Thread, &sc );
58  assert( !sc );
59
60  puts( "Init - sleep - let thread run - OK" );
61  delay_request.tv_sec = 0;
62  delay_request.tv_nsec = 5 * 100000000;
63  sc = nanosleep( &delay_request, NULL );
64  assert( !sc );
65
66  puts( "Init - pthread_key_delete - OK" );
67  sc = pthread_key_delete( Key );
68  assert( sc == 0 );
69
70  /*
71   *  Key with non-NULL destructor
72   */
73  destructor_ran = false;
74  puts( "Init - pthread_key_create with non-NULL destructor - OK" );
75  sc = pthread_key_create( &Key, destructor );
76  assert( !sc ); 
77
78  puts( "Init - pthread_create - OK" );
79  sc = pthread_create( &thread, NULL, Test_Thread, NULL );
80  assert( !sc );
81
82  puts( "Init - sleep - let thread run - OK" );
83  sc = nanosleep( &delay_request, NULL );
84  assert( !sc );
85
86  puts( "Init - verify destructor did NOT ran" );
87  assert( destructor_ran == false );
88
89  puts( "Init - pthread_key_delete - OK" );
90  sc = pthread_key_delete( Key );
91  assert( sc == 0 );
92
93  puts( "*** END OF TEST KEY 03 ***" );
94  rtems_test_exit(0);
95}
96
97/* configuration information */
98
99#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
100#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
101
102#define CONFIGURE_MAXIMUM_POSIX_THREADS  2
103#define CONFIGURE_MAXIMUM_POSIX_KEYS     1
104
105#define CONFIGURE_POSIX_INIT_THREAD_TABLE
106
107#define CONFIGURE_INIT
108#include <rtems/confdefs.h>
109
110/* global variables */
Note: See TracBrowser for help on using the repository browser.