aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2013-01-10 17:45:18 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2013-01-10 17:45:18 -0500
commit1bf0f0094cd9671adfc07cf840bde67cd4cc0c38 (patch)
tree12df5ca23e87df7813e845cb816a57a1d4b75d7d /tests
parent7ec25a0856dd998c4edd63dc4b91799a91158d00 (diff)
parentd427bf8561f488bfec36b14b02af5b8ca0b2782f (diff)
Merge branch 'mpi-master' into wip-2012.3-gpu
Conflicts: Makefile bin/rtspin.c include/litmus.h src/litmus.c
Diffstat (limited to 'tests')
-rw-r--r--tests/core_api.c80
-rw-r--r--tests/locks.c8
-rw-r--r--tests/pcp.c122
-rw-r--r--tests/runner.c47
-rw-r--r--tests/sched.c82
5 files changed, 328 insertions, 11 deletions
diff --git a/tests/core_api.c b/tests/core_api.c
index 7f7a099..c0b291e 100644
--- a/tests/core_api.c
+++ b/tests/core_api.c
@@ -20,7 +20,9 @@ TESTCASE(set_rt_task_param_invalid_params, ALL,
20 struct rt_task params; 20 struct rt_task params;
21 params.cpu = 0; 21 params.cpu = 0;
22 params.period = 100; 22 params.period = 100;
23 params.relative_deadline = params.period;
23 params.phase = 0; 24 params.phase = 0;
25 params.priority = LITMUS_LOWEST_PRIORITY;
24 params.cls = RT_CLASS_HARD; 26 params.cls = RT_CLASS_HARD;
25 params.budget_policy = NO_ENFORCEMENT; 27 params.budget_policy = NO_ENFORCEMENT;
26 28
@@ -33,8 +35,13 @@ TESTCASE(set_rt_task_param_invalid_params, ALL,
33 params.cpu = -1; 35 params.cpu = -1;
34 SYSCALL_FAILS( EINVAL, set_rt_task_param(gettid(), &params) ); 36 SYSCALL_FAILS( EINVAL, set_rt_task_param(gettid(), &params) );
35 37
36 /* bad task */ 38 /* infeasible density */
37 params.cpu = 0; 39 params.cpu = 0;
40 params.relative_deadline = 30;
41 SYSCALL_FAILS( EINVAL, set_rt_task_param(gettid(), &params) );
42
43 /* bad task */
44 params.relative_deadline = params.period;
38 SYSCALL_FAILS( EINVAL, set_rt_task_param(-1, &params) ); 45 SYSCALL_FAILS( EINVAL, set_rt_task_param(-1, &params) );
39 46
40 47
@@ -42,6 +49,58 @@ TESTCASE(set_rt_task_param_invalid_params, ALL,
42 SYSCALL( set_rt_task_param(gettid(), &params) ); 49 SYSCALL( set_rt_task_param(gettid(), &params) );
43} 50}
44 51
52TESTCASE(reject_bad_priorities, P_FP,
53 "reject invalid priorities")
54{
55 struct rt_task params;
56 params.cpu = 0;
57 params.exec_cost = 10;
58 params.period = 100;
59 params.relative_deadline = params.period;
60 params.phase = 0;
61 params.cls = RT_CLASS_HARD;
62 params.budget_policy = NO_ENFORCEMENT;
63
64 SYSCALL( be_migrate_to(params.cpu) );
65
66 /* too high */
67 params.priority = 0;
68 SYSCALL( set_rt_task_param(gettid(), &params) );
69 SYSCALL_FAILS( EINVAL, task_mode(LITMUS_RT_TASK) );
70
71 /* too low */
72 params.priority = LITMUS_MAX_PRIORITY;
73 SYSCALL( set_rt_task_param(gettid(), &params) );
74 SYSCALL_FAILS( EINVAL, task_mode(LITMUS_RT_TASK) );
75
76}
77
78TESTCASE(accept_valid_priorities, P_FP,
79 "accept lowest and highest valid priorities")
80{
81 struct rt_task params;
82 params.cpu = 0;
83 params.exec_cost = 10;
84 params.period = 100;
85 params.relative_deadline = params.period;
86 params.phase = 0;
87 params.cls = RT_CLASS_HARD;
88 params.budget_policy = NO_ENFORCEMENT;
89
90 SYSCALL( be_migrate_to(params.cpu) );
91
92 /* acceptable */
93 params.priority = LITMUS_LOWEST_PRIORITY;
94 SYSCALL( set_rt_task_param(gettid(), &params) );
95 SYSCALL( task_mode(LITMUS_RT_TASK) );
96 SYSCALL( task_mode(BACKGROUND_TASK) );
97
98 params.priority = LITMUS_HIGHEST_PRIORITY;
99 SYSCALL( set_rt_task_param(gettid(), &params) );
100 SYSCALL( task_mode(LITMUS_RT_TASK) );
101 SYSCALL( task_mode(BACKGROUND_TASK) );
102}
103
45TESTCASE(job_control_non_rt, ALL, 104TESTCASE(job_control_non_rt, ALL,
46 "reject job control for non-rt tasks") 105 "reject job control for non-rt tasks")
47{ 106{
@@ -80,7 +139,7 @@ TESTCASE(rt_fork_non_rt, LITMUS,
80 /* parent */ 139 /* parent */
81 140
82 SYSCALL( sleep_next_period() ); 141 SYSCALL( sleep_next_period() );
83 SYSCALL( wait_for_job_release(20) ); 142 SYSCALL( wait_for_job_release(3) );
84 SYSCALL( get_job_no(&job_no) ); 143 SYSCALL( get_job_no(&job_no) );
85 144
86 SYSCALL( task_mode(BACKGROUND_TASK) ); 145 SYSCALL( task_mode(BACKGROUND_TASK) );
@@ -90,3 +149,20 @@ TESTCASE(rt_fork_non_rt, LITMUS,
90 ASSERT(WEXITSTATUS(status) == 0); 149 ASSERT(WEXITSTATUS(status) == 0);
91 } 150 }
92} 151}
152
153TESTCASE(ctrl_page_writable, ALL,
154 "tasks have write access to /dev/litmus/ctrl mappings")
155{
156 volatile int *ctrl_page = (volatile int*) get_ctrl_page();
157
158 /* init_litmus() should have mapped the page already */
159 ASSERT(ctrl_page != NULL);
160
161 /* These should work without page faults. */
162 enter_np();
163 exit_np();
164
165 /* Try poking the memory directly. */
166
167 ctrl_page[32] = 0x12345678;
168}
diff --git a/tests/locks.c b/tests/locks.c
index 65b932a..d7ebfe2 100644
--- a/tests/locks.c
+++ b/tests/locks.c
@@ -6,7 +6,7 @@
6#include "litmus.h" 6#include "litmus.h"
7 7
8 8
9TESTCASE(not_lock_fmlp_be, GSN_EDF | PSN_EDF, 9TESTCASE(not_lock_fmlp_be, GSN_EDF | PSN_EDF | P_FP,
10 "don't let best-effort tasks lock FMLP semaphores") 10 "don't let best-effort tasks lock FMLP semaphores")
11{ 11{
12 int fd, od; 12 int fd, od;
@@ -29,7 +29,7 @@ TESTCASE(not_lock_fmlp_be, GSN_EDF | PSN_EDF,
29 29
30} 30}
31 31
32TESTCASE(not_lock_srp_be, PSN_EDF, 32TESTCASE(not_lock_srp_be, PSN_EDF | P_FP,
33 "don't let best-effort tasks open SRP semaphores") 33 "don't let best-effort tasks open SRP semaphores")
34{ 34{
35 int fd, od; 35 int fd, od;
@@ -46,7 +46,7 @@ TESTCASE(not_lock_srp_be, PSN_EDF,
46 46
47} 47}
48 48
49TESTCASE(lock_srp, PSN_EDF, 49TESTCASE(lock_srp, PSN_EDF | P_FP,
50 "SRP acquisition and release") 50 "SRP acquisition and release")
51{ 51{
52 int fd, od; 52 int fd, od;
@@ -78,7 +78,7 @@ TESTCASE(lock_srp, PSN_EDF,
78} 78}
79 79
80 80
81TESTCASE(lock_fmlp, PSN_EDF | GSN_EDF, 81TESTCASE(lock_fmlp, PSN_EDF | GSN_EDF | P_FP,
82 "FMLP acquisition and release") 82 "FMLP acquisition and release")
83{ 83{
84 int fd, od; 84 int fd, od;
diff --git a/tests/pcp.c b/tests/pcp.c
new file mode 100644
index 0000000..88d1be3
--- /dev/null
+++ b/tests/pcp.c
@@ -0,0 +1,122 @@
1#include <fcntl.h>
2#include <unistd.h>
3#include <stdio.h>
4
5#include "tests.h"
6#include "litmus.h"
7
8
9TESTCASE(lock_pcp, P_FP,
10 "PCP acquisition and release")
11{
12 int fd, od, cpu = 0;
13
14 SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT) );
15
16 SYSCALL( sporadic_partitioned(10, 100, cpu) );
17 SYSCALL( task_mode(LITMUS_RT_TASK) );
18
19 SYSCALL( od = open_pcp_sem(fd, 0, cpu) );
20
21 SYSCALL( litmus_lock(od) );
22 SYSCALL( litmus_unlock(od) );
23
24 SYSCALL( litmus_lock(od) );
25 SYSCALL( litmus_unlock(od) );
26
27 SYSCALL( litmus_lock(od) );
28 SYSCALL( litmus_unlock(od) );
29
30 /* tasks may not unlock resources they don't own */
31 SYSCALL_FAILS(EINVAL, litmus_unlock(od) );
32
33 SYSCALL( od_close(od) );
34
35 SYSCALL( close(fd) );
36
37 SYSCALL( remove(".pcp_locks") );
38}
39
40TESTCASE(lock_dpcp, P_FP,
41 "DPCP acquisition and release")
42{
43 int fd, od, cpu = 1;
44
45 SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT) );
46
47 SYSCALL( sporadic_partitioned(10, 100, 0) );
48 SYSCALL( task_mode(LITMUS_RT_TASK) );
49
50 SYSCALL( od = open_dpcp_sem(fd, 0, cpu) );
51
52 SYSCALL( litmus_lock(od) );
53 SYSCALL( litmus_unlock(od) );
54
55 SYSCALL( litmus_lock(od) );
56 SYSCALL( litmus_unlock(od) );
57
58 SYSCALL( litmus_lock(od) );
59 SYSCALL( litmus_unlock(od) );
60
61 /* tasks may not unlock resources they don't own */
62 SYSCALL_FAILS(EINVAL, litmus_unlock(od) );
63
64 SYSCALL( od_close(od) );
65
66 SYSCALL( close(fd) );
67
68 SYSCALL( remove(".pcp_locks") );
69}
70
71TESTCASE(not_lock_pcp_be, P_FP,
72 "don't let best-effort tasks lock (D|M-)PCP semaphores")
73{
74 int fd, od;
75
76 SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT) );
77
78 /* BE tasks are not even allowed to open a PCP semaphore */
79 SYSCALL_FAILS(EPERM, od = open_pcp_sem(fd, 0, 1) );
80
81 /* BE tasks are not allowed to open a D-PCP semaphore */
82 SYSCALL_FAILS(EPERM, od = open_dpcp_sem(fd, 0, 1) );
83
84 /* BE tasks are not allowed to open an M-PCP semaphore */
85 SYSCALL_FAILS(EPERM, od = open_mpcp_sem(fd, 0) );
86
87 SYSCALL( close(fd) );
88
89 SYSCALL( remove(".pcp_locks") );
90
91}
92
93TESTCASE(lock_mpcp, P_FP,
94 "MPCP acquisition and release")
95{
96 int fd, od;
97
98 SYSCALL( fd = open(".pcp_locks", O_RDONLY | O_CREAT) );
99
100 SYSCALL( sporadic_partitioned(10, 100, 0) );
101 SYSCALL( task_mode(LITMUS_RT_TASK) );
102
103 SYSCALL( od = open_mpcp_sem(fd, 0) );
104
105 SYSCALL( litmus_lock(od) );
106 SYSCALL( litmus_unlock(od) );
107
108 SYSCALL( litmus_lock(od) );
109 SYSCALL( litmus_unlock(od) );
110
111 SYSCALL( litmus_lock(od) );
112 SYSCALL( litmus_unlock(od) );
113
114 /* tasks may not unlock resources they don't own */
115 SYSCALL_FAILS(EINVAL, litmus_unlock(od) );
116
117 SYSCALL( od_close(od) );
118
119 SYSCALL( close(fd) );
120
121 SYSCALL( remove(".pcp_locks") );
122}
diff --git a/tests/runner.c b/tests/runner.c
index ccf8d46..0fd3aa7 100644
--- a/tests/runner.c
+++ b/tests/runner.c
@@ -6,6 +6,7 @@
6#include <string.h> 6#include <string.h>
7#include <stdio.h> 7#include <stdio.h>
8 8
9#define PROC_ACTIVE_PLUGIN "/proc/litmus/active_plugin"
9 10
10/* auto generated by Makefile */ 11/* auto generated by Makefile */
11#include "../test_catalog.inc" 12#include "../test_catalog.inc"
@@ -27,10 +28,13 @@ int run_test(struct testcase *tc) {
27 } else { 28 } else {
28 /* parent: wait for completion of test */ 29 /* parent: wait for completion of test */
29 SYSCALL( waitpid(pid, &status, 0) ); 30 SYSCALL( waitpid(pid, &status, 0) );
30 if (WEXITSTATUS(status) == 0) 31 if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
31 printf("ok.\n"); 32 printf("ok.\n");
33 else if (WIFSIGNALED(status)) {
34 printf("failed (%s)!\n", strsignal(WTERMSIG(status)));
35 }
32 } 36 }
33 return WEXITSTATUS(status) == 0; 37 return WIFEXITED(status) && WEXITSTATUS(status) == 0;
34} 38}
35 39
36int run_tests(int* testidx, int num_tests, const char* plugin) 40int run_tests(int* testidx, int num_tests, const char* plugin)
@@ -46,17 +50,50 @@ int run_tests(int* testidx, int num_tests, const char* plugin)
46 return ok; 50 return ok;
47} 51}
48 52
53static int get_active_plugin(char *buf, size_t buf_size)
54{
55 FILE *f;
56 size_t nread;
57
58 f = fopen(PROC_ACTIVE_PLUGIN, "r");
59 if (f) {
60 /* proc files read in one go */
61 nread = fread(buf, sizeof(char), buf_size - 1, f);
62 fclose(f);
63
64 /* remove trailing newline */
65 if (nread > 0 && buf[nread - 1] == '\n')
66 nread--;
67
68 /* null terminate buffer */
69 if (nread > 0) {
70 buf[nread] = '\0';
71 return 1;
72 }
73 }
74 return 0;
75}
76
49#define streq(s1, s2) (!strcmp(s1, s2)) 77#define streq(s1, s2) (!strcmp(s1, s2))
50 78
51int main(int argc, char** argv) 79int main(int argc, char** argv)
52{ 80{
53 int ok, i; 81 int ok, i;
82 char active_plugin[256];
83 char *plugin_name = NULL;
54 84
55 printf("** LITMUS^RT test suite.\n"); 85 printf("** LITMUS^RT test suite.\n");
56 86
57 if (argc == 2) { 87 if (argc == 2)
88 plugin_name = argv[1];
89 else if (get_active_plugin(active_plugin, sizeof(active_plugin))) {
90 /* run tests for currently active plugin */
91 plugin_name = active_plugin;
92 }
93
94 if (plugin_name) {
58 for (i = 0; i < NUM_PLUGINS; i++) 95 for (i = 0; i < NUM_PLUGINS; i++)
59 if (streq(testsuite[i].plugin, argv[1])) { 96 if (streq(testsuite[i].plugin, plugin_name)) {
60 ok = run_tests(testsuite[i].testcases, 97 ok = run_tests(testsuite[i].testcases,
61 testsuite[i].num_cases, 98 testsuite[i].num_cases,
62 testsuite[i].plugin); 99 testsuite[i].plugin);
@@ -64,7 +101,7 @@ int main(int argc, char** argv)
64 ok, testsuite[i].num_cases - ok); 101 ok, testsuite[i].num_cases - ok);
65 return ok == testsuite[i].num_cases ? 0 : 3; 102 return ok == testsuite[i].num_cases ? 0 : 3;
66 } 103 }
67 fprintf(stderr, "** Unknown plugin: '%s'\n", argv[1]); 104 fprintf(stderr, "** Unknown plugin: '%s'\n", plugin_name);
68 return 1; 105 return 1;
69 } else { 106 } else {
70 fprintf(stderr, "Usage: %s <plugin name>\n", argv[0]); 107 fprintf(stderr, "Usage: %s <plugin name>\n", argv[0]);
diff --git a/tests/sched.c b/tests/sched.c
new file mode 100644
index 0000000..ab47a91
--- /dev/null
+++ b/tests/sched.c
@@ -0,0 +1,82 @@
1#include <sys/wait.h> /* for waitpid() */
2#include <unistd.h>
3#include <stdio.h>
4
5#include "tests.h"
6#include "litmus.h"
7
8TESTCASE(preempt_on_resume, P_FP | PSN_EDF,
9 "preempt lower-priority task when a higher-priority task resumes")
10{
11 int child_hi, child_lo, status, waiters;
12 lt_t delay = ms2lt(100);
13 double start, stop;
14
15 struct rt_task params;
16 params.cpu = 0;
17 params.exec_cost = ms2lt(10000);
18 params.period = ms2lt(100000);
19 params.relative_deadline = params.period;
20 params.phase = 0;
21 params.cls = RT_CLASS_HARD;
22 params.budget_policy = NO_ENFORCEMENT;
23
24 child_lo = FORK_TASK(
25 params.priority = LITMUS_LOWEST_PRIORITY;
26 SYSCALL( set_rt_task_param(gettid(), &params) );
27 SYSCALL( be_migrate_to(params.cpu) );
28 SYSCALL( task_mode(LITMUS_RT_TASK) );
29
30 SYSCALL( wait_for_ts_release() );
31
32 start = cputime();
33
34 while (cputime() - start < 10)
35 ;
36
37 );
38
39 child_hi = FORK_TASK(
40 params.priority = LITMUS_HIGHEST_PRIORITY;
41 params.relative_deadline -= 1000000;
42 SYSCALL( set_rt_task_param(gettid(), &params) );
43 SYSCALL( be_migrate_to(params.cpu) );
44 SYSCALL( task_mode(LITMUS_RT_TASK) );
45
46 SYSCALL( wait_for_ts_release() );
47
48 start = cputime();
49
50 while (cputime() - start < 0.1)
51 ;
52
53 start = wctime();
54 SYSCALL( lt_sleep(ms2lt(100)) );
55 stop = wctime();
56
57 SYSCALL( kill(child_lo, SIGUSR2) );
58
59 if (stop - start >= 0.2)
60 fprintf(stderr, "\nHi-prio delay = %fsec\n",
61 stop - start - (ms2lt(100) / 1E9));
62
63 /* Assert we woke up 'soonish' after the sleep. */
64 ASSERT( stop - start < 0.2 );
65 );
66
67
68 do {
69 waiters = get_nr_ts_release_waiters();
70 ASSERT( waiters >= 0 );
71 } while (waiters != 2);
72
73 waiters = release_ts(&delay);
74
75 SYSCALL( waitpid(child_hi, &status, 0) );
76 ASSERT( status == 0 );
77
78 SYSCALL( waitpid(child_lo, &status, 0) );
79 ASSERT( status == SIGUSR2);
80}
81
82