]> code.delx.au - pulseaudio/blob - polyp/cpulimit-test.c
add simple hardware auto detection module
[pulseaudio] / polyp / 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 "cpulimit.h"
33 #include "mainloop.h"
34 #include "gccmacro.h"
35
36 #ifdef TEST2
37 #include "mainloop-signal.h"
38 #endif
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_GCC_UNUSED pa_signal_event *e, PA_GCC_UNUSED int sig, PA_GCC_UNUSED 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 } else
54 raise(SIGUSR1);
55 }
56
57 #endif
58
59 int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
60 pa_mainloop *m;
61
62 m = pa_mainloop_new();
63 assert(m);
64
65 pa_cpu_limit_init(pa_mainloop_get_api(m));
66
67 time(&start);
68
69 #ifdef TEST2
70 pa_signal_init(pa_mainloop_get_api(m));
71 pa_signal_new(SIGUSR1, func, NULL);
72 raise(SIGUSR1);
73 pa_mainloop_run(m, NULL);
74 pa_signal_done();
75 #else
76 for (;;) {
77 time_t now;
78 time(&now);
79
80 if ((now - start) >= 30) {
81 fprintf(stderr, "Test failed\n");
82 break;
83 }
84 }
85 #endif
86
87 pa_cpu_limit_done();
88
89 pa_mainloop_free(m);
90
91 return 0;
92 }