From 69859f2a43b993b4f96eeda82c64a379cedea6f2 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Dec 2012 14:02:56 +0000 Subject: [PATCH] working on ft tests. Not finished yet git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6034 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/tests/ft/Makefile | 8 +-- .../src/tests/ft/ftcontrollertest.cc | 41 +++++++------ libretroshare/src/tests/ft/ftcrc32test.cc | 59 ++++++++++--------- .../ft/{ftdata_test.cc => ftdata_dummy.cc} | 14 ++++- .../ft/{ftdata_test.h => ftdata_dummy.h} | 7 ++- libretroshare/src/tests/ft/ftdataplextest.cc | 37 +++++++++--- .../src/tests/ft/ftfilecreatortest.cc | 4 +- .../{ftsearch_test.cc => ftsearch_dummy.cc} | 2 +- .../ft/{ftsearch_test.h => ftsearch_dummy.h} | 0 .../src/tests/ft/fttransfermoduletest.cc | 3 +- .../src/tests/ft/perform_auto_tests.sh | 21 +++++++ libretroshare/src/tests/ft/pqitestor.cc | 4 +- libretroshare/src/tests/ft/pqitestor.h | 15 +++-- 13 files changed, 142 insertions(+), 73 deletions(-) rename libretroshare/src/tests/ft/{ftdata_test.cc => ftdata_dummy.cc} (91%) rename libretroshare/src/tests/ft/{ftdata_test.h => ftdata_dummy.h} (92%) rename libretroshare/src/tests/ft/{ftsearch_test.cc => ftsearch_dummy.cc} (92%) rename libretroshare/src/tests/ft/{ftsearch_test.h => ftsearch_dummy.h} (100%) create mode 100755 libretroshare/src/tests/ft/perform_auto_tests.sh diff --git a/libretroshare/src/tests/ft/Makefile b/libretroshare/src/tests/ft/Makefile index 3588da057..aaddc3214 100644 --- a/libretroshare/src/tests/ft/Makefile +++ b/libretroshare/src/tests/ft/Makefile @@ -10,7 +10,7 @@ OPS_TOP_DIR = ../../../../openpgpsdk/src include $(RS_TOP_DIR)/tests/scripts/config.mk ############################################################### -TESTOBJ = ftfilemappertest.o ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o fttransfermoduletest.o ftcrc32test.o ftcrossprovidercreatortest.o ftcontrollertest.o ftserver1test.o ftserver2test.o ftserver3test.o ftdata_test.o ftsearch_test.o +TESTOBJ = ftfilemappertest.o ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o fttransfermoduletest.o ftcrc32test.o ftcrossprovidercreatortest.o ftcontrollertest.o ftserver1test.o ftserver2test.o ftserver3test.o ftdata_dummy.o ftsearch_dummy.o TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest fttransfermoduletest ftcrc32test ftcrossprovidercreatortest ftcontrollertest ftserver1test ftserver2test fttransfermoduletest ftserver3test #ftfilemappertest @@ -33,13 +33,13 @@ ftfileprovidertest : ftfileprovidertest.o $(CC) $(CFLAGS) -o ftfileprovidertest ftfileprovidertest.o $(LIBS) fttransfermoduletest : fttransfermoduletest.o - $(CC) $(CFLAGS) -o fttransfermoduletest fttransfermoduletest.o $(LIBS) + $(CC) $(CFLAGS) -o fttransfermoduletest ftdata_dummy.o ftsearch_dummy.o fttransfermoduletest.o $(LIBS) ftextralisttest : ftextralisttest.o $(CC) $(CFLAGS) -o ftextralisttest ftextralisttest.o $(LIBS) -ftdataplextest : ftdataplextest.o ftsearch_test.o ftdata_test.o - $(CC) $(CFLAGS) -o ftdataplextest ftdata_test.o ftdataplextest.o ftsearch_test.o $(LIBS) +ftdataplextest : ftdataplextest.o ftsearch_dummy.o ftdata_dummy.o + $(CC) $(CFLAGS) -o ftdataplextest ftdata_dummy.o ftdataplextest.o ftsearch_dummy.o $(LIBS) ftserver1test : ftserver1test.o $(CC) $(CFLAGS) -o ftserver1test ftserver1test.o $(LIBS) diff --git a/libretroshare/src/tests/ft/ftcontrollertest.cc b/libretroshare/src/tests/ft/ftcontrollertest.cc index 37f8f85d4..5bfa5743a 100644 --- a/libretroshare/src/tests/ft/ftcontrollertest.cc +++ b/libretroshare/src/tests/ft/ftcontrollertest.cc @@ -37,6 +37,9 @@ //#include "pqi/p3authmgr.h" //#include "pqi/p3connmgr.h" +#include "pqi/p3peermgr.h" +#include "pqi/p3linkmgr.h" +#include "pqi/p3netmgr.h" #include "util/rsdebug.h" @@ -79,7 +82,7 @@ int main(int argc, char **argv) std::list extraList; std::list peerIds; std::map mFtServers; - std::map mConnMgrs; + std::map mLinkMgrs; ftServer *mLoadServer = NULL; std::list mOtherServers; @@ -184,22 +187,24 @@ int main(int argc, char **argv) } } - p3AuthMgr *authMgr = new p3DummyAuthMgr(*it, friendList); - p3ConnectMgr *connMgr = new p3ConnectMgr(authMgr); - mConnMgrs[*it] = connMgr; + //p3AuthMgr *authMgr = new p3DummyAuthMgr(*it, friendList); + p3PeerMgrIMPL *peerMgr = new p3PeerMgrIMPL; + p3NetMgrIMPL *netMgr = new p3NetMgrIMPL ; + p3LinkMgrIMPL *linkMgr = new p3LinkMgrIMPL(peerMgr,netMgr); + mLinkMgrs[*it] = linkMgr; for(fit = friendList.begin(); fit != friendList.end(); fit++) { /* add as peer to authMgr */ - connMgr->addFriend(fit->id); + peerMgr->addFriend(fit->id); } P3Pipe *pipe = new P3Pipe(); //(*it); /* add server */ ftServer *server; - server = new ftServer(connMgr); + server = new ftServer(peerMgr,linkMgr); mFtServers[*it] = server; if (!mLoadServer) { @@ -230,7 +235,7 @@ int main(int argc, char **argv) NotifyBase *base = NULL; server->SetupFtServer(base); - testHub->addP3Pipe(*it, pipe, connMgr); + testHub->addP3Pipe(*it, pipe, linkMgr); server->StartupThreads(); /* setup any extra bits */ @@ -239,7 +244,7 @@ int main(int argc, char **argv) server->setSharedDirectories(fileList); for(eit = extraList.begin(); eit != extraList.end(); eit++) { - server->ExtraFileHash(*eit, 3600, 0); + server->ExtraFileHash(*eit, 3600, TransferRequestFlags(0)); } } @@ -250,14 +255,14 @@ int main(int argc, char **argv) mLoadServer->setSharedDirectories(fileList); for(eit = extraList.begin(); eit != extraList.end(); eit++) { - mLoadServer->ExtraFileHash(*eit, 3600, 0); + mLoadServer->ExtraFileHash(*eit, 3600, TransferRequestFlags(0)); } } /* stick your real test here */ std::map::iterator sit; - std::map::iterator cit; + std::map::iterator cit; /* Start up test thread */ pthread_t tid; @@ -285,7 +290,7 @@ int main(int argc, char **argv) (sit->second)->tick(); } - for(cit = mConnMgrs.begin(); cit != mConnMgrs.end(); cit++) + for(cit = mLinkMgrs.begin(); cit != mLinkMgrs.end(); cit++) { /* update */ (cit->second)->tick(); @@ -334,7 +339,8 @@ void *do_server_test_thread(void *data) REPORT("Successfully Found ExtraFile"); /* now we can try a search (should succeed) */ - uint32_t hintflags = 0; + FileSearchFlags hintflags; + if (mFt->loadServer->FileDetails(info.hash, hintflags, info2)) { CHECK(info2.hash == info.hash); @@ -361,6 +367,7 @@ void *do_server_test_thread(void *data) /* search with other flags (should fail) */ hintflags = RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY; + if (mFt->loadServer->FileDetails(info.hash, hintflags, info2)) { REPORT2( false, "Search for Extra File (Fail Flags)"); @@ -383,18 +390,19 @@ void *do_server_test_thread(void *data) ftServer *server=mFt->loadServer; std::string fname,filehash,destination; - uint32_t size,flags; + uint32_t size; + FileSearchFlags flags; std::list srcIds; /* select a file from otherServers */ - if (mFt->otherServers == NULL) + if (mFt->otherServers.empty() ) { REPORT2(false,"No otherServers available"); exit(1); } DirDetails details; - flags = DIR_FLAGS_DETAILS | DIR_FLAGS_REMOTE; + flags = RS_FILE_HINTS_REMOTE; void *ref = NULL; if(!server->RequestDirDetails(ref,details,flags)) @@ -407,8 +415,7 @@ void *do_server_test_thread(void *data) REPORT("RemoteDirModel::downloadSelected() Calling File Request"); std::list srcIds; srcIds.push_back(details.id); - server->FileRequest(details.name, details.hash, - details.count, "", 0, srcIds); + server->FileRequest(details.name, details.hash, details.count, "", TransferRequestFlags(0), srcIds); } exit(1); diff --git a/libretroshare/src/tests/ft/ftcrc32test.cc b/libretroshare/src/tests/ft/ftcrc32test.cc index 35e39c773..d1220ed2f 100644 --- a/libretroshare/src/tests/ft/ftcrc32test.cc +++ b/libretroshare/src/tests/ft/ftcrc32test.cc @@ -34,34 +34,37 @@ #endif #include "util/rsdir.h" +#include +#include -void usage(char *name) -{ - std::cerr << "Computes a CRC32 map of a file." << std::endl; - std::cerr << "Usage: " << name << " -h " << std::endl; -} - int main(int argc, char **argv) { - int c; - uint32_t period = 1; - uint32_t dPeriod = 600; /* default 10 minutes */ + int c; + uint32_t period = 1; + uint32_t dPeriod = 600; /* default 10 minutes */ - std::list hashList; + std::string inputfile ; + + argstream as(argc,argv) ; + + as >> parameter('i',"input",inputfile,"Input file to hash. If none, a random file will be created in /tmp",false) + >> help() ; + + as.defaultErrorHandling() ; + + if(inputfile == "") + { + uint64_t S = 3983782 ; + std::cerr << "Creating a dummy input file in /tmp, of size " << S << std::endl; + inputfile = "crc_test_data.bin" ; + + if(!FileUtils::createRandomFile(inputfile,S)) + return 1 ; + } + + std::list hashList ; + hashList.push_back(inputfile) ; - while(-1 != (c = getopt(argc, argv, "f:h:"))) - { - switch (c) - { - case 'f': - hashList.push_back(std::string(optarg)); - break; - default: - usage(argv[0]); - break; - } - } - uint32_t flags = 0; for(std::list::const_iterator it(hashList.begin()); it != hashList.end(); it++) { @@ -79,7 +82,7 @@ int main(int argc, char **argv) if(f == NULL) { std::cerr << "Could not open this file! Sorry." << std::endl ; - return 0 ; + return 1 ; } CRC32Map crc_map ; @@ -87,7 +90,7 @@ int main(int argc, char **argv) { std::cerr << "Could not fseek to end of this file! Sorry." << std::endl ; fclose(f) ; - return 0 ; + return 1 ; } size = ftell(f) ; @@ -96,7 +99,7 @@ int main(int argc, char **argv) { std::cerr << "Could not fseek to beginning of this file! Sorry." << std::endl ; fclose(f) ; - return 0 ; + return 1 ; } std::cerr << "File size:" << size << std::endl ; @@ -109,9 +112,9 @@ int main(int argc, char **argv) for(uint32_t i=0;i +#include +#include #include "ft/ftextralist.h" #include "ft/ftdatamultiplex.h" #include "ft/ftfilesearch.h" -#include "ftdata_test.h" -#include "ftsearch_test.h" +#include "ftdata_dummy.h" +#include "ftsearch_dummy.h" void do_random_server_test(ftDataMultiplex *mplex, ftExtraList *eList, std::list &files); +INITTEST() ; void usage(char *name) { @@ -78,15 +82,26 @@ int main(int argc, char **argv) if (optind >= argc) { - std::cerr << "Missing Files" << std::endl; - usage(argv[0]); - } + uint32_t N = 4 ; + std::cerr << "Missing Files. Generating " << N << " random files." << std::endl; - for(; optind < argc; optind++) - { - std::cerr << "Adding: " << argv[optind] << std::endl; - fileList.push_back(std::string(argv[optind])); + for(uint32_t i=0;istart(); @@ -121,6 +136,10 @@ int main(int argc, char **argv) /* just request random data packets first */ do_random_server_test(ftmplex, eList, fileList); + + FINALREPORT("FtDataPlex test") ; + + return TESTRESULT() ; } diff --git a/libretroshare/src/tests/ft/ftfilecreatortest.cc b/libretroshare/src/tests/ft/ftfilecreatortest.cc index c759239cb..f92329047 100644 --- a/libretroshare/src/tests/ft/ftfilecreatortest.cc +++ b/libretroshare/src/tests/ft/ftfilecreatortest.cc @@ -128,6 +128,8 @@ int test_fill(ftFileCreator *creator) REPORT("Test Fill"); - return 1; + int res = TESTRESULT(); + std::cerr << "Test result: " << res << std::endl; + return res ; } diff --git a/libretroshare/src/tests/ft/ftsearch_test.cc b/libretroshare/src/tests/ft/ftsearch_dummy.cc similarity index 92% rename from libretroshare/src/tests/ft/ftsearch_test.cc rename to libretroshare/src/tests/ft/ftsearch_dummy.cc index f80670c37..72b59d471 100644 --- a/libretroshare/src/tests/ft/ftsearch_test.cc +++ b/libretroshare/src/tests/ft/ftsearch_dummy.cc @@ -1,4 +1,4 @@ -#include "ftsearch_test.h" +#include "ftsearch_dummy.h" bool ftSearchDummy::search(const std::string& /*hash*/, FileSearchFlags hintflags, FileInfo &/*info*/) const { diff --git a/libretroshare/src/tests/ft/ftsearch_test.h b/libretroshare/src/tests/ft/ftsearch_dummy.h similarity index 100% rename from libretroshare/src/tests/ft/ftsearch_test.h rename to libretroshare/src/tests/ft/ftsearch_dummy.h diff --git a/libretroshare/src/tests/ft/fttransfermoduletest.cc b/libretroshare/src/tests/ft/fttransfermoduletest.cc index a16baedab..f98d47a93 100644 --- a/libretroshare/src/tests/ft/fttransfermoduletest.cc +++ b/libretroshare/src/tests/ft/fttransfermoduletest.cc @@ -46,7 +46,8 @@ #include "ft/fttransfermodule.h" #include "util/utest.h" -#include "ftdata_test.h" +#include "ftdata_dummy.h" +#include "ftsearch_dummy.h" INITTEST() diff --git a/libretroshare/src/tests/ft/perform_auto_tests.sh b/libretroshare/src/tests/ft/perform_auto_tests.sh new file mode 100755 index 000000000..6e3eca808 --- /dev/null +++ b/libretroshare/src/tests/ft/perform_auto_tests.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +printresult() { + if test "$?" = "0"; then + echo ' 'PASSED + else + echo *FAILED* + fi +} + +# Warning: printresult needs to be called before anything else because it contains the +# result of the call to the test program, until the next command. + +exes="ftcrc32test ftdataplextest ftfilecreatortest ftfileprovidertest ftextralisttest fttransfermoduletest ftcrossprovidercreatortest" + +for exe in $exes; do + ./$exe > /dev/null 2>&1 ; result=`printresult`; echo "-- $exe \t test :" $result ; +done + + + diff --git a/libretroshare/src/tests/ft/pqitestor.cc b/libretroshare/src/tests/ft/pqitestor.cc index 85756c40b..623ba0dd6 100644 --- a/libretroshare/src/tests/ft/pqitestor.cc +++ b/libretroshare/src/tests/ft/pqitestor.cc @@ -40,14 +40,14 @@ P3Hub::P3Hub(uint32_t flags, RsSerialiser *rss) return; } -void P3Hub::addP3Pipe(std::string id, P3Pipe *pqi, p3ConnectMgr *mgr) +void P3Hub::addP3Pipe(std::string id, P3Pipe *pqi, p3LinkMgr *mgr) { hubItem item(id, pqi, mgr); std::map::iterator it; for(it = mPeers.begin(); it != mPeers.end(); it++) { - (it->second).mConnMgr->connectResult(id, true, 0); + (it->second).mLinkMgr->connectResult(id, true, 0); mgr->connectResult(it->first, true, 0); } diff --git a/libretroshare/src/tests/ft/pqitestor.h b/libretroshare/src/tests/ft/pqitestor.h index 2dbad359c..763e70572 100644 --- a/libretroshare/src/tests/ft/pqitestor.h +++ b/libretroshare/src/tests/ft/pqitestor.h @@ -52,14 +52,14 @@ class hubItem { public: hubItem() - :mPQI(NULL), mConnMgr(NULL) { return; } + :mPQI(NULL), mLinkMgr(NULL) { return; } - hubItem(std::string id, P3Pipe *pqi, p3ConnectMgr *mgr) - :mPeerId(id), mPQI(pqi), mConnMgr(mgr) { return; } + hubItem(std::string id, P3Pipe *pqi, p3LinkMgr *mgr) + :mPeerId(id), mPQI(pqi), mLinkMgr(mgr) { return; } std::string mPeerId; P3Pipe *mPQI; - p3ConnectMgr *mConnMgr; + p3LinkMgr *mLinkMgr; }; @@ -68,7 +68,7 @@ class P3Hub: public RsThread public: P3Hub(uint32_t flags, RsSerialiser *rss); -void addP3Pipe(std::string id, P3Pipe *, p3ConnectMgr *mgr); +void addP3Pipe(std::string id, P3Pipe *, p3LinkMgr *mgr); virtual void run(); @@ -137,6 +137,11 @@ class P3Pipe: public P3Interface virtual RsFileCRC32Map* GetFileCRC32Map() ; virtual int SendFileCRC32Map(RsFileCRC32Map*) ; + virtual RsFileSingleChunkCrcRequest* GetFileSingleChunkCrcRequest() ; + virtual int SendFileSingleChunkCrcRequest(RsFileSingleChunkCrcRequest*) ; + virtual RsFileSingleChunkCrc* GetFileSingleChunkCrc() ; + virtual int SendFileSingleChunkCrc(RsFileSingleChunkCrc*) ; + /* Lower Interface for PQIHub */ RsItem *PopSentItem();