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

Last change on this file since 9a4eca5 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 25, 2014 at 7:06:16 AM

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

  • Property mode set to 100644
File size: 2.7 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
20const char rtems_test_name[] = "PSXKEY 10";
21
22/* forward declarations to avoid warnings */
23rtems_task Init(rtems_task_argument argument);
24rtems_task Test_Thread(rtems_task_argument argument);
25
26void destructor(void *value);
27
28int Data_array[1] = {1};
29
30pthread_key_t key;
31volatile bool destructor_ran;
32
33void destructor(void *value)
34{
35  destructor_ran = true;
36}
37
38rtems_task Test_Thread( rtems_task_argument arg )
39{
40  void *argument = (void *) arg;
41  int sc;
42
43  puts( "Test_Thread - key pthread_setspecific - OK" );
44  sc = pthread_setspecific( key, argument );
45  rtems_test_assert( !sc );
46
47  puts( "Test_Thread - pthread key delete - OK" );
48  sc = pthread_key_delete( key );
49  rtems_test_assert( sc == 0 );
50
51  puts( "Test_Thread - exit but don't run key destructors - OK" );
52  rtems_task_delete( RTEMS_SELF );
53}
54
55rtems_task Init( rtems_task_argument ignored )
56{
57  rtems_id          thread;
58  rtems_status_code rc;
59  int               sc;
60  struct timespec   delay_request;
61
62  TEST_BEGIN();
63
64  puts( "Init - pthread key create with destructor - OK" );
65  sc = pthread_key_create( &key, destructor );
66  rtems_test_assert( !sc );
67
68  puts( "Init - thread create - OK" );
69  rc = rtems_task_create(
70    rtems_build_name( 'T', 'E', 'S', 'T' ), 
71    1,
72    RTEMS_MINIMUM_STACK_SIZE,
73    RTEMS_DEFAULT_MODES,
74    RTEMS_DEFAULT_ATTRIBUTES,
75    &thread
76  );
77  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
78
79  rc = rtems_task_start( thread, Test_Thread, 0 );
80  rtems_test_assert( rc == RTEMS_SUCCESSFUL );
81
82  puts( "Init - sleep - let thread run - OK" );
83  delay_request.tv_sec = 0;
84  delay_request.tv_nsec = 8 * 100000000;
85  sc = nanosleep( &delay_request, NULL );
86  rtems_test_assert( !sc );
87
88  puts( "Init - verify destructor did NOT run - OK" );
89  rtems_test_assert( destructor_ran == false );
90
91  /* puts( "Init - pthread key delete - OK" ); */
92  /* sc = pthread_key_delete( key ); */
93  /* rtems_test_assert( sc == 0 ); */
94
95  TEST_END();
96  rtems_test_exit(0);
97}
98
99/* configuration information */
100
101#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
102#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
103
104#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
105
106#define CONFIGURE_MAXIMUM_TASKS          2
107#define CONFIGURE_MAXIMUM_POSIX_KEYS     1
108
109#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
110
111#define CONFIGURE_INIT
112#include <rtems/confdefs.h>
113
114/* global variables */
Note: See TracBrowser for help on using the repository browser.