]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/fwp/fwp/lib/fwp/tests/fwp_vrestest/fwp_vrestest1.c
Fix uninitialized memory bug that caused the test to fail sometimes
[frescor/frsh-forb.git] / src / fwp / fwp / lib / fwp / tests / fwp_vrestest / fwp_vrestest1.c
1 /**
2  * \file fwp_vrestest1.c  
3  *
4  * This a test application that:
5  * - creates vres without negotiation
6  * - creates send and receive endpoint 
7  * - binds that endpoint to vres
8  * - in cycle (NUM loops) sends messages and prints send time
9  * - receives messages
10  * - destroys vres
11  *
12  */
13 #define  CONFIGURE_FWP_MNGT 0
14 #include "fwp_confdefs.h"
15 #include "fwp.h"
16
17 #include <errno.h>
18 #include <stdio.h>
19 #include <arpa/inet.h>
20 #include <time.h>
21 #define WVTEST_CONFIGURED
22 #include <wvtest.h>
23 #include <stdlib.h>
24
25 #define  NUM  2
26
27 WVTEST_MAIN("FWP VRES single thread")
28 {
29 //      struct sockaddr_in local_addr, rem_addr, from;
30         ssize_t len;
31         fwp_vres_t *vres1, *vres2;
32         struct fwp_vres_params vparam1;
33         char msg1[15];
34         char buffer[30];
35         struct fwp_endpoint *sepoint, *repoint;
36         int count;
37         struct timespec  sendtime;
38         fwp_endpoint_attr_t attr;
39         unsigned int from;
40         
41         fwp_endpoint_attr_init(&attr);
42
43         memset(&vparam1, 0, sizeof(vparam1));
44         vparam1.ac_id = FWP_AC_VO; 
45         vparam1.budget = 100;
46         vparam1.period.tv_sec = 2; 
47         vparam1.period.tv_nsec = 111111; 
48
49         if (WVFAIL(fwp_init() != 0)) {
50                 printf("fwp_init failed!\n");
51                 exit(1);
52         }       
53         
54         if (WVFAIL(fwp_vres_create(&vparam1, &vres1) < 0)) {
55                 printf("Unable to create vres1\n");
56                 exit(1);
57         }
58
59         if (WVFAIL(fwp_vres_create(&vparam1, &vres2) < 0)) {
60                 printf("Unable to create vres2\n");
61                 exit(1);
62         }
63
64         /* local_addr should be handled when creating socket */
65         if (WVFAIL(fwp_receive_endpoint_create(7777, &attr, &repoint) < 0)) {
66                 exit(1);
67         }
68         
69         if (WVFAIL(fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
70                                             &sepoint) < 0)) {
71                 exit(1);
72         }
73
74         WVPASS(fwp_send_endpoint_bind(sepoint, vres1) == 0);
75         
76         for (count = 0; count < NUM; count++) { 
77                 sprintf(msg1,"msg%d",count);
78                 WVPASSEQ(fwp_send_sync(sepoint, msg1, sizeof(msg1)), sizeof(msg1));
79                 
80                 clock_gettime(CLOCK_MONOTONIC, &sendtime);
81                 printf("Sent: sec = %ld nsec = %ld \n", sendtime.tv_sec,
82                        sendtime.tv_nsec);
83                 
84                 if (WVFAIL((len = fwp_recv(repoint, buffer, sizeof(buffer), &from, 0)) < 0)) {
85                         perror("Error while receiving data");
86                         exit(1);
87                 } 
88                 else printf("Received - %s\n", buffer);
89                 WVPASSEQSTR(msg1, buffer);
90         }
91
92         if (WVFAIL(fwp_vres_destroy(vres1) < 0)) {
93                 perror("Unable to destroy vres1\n");
94                 exit(1);
95         }
96         if (WVFAIL(fwp_vres_destroy(vres2) < 0)) {
97                 perror("Unable to destroy vres1\n");
98                 exit(1);
99         }
100         WVPASSEQ(fwp_endpoint_destroy(sepoint), 0);
101         WVPASSEQ(fwp_endpoint_destroy(repoint), 0);
102         printf("Vres1 detroyed\n");
103         printf("Test PASSED!\n");
104 }