]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - 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
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 synchronous communication")
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         vparam1.ac_id = FWP_AC_VO; 
44         vparam1.budget = 100;
45         vparam1.period.tv_sec = 2; 
46         vparam1.period.tv_nsec = 111111; 
47
48         if (WVFAIL(fwp_init() != 0)) {
49                 printf("fwp_init failed!\n");
50                 exit(1);
51         }       
52         
53         if (WVFAIL(fwp_vres_create(&vparam1, &vres1) < 0)) {
54                 printf("Unable to create vres1\n");
55                 exit(1);
56         }
57
58         if (WVFAIL(fwp_vres_create(&vparam1, &vres2) < 0)) {
59                 printf("Unable to create vres2\n");
60                 exit(1);
61         }
62
63         /* local_addr should be handled when creating socket */
64         if (WVFAIL(fwp_receive_endpoint_create(7777, &attr, &repoint) < 0)) {
65                 exit(1);
66         }
67         
68         if (WVFAIL(fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
69                                             &sepoint) < 0)) {
70                 exit(1);
71         }
72
73         WVPASS(fwp_send_endpoint_bind(sepoint, vres1) == 0);
74         
75         for (count = 0; count < NUM; count++) { 
76                 sprintf(msg1,"msg%d",count);
77                 WVPASSEQ(fwp_send_sync(sepoint, msg1, sizeof(msg1)), sizeof(msg1));
78                 
79                 clock_gettime(CLOCK_MONOTONIC, &sendtime);
80                 printf("Sent: sec = %ld nsec = %ld \n", sendtime.tv_sec,
81                        sendtime.tv_nsec);
82                 
83                 if (WVFAIL((len = fwp_recv(repoint, buffer, sizeof(buffer), &from, 0)) < 0)) {
84                         perror("Error while receiving data");
85                         exit(1);
86                 } 
87                 else printf("Received - %s\n", buffer);
88                 WVPASSEQSTR(msg1, buffer);
89         }
90
91         if (WVFAIL(fwp_vres_destroy(vres1) < 0)) {
92                 perror("Unable to destroy vres1\n");
93                 exit(1);
94         }
95         if (WVFAIL(fwp_vres_destroy(vres2) < 0)) {
96                 perror("Unable to destroy vres1\n");
97                 exit(1);
98         }
99         WVPASSEQ(fwp_endpoint_destroy(sepoint), 0);
100         WVPASSEQ(fwp_endpoint_destroy(repoint), 0);
101         printf("Vres1 detroyed\n");
102         printf("Test PASSED!\n");
103 }