source: rtems/testsuites/tmtests/tm05/task1.c

Last change on this file was b331f40, checked in by Joel Sherrill <joel@…>, on 04/01/22 at 19:05:19

testsuites/tmtests/*: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[b331f40]1/* SPDX-License-Identifier: BSD-2-Clause */
2
[ac7d5ef0]3/*
[9410d011]4 *  COPYRIGHT (c) 1989-2013.
[ac7d5ef0]5 *  On-Line Applications Research Corporation (OAR).
6 *
[b331f40]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.
[ac7d5ef0]27 */
28
[a4bc4d6e]29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
[fdeaa64]33#include <rtems/btimer.h>
34
[d1128e2]35#define CONFIGURE_INIT
[ac7d5ef0]36#include "system.h"
37
[2ead50a]38const char rtems_test_name[] = "TIME TEST 5";
39
[4389287a]40rtems_id   Task_id[OPERATION_COUNT+1];
[0720ff4]41uint32_t   Task_index;
[ac7d5ef0]42
43rtems_task High_task(
44  rtems_task_argument argument
45);
46
47rtems_task Middle_tasks(
48  rtems_task_argument argument
49);
50
51rtems_task Low_task(
52  rtems_task_argument argument
53);
54
[2db98e91]55extern void test_init(void);
[ac7d5ef0]56
[4389287a]57int operation_count = OPERATION_COUNT;
58
[ac7d5ef0]59rtems_task Init(
60  rtems_task_argument argument
61)
62{
[3a4ae6c]63  Print_Warning();
64
[2ead50a]65  TEST_BEGIN();
[ac7d5ef0]66
67  test_init();
68
[51b3cbca]69  rtems_task_exit();
[ac7d5ef0]70}
71
[2db98e91]72void test_init(void)
[ac7d5ef0]73{
74  rtems_status_code   status;
75  rtems_task_entry    task_entry;
76  rtems_task_priority priority;
[0720ff4]77  uint32_t      index;
[ac7d5ef0]78
[4389287a]79  priority = RTEMS_MAXIMUM_PRIORITY - 1;
80
81  if ( OPERATION_COUNT > RTEMS_MAXIMUM_PRIORITY - 2 )
82    operation_count =  RTEMS_MAXIMUM_PRIORITY - 2;
[ac7d5ef0]83
[4389287a]84  for( index = 0; index <= operation_count ; index++ ) {
[ac7d5ef0]85
86    status = rtems_task_create(
87      rtems_build_name( 'T', 'I', 'M', 'E' ),
88      priority,
[3652ad35]89      RTEMS_MINIMUM_STACK_SIZE,
[ac7d5ef0]90      RTEMS_DEFAULT_MODES,
91      RTEMS_DEFAULT_ATTRIBUTES,
92      &Task_id[ index ]
93    );
94    directive_failed( status, "rtems_task_create loop" );
95
96    priority--;
97
98    if ( index==0 )                    task_entry = Low_task;
[4389287a]99    else if ( index==operation_count ) task_entry = High_task;
[ac7d5ef0]100    else                               task_entry = Middle_tasks;
101
102    status = rtems_task_start( Task_id[ index ], task_entry, 0 );
103    directive_failed( status, "rtems_task_start loop" );
104  }
105}
106
107rtems_task High_task(
108  rtems_task_argument argument
109)
110{
[dbf4f17]111  benchmark_timer_initialize();
[ac7d5ef0]112
113  (void) rtems_task_suspend( RTEMS_SELF );
114
[dbf4f17]115  end_time = benchmark_timer_read();
[ac7d5ef0]116
117  put_time(
[9410d011]118    "rtems_task_resume: task readied preempts caller",
[ac7d5ef0]119    end_time,
[4389287a]120    operation_count,
[ac7d5ef0]121    0,
[e58e29fd]122    0
[ac7d5ef0]123  );
124
[2ead50a]125  TEST_END();
[b454bc9]126  rtems_test_exit( 0 );
[ac7d5ef0]127}
128
129rtems_task Middle_tasks(
130  rtems_task_argument argument
131)
132{
133  (void) rtems_task_suspend( RTEMS_SELF );
134
135  Task_index++;
136  (void) rtems_task_resume( Task_id[ Task_index ] );
137}
138
139rtems_task Low_task(
140  rtems_task_argument argument
141)
142{
143
[dbf4f17]144  end_time = benchmark_timer_read();
[ac7d5ef0]145
146  put_time(
[5c491aef]147    "rtems_task_suspend: calling task",
[ac7d5ef0]148    end_time,
[4389287a]149    operation_count,
[ac7d5ef0]150    0,
[e58e29fd]151    0
[ac7d5ef0]152  );
153
154  Task_index = 1;
[dbf4f17]155  benchmark_timer_initialize();
[ac7d5ef0]156  (void) rtems_task_resume( Task_id[ Task_index ] );
157}
Note: See TracBrowser for help on using the repository browser.