mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
added some automatic test scripts. Needs to be done in all directories. Only serializer/ and util/ done now.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6018 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
470b3df7c2
commit
986c2cf3e6
@ -15,6 +15,13 @@ tcponudp : manual tests convert to automatic
|
||||
dht : manual tests ignore - old code - to be replaced soon.
|
||||
serialiser : automatic tests complete tests, update tests.
|
||||
|
||||
Suggestion to automate all tests
|
||||
================================
|
||||
|
||||
* each directory contains multiple executables.
|
||||
- by default, each executable should perform an automatic test
|
||||
- each executable should return 0 when passed, !=0 otherwise
|
||||
- each directory has a script "perform_auto_tests.sh" that calls all programs in the directory
|
||||
|
||||
|
||||
|
||||
|
@ -68,6 +68,15 @@ bool ftDataSendPair::sendCRC32Map(const std::string& peer_id,const std::strin
|
||||
{
|
||||
return mDataRecv->recvCRC32Map(peer_id,hash,crcmap) ;
|
||||
}
|
||||
|
||||
bool ftDataSendPair::sendSingleChunkCRCRequest(const std::string& peer_id, const std::string& hash, unsigned int c_id)
|
||||
{
|
||||
return mDataRecv->recvSingleChunkCRCRequest(peer_id,hash,c_id) ;
|
||||
}
|
||||
bool ftDataSendPair::sendSingleChunkCRC(const std::string& peer_id, const std::string& hash, uint32_t c_id, const Sha1CheckSum& crc)
|
||||
{
|
||||
return mDataRecv->recvSingleChunkCRC(peer_id,hash,c_id,crc) ;
|
||||
}
|
||||
/* Client Send */
|
||||
bool ftDataSendDummy::sendDataRequest(const std::string &/*peerId*/, const std::string &/*hash*/,
|
||||
uint64_t /*size*/, uint64_t /*offset*/, uint32_t /*chunksize*/)
|
||||
@ -144,3 +153,12 @@ bool ftDataRecvDummy::sendCRC32Map(const std::string& /*peer_id*/,const std::st
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftDataSendDummy::sendSingleChunkCRCRequest(const std::string&, const std::string&, unsigned int)
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
bool ftDataSendDummy::sendSingleChunkCRC(const std::string&, const std::string&, uint32_t, const Sha1CheckSum&)
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
|
13
libretroshare/src/tests/perform_all_auto_tests.sh
Executable file
13
libretroshare/src/tests/perform_all_auto_tests.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo Performing all tests on subdirs.
|
||||
|
||||
subdirs="util serialiser pgp upnp general tcponudp"
|
||||
|
||||
for dir in $subdirs; do
|
||||
echo Tests for directory: $dir
|
||||
cd $dir
|
||||
./perform_auto_tests.sh
|
||||
cd ..
|
||||
done
|
||||
|
34
libretroshare/src/tests/serialiser/perform_auto_tests.sh
Executable file
34
libretroshare/src/tests/serialiser/perform_auto_tests.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/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="rsstatusitem_test \
|
||||
tlvbase_test \
|
||||
rsserial_test \
|
||||
tlvtypes_test \
|
||||
rsmsgitem_test \
|
||||
rstunnelitem_test \
|
||||
tlvrandom_test \
|
||||
rstlvwidetest \
|
||||
rsconfigitem_test \
|
||||
rsturtleitem_test \
|
||||
tlvitems_test \
|
||||
distribitem_test \
|
||||
tlvstack_test \
|
||||
tlvbase_test2"
|
||||
|
||||
for exe in $exes; do
|
||||
./$exe > /dev/null 2>&1 ; result=`printresult`; echo "-- $exe \t test :" $result ;
|
||||
done
|
||||
|
||||
|
||||
|
21
libretroshare/src/tests/util/perform_auto_tests.sh
Executable file
21
libretroshare/src/tests/util/perform_auto_tests.sh
Executable 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="sha1_test"
|
||||
|
||||
for exe in $exes; do
|
||||
./$exe > /dev/null 2>&1 ; result=`printresult`; echo "-- $exe \t test :" $result ;
|
||||
done
|
||||
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include "../common/argstream.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
@ -41,41 +42,52 @@ void printHelp(int argc,char *argv[])
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
if(argc != 2)
|
||||
{
|
||||
printHelp(argc,argv) ;
|
||||
return -1 ;
|
||||
}
|
||||
std::string inputfile ;
|
||||
argstream as(argc,argv) ;
|
||||
|
||||
FILE *f = RsDirUtil::rs_fopen(argv[1],"r") ;
|
||||
as >> parameter('i',"input",inputfile,"input file name to hash",false)
|
||||
>> help() ;
|
||||
|
||||
as.defaultErrorHandling() ;
|
||||
|
||||
if(inputfile.empty())
|
||||
inputfile = argv[0] ;
|
||||
|
||||
FILE *f = RsDirUtil::rs_fopen(inputfile.c_str(),"r") ;
|
||||
|
||||
if(f == NULL)
|
||||
{
|
||||
std::cerr << "Cannot open file " << argv[1] << " for read !" << std::endl;
|
||||
std::cerr << "Cannot open file " << inputfile << " for read !" << std::endl;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
std::cerr << "Testing sha1" << std::endl;
|
||||
std::cerr << "Testing sha1" << std::endl;
|
||||
uint32_t SIZE = 1024*1024 ;
|
||||
unsigned char *buf = new unsigned char[SIZE] ;
|
||||
int len = fread(buf,1,SIZE,f) ;
|
||||
|
||||
std::cerr << "Read " << len << " bytes" << std::endl;
|
||||
std::cerr << "Read " << len << " bytes" << std::endl;
|
||||
|
||||
Sha1CheckSum sum = RsDirUtil::sha1sum(buf,len) ;
|
||||
std::cerr << std::hex << sum.fourbytes[0] << std::endl;
|
||||
std::cerr << "New method : " << sum.toStdString() << std::endl;
|
||||
{
|
||||
std::cerr << std::hex << sum.fourbytes[0] << std::endl;
|
||||
std::cerr << "New method : " << sum.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
std::string hash ;
|
||||
uint64_t size ;
|
||||
RsDirUtil::getFileHash(argv[1],hash,size) ;
|
||||
RsDirUtil::getFileHash(inputfile.c_str(),hash,size) ;
|
||||
|
||||
std::cerr << "Old method : " << hash << std::endl;
|
||||
std::cerr << "Old method : " << hash << std::endl;
|
||||
if(hash != sum.toStdString())
|
||||
return -1 ;
|
||||
|
||||
Sha1CheckSum H(hash) ;
|
||||
std::cerr << "Hashed transformed: " << H.toStdString() << std::endl;
|
||||
std::cerr << "Hashed transformed: " << H.toStdString() << std::endl;
|
||||
if(hash != H.toStdString())
|
||||
return -1 ;
|
||||
|
||||
std::cerr << "Computing all chunk hashes:" << std::endl;
|
||||
std::cerr << "Computing all chunk hashes:" << std::endl;
|
||||
|
||||
fseek(f,0,SEEK_SET) ;
|
||||
int n=0 ;
|
||||
@ -83,7 +95,7 @@ int main(int argc,char *argv[])
|
||||
while(len = fread(buf,1,SIZE,f))
|
||||
{
|
||||
Sha1CheckSum sum = RsDirUtil::sha1sum(buf,len) ;
|
||||
std::cerr << "Chunk " << n << ": " << sum.toStdString() << std::endl;
|
||||
std::cerr << "Chunk " << n << ": " << sum.toStdString() << std::endl;
|
||||
n++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user