1 /***
2 This file is part of PulseAudio.
3
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
8
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
16 ***/
17
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include <check.h>
23 #include <signal.h>
24
25 #include <pulsecore/poll.h>
26 #include <pulsecore/log.h>
27 #include <pulsecore/rtpoll.h>
28
before(pa_rtpoll_item * i)29 static int before(pa_rtpoll_item *i) {
30 pa_log("before");
31 return 0;
32 }
33
after(pa_rtpoll_item * i)34 static void after(pa_rtpoll_item *i) {
35 pa_log("after");
36 }
37
worker(pa_rtpoll_item * w)38 static int worker(pa_rtpoll_item *w) {
39 pa_log("worker");
40 return 0;
41 }
42
START_TEST(rtpoll_test)43 START_TEST (rtpoll_test) {
44 pa_rtpoll *p;
45 pa_rtpoll_item *i, *w;
46 struct pollfd *pollfd;
47
48 p = pa_rtpoll_new();
49
50 i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
51 pa_rtpoll_item_set_before_callback(i, before, NULL);
52 pa_rtpoll_item_set_after_callback(i, after, NULL);
53
54 pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
55 pollfd->fd = 0;
56 pollfd->events = POLLIN;
57
58 w = pa_rtpoll_item_new(p, PA_RTPOLL_NORMAL, 0);
59 pa_rtpoll_item_set_before_callback(w, worker, NULL);
60
61 pa_rtpoll_set_timer_relative(p, 10000000); /* 10 s */
62
63 fail_unless(pa_rtpoll_run(p) >= 0);
64
65 pa_rtpoll_item_free(i);
66
67 i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
68 pa_rtpoll_item_set_before_callback(i, before, NULL);
69 pa_rtpoll_item_set_after_callback(i, after, NULL);
70
71 pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
72 pollfd->fd = 0;
73 pollfd->events = POLLIN;
74
75 fail_unless(pa_rtpoll_run(p) >= 0);
76
77 pa_rtpoll_item_free(i);
78
79 pa_rtpoll_item_free(w);
80
81 pa_rtpoll_free(p);
82 }
83 END_TEST
84
main(int argc,char * argv[])85 int main(int argc, char *argv[]) {
86 int failed = 0;
87 Suite *s;
88 TCase *tc;
89 SRunner *sr;
90
91 s = suite_create("RT Poll");
92 tc = tcase_create("rtpoll");
93 tcase_add_test(tc, rtpoll_test);
94 /* the default timeout is too small,
95 * set it to a reasonable large one.
96 */
97 tcase_set_timeout(tc, 60 * 60);
98 suite_add_tcase(s, tc);
99
100 sr = srunner_create(s);
101 srunner_run_all(sr, CK_NORMAL);
102 failed = srunner_ntests_failed(sr);
103 srunner_free(sr);
104
105 return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
106 }
107