source:
rtems/testsuites/psxtests/psxstack01/init.c
@
33c46f1
Last change on this file since 33c46f1 was 33c46f1, checked in by Joel Sherrill <joel.sherrill@…>, on 10/21/10 at 21:22:25 | |
---|---|
|
|
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 | #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ |
13 | #include <pmacros.h> |
14 | #include <errno.h> |
15 | #include <pthread.h> |
16 | #include <sched.h> |
17 | |
18 | #include <rtems/posix/pthread.h> /* for PTHREAD_MINIMUM_STACK_SIZE */ |
19 | |
20 | void *Stack_Low; |
21 | void *Stack_High; |
22 | |
23 | void *Test_Thread(void *arg) |
24 | { |
25 | #if defined(__GNUC__) |
26 | void *sp = __builtin_frame_address(0); |
27 | |
28 | #if 0 |
29 | printf( "Stack(%p - %p) and sp=%p\n", Stack_Low, Stack_High, sp ); |
30 | #endif |
31 | |
32 | if ( sp >= Stack_Low && sp <= Stack_High ) |
33 | puts( "Test_Thread - running on user provided stack - OK" ); |
34 | else { |
35 | puts( "Test_Thread - ERROR running on other stack" ); |
36 | rtems_test_exit(0); |
37 | } |
38 | #else |
39 | puts( "Test_Thread - no way to get stack pointer and verify" ); |
40 | #endif |
41 | puts( "Test_Thread - delete self" ); |
42 | return NULL; |
43 | } |
44 | |
45 | void *POSIX_Init( |
46 | void *argument |
47 | ) |
48 | { |
49 | int sc; |
50 | pthread_t id; |
51 | pthread_attr_t attr; |
52 | struct timespec delay_request; |
53 | |
54 | puts( "\n\n*** POSIX STACK ATTRIBUTE TEST 01 ***" ); |
55 | |
56 | puts( "Init - Allocate stack from heap" ); |
57 | Stack_Low = malloc(PTHREAD_MINIMUM_STACK_SIZE); |
58 | rtems_test_assert( Stack_Low ); |
59 | Stack_High = Stack_Low + PTHREAD_MINIMUM_STACK_SIZE; |
60 | |
61 | puts( "Init - Initialize thread attribute for user provided stack" ); |
62 | sc = pthread_attr_init( &attr ); |
63 | rtems_test_assert( !sc ); |
64 | |
65 | sc = pthread_attr_setstackaddr( &attr, Stack_Low ); |
66 | rtems_test_assert( !sc ); |
67 | |
68 | sc = pthread_attr_setstacksize( &attr, PTHREAD_MINIMUM_STACK_SIZE ); |
69 | rtems_test_assert( !sc ); |
70 | |
71 | /* create threads */ |
72 | sc = pthread_create( &id, &attr, Test_Thread, NULL ); |
73 | rtems_test_assert( !sc ); |
74 | |
75 | puts( "Init - let other thread run" ); |
76 | delay_request.tv_sec = 0; |
77 | delay_request.tv_nsec = 5 * 100000000; |
78 | sc = nanosleep( &delay_request, NULL ); |
79 | rtems_test_assert( !sc ); |
80 | |
81 | puts( "*** END OF POSIX STACK ATTRIBUTE TEST 01 ***" ); |
82 | rtems_test_exit(0); |
83 | |
84 | return NULL; /* just so the compiler thinks we returned something */ |
85 | } |
86 | |
87 | /* configuration information */ |
88 | |
89 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
90 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
91 | |
92 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
93 | |
94 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
95 | |
96 | #define CONFIGURE_INIT |
97 | #include <rtems/confdefs.h> |
Note: See TracBrowser
for help on using the repository browser.