- added TestUtils class to handle generating random files and random SSL/PGP ids.

- fixed ftcontollertest. This should help fixing ftserver[123]test as well
- improved pqiTestor using templates (lots of identical functions replaced)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6036 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-12-26 19:53:27 +00:00
parent 66207b81e5
commit 4e586c84ba
11 changed files with 278 additions and 195 deletions

View File

@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <util/rsid.h>
class TestUtils
{
public:
// Creates a random file of the given size at the given place. Useful for file transfer tests.
//
static bool createRandomFile(const std::string& filename,const uint64_t size)
{
FILE *f = fopen(filename.c_str(),"wb") ;
if(f == NULL)
return 0 ;
uint32_t S = 5000 ;
uint32_t *data = new uint32_t[S] ;
for(uint64_t i=0;i<size;i+=4*S)
{
for(uint32_t j=0;j<S;++j)
data[j] = lrand48() ;
uint32_t to_write = std::min((uint64_t)(4*S),size - i) ;
if(to_write != fwrite((void*)data,1,to_write,f))
return 0 ;
}
fclose(f) ;
return true ;
}
static std::string createRandomSSLId()
{
return t_RsGenericIdType<16>::random().toStdString(false);
}
static std::string createRandomPGPId()
{
return t_RsGenericIdType<8>::random().toStdString(true);
}
};

View File

@ -0,0 +1,24 @@
#!/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="searchtest \
fitest2 \
fimontest \
fisavetest"
for exe in $exes; do
./$exe > /dev/null 2>&1 ; result=`printresult`; echo "-- $exe \t test :" $result ;
done

View File

@ -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_dummy.o ftsearch_dummy.o
TESTOBJ = pqitestor.o 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
@ -20,8 +20,8 @@ all: tests
ftfilemappertest : ftfilemappertest.o
$(CC) $(CFLAGS) -o ftfilemappertest ftfilemappertest.o $(LIBS)
ftcontrollertest : ftcontrollertest.o
$(CC) $(CFLAGS) -o ftcontrollertest ftcontrollertest.o $(LIBS)
ftcontrollertest : ftcontrollertest.o pqitestor.o
$(CC) $(CFLAGS) -o ftcontrollertest ftcontrollertest.o pqitestor.o $(LIBS)
ftfilecreatortest : ftfilecreatortest.o
$(CC) $(CFLAGS) -o ftfilecreatortest ftfilecreatortest.o $(LIBS)

View File

