]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
forb: Convert syncobj test to wvtest style
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 20 Feb 2011 08:37:39 +0000 (09:37 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 20 Feb 2011 10:00:48 +0000 (11:00 +0100)
src/tests/Makefile.omk
src/tests/test_syncobj.c

index 1bc15b2cd35a1718328cc68a4489b399a3c94099..d05eadc57499ecd82610f5bf7bf73da6356fed40 100644 (file)
@@ -1,8 +1,8 @@
 SUBDIRS = $(ALL_OMK_SUBDIRS)
 
-wvtest_PROGRAMS += hello_inproc test_proto_inet discovery
+wvtest_PROGRAMS += hello_inproc test_proto_inet discovery syncobj
 
-test_PROGRAMS += hello_remote syncobj regobjref executor_id #executor_calls
+test_PROGRAMS += hello_remote regobjref executor_id #executor_calls
 ifeq ($(CONFIG_FORB_PROTO_UNIX),y)
 wvtest_PROGRAMS += test_proto_unix
 endif
index 7e75a3c9e2730634a328ea6593b334ca3e2088f4..f1b9ce384d5655f0f2f44b3fd1d97e6cb16c7bbc 100644 (file)
@@ -58,6 +58,7 @@
 #include <forb/syncobj.h>
 #include <fosa.h>
 #include <error.h>
+#include <wvtest.h>
 
 forb_syncobj_t syncobj;
 
@@ -69,40 +70,39 @@ void *thread(void *arg)
 
        fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &hello_time);
        hello_time = fosa_abs_time_incr(hello_time, hello_interval);
-       ret = forb_syncobj_timedwait(&syncobj, &hello_time);
+       WVPASSEQ(ret = forb_syncobj_timedwait(&syncobj, &hello_time), 0);
        if (ret != 0) {
                error(1, errno, "forb_syncobj_timedwait() error %d\n", ret);
        }
 
        fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
-       if (fosa_abs_time_smaller_or_equal(hello_time, now)) {
+       if (WVFAIL(fosa_abs_time_smaller_or_equal(hello_time, now))) {
                error(1, 0, "Should not wait longet than timeout\n");
        }
        return NULL;
 }
 
-int main()
+WVTEST_MAIN("FORB's syncobj")
 {
        fosa_abs_time_t now, hello_time;
-       fosa_rel_time_t hello_interval = fosa_msec_to_rel_time(1000);
+       fosa_rel_time_t hello_interval = fosa_msec_to_rel_time(100);
        int ret;
-       fosa_thread_id_t tid;
+       pthread_t tid;
 
-       forb_syncobj_init(&syncobj, 0);
+       WVPASSEQ(forb_syncobj_init(&syncobj, 0), 0);
 
        fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &hello_time);
        hello_time = fosa_abs_time_incr(hello_time, hello_interval);
 
        ret = forb_syncobj_timedwait(&syncobj, &hello_time);
-       if (ret != 0 && ret != FOSA_ETIMEDOUT) {
+       if (!WVPASS(ret == FOSA_ETIMEDOUT || ret == 0)) {
                error(1, errno, "forb_syncobj_timedwait() error %d\n", ret);
        }
        fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
-       if (fosa_abs_time_smaller_or_equal(now, hello_time)) {
+       if (WVFAIL(fosa_abs_time_smaller_or_equal(now, hello_time))) {
                error(1, 0, "Wait less then timeout\n");
        }
-
-       fosa_thread_create(&tid, NULL, thread, NULL);
+       pthread_create(&tid, NULL, thread, NULL);
        forb_syncobj_signal(&syncobj);
-       return 0;
+       pthread_join(tid, NULL);
 }