source: rtems/testsuites/psxtests/psxkey08/init.c @ b5c9064

4.115
Last change on this file since b5c9064 was b5c9064, checked in by Zhongwei Yao <ashi08104@…>, on 08/05/13 at 13:20:45

Unlimited objects support for POSIX keys

This patch enables unlimited model in POSIX key manger and have a decent
runtime on POSIX key searching, adding and deleting operations. Memory
overhead is lower than current implementation when the size of key and key
value becomes big.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 *  Copyright (c) 2012 Zhongwei Yao.
3 *  COPYRIGHT (c) 1989-2012.
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.com/license/LICENSE.
9 */
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#include "tmacros.h"
16
17#include <stdio.h>
18#include <rtems.h>
19#include <pthread.h>
20#include <unistd.h>
21#include <errno.h>
22
23pthread_key_t Key;
24int created_task_count, setted_task_count, got_task_count;
25int all_thread_created;
26rtems_id sema1, sema2;
27rtems_name name1, name2;
28
29/* forward declarations to avoid warnings */
30rtems_task Init(rtems_task_argument arg);
31rtems_task test_task(rtems_task_argument arg);
32
33rtems_task test_task(rtems_task_argument arg)
34{
35  int sc;
36  int *value_p, *value_p2;
37
38  value_p = malloc( sizeof( int ) );
39  //printf( "Test_Task%d  - Key pthread_setspecific - OK\n", (int)rtems_task_self() );
40  sc = pthread_setspecific( Key, value_p );
41  rtems_test_assert( !sc );
42  ++setted_task_count;
43  sc = rtems_semaphore_release( sema1 );
44
45  /**
46   * blocked untill all tasks have been created.
47   */
48  rtems_semaphore_obtain( sema2 , RTEMS_WAIT, 0 );
49
50  //printf( "Test_Task%d  - Key pthread_getspecific - OK\n", (int)rtems_task_self() );
51  value_p2 = pthread_getspecific( Key );
52  rtems_test_assert( value_p == value_p2 );
53  ++got_task_count;
54
55  pthread_exit( 0 );
56}
57
58rtems_task Init(rtems_task_argument arg)
59{
60  rtems_status_code status;
61  int              sc;
62  rtems_id        *task_id_p;
63
64  all_thread_created = 0;
65
66  puts( "\n\n*** TEST KEY 08 ***" );
67
68  puts( "Init - Semaphore 1 create - OK" );
69  name1 = rtems_build_name('S', 'E', 'M', '1');
70  sc = rtems_semaphore_create( name1, 0,
71                               RTEMS_SIMPLE_BINARY_SEMAPHORE |
72                               RTEMS_FIFO,
73                               0, &sema1 );
74  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
75
76  puts( "Init - Semaphore 2 create - OK" );
77  name2 = rtems_build_name('S', 'E', 'M', '2');
78  sc = rtems_semaphore_create( name2, 0,
79                               RTEMS_SIMPLE_BINARY_SEMAPHORE |
80                               RTEMS_FIFO,
81                               0, &sema2 );
82  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
83
84  puts( "Init - pthread Key create - OK" );
85  sc = pthread_key_create( &Key, NULL );
86  rtems_test_assert( !sc );
87
88  for( ; ; )
89    {
90      task_id_p = malloc( sizeof( rtems_id ) );
91      rtems_test_assert( task_id_p );
92      sc = rtems_task_create(
93             rtems_build_name('T','A',created_task_count, ' '),
94             1,
95             RTEMS_MINIMUM_STACK_SIZE,
96             RTEMS_DEFAULT_MODES,
97             RTEMS_DEFAULT_ATTRIBUTES,
98             task_id_p
99             );
100      rtems_test_assert( (sc == RTEMS_UNSATISFIED) || (sc == RTEMS_TOO_MANY) || (sc == RTEMS_SUCCESSFUL) );
101      /**
102       * when return is RTEMS_TOO_MANY or RTEMS_UNSATISFIED, there is not
103       * enough source to create task.
104       */
105      if ( (sc == RTEMS_TOO_MANY) || (sc == RTEMS_UNSATISFIED) )
106        {
107          break;
108        }
109      ++created_task_count;
110      sc = rtems_task_start( *task_id_p,  test_task, 0 );
111      rtems_test_assert( sc == RTEMS_SUCCESSFUL );
112      sc = rtems_semaphore_obtain( sema1, RTEMS_WAIT, 0 );
113      rtems_test_assert( sc == RTEMS_SUCCESSFUL );
114    }
115
116  printf( "Init - %d tasks have been created - OK\n", created_task_count );
117  printf( "Init - %d tasks have been setted key data - OK\n", setted_task_count );
118  rtems_test_assert( created_task_count == setted_task_count );
119
120  /* unblock all created tasks to let them set key data.*/
121  puts( "Init - flush semaphore 2 - OK" );
122  sc = rtems_semaphore_flush( sema2 );
123  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
124
125  puts( "Init - sleep to yield processor - OK" );
126  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
127  directive_failed( status, "rtems_task_wake_after" );
128
129  printf( "Init - %d Tasks have been got key data - OK\n", got_task_count );
130  rtems_test_assert( created_task_count == got_task_count );
131  puts( "Init - pthread Key delete - OK" );
132  sc = pthread_key_delete( Key );
133  rtems_test_assert( sc == 0 );
134
135  puts( "Init - semaphore 1 delete - OK" );
136  sc = rtems_semaphore_delete( sema1 );
137  rtems_test_assert( !sc );
138
139  puts( "Init - semaphore 2 delete - OK" );
140  sc = rtems_semaphore_delete( sema2 );
141  rtems_test_assert( !sc );
142
143  puts( "*** END OF TEST KEY 08***" );
144  exit(0);
145}
146
147/* configuration information */
148#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
149#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
150
151#define CONFIGURE_MAXIMUM_TASKS rtems_resource_unlimited(5)
152#define CONFIGURE_MAXIMUM_SEMAPHORES 2
153#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
154
155#define CONFIGURE_INIT_TASK_INITIAL_MODES \
156  (RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(0))
157
158#define CONFIGURE_INIT_TASK_PRIORITY 4
159#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
160
161#define CONFIGURE_UNIFIED_WORK_AREAS
162
163#define CONFIGURE_INIT
164#include <rtems/confdefs.h>
165/* end of file */
Note: See TracBrowser for help on using the repository browser.