@ -29,6 +29,7 @@
#include "retroshare/rsfiles.h"
#include "retroshare/rspeers.h"
#include "retroshare/rsiface.h"
#include "ft/ftserver.h"
#include "ft/ftextralist.h"
@ -41,6 +42,10 @@
#include "pqi/p3linkmgr.h"
#include "pqi/p3netmgr.h"
#include "pqi/authssl.h"
#include "pqi/authgpg.h"
#include "common/testutils.h"
#include "util/rsdebug.h"
#include "pqitestor.h"
@ -50,6 +55,41 @@
#include <sstream>
class FakeGPG: public AuthGPG
{
public:
FakeGPG(const std::string& ownId)
:AuthGPG("pgp_pubring.pgp","pgp_secring.pgp","pgp_trustdb.pgp","lock"), mOwnId(ownId)
{
}
virtual std::string getGPGOwnId()
{
return mOwnId ;
}
virtual bool isGPGAccepted(const std::string& pgp_id) { return true ; }
private:
std::string mOwnId ;
};
class FakeSSL: public AuthSSLimpl
{
public:
FakeSSL(const std::string& ownId)
: mOwnId(ownId)
{
}
virtual std::string OwnId()
{
return mOwnId ;
}
private:
std::string mOwnId ;
};
class TestData
{
@ -72,49 +112,66 @@ void usage(char *name)
int main(int argc, char **argv)
{
int c;
uint32_t period = 1;
uint32_t debugLevel = 5;
bool debugStderr = true;
int c;
uint32_t debugLevel = 5;
bool loadAll = false;
std::list<SharedDirInfo> fileList;
std::list<std::string> extraList;
std::list<SharedDirInfo> fileList;
std::list<std::string> extraList;
std::list<std::string> peerIds;
std::map<std::string, ftServer *> mFtServers;
std::map<std::string, p3LinkMgrIMPL *> mLinkMgrs;
ftServer *mLoadServer = NULL;
std::list<ftServer *> mOtherServers;
std::list<std::string>::iterator eit;
std::list<std::string>::iterator eit;
while(-1 != (c = getopt(argc, argv, "asd:p:e:")))
{
switch (c)
{
case 'p':
peerIds.push_back(optarg);
break;
case 'd':
debugLevel = atoi(optarg);
break;
case 's':
debugStderr = true;
break;
case 'e':
extraList.push_back(optarg);
break;
case 'a':
loadAll = true;
break;
default:
usage(argv[0]);
break;
}
}
while(-1 != (c = getopt(argc, argv, "asd:p:e:")))
{
switch (c)
{
case 'p':
peerIds.push_back(optarg);
break;
case 'd':
debugLevel = atoi(optarg);
break;
// case 's':
// debugStderr = true;
// break;
case 'e':
extraList.push_back(optarg);
break;
case 'a':
loadAll = true;
break;
default:
usage(argv[0]);
break;
}
}
if(peerIds.empty())
{
peerIds.push_back(TestUtils::createRandomSSLId()) ;
// then add some other peer ids.
peerIds.push_back(TestUtils::createRandomSSLId()) ;
peerIds.push_back(TestUtils::createRandomSSLId()) ;
peerIds.push_back(TestUtils::createRandomSSLId()) ;
}
std::string ssl_own_id = TestUtils::createRandomSSLId() ;
std::string gpg_own_id = TestUtils::createRandomPGPId() ;
FakeGPG fakeGPG(gpg_own_id) ;
AuthGPG::setAuthGPG_debug(&fakeGPG) ;
FakeSSL fakeSSL(ssl_own_id) ;
AuthSSL::setAuthSSL_debug(&fakeSSL) ;
/* do logging */
setOutputLevel(debugLevel);
setOutputLevel(debugLevel);
if (optind >= argc)
{
@ -155,6 +212,7 @@ int main(int argc, char **argv)
{
RsPeerDetails pad;
pad.id = *it;
pad.gpg_id = TestUtils::createRandomPGPId() ;
pad.name = *it;
pad.trustLvl = 5;
pad.ownsign = true;
@ -162,8 +220,7 @@ int main(int argc, char **argv)
baseFriendList.push_back(pad);
std::cerr << "ftserver1test::setup peer: " << *it;
std::cerr << std::endl;
std::cerr << "ftserver1test::setup peer: " << *it << std::endl;
}
std::ostringstream pname;
@ -188,7 +245,7 @@ int main(int argc, char **argv)
}
//p3AuthMgr *authMgr = new p3DummyAuthMgr(*it, friendList);
p3PeerMgrIMPL *peerMgr = new p3PeerMgrIMPL;
p3PeerMgrIMPL *peerMgr = new p3PeerMgrIMPL(ssl_own_id,gpg_own_id,"My GPG name","My SSL location");
p3NetMgrIMPL *netMgr = new p3NetMgrIMPL ;
p3LinkMgrIMPL *linkMgr = new p3LinkMgrIMPL(peerMgr,netMgr);
mLinkMgrs[*it] = linkMgr;
@ -197,7 +254,7 @@ int main(int argc, char **argv)
for(fit = friendList.begin(); fit != friendList.end(); fit++)
{
/* add as peer to authMgr */
peerMgr->addFriend(fit->id);
peerMgr->addFriend(fit->id,fit->gpg_id);
}
P3Pipe *pipe = new P3Pipe(); //(*it);
@ -226,13 +283,13 @@ int main(int argc, char **argv)
std::string localpath = cachepath + "/local";
RsDirUtil::checkCreateDirectory(localpath);
std::string remotepath = cachepath + "/remote";
RsDirUtil::checkCreateDirectory(remotepath);
server->setConfigDirectory(configpath);
NotifyBase *base = NULL;
NotifyBase *base = new NotifyBase;
server->SetupFtServer(base);
testHub->addP3Pipe(*it, pipe, linkMgr);
@ -258,7 +315,7 @@ int main(int argc, char **argv)
mLoadServer->ExtraFileHash(*eit, 3600, TransferRequestFlags(0));
}
}
/* stick your real test here */
std::map<std::string, ftServer *>::iterator sit;
@ -273,7 +330,7 @@ int main(int argc, char **argv)
mFt->otherServers = mOtherServers;
mFt->extraList = extraList;
void *data = (void *) mFt;
void *data = (void *) mFt;
pthread_create(&tid, 0, &do_server_test_thread, data);
pthread_detach(tid); /* so memory is reclaimed in linux */
@ -390,7 +447,6 @@ void *do_server_test_thread(void *data)
ftServer *server=mFt->loadServer;
std::string fname,filehash,destination;
uint32_t size;
FileSearchFlags flags;
std::list<std::string> srcIds;

