diff options
| author | Joseph Henry <[email protected]> | 2016-10-21 15:44:36 -0700 |
|---|---|---|
| committer | Joseph Henry <[email protected]> | 2016-10-21 15:44:36 -0700 |
| commit | 12bd9439db82ed8d60f3a2879b3a23e61f341e7d (patch) | |
| tree | 887c732640a6616dc2957b0c1c2a8531d3a8ceb5 /zerotierone/selftest.cpp | |
| parent | 3dfea66bd421ec075ddbd7b3f8134f05b3ecc6ff (diff) | |
updated included zerotierone src0.6.0
Diffstat (limited to 'zerotierone/selftest.cpp')
| -rw-r--r-- | zerotierone/selftest.cpp | 129 |
1 files changed, 72 insertions, 57 deletions
diff --git a/zerotierone/selftest.cpp b/zerotierone/selftest.cpp index aecccd2..33ec9e4 100644 --- a/zerotierone/selftest.cpp +++ b/zerotierone/selftest.cpp @@ -53,6 +53,10 @@ #include "osdep/PortMapper.hpp" #include "osdep/Thread.hpp" +#ifdef ZT_ENABLE_NETWORK_CONTROLLER +#include "controller/SqliteNetworkController.hpp" +#endif // ZT_ENABLE_NETWORK_CONTROLLER + #ifdef __WINDOWS__ #include <tchar.h> #endif @@ -501,6 +505,19 @@ static int testCertificate() return -1; } + std::cout << "[certificate] Testing string serialization... "; + CertificateOfMembership copyA(cA.toString()); + CertificateOfMembership copyB(cB.toString()); + if (copyA != cA) { + std::cout << "FAIL" << std::endl; + return -1; + } + if (copyB != cB) { + std::cout << "FAIL" << std::endl; + return -1; + } + std::cout << "PASS" << std::endl; + std::cout << "[certificate] Generating two certificates that should not agree..."; cA = CertificateOfMembership(10000,100,1,idA.address()); cB = CertificateOfMembership(10101,100,1,idB.address()); @@ -747,65 +764,28 @@ static int testOther() } std::cout << "PASS" << std::endl; - std::cout << "[other] Testing/fuzzing Dictionary... "; std::cout.flush(); + std::cout << "[other] Testing Dictionary... "; std::cout.flush(); for(int k=0;k<1000;++k) { - Dictionary<8194> test; - char key[32][16]; - char value[32][128]; - for(unsigned int q=0;q<32;++q) { - Utils::snprintf(key[q],16,"%.8lx",(unsigned long)rand()); - int r = rand() % 128; - for(int x=0;x<r;++x) - value[q][x] = ("0123456789\0\t\r\n= ")[rand() % 16]; - value[q][r] = (char)0; - test.add(key[q],value[q],r); - } - for(unsigned int q=0;q<1024;++q) { - //int r = rand() % 128; - int r = 31; - char tmp[128]; - if (test.get(key[r],tmp,sizeof(tmp)) >= 0) { - if (strcmp(value[r],tmp)) { - std::cout << "FAILED (invalid value)!" << std::endl; - return -1; - } - } else { - std::cout << "FAILED (can't find key '" << key[r] << "')!" << std::endl; - return -1; - } - } - for(unsigned int q=0;q<31;++q) { - char tmp[128]; - test.erase(key[q]); - if (test.get(key[q],tmp,sizeof(tmp)) >= 0) { - std::cout << "FAILED (key should have been erased)!" << std::endl; - return -1; - } - if (test.get(key[q+1],tmp,sizeof(tmp)) < 0) { - std::cout << "FAILED (key should NOT have been erased)!" << std::endl; - return -1; - } + Dictionary a,b; + int nk = rand() % 32; + for(int q=0;q<nk;++q) { + std::string k,v; + int kl = (rand() % 512); + int vl = (rand() % 512); + for(int i=0;i<kl;++i) + k.push_back((char)rand()); + for(int i=0;i<vl;++i) + v.push_back((char)rand()); + a[k] = v; } - } - int foo = 0; - volatile int *volatile bar = &foo; // force compiler not to optimize out test.get() below - for(int k=0;k<200;++k) { - int r = rand() % 8194; - unsigned char tmp[8194]; - for(int q=0;q<r;++q) - tmp[q] = (unsigned char)((rand() % 254) + 1); // don't put nulls since those will always just terminate scan - tmp[r] = (r % 32) ? (char)(rand() & 0xff) : (char)0; // every 32nd iteration don't terminate the string maybe... - Dictionary<8194> test((const char *)tmp); - for(unsigned int q=0;q<100;++q) { - char tmp[128]; - for(unsigned int x=0;x<128;++x) - tmp[x] = (char)(rand() & 0xff); - tmp[127] = (char)0; - char value[8194]; - *bar += test.get(tmp,value,sizeof(value)); + std::string aser = a.toString(); + b.fromString(aser); + if (a != b) { + std::cout << "FAIL!" << std::endl; + return -1; } } - std::cout << "PASS (junk value to prevent optimization-out of test: " << foo << ")" << std::endl; + std::cout << "PASS" << std::endl; return 0; } @@ -958,6 +938,42 @@ static int testPhy() return 0; } +static int testSqliteNetworkController() +{ +#ifdef ZT_ENABLE_NETWORK_CONTROLLER + + OSUtils::rm("./selftest_network_controller.db"); + + try { + std::cout << "[network-controller] Generating signing identity..." << std::endl; + Identity signingId; + signingId.generate(); + + { + std::cout << "[network-controller] Creating database..." << std::endl; + SqliteNetworkController controller("./selftest_network_controller.db"); + std::cout << "[network-controller] Closing database..." << std::endl; + } + + { + std::cout << "[network-controller] Re-opening database..." << std::endl; + SqliteNetworkController controller("./selftest_network_controller.db"); + std::cout << "[network-controller] Closing database..." << std::endl; + } + } catch (std::runtime_error &exc) { + std::cout << "FAIL! (unexpected exception: " << exc.what() << ")" << std::endl; + return -1; + } catch ( ... ) { + std::cout << "FAIL! (unexpected exception: ...)" << std::endl; + return -1; + } + + OSUtils::rm("./selftest_network_controller.db"); + +#endif // ZT_ENABLE_NETWORK_CONTROLLER + return 0; +} + static int testResolver() { std::cout << "[resolver] Testing BackgroundResolver..."; std::cout.flush(); @@ -975,7 +991,6 @@ static int testResolver() return 0; } -/* static int testHttp() { std::map<std::string,std::string> requestHeaders,responseHeaders; @@ -1018,7 +1033,6 @@ static int testHttp() return 0; } -*/ #ifdef __WINDOWS__ int _tmain(int argc, _TCHAR* argv[]) @@ -1076,6 +1090,7 @@ int main(int argc,char **argv) srand((unsigned int)time(0)); ///* + r |= testSqliteNetworkController(); r |= testOther(); r |= testCrypto(); r |= testPacket(); |
