summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/sprmsched02/init.c
blob: 235e91636bccddfe52b3a7f9901f9a0d972ae9dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 *  COPYRIGHT (c) 2017 Kuan-Hsun Chen.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#define TEST_INIT

#include <rtems/cpuuse.h>
#include <tmacros.h>
#include <rtems/rtems/ratemonimpl.h>
#include "test_support.h"

const char rtems_test_name[] = "SPRMSCHED 2";

/* forward declarations to avoid warnings */
rtems_task Init( rtems_task_argument argument );
static void modify_count( rtems_id id );

static void modify_count(
  rtems_id            id
)
{
  Rate_monotonic_Control                  *the_period;
  ISR_lock_Context                        lock_context;

  the_period = _Rate_monotonic_Get( id, &lock_context );
  _Rate_monotonic_Acquire_critical( the_period, &lock_context );
  the_period->postponed_jobs = UINT32_MAX;
  _Rate_monotonic_Release( the_period, &lock_context );
}

rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_id                                period_id;
  rtems_name                              period_name;
  rtems_rate_monotonic_period_status      period_status;
  rtems_status_code                       status;
  int                                     i;

  period_name = rtems_build_name('P','E','R','1');

  TEST_BEGIN();

  /* create period */
  status = rtems_rate_monotonic_create(
      period_name,
      &period_id
  );
  directive_failed( status, "rate_monotonic_create" );

  /* modify the count to UINT32_MAX and attempt to miss deadline*/
  puts( "Testing overflow condition" );
  rtems_test_spin_until_next_tick();
  status = rtems_rate_monotonic_period( period_id, 50 );
  directive_failed( status, "rate_monotonic_period above loop" );

  puts( "Modify the count of postponed_job manually" );
  modify_count( period_id );

  /* Check the status */
  status = rtems_rate_monotonic_get_status( period_id, &period_status );
  directive_failed( status, "rate_monotonic_get_status" );
  printf( "Init Postponed jobs = %"PRIu32", and expected %"PRIu32"\n", period_status.postponed_jobs_count, UINT32_MAX );
  rtems_test_assert( period_status.postponed_jobs_count == UINT32_MAX );

  for ( i=1 ; i <= 2 ; i++ ) {
    status = rtems_task_wake_after( 100 );
    directive_failed( status, "rtems_task_wake_after(100)" );
    puts( "Task misses its deadline." );

    /* Check the status */
    status = rtems_rate_monotonic_get_status( period_id, &period_status );
    directive_failed( status, "rate_monotonic_get_status" );

    /* print out the count which should keep in UINT32_MAX, since the period still misses its deadline */
    printf( "Count = %"PRIu32", and expected %"PRIu32"\n", period_status.postponed_jobs_count, UINT32_MAX);
    rtems_test_assert( period_status.postponed_jobs_count == UINT32_MAX);

    rtems_test_spin_until_next_tick();
    status = rtems_rate_monotonic_period( period_id, 50 );
    fatal_directive_status(
      status,
      RTEMS_TIMEOUT,
      "rtems_rate_monotonic_period 2-n"
    );


  }

  TEST_END();

  rtems_test_exit(0);
}

/* configuration information */

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MILLISECONDS_PER_TICK 1

#define CONFIGURE_MAXIMUM_TASKS             1
#define CONFIGURE_MAXIMUM_PERIODS           1

#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE


#define CONFIGURE_INIT

#include <rtems/confdefs.h>
/* end of file */