View File

@ -39,8 +39,8 @@
#include "ft/ftdatamultiplex.h"
#include "ft/ftfilesearch.h"
#include "pqi/p3authmgr.h"
#include "pqi/p3connmgr.h"
#include "pqi/p3linkmgr.h"
#include "pqi/p3peermgr.h"
#include "util/rsdebug.h"

View File

@ -24,7 +24,7 @@
*/
#include "ft/pqitestor.h"
#include "pqi/p3connmgr.h"
#include "pqi/p3linkmgr.h"
/******
*#define HUB_DEBUG 1
@ -47,8 +47,9 @@ void P3Hub::addP3Pipe(std::string id, P3Pipe *pqi, p3LinkMgr *mgr)
std::map<std::string, hubItem>::iterator it;
for(it = mPeers.begin(); it != mPeers.end(); it++)
{
(it->second).mLinkMgr->connectResult(id, true, 0);
mgr->connectResult(it->first, true, 0);
sockaddr_in remote_addr ;
(it->second).mLinkMgr->connectResult(id, true, 0,remote_addr);
mgr->connectResult(it->first, true, 0,remote_addr);
}
mPeers[id] = item;
@ -211,7 +212,7 @@ void P3Hub::run()
PQIPipe::PQIPipe(std::string peerId)
:PQInterface(peerId)
:PQInterface(peerId),pipeMtx("Pipe mutex")
{
return;
}
@ -330,115 +331,3 @@ int P3Pipe::PushRecvdItem(RsItem *item)
return 1;
}
int P3Pipe::SearchSpecific(RsCacheRequest *item)
{
SendAllItem(item);
return 1;
}
int P3Pipe::SendSearchResult(RsCacheItem *item)
{
SendAllItem(item);
return 1;
}
int P3Pipe::SendFileRequest(RsFileRequest *item)
{
SendAllItem(item);
return 1;
}
int P3Pipe::SendFileData(RsFileData *item)
{
SendAllItem(item);
return 1;
}
int P3Pipe::SendRsRawItem(RsRawItem *item)
{
SendAllItem(item);
return 1;
}
// Cache Requests
RsCacheRequest *P3Pipe::RequestedSearch()
{
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
if (mRecvdRsCacheRequests.size() == 0)
{
return NULL;
}
RsCacheRequest *item = mRecvdRsCacheRequests.front();
mRecvdRsCacheRequests.pop_front();
return item;
}
// Cache Results
RsCacheItem *P3Pipe::GetSearchResult()
{
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
if (mRecvdRsCacheItems.size() == 0)
{
return NULL;
}
RsCacheItem *item = mRecvdRsCacheItems.front();
mRecvdRsCacheItems.pop_front();
return item;
}
// FileTransfer.
RsFileRequest *P3Pipe::GetFileRequest()
{
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
if (mRecvdRsFileRequests.size() == 0)
{
return NULL;
}
RsFileRequest *item = mRecvdRsFileRequests.front();
mRecvdRsFileRequests.pop_front();
return item;
}
RsFileData *P3Pipe::GetFileData()
{
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
if (mRecvdRsFileDatas.size() == 0)
{
return NULL;
}
RsFileData *item = mRecvdRsFileDatas.front();
mRecvdRsFileDatas.pop_front();
return item;
}
RsRawItem *P3Pipe::GetRsRawItem()
{
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
if (mRecvdRsRawItems.size() == 0)
{
return NULL;
}
RsRawItem *item = mRecvdRsRawItems.front();
mRecvdRsRawItems.pop_front();
return item;
}

View File

@ -37,6 +37,7 @@
#include "pqi/pqi.h"
#include "util/rsthreads.h"
#include "serialiser/rsbaseitems.h"
#include <string>
@ -45,8 +46,7 @@ class PQIPipe;
class PQIHub;
class P3Pipe;
class P3Hub;
class p3ConnectMgr;
class p3LinkMgr;
class hubItem
{
@ -116,31 +116,30 @@ class P3Pipe: public P3Interface
virtual int status() { return 1; }
/* Overloaded from P3Interface */
virtual int SearchSpecific(RsCacheRequest *item);
virtual int SendSearchResult(RsCacheItem *item);
virtual int SendFileRequest(RsFileRequest *item);
virtual int SendFileData(RsFileData *item);
virtual int SendRsRawItem(RsRawItem *item);
virtual RsCacheRequest *RequestedSearch();
virtual RsCacheItem *GetSearchResult();
virtual RsFileRequest *GetFileRequest();
virtual RsFileData *GetFileData();
virtual RsRawItem *GetRsRawItem();
virtual RsCacheRequest *RequestedSearch() { return GetSpecificItem(mRecvdRsCacheRequests) ; }
virtual RsCacheItem *GetSearchResult() { return GetSpecificItem(mRecvdRsCacheItems) ; }
virtual RsFileRequest *GetFileRequest() { return GetSpecificItem(mRecvdRsFileRequests) ; }
virtual RsFileData *GetFileData() { return GetSpecificItem(mRecvdRsFileDatas) ; }
virtual RsRawItem *GetRsRawItem() { return GetSpecificItem(mRecvdRsRawItems) ; }
virtual RsFileChunkMapRequest* GetFileChunkMapRequest() { return GetSpecificItem(mRecvdRsChunkMapRequests) ; }
virtual RsFileChunkMap* GetFileChunkMap() { return GetSpecificItem(mRecvdRsChunkMaps) ; }
virtual RsFileCRC32MapRequest* GetFileCRC32MapRequest() { return GetSpecificItem(mRecvdRsCRC32MapRequests) ; }
virtual RsFileCRC32Map* GetFileCRC32Map() { return GetSpecificItem(mRecvdRsCRC32Maps) ; }
virtual RsFileSingleChunkCrcRequest* GetFileSingleChunkCrcRequest() { return GetSpecificItem(mRecvdRsSingleChunkCRCRequests) ; }
virtual RsFileSingleChunkCrc* GetFileSingleChunkCrc() { return GetSpecificItem(mRecvdRsSingleChunkCRCs) ; }
virtual RsFileChunkMapRequest* GetFileChunkMapRequest() ;
virtual int SendFileChunkMapRequest(RsFileChunkMapRequest*) ;
virtual RsFileChunkMap* GetFileChunkMap() ;
virtual int SendFileChunkMap(RsFileChunkMap*) ;
virtual RsFileCRC32MapRequest* GetFileCRC32MapRequest() ;
virtual int SendFileCRC32MapRequest(RsFileCRC32MapRequest*) ;
virtual RsFileCRC32Map* GetFileCRC32Map() ;
virtual int SendFileCRC32Map(RsFileCRC32Map*) ;
virtual RsFileSingleChunkCrcRequest* GetFileSingleChunkCrcRequest() ;
virtual int SendFileSingleChunkCrcRequest(RsFileSingleChunkCrcRequest*) ;
virtual RsFileSingleChunkCrc* GetFileSingleChunkCrc() ;
virtual int SendFileSingleChunkCrc(RsFileSingleChunkCrc*) ;
virtual int SearchSpecific(RsCacheRequest *item) { SendAllItem(item); return 1 ; }
virtual int SendSearchResult(RsCacheItem *item) { SendAllItem(item); return 1 ; }
virtual int SendFileRequest(RsFileRequest *item) { SendAllItem(item); return 1 ; }
virtual int SendFileData(RsFileData *item) { SendAllItem(item); return 1 ; }
virtual int SendRsRawItem(RsRawItem *item) { SendAllItem(item); return 1 ; }
virtual int SendFileChunkMapRequest(RsFileChunkMapRequest*item) { SendAllItem(item); return 1 ; }
virtual int SendFileChunkMap(RsFileChunkMap*item) { SendAllItem(item); return 1 ; }
virtual int SendFileCRC32MapRequest(RsFileCRC32MapRequest*item) { SendAllItem(item); return 1 ; }
virtual int SendFileCRC32Map(RsFileCRC32Map*item) { SendAllItem(item); return 1 ; }
virtual int SendFileSingleChunkCrcRequest(RsFileSingleChunkCrcRequest*item) { SendAllItem(item); return 1 ; }
virtual int SendFileSingleChunkCrc(RsFileSingleChunkCrc*item) { SendAllItem(item); return 1 ; }
/* Lower Interface for PQIHub */
@ -148,6 +147,18 @@ class P3Pipe: public P3Interface
int PushRecvdItem(RsItem *item);
private:
template<class T> T *GetSpecificItem(std::list<T*>& item_list)
{
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
if (item_list.size() == 0)
return NULL;
T *item = item_list.front();
item_list.pop_front();
return item;
}
int SendAllItem(RsItem *item);
@ -155,11 +166,17 @@ class P3Pipe: public P3Interface
std::list<RsItem *> mSentItems;
std::list<RsCacheRequest *> mRecvdRsCacheRequests;
std::list<RsCacheItem *> mRecvdRsCacheItems;
std::list<RsFileRequest *> mRecvdRsFileRequests;
std::list<RsFileData *> mRecvdRsFileDatas;
std::list<RsRawItem *> mRecvdRsRawItems;
std::list<RsCacheRequest *> mRecvdRsCacheRequests;
std::list<RsCacheItem *> mRecvdRsCacheItems;
std::list<RsFileRequest *> mRecvdRsFileRequests;
std::list<RsFileData *> mRecvdRsFileDatas;
std::list<RsRawItem *> mRecvdRsRawItems;
std::list<RsFileChunkMapRequest *> mRecvdRsChunkMapRequests;
std::list<RsFileChunkMap *> mRecvdRsChunkMaps;
std::list<RsFileCRC32MapRequest *> mRecvdRsCRC32MapRequests;
std::list<RsFileCRC32Map *> mRecvdRsCRC32Maps;
std::list<RsFileSingleChunkCrcRequest *> mRecvdRsSingleChunkCRCRequests;
std::list<RsFileSingleChunkCrc *> mRecvdRsSingleChunkCRCs;
};

