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, see <http://www.gnu.org/licenses/>. 16***/ 17 18#ifdef HAVE_CONFIG_H 19#include <config.h> 20#endif 21 22#include <assert.h> 23#include <time.h> 24#include <stdlib.h> 25#include <stdio.h> 26#include <signal.h> 27 28#include <check.h> 29 30#include <pulse/mainloop.h> 31 32#ifdef TEST2 33#include <pulse/mainloop-signal.h> 34#endif 35 36#include <daemon/cpulimit.h> 37 38/* A simple example for testing the cpulimit subsystem */ 39 40static time_t start; 41 42#ifdef TEST2 43 44static void func(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) { 45 time_t now; 46 time(&now); 47 48 if ((now - start) >= 30) { 49 m->quit(m, 1); 50 fprintf(stderr, "Test failed\n"); 51 ck_abort(); 52 } else 53 raise(SIGUSR1); 54} 55 56#endif 57 58START_TEST (cpulimit_test) { 59 pa_mainloop *m; 60 61 m = pa_mainloop_new(); 62 fail_unless(m != NULL); 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 ck_abort(); 82 break; 83 } 84 } 85#endif 86 87 pa_cpu_limit_done(); 88 89 pa_mainloop_free(m); 90} 91END_TEST 92 93int main(int argc, char *argv[]) { 94 int failed = 0; 95 Suite *s; 96 TCase *tc; 97 SRunner *sr; 98 99 s = suite_create("CPU Limit"); 100 tc = tcase_create("cpulimit"); 101 tcase_add_test(tc, cpulimit_test); 102 suite_add_tcase(s, tc); 103 104 sr = srunner_create(s); 105 srunner_run_all(sr, CK_NORMAL); 106 failed = srunner_ntests_failed(sr); 107 srunner_free(sr); 108 109 return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 110} 111