]> code.delx.au - pulseaudio/blob - src/tests/cpulimit-test.c
Cleaned up the includes after the restructuring. Indicate which headers are
[pulseaudio] / src / tests / cpulimit-test.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27 #include <sys/time.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <signal.h>
31
32 #include <polyp/mainloop.h>
33 #include <polypcore/gccmacro.h>
34
35 #ifdef TEST2
36 #include <polyp/mainloop-signal.h>
37 #endif
38
39 #include "../daemon/cpulimit.h"
40
41 /* A simple example for testing the cpulimit subsystem */
42
43 static time_t start;
44
45 #ifdef TEST2
46
47 static void func(pa_mainloop_api *m, PA_GCC_UNUSED pa_signal_event *e, PA_GCC_UNUSED int sig, PA_GCC_UNUSED void *userdata) {
48 time_t now;
49 time(&now);
50
51 if ((now - start) >= 30) {
52 m->quit(m, 1);
53 fprintf(stderr, "Test failed\n");
54 } else
55 raise(SIGUSR1);
56 }
57
58 #endif
59
60 int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
61 pa_mainloop *m;
62
63 m = pa_mainloop_new();
64 assert(m);
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 break;
84 }
85 }
86 #endif
87
88 pa_cpu_limit_done();
89
90 pa_mainloop_free(m);
91
92 return 0;
93 }