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
This commit is contained in:
drbob 2011-06-26 15:41:08 +00:00
parent 3c19218bec
commit 4e56166e3f
9 changed files with 94 additions and 64 deletions

View File

@ -1,7 +1,7 @@
testoutputfiles = $(foreach tt,$(1),$(tt).tstout)
%.tstout : %.sh
%.tstout : %.sh %
-sh ./$< > $@ 2>&1
%.tstout : %

View File

@ -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)

View File

@ -27,17 +27,18 @@
#include <iostream>
#include <stdlib.h>
//#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 <unistd.h>
#include <fcntl.h>
@ -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;

View File

@ -27,14 +27,15 @@
#include <iostream>
#include <stdlib.h>
//#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;

View File

@ -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 <iostream>
/* unix only
#include <netinet/in.h>
#include <arpa/inet.h>
*/
#include "tou_net.h"
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
@ -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);

View File

@ -24,7 +24,8 @@
*/
#include "udptestfn.h"
#include "udplayer.h"
#include "udp/udplayer.h"
#include <stdlib.h>
#define MAX_PEERS 16

View File

@ -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;

View File

@ -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;

View File

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