diff --git a/libretroshare/src/tests/TestNotes.txt b/libretroshare/src/tests/TestNotes.txt index 6505574cb..da2ea3e77 100644 --- a/libretroshare/src/tests/TestNotes.txt +++ b/libretroshare/src/tests/TestNotes.txt @@ -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 diff --git a/libretroshare/src/tests/ft/ftdata_test.cc b/libretroshare/src/tests/ft/ftdata_test.cc index 9e757c4f6..b5bdc4933 100644 --- a/libretroshare/src/tests/ft/ftdata_test.cc +++ b/libretroshare/src/tests/ft/ftdata_test.cc @@ -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 ; +} diff --git a/libretroshare/src/tests/perform_all_auto_tests.sh b/libretroshare/src/tests/perform_all_auto_tests.sh new file mode 100755 index 000000000..42bcf4f14 --- /dev/null +++ b/libretroshare/src/tests/perform_all_auto_tests.sh @@ -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 + diff --git a/libretroshare/src/tests/serialiser/perform_auto_tests.sh b/libretroshare/src/tests/serialiser/perform_auto_tests.sh new file mode 100755 index 000000000..e9857c4ec --- /dev/null +++ b/libretroshare/src/tests/serialiser/perform_auto_tests.sh @@ -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 + + + diff --git a/libretroshare/src/tests/util/perform_auto_tests.sh b/libretroshare/src/tests/util/perform_auto_tests.sh new file mode 100755 index 000000000..73b8699fb --- /dev/null +++ b/libretroshare/src/tests/util/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="sha1_test" + +for exe in $exes; do + ./$exe > /dev/null 2>&1 ; result=`printresult`; echo "-- $exe \t test :" $result ; +done + + + diff --git a/libretroshare/src/tests/util/sha1_test.cc b/libretroshare/src/tests/util/sha1_test.cc index 3af4c1829..1b8b5293b 100644 --- a/libretroshare/src/tests/util/sha1_test.cc +++ b/libretroshare/src/tests/util/sha1_test.cc @@ -27,6 +27,7 @@ #include "util/rsdir.h" +#include "../common/argstream.h" #include #include @@ -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++; }