]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Test for distributed module added. Uses FWP by defualt
authorMartin <molnam1@fel.cvut.cz>
Wed, 22 Oct 2008 14:29:39 +0000 (16:29 +0200)
committerMartin <molnam1@fel.cvut.cz>
Wed, 22 Oct 2008 14:29:39 +0000 (16:29 +0200)
frsh_api/Makefile.omk
frsh_api/tests/Makefile [new file with mode: 0644]
frsh_api/tests/Makefile.omk [new file with mode: 0644]
frsh_api/tests/distributed.c [new file with mode: 0644]

index 36f17b30928bfba29225474785d1d5f4c7c62f08..fee85c5a5cd99d6e9f76d826f92e337edbf2ace5 100644 (file)
@@ -1,5 +1,5 @@
 shared_LIBRARIES = frsh
 frsh_SOURCES = frsh_contract.c frsh_distributed.c frsh_core.c
 include_HEADERS = frsh_opaque_types.h
-
+#SUNBDIRS = tests
 frsh_LIBS+= fna
diff --git a/frsh_api/tests/Makefile b/frsh_api/tests/Makefile
new file mode 100644 (file)
index 0000000..b22a357
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/frsh_api/tests/Makefile.omk b/frsh_api/tests/Makefile.omk
new file mode 100644 (file)
index 0000000..fb82193
--- /dev/null
@@ -0,0 +1,3 @@
+test_PROGRAMS = distributed
+distributed_SOURCES+= distributed.c
+lib_LOADLIBES += pthread rt fwp frsh fna
diff --git a/frsh_api/tests/distributed.c b/frsh_api/tests/distributed.c
new file mode 100644 (file)
index 0000000..4f73aae
--- /dev/null
@@ -0,0 +1,130 @@
+/**
+ * \file distributed.c  
+ *
+ * This a test application that:
+ * - creates vres without negotiation
+ * - creates send and receive endpoint 
+ * - binds that endpoint to vres
+ * - in cycle (NUM loops) sends messages in separate thread and 
+ *   prints send time
+ * - receives messages in separate receiver thread
+ * - destroys vres
+ *
+ */
+#include "frsh.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#define  NUM   20
+#define  PORT  65111
+#define  PROTO FRSH_NETPF_FWP
+
+int exit_flag = 0;
+       
+void* sender()
+{
+       frsh_send_endpoint_t sepoint;
+       frsh_vres_id_t vres;
+       frsh_send_endpoint_protocol_info_t send_pinfo;
+       char msg1[10];
+       int count;
+       /*struct timespec  sendtime;*/
+       
+       send_pinfo.body = NULL;         
+       if (frsh_send_endpoint_create(PROTO, inet_addr("127.0.0.1"), PORT, 
+                                       send_pinfo, &sepoint)< 0) {
+               return NULL;
+       }
+       
+       /* Contract negotiation */
+       
+       printf("Send endpoint created\n");
+       frsh_send_endpoint_bind(vres, sepoint);
+       printf("Send endpoint bounded\n");
+       
+       sleep(2);
+       //for (count = 0; count < NUM; count++) {       
+       //fwp_set_rt_prio(90);
+       
+       count = 0;
+       while (count < NUM){
+               count++;
+               sprintf(msg1,"msg%d",count);
+               frsh_send_async(sepoint, msg1, sizeof(msg1));
+       
+               printf("sent\n");       
+               /*clock_gettime(CLOCK_MONOTONIC, &sendtime);
+               FWP_DEBUG("Sent %d: sec = %ld nsec = %ld \n", count,
+                               sendtime.tv_sec, sendtime.tv_nsec);
+               usleep(1000);*/
+       }
+       
+       while (!(exit_flag)) {
+               sleep(1);
+       }
+       
+       return NULL;
+} 
+
+void* receiver()
+{
+        size_t len;
+       char buffer[30];
+       frsh_receive_endpoint_t repoint;
+       int count;
+       struct timespec recvtime;
+       frsh_network_address_t  from;
+       frsh_receive_endpoint_protocol_info_t recv_pinfo;
+       frsh_endpoint_queueing_info_t qinfo;
+       
+       recv_pinfo.body = NULL;
+       /* local_addr should be handled when creating socket */
+       if (frsh_receive_endpoint_create(PROTO, PORT, qinfo, recv_pinfo, 
+                       &repoint) < 0){
+               return NULL;
+       }
+       printf("Receive endpoint created\n");
+       
+       for (count = 1; count <= NUM; count++) {        
+               
+               if ((frsh_receive_sync(repoint, buffer, sizeof(buffer), &len, 
+                       &from))){
+                               perror("Error while receiving data");
+                               return NULL;
+               } 
+                       else printf("Received - %s\n", buffer);
+               
+               clock_gettime(CLOCK_MONOTONIC, &recvtime);
+               printf("Received %d: sec = %ld nsec = %ld \n", count, 
+                               recvtime.tv_sec, recvtime.tv_nsec);
+       }
+
+       exit_flag = 1;
+
+       return NULL;
+}
+
+int main()
+{
+       pthread_attr_t  thattr;
+       pthread_t       thread;
+
+       printf("Start\n");
+       if (frsh_distributed_init()) {
+               fprintf(stderr,"FRSH distributed modul initialization failed.\n");
+       }
+       
+       pthread_attr_init(&thattr);
+       pthread_create(&thread, &thattr, sender, NULL); 
+       pthread_create(&thread, &thattr, receiver, NULL); 
+       pthread_join(thread, (void**) NULL);    
+
+       printf("Test PASSED!\n");
+       return 0;
+}