]> rtime.felk.cvut.cz Git - rtems-devel.git/blob - rtems-tests/prioinh_posix/init.c
Portable version of priority inheritance check (Posix API based).
[rtems-devel.git] / rtems-tests / prioinh_posix / init.c
1 /*  Init
2  *
3  *  This routine is the initialization task for this test program.
4  *  It is called from init_exec and has the responsibility for creating
5  *  and starting the tasks that make up the test.  If the time of day
6  *  clock is required for the test, it should also be set to a known
7  *  value by this function.
8  *
9  *  Input parameters:  NONE
10  *
11  *  Output parameters:  NONE
12  *
13  *  COPYRIGHT (c) 1989-1999.
14  *  On-Line Applications Research Corporation (OAR).
15  *
16  *  The license and distribution terms for this file may be
17  *  found in the file LICENSE in this distribution or at
18  *  http://www.rtems.com/license/LICENSE.
19  *
20  *  $Id: init.c,v 1.12.4.1 2003/09/04 18:46:30 joel Exp $
21  */
22
23 #define CONFIGURE_INIT
24 #include "system.h"
25 #include "app_def.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <rtems/error.h>
29 #include <rtems/monitor.h>
30 #include <rtems/shell.h>
31 #include <pthread.h>
32
33 #define VER_CODE(major,minor,patch) (major*0x10000+minor*0x100+patch)
34
35 #define BUILD_VERSION_STRING(major,minor,patch) \
36         __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch)
37
38 #define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
39
40 #if RTEMS_VER_CODE < VER_CODE(4,7,99)
41   #define rtems_shell_add_cmd shell_add_cmd
42   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
43                 shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever)
44 #elif RTEMS_VER_CODE < VER_CODE(4,9,99)
45   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
46           rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
47 #endif
48
49 void 
50 bad_rtems_status(rtems_status_code status, int fail_level, const char *text)
51 {
52   printf("ERROR: %s status %s\n", text, rtems_status_text(status));
53   status = rtems_task_delete( RTEMS_SELF );
54 }
55
56 int testcmd_forshell(int argc, char **argv)
57 {
58   int i;
59   printf("Command %s called\n",argv[0]);
60   for(i=1;i<argc;i++)
61     if(argv[i])
62       printf("%s",argv[i]);
63   printf("\n");
64   return 0;
65 }
66
67 rtems_task Init(
68   rtems_task_argument ignored
69 )
70 {
71   rtems_status_code status;
72   pthread_attr_t taskattr;
73   struct sched_param schedparam;
74   pthread_t task_id;
75
76   printf( "\n\nRTEMS v "
77           BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
78           "\n");
79   
80   rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL);
81   /*rtems_capture_cli_init (0);*/
82   
83   printf( "Starting application prioinh_check\n" );
84
85   status = pthread_attr_init(&taskattr);
86   if(status!=0) bad_status(status, 0, "pthread_attr_init 1" );
87   status = pthread_attr_setinheritsched(&taskattr, PTHREAD_EXPLICIT_SCHED);
88   if(status!=0) bad_status(status, 0, "pthread_attr_setinheritsched 1" );
89   status = pthread_attr_setschedpolicy(&taskattr, SCHED_FIFO);
90   if(status!=0) bad_status(status, 0, "pthread_attr_setschedpolicy 1" );
91   schedparam.sched_priority = sched_get_priority_min(SCHED_FIFO) + TASK_1_PRIORITY;
92   status = pthread_attr_setschedparam(&taskattr, &schedparam);
93   if(status!=0) bad_status(status, 0, "pthread_attr_setschedparam 1" );
94   status = pthread_create(&task_id, &taskattr, Task_1, NULL);
95   if(status!=0) bad_status(status, 0, "pthread_create 1\n");
96
97   if(1) {
98
99     rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
100               SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
101
102     rtems_shell_add_cmd("testcmd", "app",
103                 "test command for shell",
104                 testcmd_forshell);
105
106     //rtems_monitor_wakeup();
107
108   }
109
110   status = rtems_task_delete( RTEMS_SELF );
111   
112   printf( "*** END OF TEST2 ***\n" );
113   exit( 0 );
114 }