source: rtems/testsuites/psxtests/psxstack02/init.c @ b422aa3f

5
Last change on this file since b422aa3f was b422aa3f, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 26, 2018 at 2:05:45 PM

tests: Remove configure feature checks

Update #3409.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include "test_support.h"
16
17#include <errno.h>
18#include <pthread.h>
19#include <sched.h>
20
21#include <rtems/posix/pthreadimpl.h>
22#include <rtems/score/stackimpl.h>
23
24const char rtems_test_name[] = "PSXSTACK 2";
25
26/* forward declarations to avoid warnings */
27void *POSIX_Init(void *argument);
28void *Test_Thread(void *arg);
29
30void *Stack_Low;
31void *Stack_High;
32
33void *Test_Thread(void *arg)
34{
35  #if defined(__GNUC__)
36    void *sp = __builtin_frame_address(0);
37
38    #if 0
39      printf( "Stack(%p - %p) and sp=%p\n", Stack_Low, Stack_High, sp );
40    #endif
41
42    if ( sp >= Stack_Low && sp <= Stack_High )
43      puts( "Test_Thread - running on user provided stack - OK" );
44    else {
45      puts( "Test_Thread - ERROR running on other stack" );
46      rtems_test_exit(0);
47    }
48  #else
49      puts( "Test_Thread - no way to get stack pointer and verify" );
50  #endif
51  puts( "Test_Thread - delete self" );
52  return NULL;
53}
54
55void *POSIX_Init(void *argument)
56{
57  int                 sc;
58  pthread_t           id;
59  pthread_attr_t      attr;
60  struct timespec     delay_request;
61
62  TEST_BEGIN();
63
64  puts( "Init - Allocate stack from heap" );
65  Stack_Low = malloc(PTHREAD_MINIMUM_STACK_SIZE);
66  rtems_test_assert( Stack_Low );
67  Stack_High = Stack_Low + PTHREAD_MINIMUM_STACK_SIZE;
68
69  puts( "Init - Initialize thread attribute for user provided stack" );
70  sc = pthread_attr_init( &attr );
71  rtems_test_assert( !sc );
72
73  sc = pthread_attr_setstack( &attr, Stack_Low, PTHREAD_MINIMUM_STACK_SIZE );
74  rtems_test_assert( !sc );
75
76  /* create threads */
77  sc = pthread_create( &id, &attr, Test_Thread, NULL );
78  rtems_test_assert( !sc );
79
80  puts( "Init - let other thread run" );
81  delay_request.tv_sec = 0;
82  delay_request.tv_nsec = 5 * 100000000;
83  sc = nanosleep( &delay_request, NULL );
84  rtems_test_assert( !sc );
85
86  TEST_END();
87
88  rtems_test_exit(0);
89}
90
91/* configuration information */
92
93#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
94#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
95
96#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
97
98#define CONFIGURE_MAXIMUM_POSIX_THREADS        2
99
100#define CONFIGURE_POSIX_INIT_THREAD_TABLE
101
102#define CONFIGURE_INIT
103#include <rtems/confdefs.h>
104/* end of file */
Note: See TracBrowser for help on using the repository browser.