source: rtems/testsuites/samples/unlimited/init.c @ 51a95ff9

4.11
Last change on this file since 51a95ff9 was 51a95ff9, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 7, 2014 at 10:43:18 PM

samples/unlimited: Fix printf() warning and clean up

  • Property mode set to 100644
File size: 2.2 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#define CONFIGURE_INIT
15
16#include "system.h"
17#include "tmacros.h"
18#include <stdio.h>
19#include <stdlib.h>
20
21const char rtems_test_name[] = "UNLIMITED TASK";
22
23rtems_id task_id[MAX_TASKS];
24
25rtems_task Init(
26  rtems_task_argument ignored
27)
28{
29  rtems_task_priority old_priority;
30  rtems_mode          old_mode;
31  uint32_t            task;
32
33  TEST_BEGIN();
34
35  /* lower the task priority to allow created tasks to execute */
36
37  rtems_task_set_priority(
38    RTEMS_SELF, RTEMS_MAXIMUM_PRIORITY - 1, &old_priority);
39  rtems_task_mode(RTEMS_PREEMPT,  RTEMS_PREEMPT_MASK, &old_mode);
40
41  /*
42   * Invalid state if the task id is 0
43   */
44
45  for (task = 0; task < MAX_TASKS; task++)
46    task_id[task] = 0;
47
48  test1();
49  test2();
50  test3();
51
52  TEST_END();
53  exit( 0 );
54}
55
56rtems_task test_task(
57  rtems_task_argument my_number
58)
59{
60  rtems_event_set out;
61  unsigned int    my_n = (unsigned int) my_number;
62
63  printf( "task %u has started.\n",  my_n);
64
65  rtems_event_receive(1, RTEMS_WAIT | RTEMS_EVENT_ANY, 0, &out);
66
67  printf( "task %u ending.\n",  my_n);
68
69  rtems_task_delete(RTEMS_SELF);
70}
71
72void destroy_all_tasks(
73  const char *who
74)
75{
76  uint32_t   task;
77
78  /*
79   *  If the id is not zero, signal the task to delete.
80   */
81
82  for (task = 0; task < MAX_TASKS; task++) {
83    if (task_id[task]) {
84      printf(
85        " %s : signal task %08" PRIxrtems_id " to delete, ",
86         who,
87         task_id[task]
88      );
89      fflush(stdout);
90      rtems_event_send(task_id[task], 1);
91      task_id[task] = 0;
92    }
93  }
94}
95
96bool status_code_bad(
97  rtems_status_code status_code
98)
99{
100  if (status_code != RTEMS_SUCCESSFUL)
101  {
102    printf("failure, ");
103
104    if (status_code == RTEMS_TOO_MANY)
105    {
106      printf("too many.\n");
107      return TRUE;
108    }
109    if (status_code == RTEMS_UNSATISFIED)
110    {
111      printf("unsatisfied.\n");
112      return TRUE;
113    }
114
115    printf("error code = %i\n", status_code);
116    exit( 1 );
117  }
118  return FALSE;
119}
Note: See TracBrowser for help on using the repository browser.