source: rtems/testsuites/mptests/mp08/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.5 KB
RevLine 
[42d4ebe]1/* SPDX-License-Identifier: BSD-2-Clause */
2
[ac7d5ef0]3/*  Test_task
4 *
5 *  This task tests global semaphore operations.  It verifies that
6 *  global semaphore errors are correctly returned.
7 *
8 *  Input parameters:
9 *    argument - task argument
10 *
11 *  Output parameters:  NONE
12 *
[9992cac]13 *  COPYRIGHT (c) 1989-2009.
[ac7d5ef0]14 *  On-Line Applications Research Corporation (OAR).
15 *
[42d4ebe]16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
[ac7d5ef0]36 */
37
[a4bc4d6e]38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#endif
41
[ac7d5ef0]42#include "system.h"
43
44rtems_task Test_task(
45  rtems_task_argument argument
46)
47{
[d8e681e]48  uint32_t    count;
[ac7d5ef0]49  rtems_status_code status;
50
51  puts( "Getting SMID of semaphore" );
52
53  do {
54    status = rtems_semaphore_ident(
55      Semaphore_name[ 1 ],
56      RTEMS_SEARCH_ALL_NODES,
57      &Semaphore_id[ 1 ]
58    );
59  } while ( !rtems_is_status_successful( status ) );
60
[a00dff42]61  if ( rtems_object_get_local_node() == 2 ) {
[ac7d5ef0]62    status = rtems_semaphore_delete( Semaphore_id[ 1 ] );
63    fatal_directive_status(
64      status,
65      RTEMS_ILLEGAL_ON_REMOTE_OBJECT,
66      "rtems_semaphore_delete did not return RTEMS_ILLEGAL_ON_REMOTE_OBJECT"
67    );
68    puts(
69      "rtems_semaphore_delete correctly returned RTEMS_ILLEGAL_ON_REMOTE_OBJECT"
70    );
71  }
72
73  count = 0;            /* number of times node 1 releases semaphore */
74  while ( FOREVER ) {
75    put_dot( 'p' );
76    status = rtems_semaphore_obtain(
77      Semaphore_id[ 1 ],
78      RTEMS_DEFAULT_OPTIONS,
79      RTEMS_NO_TIMEOUT
80    );
81    if ( status != RTEMS_SUCCESSFUL ) {
82      fatal_directive_status(
83        status,
84        RTEMS_OBJECT_WAS_DELETED,
85        "rtems_semaphore_obtain"
86      );
87      puts( "\nGlobal semaphore deleted" );
88      puts( "*** END OF TEST 8 ***" );
[116845e8]89      rtems_test_exit( 0 );
[ac7d5ef0]90    }
91
[a00dff42]92    if ( rtems_object_get_local_node() == 1 && ++count == 1000 ) {
[9992cac]93      status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
[ac7d5ef0]94      directive_failed( status, "rtems_task_wake_after" );
95
96      puts( "\nDeleting global semaphore" );
97      status = rtems_semaphore_delete( Semaphore_id[ 1 ] );
98      directive_failed( status, "rtems_semaphore_delete" );
99
100      puts( "*** END OF TEST 8 ***" );
[116845e8]101      rtems_test_exit( 0 );
[ac7d5ef0]102    }
103    else {
104      put_dot( 'v' );
105      status = rtems_semaphore_release( Semaphore_id[ 1 ] );
106      directive_failed( status, "rtems_semaphore_release FAILED!!" );
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.