From 16cb0a3245a738633e3e21432386631f6cf0c202 Mon Sep 17 00:00:00 2001 From: Bjoern Brandenburg Date: Wed, 19 Mar 2014 14:06:44 +0100 Subject: Add test cases for exiting/mode-changing lock holders This crashes old versions of the kernel. Kernel patches fixing the various panics have been merged into the kernel staging tree. --- tests/locks.c | 169 +++++++++++++++++++++++++++++++++++++++ tests/pcp.c | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) (limited to 'tests') diff --git a/tests/locks.c b/tests/locks.c index c3eba4e..bc35a8e 100644 --- a/tests/locks.c +++ b/tests/locks.c @@ -1,6 +1,7 @@ #include #include #include +#include /* for waitpid() */ #include "tests.h" #include "litmus.h" @@ -108,3 +109,171 @@ TESTCASE(lock_fmlp, PSN_EDF | GSN_EDF | P_FP, SYSCALL( remove(".fmlp_locks") ); } + +TESTCASE(srp_lock_mode_change, P_FP | PSN_EDF, + "SRP task becomes non-RT task while holding lock") +{ + int fd, od; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_srp_sem(fd, 0) ); + + SYSCALL( litmus_lock(od) ); + + SYSCALL( task_mode(BACKGROUND_TASK) ); + + SYSCALL( litmus_unlock(od) ); + + SYSCALL( od_close(od) ); + + exit(0); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 0 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".locks") ); +} + +TESTCASE(fmlp_lock_mode_change, P_FP | PSN_EDF | GSN_EDF, + "FMLP task becomes non-RT task while holding lock") +{ + int fd, od; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_fmlp_sem(fd, 0) ); + + SYSCALL( litmus_lock(od) ); + + SYSCALL( task_mode(BACKGROUND_TASK) ); + + SYSCALL( litmus_unlock(od) ); + + SYSCALL( od_close(od) ); + + exit(0); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 0 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".locks") ); +} + +TESTCASE(srp_lock_teardown, P_FP | PSN_EDF, + "SRP task exits while holding lock") +{ + int fd, od; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + exit(0); + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_srp_sem(fd, 0) ); + + SYSCALL( litmus_lock(od) ); + exit(123); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 123 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".locks") ); +} + +TESTCASE(fmlp_lock_teardown, P_FP | PSN_EDF | GSN_EDF, + "FMLP task exits while holding lock") +{ + int fd, od; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + exit(0); + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_fmlp_sem(fd, 0) ); + + SYSCALL( litmus_lock(od) ); + exit(123); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 123 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".locks") ); +} diff --git a/tests/pcp.c b/tests/pcp.c index ed1920a..0b95a23 100644 --- a/tests/pcp.c +++ b/tests/pcp.c @@ -432,3 +432,255 @@ TESTCASE(lock_mpcp, P_FP, SYSCALL( remove(".pcp_locks") ); } + +TESTCASE(pcp_lock_mode_change, P_FP, + "PCP task becomes non-RT task while holding lock") +{ + int fd, od, cpu = 0; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_pcp_sem(fd, 0, cpu) ); + + SYSCALL( litmus_lock(od) ); + + SYSCALL( task_mode(BACKGROUND_TASK) ); + + SYSCALL( litmus_unlock(od) ); + + SYSCALL( od_close(od) ); + + exit(0); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 0 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); +} + +TESTCASE(mpcp_lock_mode_change, P_FP, + "MPCP task becomes non-RT task while holding lock") +{ + int fd, od; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_mpcp_sem(fd, 0) ); + + SYSCALL( litmus_lock(od) ); + + SYSCALL( task_mode(BACKGROUND_TASK) ); + + SYSCALL( litmus_unlock(od) ); + + SYSCALL( od_close(od) ); + + exit(0); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 0 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); +} + +TESTCASE(dpcp_lock_mode_change, P_FP, + "DPCP task becomes non-RT task while holding lock") +{ + int fd, od, cpu = 0; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 1; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_dpcp_sem(fd, 0, cpu) ); + + SYSCALL( litmus_lock(od) ); + + SYSCALL( task_mode(BACKGROUND_TASK) ); + + SYSCALL( litmus_unlock(od) ); + + SYSCALL( od_close(od) ); + + exit(0); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 0 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); +} + +TESTCASE(pcp_lock_teardown, P_FP, + "PCP task exits while holding lock") +{ + int fd, od, cpu = 0; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + exit(0); + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_pcp_sem(fd, 0, cpu) ); + + SYSCALL( litmus_lock(od) ); + exit(123); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 123 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); +} + +TESTCASE(dpcp_lock_teardown, P_FP, + "DPCP task exits while holding lock") +{ + int fd, od, cpu = 0; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 1; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + exit(0); + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_dpcp_sem(fd, 0, cpu) ); + + SYSCALL( litmus_lock(od) ); + exit(123); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 123 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); +} + +TESTCASE(mpcp_lock_teardown, P_FP, + "MPCP task exits while holding lock") +{ + int fd, od; + + int child, status; + + struct rt_task params; + init_rt_task_param(¶ms); + params.cpu = 0; + params.exec_cost = ms2ns(10000); + params.period = ms2ns(100000); + params.relative_deadline = params.period; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT, S_IRUSR) ); + + exit(0); + + child = FORK_TASK( + params.priority = LITMUS_LOWEST_PRIORITY; + SYSCALL( set_rt_task_param(gettid(), ¶ms) ); + SYSCALL( be_migrate_to_cpu(params.cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_mpcp_sem(fd, 0) ); + + SYSCALL( litmus_lock(od) ); + exit(123); + ); + + SYSCALL( waitpid(child, &status, 0) ); + ASSERT( WIFEXITED(status) ); + ASSERT( WEXITSTATUS(status) == 123 ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); +} -- cgit v1.2.2