diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2014-06-12 07:32:21 -0400 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2014-06-12 08:16:10 -0400 |
| commit | 54ab0e29794e9f22aacd206102d9e4d643e28efe (patch) | |
| tree | d0d5bcfbe0b207aa099e7233818ec83fea9ab763 | |
| parent | aabfa10d86f2be6416eabedd03f52b548379f2d6 (diff) | |
Add test cases for enforcement of periods of periodic tasks
| -rw-r--r-- | tests/sched.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/sched.c b/tests/sched.c index 6fd6d89..a91e736 100644 --- a/tests/sched.c +++ b/tests/sched.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include <sys/wait.h> /* for waitpid() */ | 1 | #include <sys/wait.h> /* for waitpid() */ |
| 2 | #include <unistd.h> | 2 | #include <unistd.h> |
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <math.h> | ||
| 4 | 5 | ||
| 5 | #include "tests.h" | 6 | #include "tests.h" |
| 6 | #include "litmus.h" | 7 | #include "litmus.h" |
| @@ -76,4 +77,86 @@ TESTCASE(preempt_on_resume, P_FP | PSN_EDF, | |||
| 76 | ASSERT( status == SIGUSR2); | 77 | ASSERT( status == SIGUSR2); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 80 | #define PERIOD 100 /* in ms */ | ||
| 81 | #define JOBS 10 | ||
| 82 | #define ACCEPTABLE_MARGIN 5 /* in ms --- must be largish for QEMU */ | ||
| 79 | 83 | ||
| 84 | TESTCASE(jobs_are_rate_limited, LITMUS, | ||
| 85 | "periodic jobs are rate-limited (w/o synchronous release)") | ||
| 86 | { | ||
| 87 | struct rt_task params; | ||
| 88 | double start, end, actual_delta_ms; | ||
| 89 | int i; | ||
| 90 | |||
| 91 | init_rt_task_param(¶ms); | ||
| 92 | params.cpu = 0; | ||
| 93 | params.exec_cost = ms2ns(40); | ||
| 94 | params.period = ms2ns(PERIOD); | ||
| 95 | params.release_policy = TASK_PERIODIC; | ||
| 96 | |||
| 97 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
| 98 | SYSCALL( be_migrate_to_cpu(params.cpu) ); | ||
| 99 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
| 100 | |||
| 101 | start = wctime(); | ||
| 102 | for (i = 0; i < JOBS; i++) | ||
| 103 | SYSCALL( sleep_next_period() ); | ||
| 104 | end = wctime(); | ||
| 105 | |||
| 106 | SYSCALL( task_mode(BACKGROUND_TASK) ); | ||
| 107 | |||
| 108 | actual_delta_ms = (end - start) * 1000.0; | ||
| 109 | if (fabs(JOBS * PERIOD - actual_delta_ms) > ACCEPTABLE_MARGIN) | ||
| 110 | fprintf(stderr, "actual_delta_ms:%.4f expected:%.4f\n", | ||
| 111 | actual_delta_ms, (double) (JOBS * PERIOD)); | ||
| 112 | ASSERT( fabs(JOBS * PERIOD - actual_delta_ms) <= ACCEPTABLE_MARGIN); | ||
| 113 | } | ||
| 114 | |||
| 115 | TESTCASE(jobs_are_rate_limited_synch, LITMUS, | ||
| 116 | "periodic jobs are rate-limited (w/ synchronous release)") | ||
| 117 | { | ||
| 118 | struct rt_task params; | ||
| 119 | double start, end, actual_delta_ms; | ||
| 120 | int i; | ||
| 121 | int child, status, waiters; | ||
| 122 | lt_t delay = ms2ns(100); | ||
| 123 | |||
| 124 | child = FORK_TASK( | ||
| 125 | init_rt_task_param(¶ms); | ||
| 126 | params.cpu = 0; | ||
| 127 | params.exec_cost = ms2ns(5); | ||
| 128 | params.period = ms2ns(PERIOD); | ||
| 129 | params.release_policy = TASK_PERIODIC; | ||
| 130 | |||
| 131 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
| 132 | SYSCALL( be_migrate_to_cpu(params.cpu) ); | ||
| 133 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
| 134 | |||
| 135 | SYSCALL( wait_for_ts_release() ); | ||
| 136 | |||
| 137 | start = wctime(); | ||
| 138 | for (i = 0; i < JOBS; i++) | ||
| 139 | SYSCALL( sleep_next_period() ); | ||
| 140 | end = wctime(); | ||
| 141 | |||
| 142 | SYSCALL( task_mode(BACKGROUND_TASK) ); | ||
| 143 | |||
| 144 | actual_delta_ms = (end - start) * 1000.0; | ||
| 145 | if (fabs(JOBS * PERIOD - actual_delta_ms) > ACCEPTABLE_MARGIN) | ||
| 146 | fprintf(stderr, "actual_delta_ms:%.4f expected:%.4f\n", | ||
| 147 | actual_delta_ms, (double) (JOBS * PERIOD)); | ||
| 148 | ASSERT( fabs(JOBS * PERIOD - actual_delta_ms) <= ACCEPTABLE_MARGIN); | ||
| 149 | ); | ||
| 150 | |||
| 151 | do { | ||
| 152 | waiters = get_nr_ts_release_waiters(); | ||
| 153 | ASSERT( waiters >= 0 ); | ||
| 154 | } while (waiters != 1); | ||
| 155 | |||
| 156 | waiters = release_ts(&delay); | ||
| 157 | |||
| 158 | |||
| 159 | /* wait for child to exit */ | ||
| 160 | SYSCALL( waitpid(child, &status, 0) ); | ||
| 161 | ASSERT( status == 0 ); | ||
| 162 | } | ||
