source: rtems/testsuites/sptests/spintrcritical16/init.c @ 8028089

4.115
Last change on this file since 8028089 was 8028089, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/14 at 13:18:07

tests: Rework interrupt critical tests

This avoids test durations of more than one hour on fast targets, since
fast targets can count a lot during one clock tick period, so the minor
loop iteration count was quite high. Estimate now the test body
duration to iterate only through the interesting time window.

Add and use interrupt_critical_section_test().

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include <intrcritical.h>
16
17#include <rtems/rtems/semimpl.h>
18
19const char rtems_test_name[] = "SPINTRCRITICAL 16";
20
21/* forward declarations to avoid warnings */
22rtems_task Init(rtems_task_argument argument);
23rtems_timer_service_routine test_release_from_isr(rtems_id  timer, void *arg);
24Thread_blocking_operation_States getState(void);
25
26Thread_Control *Main_TCB;
27rtems_id        Semaphore;
28volatile bool   case_hit = false;
29
30Thread_blocking_operation_States getState(void)
31{
32  Objects_Locations  location;
33  Semaphore_Control *sem;
34
35  sem = (Semaphore_Control *)_Objects_Get(
36    &_Semaphore_Information, Semaphore, &location );
37  if ( location != OBJECTS_LOCAL ) {
38    puts( "Bad object lookup" );
39    rtems_test_exit(0);
40  }
41  _Thread_Unnest_dispatch();
42
43  return sem->Core_control.semaphore.Wait_queue.sync_state;
44}
45
46rtems_timer_service_routine test_release_from_isr(
47  rtems_id  timer,
48  void     *arg
49)
50{
51  if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
52    case_hit = true;
53    (void) rtems_semaphore_release( Semaphore );
54  }
55
56  if ( Main_TCB->Wait.queue != NULL ) {
57    _Thread_queue_Process_timeout( Main_TCB );
58  }
59}
60
61static bool test_body( void *arg )
62{
63  rtems_status_code sc;
64
65  (void) arg;
66
67  sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 2 );
68  rtems_test_assert( sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT );
69
70  return case_hit;
71}
72
73rtems_task Init(
74  rtems_task_argument ignored
75)
76{
77  rtems_status_code     sc;
78
79  TEST_BEGIN();
80  puts(
81    "Init - Trying to generate timeout of a thread that had its blocking\n"
82    "Init -   request satisfied while blocking but before time timeout"
83  );
84
85  puts( "Init - rtems_semaphore_create - OK" );
86  sc = rtems_semaphore_create(
87    rtems_build_name( 'S', 'M', '1', ' ' ),
88    0,
89    RTEMS_DEFAULT_ATTRIBUTES,
90    RTEMS_NO_PRIORITY,
91    &Semaphore
92  );
93  directive_failed( sc, "rtems_semaphore_create of SM1" );
94
95  Main_TCB  = _Thread_Get_executing();
96
97  interrupt_critical_section_test( test_body, NULL, test_release_from_isr );
98
99  if ( case_hit ) {
100    puts( "Init - Case hit" );
101    TEST_END();
102  } else
103    puts( "Init - Case not hit - ran too long" );
104
105
106  rtems_test_exit(0);
107}
108
109/* configuration information */
110
111#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
112#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
113
114#define CONFIGURE_MAXIMUM_TASKS          1
115#define CONFIGURE_MAXIMUM_TIMERS         1
116#define CONFIGURE_MAXIMUM_SEMAPHORES     1
117#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
118#define CONFIGURE_MICROSECONDS_PER_TICK  1000
119#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
120
121#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
122
123#define CONFIGURE_INIT
124#include <rtems/confdefs.h>
125
126/* global variables */
Note: See TracBrowser for help on using the repository browser.