source: rtems/testsuites/samples/unlimited/init.c

Last change on this file was e71f0909, checked in by Joel Sherrill <joel@…>, on 04/07/22 at 16:13:34

testsuites/samples: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2012.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#define CONFIGURE_INIT
34
35#include "system.h"
36#include "tmacros.h"
37#include <stdio.h>
38#include <stdlib.h>
39
40const char rtems_test_name[] = "UNLIMITED TASK";
41
42rtems_id task_id[MAX_TASKS];
43
44rtems_task Init(
45  rtems_task_argument ignored
46)
47{
48  rtems_task_priority old_priority;
49  rtems_mode          old_mode;
50  uint32_t            task;
51
52  TEST_BEGIN();
53
54  /* lower the task priority to allow created tasks to execute */
55
56  rtems_task_set_priority(
57    RTEMS_SELF, RTEMS_MAXIMUM_PRIORITY - 1, &old_priority);
58  rtems_task_mode(RTEMS_PREEMPT,  RTEMS_PREEMPT_MASK, &old_mode);
59
60  /*
61   * Invalid state if the task id is 0
62   */
63
64  for (task = 0; task < MAX_TASKS; task++)
65    task_id[task] = 0;
66
67  test1();
68  test2();
69  test3();
70
71  TEST_END();
72  exit( 0 );
73}
74
75rtems_task test_task(
76  rtems_task_argument my_number
77)
78{
79  rtems_event_set out;
80  unsigned int    my_n = (unsigned int) my_number;
81
82  printf( "task %u has started.\n",  my_n);
83
84  rtems_event_receive(1, RTEMS_WAIT | RTEMS_EVENT_ANY, 0, &out);
85
86  printf( "task %u ending.\n",  my_n);
87
88  rtems_task_exit();
89}
90
91void destroy_all_tasks(
92  const char *who
93)
94{
95  uint32_t   task;
96
97  /*
98   *  If the id is not zero, signal the task to delete.
99   */
100
101  for (task = 0; task < MAX_TASKS; task++) {
102    if (task_id[task]) {
103      printf(
104        " %s : signal task %08" PRIxrtems_id " to delete, ",
105         who,
106         task_id[task]
107      );
108      fflush(stdout);
109      rtems_event_send(task_id[task], 1);
110      task_id[task] = 0;
111    }
112  }
113}
114
115bool status_code_bad(
116  rtems_status_code status_code
117)
118{
119  if (status_code != RTEMS_SUCCESSFUL)
120  {
121    printf("failure, ");
122
123    if (status_code == RTEMS_TOO_MANY)
124    {
125      printf("too many.\n");
126      return TRUE;
127    }
128    if (status_code == RTEMS_UNSATISFIED)
129    {
130      printf("unsatisfied.\n");
131      return TRUE;
132    }
133
134    printf("error code = %i\n", status_code);
135    exit( 1 );
136  }
137  return FALSE;
138}
Note: See TracBrowser for help on using the repository browser.