View File

@ -0,0 +1,22 @@
#!/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="random_test \
memory_management_test "
for exe in $exes; do
./$exe > /dev/null 2>&1 ; result=`printresult`; echo "-- $exe \t test :" $result ;
done

View File

@ -1,8 +1,17 @@
#!/bin/sh
echo Performing all tests on subdirs.
# This is the main script for performing all tests automatically.
# - in order to add new directories, just list them in the $subdirs variable below
subdirs="util serialiser pgp upnp general tcponudp"
echo "****************************************"
echo "*** RetroShare automatic test suite. ***"
echo "****************************************"
echo "Performing all tests on subdirs."
echo "(Some tests take a few minutes. Be patient) "
echo
echo
subdirs="util serialiser dbase upnp general pgp tcponudp"
for dir in $subdirs; do
echo Tests for directory: $dir

View File

@ -26,7 +26,7 @@ OPSDIR = $(OPS_TOP_DIR)/lib
LIBRS = $(LIBDIR)/libretroshare.a
BITDHT = $(BITDIR)/libbitdht.a
# Unix: Linux/Cygwin
INCLUDE = -I $(RS_TOP_DIR) -I$(OPENPGP_INCLUDE_DIR)
INCLUDE = -I$(RS_TOP_DIR) -I$(OPS_TOP_DIR) -I$(DHT_TOP_DIR)
CFLAGS = -Wall -g $(INCLUDE) -I..
#CFLAGS += -fprofile-arcs -ftest-coverage
CFLAGS += ${DEFINES}

View File

@ -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="upnpforward"
for exe in $exes; do
./$exe > /dev/null 2>&1 ; result=`printresult`; echo "-- $exe \t test :" $result ;
done