source: rtems/testsuites/mptests/mp01/task1.c

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

testsuites/mptests/*: Change license to BSD-2.

Updates #3053.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*  Test_task
4 *
5 *  This task is used for three test tasks.  It obtains its task id and
6 *  based upon that id, performs certain actions.
7 *
8 *       Task_1 delays 5 seconds and deletes itself.
9 *       Task_2 delays 10 seconds and then loops until
10 *             deleted by the third task.
11 *       Task 3 delays 15 seconds, then deletes task 2 and itself.
12 *
13 *  Input parameters:
14 *    argument - task argument
15 *
16 *  Output parameters:  NONE
17 *
18 *  COPYRIGHT (c) 1989-2009.
19 *  On-Line Applications Research Corporation (OAR).
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in the
28 *    documentation and/or other materials provided with the distribution.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 */
42
43#ifdef HAVE_CONFIG_H
44#include "config.h"
45#endif
46
47#include "system.h"
48
49rtems_task Test_task(
50  rtems_task_argument argument
51)
52{
53  rtems_status_code status;
54  rtems_id          tid;
55  rtems_time_of_day time;
56
57  status = rtems_task_ident( RTEMS_WHO_AM_I, RTEMS_SEARCH_ALL_NODES, &tid );
58  directive_failed( status, "rtems_task_ident" );
59
60  status = rtems_clock_get_tod( &time );
61  directive_failed( status, "rtems_clock_get_tod" );
62
63  put_name( Task_name[ task_number( tid ) ], FALSE );
64  print_time( " - rtems_clock_get_tod - ", &time, "\n" );
65
66  status = rtems_task_wake_after( task_number( tid ) * 1 * rtems_clock_get_ticks_per_second() );
67  directive_failed( status, "rtems_task_wake_after" );
68
69  status = rtems_clock_get_tod( &time );
70  directive_failed( status, "rtems_clock_get_tod" );
71  put_name( Task_name[ task_number( tid ) ], FALSE );
72  print_time( " - rtems_clock_get_tod - ", &time, "\n" );
73
74  if ( task_number(tid) == 1 ) {          /* TASK 1 */
75    put_name( Task_name[ 1 ], FALSE );
76    printf( " - deleting self\n" );
77    rtems_task_exit();
78  }
79  else if ( task_number(tid) == 2 ) {     /* TASK 2 */
80    put_name( Task_name[ 2 ], FALSE );
81    printf( " - waiting to be deleted by " );
82    put_name( Task_name[ 3 ], TRUE );
83    while ( FOREVER );
84  }
85  else {                                  /* TASK 3 */
86    put_name( Task_name[ 3 ], FALSE );
87    printf( " - getting TID of " );
88    put_name( Task_name[ 2 ], TRUE );
89    do {
90      status = rtems_task_ident( Task_name[ 2 ], RTEMS_SEARCH_ALL_NODES, &tid );
91    } while ( status != RTEMS_SUCCESSFUL );
92    directive_failed( status, "rtems_task_ident" );
93
94    put_name( Task_name[ 3 ], FALSE );
95    printf( " - deleting " );
96    put_name( Task_name[ 2 ], TRUE );
97    status = rtems_task_delete( tid );
98    directive_failed( status, "rtems_task_delete of Task 2" );
99
100    puts( "*** END OF TEST 1 ***" );
101    rtems_test_exit(0);
102  }
103}
Note: See TracBrowser for help on using the repository browser.