tests: modify lock-autospawn-test to use 'check' framework

This commit is contained in:
Deng Zhengrong 2012-07-29 06:58:30 +08:00 committed by Arun Raghavan
parent d9841a9431
commit b095ebd502
2 changed files with 34 additions and 10 deletions

View file

@ -23,6 +23,8 @@
#include <config.h>
#endif
#include <check.h>
#include <string.h>
#include <pulsecore/poll.h>
@ -32,11 +34,11 @@
#include <pulse/util.h>
static void thread_func(void*k) {
pa_assert_se(pa_autospawn_lock_init() >= 0);
fail_unless(pa_autospawn_lock_init() >= 0);
pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k));
pa_assert_se(pa_autospawn_lock_acquire(TRUE) > 0);
fail_unless(pa_autospawn_lock_acquire(TRUE) > 0);
pa_log("%i, Got the lock!, Sleeping for 5s", PA_PTR_TO_INT(k));
@ -52,7 +54,7 @@ static void thread_func(void*k) {
static void thread_func2(void *k) {
int fd;
pa_assert_se((fd = pa_autospawn_lock_init()) >= 0);
fail_unless((fd = pa_autospawn_lock_init()) >= 0);
pa_log("%i, Trying to acquire lock.", PA_PTR_TO_INT(k));
@ -63,13 +65,13 @@ static void thread_func2(void *k) {
if ((j = pa_autospawn_lock_acquire(FALSE)) > 0)
break;
pa_assert(j == 0);
fail_unless(j == 0);
memset(&pollfd, 0, sizeof(pollfd));
pollfd.fd = fd;
pollfd.events = POLLIN;
pa_assert_se(pa_poll(&pollfd, 1, -1) == 1);
fail_unless(pa_poll(&pollfd, 1, -1) == 1);
pa_log("%i, woke up", PA_PTR_TO_INT(k));
}
@ -85,7 +87,7 @@ static void thread_func2(void *k) {
pa_autospawn_lock_done(FALSE);
}
int main(int argc, char**argv) {
START_TEST (lockautospawn_test) {
pa_thread *a, *b, *c, *d;
pa_assert_se((a = pa_thread_new("test1", thread_func, PA_INT_TO_PTR(1))));
@ -102,6 +104,28 @@ int main(int argc, char**argv) {
pa_thread_free(b);
pa_thread_free(c);
pa_thread_free(d);
return 0;
}
END_TEST
int main(int argc, char *argv[]) {
int failed = 0;
Suite *s;
TCase *tc;
SRunner *sr;
s = suite_create("Lock Auto Spawn");
tc = tcase_create("lockautospawn");
tcase_add_test(tc, lockautospawn_test);
/* the default timeout is too small,
* set it to a reasonable large one.
*/
tcase_set_timeout(tc, 60 * 60);
suite_add_tcase(s, tc);
sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}