]> git.saurik.com Git - apple/launchd.git/blob - launchd/testing/missed-EVFILT_TIMER.c
launchd-392.39.tar.gz
[apple/launchd.git] / launchd / testing / missed-EVFILT_TIMER.c
1 #include <sys/types.h>
2 #include <sys/event.h>
3 #include <sys/time.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <assert.h>
7
8 void
9 test5225889(int first, int second)
10 {
11 struct timeval tvs, tve, tvd;
12 struct timespec timeout = { 30, 0 };
13 struct kevent kev;
14 int r, kq = kqueue();
15
16 fprintf(stdout, "First timer %i being updated to %i.\n", first, second);
17
18 assert(kq != -1);
19
20 EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, first, NULL);
21 r = kevent(kq, &kev, 1, NULL, 0, NULL);
22 assert(r != -1);
23
24 EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, second, NULL);
25 r = kevent(kq, &kev, 1, NULL, 0, NULL);
26 assert(r != -1);
27
28 gettimeofday(&tvs, NULL);
29 r = kevent(kq, NULL, 0, &kev, 1, &timeout);
30 gettimeofday(&tve, NULL);
31
32 timersub(&tve, &tvs, &tvd);
33
34 fprintf(stdout, "Waited %lu seconds for kevent() to return.\n", tvd.tv_sec);
35
36 switch (r) {
37 case 1:
38 assert(kev.data == second);
39 assert(tvd.tv_sec >= second);
40 break;
41 case -1:
42 case 0:
43 default:
44 fprintf(stderr, "Bug 5225889 still exists!\n");
45 exit(EXIT_FAILURE);
46 }
47 }
48
49 int
50 main(void)
51 {
52 test5225889(5, 10);
53 test5225889(10, 5);
54
55 fprintf(stdout, "Finished.\n");
56
57 exit(EXIT_SUCCESS);
58 }