From 4e56166e3f3b1540ec2cc1ff11a943c7246ebe59 Mon Sep 17 00:00:00 2001 From: drbob Date: Sun, 26 Jun 2011 15:41:08 +0000 Subject: [PATCH] Updated tests for tcponudp. Only some of these tests are still valid. the TOU interface no longer supports multiple sockets.. all the connections are attached to the same UdpStack. Multiple sockets will be re-introduced in the next TOU iteration. At that point the remaining tests will be fixed up. * tweaked regress.mk * added scripts to launch tests. * replaced UdpLayer with UdpStacks. * only two proper tests: udp_server (passes), test_tou (fails) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4341 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/tests/scripts/regress.mk | 2 +- libretroshare/src/tests/tcponudp/Makefile | 26 ++++++---- libretroshare/src/tests/tcponudp/pair_tou.cc | 20 ++++---- libretroshare/src/tests/tcponudp/test_tou.cc | 50 +++++++++++++------ .../src/tests/tcponudp/udp_server.cc | 36 ++++++------- .../src/tests/tcponudp/udpsock_test.cc | 3 +- .../src/tests/tcponudp/udpsort_test.cc | 9 ++-- libretroshare/src/tests/tcponudp/udptestfn.cc | 2 +- libretroshare/src/tests/tcponudp/udptestfn.h | 10 ++-- 9 files changed, 94 insertions(+), 64 deletions(-) diff --git a/libretroshare/src/tests/scripts/regress.mk b/libretroshare/src/tests/scripts/regress.mk index f80b48451..7d69df664 100644 --- a/libretroshare/src/tests/scripts/regress.mk +++ b/libretroshare/src/tests/scripts/regress.mk @@ -1,7 +1,7 @@ testoutputfiles = $(foreach tt,$(1),$(tt).tstout) -%.tstout : %.sh +%.tstout : %.sh % -sh ./$< > $@ 2>&1 %.tstout : % diff --git a/libretroshare/src/tests/tcponudp/Makefile b/libretroshare/src/tests/tcponudp/Makefile index 24db1e1d6..6186f9f2c 100644 --- a/libretroshare/src/tests/tcponudp/Makefile +++ b/libretroshare/src/tests/tcponudp/Makefile @@ -5,26 +5,30 @@ DHT_TOP_DIR = ../../../../libbitdht/src ############################################################### ############################################################### -include $(RS_TOP_DIR)/scripts/config.mk +include $(RS_TOP_DIR)/tests/scripts/config.mk ############################################################### -BIOOBJ = bss_tou.o +#BIOOBJ = bss_tou.o -RSOBJ = tou_net.o udplayer.o udpsorter.o udptestfn.o extaddrfinder.o -RSOBJ += tcppacket.o tcpstream.o tou.o $(BIOOBJ) +#RSOBJ = tou_net.o udplayer.o udpsorter.o udptestfn.o extaddrfinder.o +#RSOBJ += tcppacket.o tcpstream.o tou.o $(BIOOBJ) -EXECS = librs udpsock_test udpsort_test udp_server -#test_tou pair_tou reset_tou internal_tou largefile_tou +OBJ = udptestfn.o + +EXECS = udpsock_test udpsort_test udp_server test_tou +#pair_tou reset_tou internal_tou largefile_tou TESTOBJ = udpsock_test.o udpsort_test.o udp_server.o test_tou.o -TESTOBJ += pair_tou.o reset_tou.o largefile_tou.o +#TESTOBJ += pair_tou.o reset_tou.o largefile_tou.o #internal_tou.o TESTS = udpsock_test udpsort_test udp_server test_tou -TESTS += pair_tou reset_tou largefile_tou +# Unfortunately the design of tou has changed over time. +# and these tests cannot be performed at the moment. +#TESTS += pair_tou reset_tou largefile_tou #internal_tou -all: librs tests +all: tests udpsock_test : $(OBJ) udpsock_test.o $(CC) $(CFLAGS) -o udpsock_test udpsock_test.o $(OBJ) $(LIBS) @@ -56,6 +60,8 @@ largefile_tou : $(OBJ) largefile_tou.o $(BIOCC) $(BIOCFLAGS) -c $< ############################################################### -include $(RS_TOP_DIR)/scripts/rules.mk +include $(RS_TOP_DIR)/tests/scripts/rules.mk ############################################################### +CFLAGS += -DRS_USE_BITDHT -I$(DHT_TOP_DIR) + diff --git a/libretroshare/src/tests/tcponudp/pair_tou.cc b/libretroshare/src/tests/tcponudp/pair_tou.cc index af62107a9..d2d7cdc80 100644 --- a/libretroshare/src/tests/tcponudp/pair_tou.cc +++ b/libretroshare/src/tests/tcponudp/pair_tou.cc @@ -27,17 +27,18 @@ #include +#include //#define USE_TCP_SOCKET // for printing sockaddr -#include "udplayer.h" +#include "udp/udpstack.h" #ifndef USE_TCP_SOCKET - #include "tou.h" + #include "tcponudp/tou.h" #endif -#include "tou_net.h" +#include "util/bdnet.h" #include #include @@ -99,8 +100,6 @@ int main(int argc, char **argv) return 1; } - tounet_init(); - /* setup the local/remote addresses. */ struct sockaddr_in laddr; @@ -109,8 +108,8 @@ int main(int argc, char **argv) laddr.sin_family = AF_INET; raddr.sin_family = AF_INET; - if ((!tounet_inet_aton(argv[optind], &(laddr.sin_addr))) || - (!tounet_inet_aton(argv[optind+2], &(raddr.sin_addr)))) + if ((!bdnet_inet_aton(argv[optind], &(laddr.sin_addr))) || + (!bdnet_inet_aton(argv[optind+2], &(raddr.sin_addr)))) { std::cerr << "Invalid addresses!" << std::endl; usage(argv[0]); @@ -122,6 +121,9 @@ int main(int argc, char **argv) std::cerr << "Local Address: " << laddr << std::endl; std::cerr << "Remote Address: " << raddr << std::endl; + UdpStack udps(laddr); + tou_init((void *) &udps); + #ifdef USE_TCP_SOCKET int sockfd = socket(PF_INET, SOCK_STREAM, 0); @@ -284,8 +286,8 @@ int main(int argc, char **argv) char data[bufsize]; int readsize = 0; - tounet_fcntl(0, F_SETFL, O_NONBLOCK); - tounet_fcntl(1,F_SETFL,O_NONBLOCK); + bdnet_fcntl(0, F_SETFL, O_NONBLOCK); + bdnet_fcntl(1,F_SETFL,O_NONBLOCK); bool doneWrite = false; bool doneRead = false; diff --git a/libretroshare/src/tests/tcponudp/test_tou.cc b/libretroshare/src/tests/tcponudp/test_tou.cc index 8ace8c12c..70fc89b12 100644 --- a/libretroshare/src/tests/tcponudp/test_tou.cc +++ b/libretroshare/src/tests/tcponudp/test_tou.cc @@ -27,14 +27,15 @@ #include +#include //#define USE_TCP_SOCKET // for printing sockaddr -#include "udplayer.h" +#include "udp/udpstack.h" #ifndef USE_TCP_SOCKET - #include "tou.h" + #include "tcponudp/tou.h" #endif /* shouldn't do this - but for convenience @@ -44,7 +45,7 @@ * This includes the whole networking interface */ -#include "tou_net.h" +#include "util/bdnet.h" /* These three includes appear to work in both W & L. * and they shouldn't!!!! maybe cygwin is allowing it... @@ -109,7 +110,6 @@ int main(int argc, char **argv) return 1; } - tounet_init(); /* setup the local/remote addresses. */ @@ -119,8 +119,8 @@ int main(int argc, char **argv) laddr.sin_family = AF_INET; raddr.sin_family = AF_INET; - if ((!tounet_inet_aton(argv[optind], &(laddr.sin_addr))) || - (!tounet_inet_aton(argv[optind+2], &(raddr.sin_addr)))) + if ((!bdnet_inet_aton(argv[optind], &(laddr.sin_addr))) || + (!bdnet_inet_aton(argv[optind+2], &(raddr.sin_addr)))) { std::cerr << "Invalid addresses!" << std::endl; usage(argv[0]); @@ -132,6 +132,8 @@ int main(int argc, char **argv) std::cerr << "Local Address: " << laddr << std::endl; std::cerr << "Remote Address: " << raddr << std::endl; + UdpStack udps(laddr); + tou_init((void *) &udps); #ifdef USE_TCP_SOCKET int sockfd = socket(PF_INET, SOCK_STREAM, 0); @@ -153,7 +155,7 @@ int main(int argc, char **argv) /* make nonblocking */ #ifdef USE_TCP_SOCKET - int err = tounet_fcntl(sockfd,F_SETFL,O_NONBLOCK); + int err = bdnet_fcntl(sockfd,F_SETFL,O_NONBLOCK); #else int err = 0; #endif @@ -168,17 +170,23 @@ int main(int argc, char **argv) #ifdef USE_TCP_SOCKET err = bind(sockfd, (struct sockaddr *) &laddr, sizeof(laddr)); -#else - err = tou_bind(sockfd, (struct sockaddr *) &laddr, sizeof(laddr)); -#endif if (err < 0) { std::cerr << "Error: Cannot bind socket: "; std::cerr << err << std::endl; return -1; } - std::cerr << "Socket Bound to: " << laddr << std::endl; +#else + err = tou_bind(sockfd, (struct sockaddr *) &laddr, sizeof(laddr)); + if (err < 0) + { + std::cerr << "As expected, cannot bind a tou socket"; + std::cerr << err << std::endl; + //return -1; + } +#endif + if (toConnect) { @@ -264,15 +272,15 @@ int main(int argc, char **argv) char buffer[bufsize]; int readsize = 0; - tounet_fcntl(0, F_SETFL, O_NONBLOCK); + bdnet_fcntl(0, F_SETFL, O_NONBLOCK); bool done = false; bool blockread = false; while(!done) { - sleep(1); + //sleep(1); //usleep(10000); - //usleep(1000); + usleep(100); if (blockread != true) { readsize = read(0, buffer, bufsize); @@ -317,18 +325,28 @@ int main(int argc, char **argv) std::cerr << "Transfer Complete: " << totalwbytes << " bytes"; std::cerr << std::endl; + + // ACTUALLY tou_close() is not blocking... + // and kills the connection instantly. + // The transfer will fail if there is any data left in the send queue (which there is in most cases). + // Interestingly.. if we slow the transmit and speed up the recv, + // Then it can succeed. + // + // The settings are done to make this fail. + return 1; } /* recv data */ int bufsize = 1523; char data[bufsize]; - tounet_fcntl(1,F_SETFL,O_NONBLOCK); + bdnet_fcntl(1,F_SETFL,O_NONBLOCK); while(1) { - sleep(1); + //sleep(1); //usleep(10000); //usleep(1000); + usleep(100); int writesize = bufsize; int ret; diff --git a/libretroshare/src/tests/tcponudp/udp_server.cc b/libretroshare/src/tests/tcponudp/udp_server.cc index d6bd3c49f..1f720561a 100644 --- a/libretroshare/src/tests/tcponudp/udp_server.cc +++ b/libretroshare/src/tests/tcponudp/udp_server.cc @@ -26,18 +26,13 @@ -#include "udplayer.h" -#include "tcpstream.h" +#include "udp/udpstack.h" +#include "tcponudp/udppeer.h" +#include "tcponudp/tcpstream.h" +#include "tcponudp/tou.h" #include -/* unix only -#include -#include -*/ - -#include "tou_net.h" - #include #include #include @@ -94,7 +89,6 @@ int main(int argc, char **argv) /* setup the local/remote addresses. */ - tounet_init(); struct sockaddr_in laddr; struct sockaddr_in raddr; @@ -102,8 +96,8 @@ int main(int argc, char **argv) laddr.sin_family = AF_INET; raddr.sin_family = AF_INET; - if ((!tounet_inet_aton(argv[optind], &(laddr.sin_addr))) || - (!tounet_inet_aton(argv[optind+2], &(raddr.sin_addr)))) + if ((!bdnet_inet_aton(argv[optind], &(laddr.sin_addr))) || + (!bdnet_inet_aton(argv[optind+2], &(raddr.sin_addr)))) { std::cerr << "Invalid addresses!" << std::endl; usage(argv[0]); @@ -115,16 +109,18 @@ int main(int argc, char **argv) std::cerr << "Local Address: " << laddr << std::endl; std::cerr << "Remote Address: " << raddr << std::endl; - UdpSorter udps(laddr); + UdpStack udps(laddr); + UdpPeerReceiver *upr = new UdpPeerReceiver(&udps); + udps.addReceiver(upr); + if (!udps.okay()) { std::cerr << "UdpSorter not Okay (Cannot Open Local Address): " << laddr << std::endl; exit(1); } - - TcpStream tcp(&udps); - udps.addUdpPeer(&tcp, raddr); + TcpStream tcp(upr); + upr->addUdpPeer(&tcp, raddr); if (toConnect) { @@ -157,15 +153,15 @@ int main(int argc, char **argv) char buffer[bufsize]; int readsize = 0; - tounet_fcntl(0, F_SETFL, O_NONBLOCK); + bdnet_fcntl(0, F_SETFL, O_NONBLOCK); bool done = false; bool blockread = false; while(!done) { //sleep(1); - usleep(100000); - //usleep(1000); + //usleep(100000); + usleep(1000); if (blockread != true) { readsize = read(0, buffer, bufsize); @@ -219,7 +215,7 @@ int main(int argc, char **argv) /* recv data */ int bufsize = 1523; char data[bufsize]; - tounet_fcntl(1,F_SETFL,O_NONBLOCK); + bdnet_fcntl(1,F_SETFL,O_NONBLOCK); while(1) { //sleep(1); diff --git a/libretroshare/src/tests/tcponudp/udpsock_test.cc b/libretroshare/src/tests/tcponudp/udpsock_test.cc index fe87e4cf9..bc9aeaf86 100644 --- a/libretroshare/src/tests/tcponudp/udpsock_test.cc +++ b/libretroshare/src/tests/tcponudp/udpsock_test.cc @@ -24,7 +24,8 @@ */ #include "udptestfn.h" -#include "udplayer.h" +#include "udp/udplayer.h" +#include #define MAX_PEERS 16 diff --git a/libretroshare/src/tests/tcponudp/udpsort_test.cc b/libretroshare/src/tests/tcponudp/udpsort_test.cc index 8427980f7..a4d025a2a 100644 --- a/libretroshare/src/tests/tcponudp/udpsort_test.cc +++ b/libretroshare/src/tests/tcponudp/udpsort_test.cc @@ -24,7 +24,8 @@ */ #include "udptestfn.h" -#include "udpsorter.h" +#include "udp/udpstack.h" +#include "tcponudp/udppeer.h" #define MAX_PEERS 16 @@ -58,7 +59,9 @@ int main(int argc, char **argv) std::cerr << argv[0] << " Local Port: " << ntohs(local.sin_port); std::cerr << std::endl; - UdpSorter udps(local); + UdpStack udps(local); + UdpPeerReceiver *upr = new UdpPeerReceiver(&udps); + udps.addReceiver(upr); for(i = 2; i < argc; i++) { @@ -68,7 +71,7 @@ int main(int argc, char **argv) std::cerr << std::endl; UdpPeerTest *pt = new UdpPeerTest(peers[i-2]); - udps.addUdpPeer(pt, peers[i-2]); + upr->addUdpPeer(pt, peers[i-2]); } int size = 12; diff --git a/libretroshare/src/tests/tcponudp/udptestfn.cc b/libretroshare/src/tests/tcponudp/udptestfn.cc index 00608216d..6c9b72431 100644 --- a/libretroshare/src/tests/tcponudp/udptestfn.cc +++ b/libretroshare/src/tests/tcponudp/udptestfn.cc @@ -25,7 +25,7 @@ #include "udptestfn.h" -void UdpRecvTest::recvPkt(void *data, int size, struct sockaddr_in &from) +int UdpRecvTest::recvPkt(void *data, int size, struct sockaddr_in &from) { /* print packet information */ std::cerr << "UdpRecvTest::recvPkt(" << size << ") from: " << from; diff --git a/libretroshare/src/tests/tcponudp/udptestfn.h b/libretroshare/src/tests/tcponudp/udptestfn.h index feb997dde..d25a23223 100644 --- a/libretroshare/src/tests/tcponudp/udptestfn.h +++ b/libretroshare/src/tests/tcponudp/udptestfn.h @@ -23,8 +23,11 @@ * */ -#include "udplayer.h" -#include "udpsorter.h" +#include "udp/udplayer.h" +#include "udp/udpstack.h" +#include "tcponudp/udppeer.h" + +//#include "udpsorter.h" #ifndef TOU_UDP_TEST_FN_H #define TOU_UDP_TEST_FN_H @@ -32,7 +35,8 @@ class UdpRecvTest: public UdpReceiver { public: -virtual void recvPkt(void *data, int size, struct sockaddr_in &from); +virtual int recvPkt(void *data, int size, struct sockaddr_in &from); +virtual int status(std::ostream&) { return 0; } };