]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
forb: Convert some older tests to wvtest framework
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 19 Feb 2011 15:22:37 +0000 (16:22 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 19 Feb 2011 15:22:37 +0000 (16:22 +0100)
src/tests/Makefile.omk
src/tests/discovery.c
src/tests/hello_inproc.c
src/tests/test_proto_inet.c

index d3fa45dc36e6ea34f7ad2d39882fafa22b268db1..1bc15b2cd35a1718328cc68a4489b399a3c94099 100644 (file)
@@ -1,9 +1,10 @@
 SUBDIRS = $(ALL_OMK_SUBDIRS)
 
-test_PROGRAMS += hello_inproc hello_remote test_proto_inet discovery   \
-               syncobj regobjref executor_id #executor_calls
+wvtest_PROGRAMS += hello_inproc test_proto_inet discovery
+
+test_PROGRAMS += hello_remote syncobj regobjref executor_id #executor_calls
 ifeq ($(CONFIG_FORB_PROTO_UNIX),y)
-test_PROGRAMS += test_proto_unix
+wvtest_PROGRAMS += test_proto_unix
 endif
 
 wvtest_PROGRAMS += sequence
@@ -47,4 +48,4 @@ syncobj_SOURCES = test_syncobj.c
 
 executor_id_SOURCES = executor_id.c
 
-executor_calls_SOURCES = executor_calls.c
\ No newline at end of file
+executor_calls_SOURCES = executor_calls.c
index 48b0a0888e7f7d790683db917d6cf4a44e70126c..51cf6fedd5f1caa2a59d3487c756eb2b5585f8ad 100644 (file)
@@ -66,6 +66,7 @@
 #include <error.h>
 #include <fosa.h>
 #include <stdio.h>
+#include <wvtest.h>
 
 #define NUM_ORBS 5
 
 #error This test should only work if there is some local protocol enabled.
 #endif
 
-int main(int argc, char *argv[])
+WVTEST_MAIN("Automatic discovery of FORB servers")
 {
+#ifndef CONFIG_FORB_PROTO_INET_DEFAULT
        forb_orb orb[NUM_ORBS];
        int i;
        bool all_peers_found = true;
        fosa_abs_time_t timeout;
 
-       for (i=0; i<NUM_ORBS; i++) {
-               orb[i] = forb_init(&argc, &argv, NULL);
-               if (!orb[i]) {
-                       error(1, errno, "Orb no. %d was not created\n", i);
-               }
-       }
+       for (i=0; i<NUM_ORBS; i++)
+               WVPASS(orb[i] = forb_init(0, NULL, NULL));
 
        fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &timeout);
        timeout = fosa_abs_time_incr(timeout,
@@ -97,9 +95,9 @@ int main(int argc, char *argv[])
                forb_peer_t *peer;
                for (j=0; j<NUM_ORBS && all_peers_found; j++) {
                        if (i==j) continue;
-                       peer = forb_peer_find_timed(forb_data(orb[i]),
-                                                   &forb_data(orb[j])->server_id,
-                                                   &timeout);
+                       WVPASS(peer = forb_peer_find_timed(forb_data(orb[i]),
+                                                          &forb_data(orb[j])->server_id,
+                                                          &timeout));
 
                        all_peers_found &= (peer != NULL);
                        if (!all_peers_found) {
@@ -112,7 +110,5 @@ int main(int argc, char *argv[])
                        }
                }
        }
-
-       printf("OK\n");
-       return 0;
+#endif
 }
index 701c9089230c871b1a8c2e99cc2511b7b9c9fff6..93015cdbb34e5bada585b6156983138644feaec4 100644 (file)
@@ -58,8 +58,9 @@
 #include "hello_impl.h"
 #include <forb.h>
 #include <error.h>
+#include <wvtest.h>
 
-int main(int argc, char *argv[])
+WVTEST_MAIN("in-proccess hello world")
 {
        forb_orb orb;
        hello hobj;
@@ -68,16 +69,15 @@ int main(int argc, char *argv[])
                .orb_id = "hello_inproc"
        };
                
-       orb = forb_init(&argc, &argv, &attr);
+       WVPASS(orb = forb_init(0, NULL, &attr));
        if (!orb) {
                error(1, errno, "Cannot initialize FORB");
        }
        hobj = hello_impl_initialize(orb);
 
        hello_message(hobj, "Hello world!", &env);
