]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blobdiff - src/fwp/fwp/lib/fwp/tests/fwp_vrestest/fwp_vrestest1.c
rtems: Use Makefile.rules which pass OMK test suite
[frescor/frsh-forb.git] / src / fwp / fwp / lib / fwp / tests / fwp_vrestest / fwp_vrestest1.c
index fc0faab2fcd62af389077111e747fb1bfade2099..ee47040715520352ef68870bcd6a252480ecd8f9 100644 (file)
 #include <stdio.h>
 #include <arpa/inet.h>
 #include <time.h>
+#define WVTEST_CONFIGURED
+#include <wvtest.h>
+#include <stdlib.h>
 
-#define  NUM  10000
+#define  NUM  2
 
-int main()
+WVTEST_MAIN("FWP VRES synchronous communication")
 {
 //     struct sockaddr_in local_addr, rem_addr, from;
         ssize_t len;
@@ -42,58 +45,59 @@ int main()
        vparam1.period.tv_sec = 2; 
        vparam1.period.tv_nsec = 111111; 
 
-       printf("Start\n");
-       if (fwp_init() != 0) {
+       if (WVFAIL(fwp_init() != 0)) {
                printf("fwp_init failed!\n");
-               return -1;
+               exit(1);
        }       
        
-       printf("Create vres1\n");
-       if ((fwp_vres_create(&vparam1, &vres1) < 0)) {
+       if (WVFAIL(fwp_vres_create(&vparam1, &vres1) < 0)) {
                printf("Unable to create vres1\n");
-               return -1;
+               exit(1);
        }
-       printf("Vres1 created\n");
-       
-       printf("Create vres2\n");
-       if ((fwp_vres_create(&vparam1, &vres2) < 0)) {
+
+       if (WVFAIL(fwp_vres_create(&vparam1, &vres2) < 0)) {
                printf("Unable to create vres2\n");
-               return -1;
+               exit(1);
        }
-       printf("Vres2 created\n");
+
        /* local_addr should be handled when creating socket */
-       if (fwp_receive_endpoint_create(7777, &attr, &repoint) < 0) {
-               return -1;
+       if (WVFAIL(fwp_receive_endpoint_create(7777, &attr, &repoint) < 0)) {
+               exit(1);
        }
-       printf("Receive endpoint created\n");
        
-       if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
-                                    &sepoint) < 0){
-               return -1;
+       if (WVFAIL(fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
+                                           &sepoint) < 0)) {
+               exit(1);
        }
-       printf("Send endpoint 1 created\n");
-       fwp_send_endpoint_bind(sepoint, vres1);
+
+       WVPASS(fwp_send_endpoint_bind(sepoint, vres1) == 0);
        
        for (count = 0; count < NUM; count++) { 
                sprintf(msg1,"msg%d",count);
-               fwp_send_sync(sepoint, msg1, sizeof(msg1));
+               WVPASSEQ(fwp_send_sync(sepoint, msg1, sizeof(msg1)), sizeof(msg1));
                
                clock_gettime(CLOCK_MONOTONIC, &sendtime);
                printf("Sent: sec = %ld nsec = %ld \n", sendtime.tv_sec,
                       sendtime.tv_nsec);
                
-               if ((len = fwp_recv(repoint, buffer, sizeof(buffer), &from, 0)) < 0) {
+               if (WVFAIL((len = fwp_recv(repoint, buffer, sizeof(buffer), &from, 0)) < 0)) {
                        perror("Error while receiving data");
-                       return -1;
+                       exit(1);
                } 
-                       else printf("Received - %s\n", buffer);
+               else printf("Received - %s\n", buffer);
+               WVPASSEQSTR(msg1, buffer);
        }
 
-       if (fwp_vres_destroy(vres1) < 0) {
+       if (WVFAIL(fwp_vres_destroy(vres1) < 0)) {
+               perror("Unable to destroy vres1\n");
+               exit(1);
+       }
+       if (WVFAIL(fwp_vres_destroy(vres2) < 0)) {
                perror("Unable to destroy vres1\n");
-               return -1;
+               exit(1);
        }
+       WVPASSEQ(fwp_endpoint_destroy(sepoint), 0);
+       WVPASSEQ(fwp_endpoint_destroy(repoint), 0);
        printf("Vres1 detroyed\n");
        printf("Test PASSED!\n");
-       return 0;
 }