]> code.delx.au - pulseaudio/blob - src/tests/cpulimit-test.c
channelmap: Add 2.1 surround
[pulseaudio] / src / tests / cpulimit-test.c
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
6 published by the Free Software Foundation; either version 2.1 of the
7 License, 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
15 License along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <assert.h>
25 #include <time.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <signal.h>
29
30 #include <check.h>
31
32 #include <pulse/mainloop.h>
33
34 #ifdef TEST2
35 #include <pulse/mainloop-signal.h>
36 #endif
37
38 #include <daemon/cpulimit.h>
39
40 /* A simple example for testing the cpulimit subsystem */
41
42 static time_t start;
43
44 #ifdef TEST2
45
46 static void func(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
47 time_t now;
48 time(&now);
49
50 if ((now - start) >= 30) {
51 m->quit(m, 1);
52 fprintf(stderr, "Test failed\n");
53 fail();
54 } else
55 raise(SIGUSR1);
56 }
57
58 #endif
59
60 START_TEST (cpulimit_test) {
61 pa_mainloop *m;
62
63 m = pa_mainloop_new();
64 fail_unless(m != NULL);
65
66 pa_cpu_limit_init(pa_mainloop_get_api(m));
67
68 time(&start);
69
70 #ifdef TEST2
71 pa_signal_init(pa_mainloop_get_api(m));
72 pa_signal_new(SIGUSR1, func, NULL);
73 raise(SIGUSR1);
74 pa_mainloop_run(m, NULL);
75 pa_signal_done();
76 #else
77 for (;;) {
78 time_t now;
79 time(&now);
80
81 if ((now - start) >= 30) {
82 fprintf(stderr, "Test failed\n");
83 fail();
84 break;
85 }
86 }
87 #endif
88
89 pa_cpu_limit_done();
90
91 pa_mainloop_free(m);
92 }
93 END_TEST
94
95 int main(int argc, char *argv[]) {
96 int failed = 0;
97 Suite *s;
98 TCase *tc;
99 SRunner *sr;
100
101 s = suite_create("CPU Limit");
102 tc = tcase_create("cpulimit");
103 tcase_add_test(tc, cpulimit_test);
104 suite_add_tcase(s, tc);
105
106 sr = srunner_create(s);
107 srunner_run_all(sr, CK_NORMAL);
108 failed = srunner_ntests_failed(sr);
109 srunner_free(sr);
110
111 return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
112 }