File:
[ELWIX - Embedded LightWeight unIX -] /
libaitsched /
example /
test_brut.c
Revision
1.4:
download - view:
text,
annotated -
select for diffs -
revision graph
Thu Jun 5 22:37:29 2014 UTC (10 years, 2 months ago) by
misho
Branches:
MAIN
CVS tags:
sched8_4,
sched8_3,
sched8_2,
sched8_1,
sched8_0,
sched7_9,
sched7_8,
sched7_7,
sched7_6,
sched7_5,
sched7_4,
sched7_3,
sched7_2,
sched7_1,
sched7_0,
sched6_9,
sched6_8,
sched6_7,
sched6_6,
sched6_5,
sched6_4,
sched6_3,
sched6_2,
sched6_1,
sched6_0,
SCHED8_3,
SCHED8_2,
SCHED8_1,
SCHED8_0,
SCHED7_9,
SCHED7_8,
SCHED7_7,
SCHED7_6,
SCHED7_5,
SCHED7_4,
SCHED7_3,
SCHED7_2,
SCHED7_1,
SCHED7_0,
SCHED6_9,
SCHED6_8,
SCHED6_7,
SCHED6_6,
SCHED6_5,
SCHED6_4,
SCHED6_3,
SCHED6_2,
SCHED6_1,
SCHED6_0,
SCHED5_2,
HEAD
version 5.2
1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <unistd.h>
4: #include <fcntl.h>
5: #include <signal.h>
6: #include <sys/types.h>
7: #include <sys/stat.h>
8: #include <sys/signal.h>
9: #include <netinet/in.h>
10: #include <aitsched.h>
11:
12: intptr_t Kill;
13: sched_root_task_t *root;
14:
15: void *event(sched_task_t *arg)
16: {
17: printf("Event::\n");
18: taskExit(arg, NULL);
19: }
20:
21: void *regular(sched_task_t *arg)
22: {
23: printf("Task(%lu):: %s\n", TASK_VAL(arg), (char*) TASK_ARG(arg));
24: fflush(stdout);
25: taskExit(arg, NULL);
26: }
27:
28: void *timer(sched_task_t *arg)
29: {
30: printf("Timer %p sec::\n", TASK_ARG(arg));
31: taskExit(arg, NULL);
32: }
33:
34: void *rtc(sched_task_t *arg)
35: {
36: printf("RTC %p sec:: rtc id %lx signo=%lu\n", TASK_ARG(arg), (long) TASK_DATA(arg), TASK_VAL(arg));
37: taskExit(arg, NULL);
38: }
39:
40: void *rtcinf(sched_task_t *arg)
41: {
42: printf("RTC(inf) sec:: rtc id %lx signo=%lu\n", (long) TASK_DATA(arg), TASK_VAL(arg));
43: schedRTCSelf(arg);
44: taskExit(arg, NULL);
45: }
46:
47: void *alarmz(sched_task_t *arg)
48: {
49: printf("Alarm %ld sec::\n", (u_long) TASK_ARG(arg));
50: taskExit(arg, NULL);
51: }
52:
53: void *node(sched_task_t *arg)
54: {
55: printf("Node %s data %ld fflags 0x%lX\n", (char*) TASK_ARG(arg), (long) TASK_RET(arg), TASK_FLAG(arg));
56: taskExit(arg, NULL);
57: }
58:
59: void *proc(sched_task_t *arg)
60: {
61: printf("Proc pid=%ld data %ld fflags 0x%lX\n", TASK_VAL(arg), (long) TASK_RET(arg), TASK_FLAG(arg));
62: taskExit(arg, NULL);
63: }
64:
65: void *sigz(sched_task_t *arg)
66: {
67: printf("Signal signal=%ld how many times %ld\n", TASK_VAL(arg), (long) TASK_RET(arg));
68: taskExit(arg, NULL);
69: }
70:
71: #ifdef EVFILT_USER
72: void *user(sched_task_t *arg)
73: {
74: printf("User trigger id %ld fflags %ld\n", TASK_VAL(arg), TASK_FLAG(arg) & NOTE_FFLAGSMASK);
75: taskExit(arg, NULL);
76: }
77: #endif
78:
79: void *susp1(sched_task_t *arg)
80: {
81: printf("Suspend 1 =%ld\n", TASK_VAL(arg));
82: taskExit(arg, NULL);
83: }
84: void *susp2(sched_task_t *arg)
85: {
86: printf("Suspend 2 =%ld\n", TASK_VAL(arg));
87: taskExit(arg, NULL);
88: }
89: void *susp3(sched_task_t *arg)
90: {
91: printf("Suspend 3 =%ld\n", TASK_VAL(arg));
92: taskExit(arg, NULL);
93: }
94:
95: void *once(sched_task_t *arg)
96: {
97: printf("once::\n");
98: taskExit(arg, NULL);
99: }
100:
101: void *thr(sched_task_t *arg)
102: {
103: printf("tid (%lx):: %s\n", TASK_VAL(arg), __func__);
104: printf("tid (%lu):: %s\n", TASK_VAL(arg), (char*) TASK_ARG(arg));
105: fflush(stdout);
106: taskExit(arg, 42);
107: }
108:
109: void *thrinf(sched_task_t *arg)
110: {
111: printf("tid INF (%lu):: %s %s\n", TASK_VAL(arg), __func__, (char*) TASK_ARG(arg));
112: fflush(stdout);
113: schedThreadSelf(arg);
114: taskExit(arg, 42);
115: }
116:
117: void *thr4kill(sched_task_t *arg)
118: {
119: char blah[BUFSIZ];
120:
121: printf("tid (%lx):: %s\n", TASK_VAL(arg), __func__);
122:
123: read(0, blah, sizeof blah);
124: if (arg)
125: printf("never see!!! (%lx):: %s (%d == %d)\n", arg ? TASK_VAL(arg) : 0,
126: arg ? (char*) TASK_ARG(arg) : NULL,
127: arg ? TASK_TYPE(arg) : -1, taskTHREAD);
128: taskExit(arg, 0);
129: }
130:
131: void sig(int s)
132: {
133: switch (s) {
134: case SIGINT:
135: case SIGTERM:
136: Kill++;
137: break;
138: case SIGUSR1:
139: schedResumeby(root, CRITERIA_ID, (void*) 0);
140: schedResumeby(root, CRITERIA_ID, (void*) 7);
141: break;
142: }
143: }
144:
145: int
146: main(int argc, char **argv)
147: {
148: struct timespec ts = { 20, 0 };
149: // struct timespec p = { 0, 10000000 };
150: int f = 0;
151: struct sigaction sa;
152: sched_task_t *t;
153: #ifdef EVFILT_USER
154: sched_task_t *tt[4];
155: #endif
156: sched_task_t *task;
157:
158: sa.sa_handler = sig;
159: sigemptyset(&sa.sa_mask);
160: sigaction(SIGTERM, &sa, NULL);
161: sigaction(SIGINT, &sa, NULL);
162: sigaction(SIGUSR1, &sa, NULL);
163:
164: root = schedBegin();
165: if (!root) {
166: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
167: return 1;
168: }
169:
170: if (!schedRTC(root, rtc, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
171: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
172: return 4;
173: }
174: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
175: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
176: return 4;
177: } else
178: ts.tv_sec = 15;
179: if (!schedRTC(root, rtc, (void*) (intptr_t) ts.tv_sec, ts, (void*) 1, 0)) {
180: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
181: return 4;
182: }
183: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
184: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
185: return 4;
186: } else
187: ts.tv_sec = 10;
188:
189: if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
190: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
191: return 2;
192: }
193:
194: if (!schedTask(root, regular, "piuk", 11, NULL, 0)) {
195: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
196: return 3;
197: }
198: if (!schedTask(root, regular, "piuk", 1, NULL, 0)) {
199: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
200: return 3;
201: }
202: if (!schedTask(root, regular, "piuk", 0, NULL, 0)) {
203: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
204: return 3;
205: }
206: if (!schedTask(root, regular, "piuk", 1000001, NULL, 0)) {
207: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
208: return 3;
209: }
210:
211: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
212: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
213: return 4;
214: }
215:
216: if (!schedRTC(root, rtc, (void*) (intptr_t) ts.tv_sec, ts, (void*) 3, 0)) {
217: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
218: return 4;
219: }
220: if (!schedRTC(root, rtc, (void*) (intptr_t) ts.tv_sec, ts, (void*) 2, 0)) {
221: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
222: return 4;
223: }
224:
225: if (!schedAlarm(root, alarmz, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
226: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
227: return 5;
228: } else {
229: ts.tv_sec = 3;
230: ts.tv_nsec = 500000000;
231: }
232:
233: if (!schedRTC(root, rtc, (void*) (intptr_t) ts.tv_sec, ts, (void*) 10, 0)) {
234: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
235: return 5;
236: }
237: if (!schedRTC(root, rtc, (void*) (intptr_t) ts.tv_sec, ts, (void*) 10, 0)) {
238: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
239: return 5;
240: } else {
241: ts.tv_sec = 1;
242: ts.tv_nsec = 0;
243: }
244:
245: if (!schedRTC(root, rtcinf, (void*) (intptr_t) ts.tv_sec, ts, (void*) 12, 0)) {
246: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
247: return 5;
248: }
249:
250: if (!schedAlarm(root, alarmz, (void*) (intptr_t) ts.tv_sec, ts, (void*) 1, 0)) {
251: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
252: return 5;
253: }
254: if (!schedAlarm(root, alarmz, (void*) (intptr_t) ts.tv_sec, ts, (void*) 2, 0)) {
255: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
256: return 5;
257: } else {
258: ts.tv_sec = 0;
259: ts.tv_nsec = 700000000;
260: }
261: if (!schedAlarm(root, alarmz, (void*) (intptr_t) ts.tv_sec, ts, (void*) 3, 0)) {
262: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
263: return 5;
264: }
265:
266: #ifdef EVFILT_USER
267: if (!(tt[0] = schedUser(root, user, NULL, 42, 0, 0))) {
268: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
269: return 6;
270: }
271: if (!(tt[1] = schedUser(root, user, NULL, 1, 0, 73))) {
272: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
273: return 6;
274: }
275: if (!(tt[2] = schedUser(root, user, NULL, 0xaa, 0, NOTE_FFAND | 0xaa))) {
276: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
277: return 6;
278: }
279: if (!(tt[3] = schedUser(root, user, NULL, -1, 0, NOTE_FFCOPY | 1003))) {
280: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
281: return 6;
282: }
283: #endif
284: if (!schedSuspend(root, susp1, NULL, 7, NULL, 0)) {
285: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
286: return 6;
287: }
288: if (!(task = schedSuspend(root, susp2, NULL, 1, NULL, 0))) {
289: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
290: return 6;
291: }
292: if (!schedSuspend(root, susp3, NULL, 0, NULL, 0)) {
293: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
294: return 6;
295: }
296:
297: if (!schedThread(root, thrinf, "OHOBOHO_i_BOZA", 0, NULL, 0)) {
298: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
299: return 7;
300: }
301: if (!schedThread(root, thrinf, "OHOBOHO_i_BOZA+1", 0, NULL, 0)) {
302: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
303: return 7;
304: }
305: if (!(t = schedThread(root, thr4kill, "0aaaa", 0, NULL, 0))) {
306: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
307: return 7;
308: }
309: if (!schedThread(root, thr, "mdaaaa this is thread task", 131072, NULL, 0)) {
310: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
311: return 7;
312: }
313: if (!schedThread(root, thr, "mdaaaa this is thread task -detached", 0, NULL, 0)) {
314: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
315: return 7;
316: }
317: if (!schedThread(root, thr, "mdaaaa this is thread task -j", 131072, NULL, 0)) {
318: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
319: return 7;
320: }
321: printf("try to cancel tid = %lx\n", TASK_VAL(t));
322: schedCancel(t);
323: if (!schedThread(root, thr, "mdaaaa this is thread task -j2", 131072 * 2, NULL, 0)) {
324: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
325: return 7;
326: }
327: if (!(t = schedThread(root, thr4kill, "0aaaa", /*4096*/0, NULL, 0))) {
328: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
329: return 7;
330: }
331: if (!schedThread(root, thr, "mdaaaa this is thread task -j3", 0, NULL, 0)) {
332: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
333: return 7;
334: }
335: sleep(1);
336: schedCancel(t);
337:
338: schedCancelby(root, taskRTC, CRITERIA_DATA, (void*) 2, NULL);
339: // schedCancelby(root, taskRTC, CRITERIA_DATA, (void*) 10, NULL);
340:
341: if (argc > 1)
342: if (!schedProc(root, proc, NULL, atoi(argv[1]), 0, 0)) {
343: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
344: return 7;
345: }
346: if (argc > 2) {
347: f = open(argv[2], O_RDWR);
348: if (f == -1) {
349: perror("open()");
350: return 8;
351: }
352: if (!schedNode(root, node, argv[2], f, 0, 0)) {
353: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
354: close(f);
355: return 8;
356: }
357: }
358:
359: #ifdef EVFILT_USER
360: schedTrigger(tt[3]);
361: schedTrigger(tt[1]);
362: #endif
363: schedResumeby(root, CRITERIA_DATA, task);
364:
365: if (!schedSignal(root, sigz, NULL, SIGUSR1, 0, 0)) {
366: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
367: close(f);
368: return 9;
369: }
370:
371: #ifdef EVFILT_USER
372: schedTrigger(tt[2]);
373: schedTrigger(tt[0]);
374: #endif
375:
376: schedCallOnce(root, once, "000000", 42, NULL, 0);
377:
378: printf("read_queue=%d timer_queue=%d\n",
379: ROOT_QUEUE_EMPTY(root, read), ROOT_QUEUE_EMPTY(root, timer));
380:
381: // schedPolling(root, &p, NULL);
382: schedRun(root, &Kill);
383: schedEnd(&root);
384:
385: if (f > 2)
386: close(f);
387: return 0;
388: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>