diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-22 11:20:50 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-22 11:20:50 -0500 |
commit | 726fc7a6c8e8f8e1036337e1503af0cbb1bb741f (patch) | |
tree | f06d08d6d484b9081d639ffaf145ad4679d91978 | |
parent | b9245ec5694dbc690b004f16e525a92db348943f (diff) |
add mode_test
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | src/mode_test.c | 112 |
2 files changed, 116 insertions, 1 deletions
@@ -3,7 +3,7 @@ CPPFLAGS=-Wall -g | |||
3 | 3 | ||
4 | LIBS= ./liblitmus.a | 4 | LIBS= ./liblitmus.a |
5 | 5 | ||
6 | TARGETS = showsched iotest set_rt_mode run timeout rt_launch edfhsb liblitmus.a wait_test np_test stdump | 6 | TARGETS = showsched iotest set_rt_mode run timeout rt_launch edfhsb liblitmus.a wait_test np_test stdump mode_test |
7 | 7 | ||
8 | vpath %.h include/ | 8 | vpath %.h include/ |
9 | vpath %.c src/ | 9 | vpath %.c src/ |
@@ -15,6 +15,9 @@ clean: | |||
15 | wait_test: wait_test.o litmus.h liblitmus.a | 15 | wait_test: wait_test.o litmus.h liblitmus.a |
16 | cc -static -o wait_test wait_test.o ${LIBS} | 16 | cc -static -o wait_test wait_test.o ${LIBS} |
17 | 17 | ||
18 | mode_test: mode_test.o litmus.h liblitmus.a | ||
19 | cc -static -o mode_test mode_test.o ${LIBS} | ||
20 | |||
18 | np_test: np_test.o litmus.h liblitmus.a | 21 | np_test: np_test.o litmus.h liblitmus.a |
19 | cc -static -o np_test np_test.o ${LIBS} | 22 | cc -static -o np_test np_test.o ${LIBS} |
20 | 23 | ||
diff --git a/src/mode_test.c b/src/mode_test.c new file mode 100644 index 0000000..811755e --- /dev/null +++ b/src/mode_test.c | |||
@@ -0,0 +1,112 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <signal.h> | ||
4 | #include <unistd.h> | ||
5 | #include <sys/time.h> | ||
6 | #include <sys/wait.h> | ||
7 | #include <sys/types.h> | ||
8 | #include <sys/stat.h> | ||
9 | #include <fcntl.h> | ||
10 | |||
11 | #include "litmus.h" | ||
12 | |||
13 | #define US_PER_MS 1000 | ||
14 | |||
15 | int prefix(void) | ||
16 | { | ||
17 | char field[1024]; | ||
18 | int prefix[1024]; | ||
19 | int i, sum = 0; | ||
20 | |||
21 | for (i = 0; i < 1024; i++) { | ||
22 | sum += field[i]; | ||
23 | prefix[i] = sum; | ||
24 | } | ||
25 | return sum; | ||
26 | } | ||
27 | |||
28 | void do_stuff(void) | ||
29 | { | ||
30 | int i =0, j =0; | ||
31 | |||
32 | for (; i < 50000; i++) | ||
33 | j += prefix(); | ||
34 | } | ||
35 | |||
36 | #define CALL(sc) do { ret = sc; if (ret == -1) {perror(" (!!) " #sc " failed: "); /*exit(1)*/;}} while (0); | ||
37 | |||
38 | unsigned int job_no; | ||
39 | |||
40 | void next(void) | ||
41 | { | ||
42 | int ret; | ||
43 | unsigned int actual; | ||
44 | CALL(get_job_no(&actual)); | ||
45 | CALL(wait_for_job_release(++job_no)); | ||
46 | printf("Now executing job %u, waited for %u\n", actual, job_no); | ||
47 | } | ||
48 | |||
49 | int main(int argc, char** argv) | ||
50 | { | ||
51 | int ret; | ||
52 | |||
53 | init_litmus(); | ||
54 | |||
55 | CALL(getpid()); | ||
56 | printf("my pid is %d\n", ret); | ||
57 | |||
58 | |||
59 | CALL(get_job_no(&job_no)); | ||
60 | printf("my job_no is %u", job_no); | ||
61 | |||
62 | CALL( task_mode(LITMUS_RT_TASK) ); | ||
63 | |||
64 | next(); | ||
65 | do_stuff(); | ||
66 | |||
67 | next(); | ||
68 | do_stuff(); | ||
69 | |||
70 | next(); | ||
71 | do_stuff(); | ||
72 | |||
73 | CALL( task_mode(BACKGROUND_TASK) ); | ||
74 | |||
75 | do_stuff(); | ||
76 | do_stuff(); | ||
77 | do_stuff(); | ||
78 | do_stuff(); | ||
79 | do_stuff(); | ||
80 | |||
81 | CALL( task_mode(LITMUS_RT_TASK) ); | ||
82 | |||
83 | do_stuff(); | ||
84 | do_stuff(); | ||
85 | do_stuff(); | ||
86 | do_stuff(); | ||
87 | do_stuff(); | ||
88 | |||
89 | |||
90 | next(); | ||
91 | next(); | ||
92 | next(); | ||
93 | next(); | ||
94 | next(); | ||
95 | next(); | ||
96 | next(); | ||
97 | |||
98 | |||
99 | next(); | ||
100 | do_stuff(); | ||
101 | |||
102 | next(); | ||
103 | do_stuff(); | ||
104 | |||
105 | next(); | ||
106 | do_stuff(); | ||
107 | |||
108 | CALL( task_mode(BACKGROUND_TASK) ); | ||
109 | printf("Exiting...\n"); | ||
110 | |||
111 | return 0; | ||
112 | } | ||