-       if (forb_exception_occurred(&env)) {
+       if (!WVPASS(!forb_exception_occurred(&env))) {
                error(1, 0, "FORB exception %d", env.major);
        }
-               
-       return 0;       
+       forb_destroy(orb);
 }
index 25e8348b55f98c758a98ac497e30dc6b103cda91..2b7cbd22bedeb798d7fa846e794cbc3170924be0 100644 (file)
@@ -54,6 +54,7 @@
 
 #include <error.h>
 #include "../proto_inet.c"
+#include <wvtest.h>
 
 const char *msg = "Hello world!";
 const char *msg2 = "Blablabla!";
@@ -63,10 +64,10 @@ char *timeout_msg = "timeout\n";
 
 void timeout(int signal)
 {
-       error(1, 0, timeout_msg);
+       //error(1, 0, timeout_msg);
 }
 
-int main()
+WVTEST_MAIN("AF_INET inter-orb protocol")
 {
        int len;
        struct inet_addr addr[NUM_PORTS];
@@ -79,23 +80,23 @@ int main()
 
        for (i=0; i<NUM_PORTS; i++) {
                addr[i].addr.s_addr = htonl(0x7f000001+i);
-               if (forb_inet_port_init(&port[i].desc, addr[i].addr, 0) != 0)
+               if (!WVPASSEQ(forb_inet_port_init(&port[i].desc, addr[i].addr, 0), 0))
                        error(1, errno, "forb_inet_port_init(%d)", i);
        }
 
 
        /* Send from zeroth node to all others (starting from 1) */
        for (i=1; i<NUM_PORTS; i++) {
-               forb_peer_t *peer;
                char buf[100];
                char tmsg[100];
-
-               peer = forb_peer_new();
+               forb_peer_t *peer;
+               
+               WVPASS(peer = forb_peer_new());
                peer->addr = port[i].desc.addr;
                peer->port = &port[0];
                
                len = strlen(msg)+1;
-               ret = inet_send(peer, msg, len);
+               WVPASSEQ(ret = inet_send(peer, msg, len), len);
 
                peer->addr = NULL;
                forb_peer_put(peer);
@@ -105,18 +106,18 @@ int main()
                sprintf(tmsg, "Timeout when sending from 0 to %d\n", i);
                timeout_msg = tmsg;
                alarm(1);       /* timeout 1s */
-               ret = inet_recv(&port[i], buf, sizeof(buf));
+               WVPASSEQ(ret = inet_recv(&port[i], buf, sizeof(buf)), len);
                alarm(0);
                if (ret != len)
                        error(1, errno, "recv(port[%d]) = %d", i, ret);
 
-               if (strcmp(msg, buf) != 0)
+               if (!WVPASS(strcmp(msg, buf) == 0))
                        error(1, errno, "port %d: received wrong data", i);
-
        }
 
+#ifndef CONFIG_FORB_PROTO_INET_DEFAULT
        len = strlen(msg2)+1;
-       ret = inet_broadcast(&port[0], msg2, len);
+       WVPASSEQ(ret = inet_broadcast(&port[0], msg2, len), len);
        if (ret != len) 
                error(1, errno, "broadcast(port[0]) = %d should be %d", ret, len);
        
@@ -127,21 +128,21 @@ int main()
                sprintf(tmsg, "Timeout when receiving broadcast for port %d\n", i);
                timeout_msg = tmsg;
                alarm(1);
-               ret = inet_recv(&port[i], buf, sizeof(buf));
+               WVPASSEQ(ret = inet_recv(&port[i], buf, sizeof(buf)), len);
                alarm(0);
                if (ret != len) 
                        error(1, errno, "broadcast recv(port[%d]) = %d should be %d (errno=%d)", i, ret, len, errno);
                //printf("broadcast received: %s\n", buf);
 
-               if (strcmp(msg2, buf) != 0)
+               if (!WVPASS(strcmp(msg2, buf) == 0))
                        error(1, errno, "port %d: broadcast received wrong data", i);
 
        }
+#endif
 
        for (i=0; i<NUM_PORTS; i++) {
                inet_port_destroy(&port[i]);
+               if (port[i].new_peer)
+                       forb_peer_put(port[i].new_peer);
        }
-
-       printf("OK\n");
-       return 0;
 }