]> code.delx.au - pulseaudio/blob - src/tests/cpulimit-test.c
Updated catalan po
[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 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 <sys/time.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <signal.h>
29
30 #include <pulse/mainloop.h>
31 #include <pulse/gccmacro.h>
32
33 #ifdef TEST2
34 #include <pulse/mainloop-signal.h>
35 #endif
36
37 #include "../daemon/cpulimit.h"
38
39 /* A simple example for testing the cpulimit subsystem */
40
41 static time_t start;
42
43 #ifdef TEST2
44
45 static void func(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) {
46 time_t now;
47 time(&now);
48
49 if ((now - start) >= 30) {
50 m->quit(m, 1);
51 fprintf(stderr, "Test failed\n");
52 } else
53 raise(SIGUSR1);
54 }
55
56 #endif
57
58 int main(int argc, char *argv[]) {
59 pa_mainloop *m;
60
61 m = pa_mainloop_new();
62 assert(m);
63
64 pa_cpu_limit_init(pa_mainloop_get_api(m));
65
66 time(&start);
67
68 #ifdef TEST2
69 pa_signal_init(pa_mainloop_get_api(m));
70 pa_signal_new(SIGUSR1, func, NULL);
71 raise(SIGUSR1);
72 pa_mainloop_run(m, NULL);
73 pa_signal_done();
74 #else
75 for (;;) {
76 time_t now;
77 time(&now);
78
79 if ((now - start) >= 30) {
80 fprintf(stderr, "Test failed\n");
81 break;
82 }
83 }
84 #endif
85
86 pa_cpu_limit_done();
87
88 pa_mainloop_free(m);
89
90 return 0;
91 }