source: rtems/testsuites/psxtests/psxkey09/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  Copyright (c) 2012 Zhongwei Yao.
3 *  COPYRIGHT (c) 1989-2014.
4 *  On-Line Applications Research Corporation (OAR).
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.org/license/LICENSE.
9 */
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#include <pthread.h>
16#include <errno.h>
17#include "tmacros.h"
18#include "pmacros.h"
19
20
21/* forward declarations to avoid warnings */
22rtems_task Init(rtems_task_argument argument);
23rtems_task Test_Thread(rtems_task_argument argument);
24void destructor(void *value);
25
26int Data_array[1] = {1};
27
28pthread_key_t key;
29volatile bool destructor_ran;
30
31void destructor(void *value)
32{
33  destructor_ran = true;
34}
35
36rtems_task Test_Thread( rtems_task_argument arg )
37{
38  void *argument = (void *)arg;
39  int   sc;
40
41  puts( "Test_Thread - key pthread_setspecific - OK" );
42  sc = pthread_setspecific( key, argument );
43  rtems_test_assert( !sc );
44
45  puts( "Test_Thread - pthread_exit to run key destructors - OK" );
46  rtems_task_delete( RTEMS_SELF );
47}
48
49rtems_task Init( rtems_task_argument ignored )
50{
51  rtems_id          thread;
52  rtems_status_code rc;
53  int               sc;
54  struct timespec   delay_request;
55
56  puts( "\n\n*** TEST KEY 09 ***" );
57
58  puts( "Init - pthread key create with destructor - OK" );
59  sc = pthread_key_create( &key, destructor );
60  rtems_test_assert( !sc );
61
62  puts( "Init - thread create - OK" );
63  rc = rtems_task_create(
64    rtems_build_name( 'T', 'E', 'S', 'T' ),
65    1,
66    RTEMS_MINIMUM_STACK_SIZE,
67    RTEMS_DEFAULT_MODES,
68    RTEMS_DEFAULT_ATTRIBUTES,
69    &thread
70  );
71  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
72
73  rc = rtems_task_start( thread, Test_Thread, (rtems_task_argument)Data_array );
74  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
75
76  puts( "Init - sleep - let thread run - OK" );
77  delay_request.tv_sec = 0;
78  delay_request.tv_nsec = 8 * 100000000;
79  sc = nanosleep( &delay_request, NULL );
80  rtems_test_assert( !sc );
81
82  puts( "Init - verify destructor run - OK" );
83  rtems_test_assert( destructor_ran == true );
84
85  puts( "Init - pthread key delete - OK" );
86  sc = pthread_key_delete( key );
87  rtems_test_assert( sc == 0 );
88
89  puts( "*** END OF TEST KEY 09 ***" );
90  rtems_test_exit(0);
91}
92
93/* configuration information */
94
95#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
96#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
97
98#define CONFIGURE_MAXIMUM_TASKS          2
99#define CONFIGURE_MAXIMUM_POSIX_KEYS     1
100
101#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
102
103#define CONFIGURE_INIT
104#include <rtems/confdefs.h>
105
106/* global variables */
Note: See TracBrowser for help on using the repository browser.