]>
code.delx.au - pulseaudio/blob - src/tests/lock-autospawn-test.c
2 This file is part of PulseAudio.
4 Copyright 2008 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio 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.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulsecore/poll.h>
31 #include <pulsecore/macro.h>
32 #include <pulsecore/thread.h>
33 #include <pulsecore/lock-autospawn.h>
34 #include <pulse/util.h>
36 static void thread_func(void*k
) {
37 fail_unless(pa_autospawn_lock_init() >= 0);
39 pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k
));
41 fail_unless(pa_autospawn_lock_acquire(true) > 0);
43 pa_log("%i, Got the lock!, Sleeping for 5s", PA_PTR_TO_INT(k
));
47 pa_log("%i, Releasing", PA_PTR_TO_INT(k
));
49 pa_autospawn_lock_release();
51 pa_autospawn_lock_done(false);
54 static void thread_func2(void *k
) {
57 fail_unless((fd
= pa_autospawn_lock_init()) >= 0);
59 pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k
));
65 if ((j
= pa_autospawn_lock_acquire(false)) > 0)
70 memset(&pollfd
, 0, sizeof(pollfd
));
72 pollfd
.events
= POLLIN
;
74 fail_unless(pa_poll(&pollfd
, 1, -1) == 1);
76 pa_log("%i, woke up", PA_PTR_TO_INT(k
));
79 pa_log("%i, Got the lock!, Sleeping for 5s", PA_PTR_TO_INT(k
));
83 pa_log("%i, Releasing", PA_PTR_TO_INT(k
));
85 pa_autospawn_lock_release();
87 pa_autospawn_lock_done(false);
90 START_TEST (lockautospawn_test
) {
91 pa_thread
*a
, *b
, *c
, *d
;
93 pa_assert_se((a
= pa_thread_new("test1", thread_func
, PA_INT_TO_PTR(1))));
94 pa_assert_se((b
= pa_thread_new("test2", thread_func2
, PA_INT_TO_PTR(2))));
95 pa_assert_se((c
= pa_thread_new("test3", thread_func2
, PA_INT_TO_PTR(3))));
96 pa_assert_se((d
= pa_thread_new("test4", thread_func
, PA_INT_TO_PTR(4))));
110 int main(int argc
, char *argv
[]) {
116 s
= suite_create("Lock Auto Spawn");
117 tc
= tcase_create("lockautospawn");
118 tcase_add_test(tc
, lockautospawn_test
);
119 /* the default timeout is too small,
120 * set it to a reasonable large one.
122 tcase_set_timeout(tc
, 60 * 60);
123 suite_add_tcase(s
, tc
);
125 sr
= srunner_create(s
);
126 srunner_run_all(sr
, CK_NORMAL
);
127 failed
= srunner_ntests_failed(sr
);
130 return (failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;