#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;
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;
}