source: rtems/testsuites/mptests/mp13/task2.c @ d24b301

5
Last change on this file since d24b301 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*  Test_task2
2 *
3 *  This task attempts to receive control of a global semaphore.
4 *  If running on the node on which the semaphore resides, the wait is
5 *  forever, otherwise it times out on a remote semaphore.
6 *
7 *  Input parameters:
8 *    argument - task argument
9 *
10 *  Output parameters:  NONE
11 *
12 *  COPYRIGHT (c) 1989-2009.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include "system.h"
25
26rtems_task Test_task2(
27  rtems_task_argument argument
28)
29{
30  rtems_status_code status;
31
32  puts( "Getting SMID of semaphore" );
33  do {
34    status = rtems_semaphore_ident(
35      Semaphore_name[ 1 ],
36      RTEMS_SEARCH_ALL_NODES,
37      &Semaphore_id[ 1 ]
38    );
39  } while ( !rtems_is_status_successful( status ) );
40
41  directive_failed( status, "rtems_semaphore_ident" );
42
43  if ( Multiprocessing_configuration.node == 1 ) {
44    status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
45    directive_failed( status, "rtems_task_wake_after" );
46
47    puts( "Releasing semaphore ..." );
48    status = rtems_semaphore_release( Semaphore_id[ 1 ] );
49    directive_failed( status, "rtems_semaphore_release" );
50
51    status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 );
52    directive_failed( status, "rtems_task_wake_after" );
53
54    puts( "Getting semaphore ..." );
55    status = rtems_semaphore_obtain(
56      Semaphore_id[ 1 ],
57      RTEMS_DEFAULT_OPTIONS,
58      RTEMS_NO_TIMEOUT
59    );
60    directive_failed( status, "rtems_semaphore_obtain" );
61
62    puts( "Getting semaphore ..." );
63    status = rtems_semaphore_obtain(
64      Semaphore_id[ 1 ],
65      RTEMS_DEFAULT_OPTIONS,
66      RTEMS_NO_TIMEOUT
67    );
68    puts( "How did I get back from here????" );
69    directive_failed( status, "rtems_semaphore_obtain" );
70  }
71
72/*
73  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 );
74  directive_failed( status, "rtems_task_wake_after" );
75*/
76
77  puts( "Getting semaphore ..." );
78  status = rtems_semaphore_obtain(
79    Semaphore_id[ 1 ],
80    RTEMS_DEFAULT_OPTIONS,
81    RTEMS_NO_TIMEOUT
82  );
83  directive_failed( status, "rtems_semaphore_obtain" );
84
85  puts( "Releasing semaphore ..." );
86  status = rtems_semaphore_release( Semaphore_id[ 1 ] );
87  directive_failed( status, "rtems_semaphore_release" );
88
89  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
90  directive_failed( status, "rtems_task_wake_after" );
91
92  puts( "Getting semaphore ..." );
93  status = rtems_semaphore_obtain(
94    Semaphore_id[ 1 ],
95    RTEMS_DEFAULT_OPTIONS,
96    2 * rtems_clock_get_ticks_per_second()
97  );
98  fatal_directive_status(
99    status,
100    RTEMS_TIMEOUT,
101    "rtems_semaphore_obtain"
102  );
103  puts( "rtems_semaphore_obtain correctly returned RTEMS_TIMEOUT" );
104
105  puts( "*** END OF TEST 13 ***" );
106  rtems_test_exit( 0 );
107}
Note: See TracBrowser for help on using the repository browser.