From 6e1ceb5ab56005fd343f52bbb8d2879e2c1493bd Mon Sep 17 00:00:00 2001 From: Sven Dziadek Date: Mon, 16 Apr 2012 21:37:40 +0200 Subject: P-FP: make PCP available to user space PCP was only used for DPCP before tests: add some basic tests for PCP under P-FP --- bin/rtspin.c | 2 +- include/litmus.h | 7 ++++++- src/litmus.c | 1 + tests/pcp.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/pcp.c diff --git a/bin/rtspin.c b/bin/rtspin.c index 1244073..87c178a 100644 --- a/bin/rtspin.c +++ b/bin/rtspin.c @@ -169,7 +169,7 @@ int main(int argc, char** argv) lt_t wcet; lt_t period; double wcet_ms, period_ms; - unsigned int priority = 0; + unsigned int priority = LITMUS_MIN_PRIORITY; int migrate = 0; int cpu = 0; int opt; diff --git a/include/litmus.h b/include/litmus.h index 2357da9..232dcf5 100644 --- a/include/litmus.h +++ b/include/litmus.h @@ -58,6 +58,7 @@ typedef enum { MPCP_SEM = 2, MPCP_VS_SEM = 3, DPCP_SEM = 4, + PCP_SEM = 5, } obj_type_t; int lock_protocol_for_name(const char* name); @@ -106,7 +107,6 @@ task_class_t str2class(const char* str); /* non-preemptive section support */ void enter_np(void); void exit_np(void); -int exit_np_trace(void); int requested_to_preempt(void); /* task system support */ @@ -138,6 +138,11 @@ static inline int open_srp_sem(int fd, int name) return od_open(fd, SRP_SEM, name); } +static inline int open_pcp_sem(int fd, int name, int cpu) +{ + return od_openx(fd, PCP_SEM, name, &cpu); +} + /* syscall overhead measuring */ int null_call(cycles_t *timestamp); diff --git a/src/litmus.c b/src/litmus.c index 9afe7a2..33937c8 100644 --- a/src/litmus.c +++ b/src/litmus.c @@ -22,6 +22,7 @@ static struct { LP(MPCP_VS), {MPCP_VS_SEM, "MPCP-VS"}, LP(DPCP), + LP(PCP), }; #define NUM_PROTOS (sizeof(protocol)/sizeof(protocol[0])) diff --git a/tests/pcp.c b/tests/pcp.c new file mode 100644 index 0000000..a893da6 --- /dev/null +++ b/tests/pcp.c @@ -0,0 +1,54 @@ +#include +#include +#include + +#include "tests.h" +#include "litmus.h" + + +TESTCASE(lock_pcp, P_FP, + "PCP acquisition and release") +{ + int fd, od, cpu = 0; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT) ); + + SYSCALL( sporadic_partitioned(10, 100, cpu) ); + SYSCALL( task_mode(LITMUS_RT_TASK) ); + + SYSCALL( od = open_pcp_sem(fd, 0, cpu) ); + + SYSCALL( litmus_lock(od) ); + SYSCALL( litmus_unlock(od) ); + + SYSCALL( litmus_lock(od) ); + SYSCALL( litmus_unlock(od) ); + + SYSCALL( litmus_lock(od) ); + SYSCALL( litmus_unlock(od) ); + + /* tasks may not unlock resources they don't own */ + SYSCALL_FAILS(EINVAL, litmus_unlock(od) ); + + SYSCALL( od_close(od) ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); +} + +TESTCASE(not_lock_pcp_be, P_FP, + "don't let best-effort tasks lock PCP semaphores") +{ + int fd, od; + + SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT) ); + + /* BE task are not even allowed to open a PCP semaphore */ + SYSCALL_FAILS(EPERM, od = open_pcp_sem(fd, 0, 1) ); + + SYSCALL( close(fd) ); + + SYSCALL( remove(".pcp_locks") ); + +} -- cgit v1.2.2