diff options
| author | Roy Spliet <rspliet@mpi-sws.org> | 2014-03-17 06:49:40 -0400 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2014-03-19 05:08:27 -0400 |
| commit | 5eea6c90c3f71b94ac83c021d783b81dadfc44dd (patch) | |
| tree | a857d499d9905bfb25412590cf812102c5727ee4 | |
| parent | 1f323b00f95c4704cdeea7918853f1e9e8d26c2e (diff) | |
liblitmus/tests: Add PCP-DPCP interleaving test
| -rw-r--r-- | tests/pcp.c | 106 |
1 files changed, 104 insertions, 2 deletions
diff --git a/tests/pcp.c b/tests/pcp.c index 19009a3..ed1920a 100644 --- a/tests/pcp.c +++ b/tests/pcp.c | |||
| @@ -2,11 +2,12 @@ | |||
| 2 | #include <unistd.h> | 2 | #include <unistd.h> |
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <sys/wait.h> /* for waitpid() */ | 4 | #include <sys/wait.h> /* for waitpid() */ |
| 5 | 5 | #include <sys/mman.h> | |
| 6 | #include <sched.h> | ||
| 6 | 7 | ||
| 7 | #include "tests.h" | 8 | #include "tests.h" |
| 8 | #include "litmus.h" | 9 | #include "litmus.h" |
| 9 | 10 | static int *volatile mutex; | |
| 10 | 11 | ||
| 11 | TESTCASE(lock_pcp, P_FP, | 12 | TESTCASE(lock_pcp, P_FP, |
| 12 | "PCP acquisition and release") | 13 | "PCP acquisition and release") |
| @@ -278,6 +279,107 @@ TESTCASE(lock_dpcp, P_FP, | |||
| 278 | SYSCALL( remove(".pcp_locks") ); | 279 | SYSCALL( remove(".pcp_locks") ); |
| 279 | } | 280 | } |
| 280 | 281 | ||
| 282 | TESTCASE(lock_dpcp_pcp, P_FP, | ||
| 283 | "DPCP-PCP interleaved priority") | ||
| 284 | { | ||
| 285 | int fd, od_dpcp, od_pcp, child_hi, child_lo, status, waiters, cpu; | ||
| 286 | lt_t delay = ms2ns(100); | ||
| 287 | struct rt_task params; | ||
| 288 | double start; | ||
| 289 | |||
| 290 | /* tasks may not unlock resources they don't own */ | ||
| 291 | SYSCALL( be_migrate_to_cpu(2) ); | ||
| 292 | |||
| 293 | init_rt_task_param(¶ms); | ||
| 294 | params.cpu = 0; | ||
| 295 | params.exec_cost = ms2ns(300); | ||
| 296 | params.period = ms2ns(300); | ||
| 297 | params.relative_deadline = params.period; | ||
| 298 | params.phase = 0; | ||
| 299 | params.cls = RT_CLASS_HARD; | ||
| 300 | params.budget_policy = NO_ENFORCEMENT; | ||
| 301 | |||
| 302 | mutex = mmap(NULL, sizeof(*mutex), PROT_READ | PROT_WRITE, | ||
| 303 | MAP_SHARED | MAP_ANONYMOUS, -1, 0); | ||
| 304 | *mutex = 0; | ||
| 305 | |||
| 306 | SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT, S_IRUSR) ); | ||
| 307 | |||
| 308 | child_lo = FORK_TASK( | ||
| 309 | params.priority = LITMUS_LOWEST_PRIORITY; | ||
| 310 | params.phase = ms2ns(50); | ||
| 311 | params.cpu = partition_to_cpu(1); | ||
| 312 | |||
| 313 | SYSCALL( be_migrate_to_cpu(params.cpu) ); | ||
| 314 | SYSCALL( init_rt_thread() ); | ||
| 315 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
| 316 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
| 317 | |||
| 318 | SYSCALL( od_dpcp = open_dpcp_sem(fd, 0, partition_to_cpu(0)) ); | ||
| 319 | |||
| 320 | SYSCALL( wait_for_ts_release() ); | ||
| 321 | |||
| 322 | SYSCALL( litmus_lock(od_dpcp) ); | ||
| 323 | cpu = sched_getcpu(); | ||
| 324 | *mutex = 1; | ||
| 325 | SYSCALL( litmus_unlock(od_dpcp) ); | ||
| 326 | |||
| 327 | /* Agent: Have I migrated? */ | ||
| 328 | ASSERT( cpu == partition_to_cpu(0) ); | ||
| 329 | |||
| 330 | SYSCALL(sleep_next_period() ); | ||
| 331 | ); | ||
| 332 | |||
| 333 | child_hi = FORK_TASK( | ||
| 334 | int preempted; | ||
| 335 | params.priority = LITMUS_HIGHEST_PRIORITY; | ||
| 336 | params.phase = 0; | ||
| 337 | params.cpu = partition_to_cpu(0); | ||
| 338 | |||
| 339 | SYSCALL( be_migrate_to_cpu(params.cpu) ); | ||
| 340 | SYSCALL( init_rt_thread() ); | ||
| 341 | SYSCALL( set_rt_task_param(gettid(), ¶ms) ); | ||
| 342 | SYSCALL( task_mode(LITMUS_RT_TASK) ); | ||
| 343 | |||
| 344 | SYSCALL( od_pcp = open_pcp_sem(fd, 1, params.cpu) ); | ||
| 345 | |||
| 346 | SYSCALL( wait_for_ts_release() ); | ||
| 347 | |||
| 348 | /* block on semaphore */ | ||
| 349 | SYSCALL( litmus_lock(od_pcp) ); | ||
| 350 | start = cputime(); | ||
| 351 | while (cputime() - start < 0.25) | ||
| 352 | ; | ||
| 353 | |||
| 354 | preempted = *mutex; | ||
| 355 | SYSCALL( litmus_unlock(od_pcp) ); | ||
| 356 | |||
| 357 | SYSCALL( od_close(od_pcp) ); | ||
| 358 | ASSERT( preempted == 1 ); | ||
| 359 | |||
| 360 | SYSCALL( kill(child_lo, SIGUSR2) ); | ||
| 361 | ); | ||
| 362 | |||
| 363 | do { | ||
| 364 | waiters = get_nr_ts_release_waiters(); | ||
| 365 | ASSERT( waiters >= 0 ); | ||
| 366 | } while (waiters != 2); | ||
| 367 | |||
| 368 | waiters = release_ts(&delay); | ||
| 369 | |||
| 370 | SYSCALL( waitpid(child_hi, &status, 0) ); | ||
| 371 | ASSERT( status == 0 ); | ||
| 372 | |||
| 373 | SYSCALL( waitpid(child_lo, &status, 0) ); | ||
| 374 | ASSERT( status == SIGUSR2); | ||
| 375 | |||
| 376 | SYSCALL( close(fd) ); | ||
| 377 | |||
| 378 | SYSCALL( remove(".pcp_locks") ); | ||
| 379 | |||
| 380 | munmap(mutex, sizeof(*mutex)); | ||
| 381 | } | ||
| 382 | |||
| 281 | TESTCASE(not_lock_pcp_be, P_FP, | 383 | TESTCASE(not_lock_pcp_be, P_FP, |
| 282 | "don't let best-effort tasks lock (D|M-)PCP semaphores") | 384 | "don't let best-effort tasks lock (D|M-)PCP semaphores") |
| 283 | { | 385 | { |
