From: bert hubert Date: Sun, 12 May 2013 11:35:47 +0000 (+0200) Subject: add rudimentary testing of our random generator. I've hooked up boost::accumulator... X-Git-Tag: auth-3.3-rc1~67 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=78cb2bd09cbb2a864dd354f5c87082edd811c4ba;p=thirdparty%2Fpdns.git add rudimentary testing of our random generator. I've hooked up boost::accumulator which makes it possible to get your FULL STATISTICS GEEK on. I'd love to see covariance tests, chi-square, Kolmogorov-Smirnov. --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index fee70cd5d0..a0bfbed146 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -177,7 +177,7 @@ tsig_tests_LDADD= -lpolarssl speedtest_SOURCES=speedtest.cc dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \ misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \ - qtype.cc sillyrecords.cc logger.cc statbag.cc nsecrecords.cc base32.cc + qtype.cc sillyrecords.cc logger.cc statbag.cc nsecrecords.cc base32.cc dnswasher_SOURCES=dnswasher.cc misc.cc unix_utility.cc qtype.cc \ logger.cc statbag.cc dnspcap.cc dnspcap.hh dnsparser.hh @@ -247,7 +247,10 @@ testrunner_SOURCES=testrunner.cc test-misc_hh.cc test-nameserver_cc.cc test-dnsr unix_utility.cc logger.cc statbag.cc arguments.cc qtype.cc dnspacket.cc \ dnswriter.cc base64.cc base32.cc dnsrecords.cc dnslabeltext.cc dnsparser.cc \ rcpgenerator.cc ednssubnet.cc nsecrecords.cc sillyrecords.cc dnssecinfra.cc \ - md5.cc test-base64_cc.cc test-iputils_hh.cc + md5.cc test-base64_cc.cc test-iputils_hh.cc test-dns_random_hh.cc aes/dns_random.cc \ + aes/aescpp.h \ + aes/aescrypt.c aes/aes.h aes/aeskey.c aes/aes_modes.c aes/aesopt.h \ + aes/aestab.c aes/aestab.h aes/brg_endian.h aes/brg_types.h testrunner_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) testrunner_LDADD= ext/polarssl-1.1.2/library/libpolarssl.a $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) diff --git a/pdns/test-dns_random_hh.cc b/pdns/test-dns_random_hh.cc new file mode 100644 index 0000000000..8f0a7c06be --- /dev/null +++ b/pdns/test-dns_random_hh.cc @@ -0,0 +1,42 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN +#include +#include +#include +#include +#include +#include +#include + +#include "dns_random.hh" +#include "namespaces.hh" + +using namespace boost; +using namespace boost::accumulators; + +typedef accumulator_set< + double + , stats + > acc_t; + + + +BOOST_AUTO_TEST_SUITE(test_dns_random_hh) + +BOOST_AUTO_TEST_CASE(test_dns_random_average) { + dns_random_init("/dev/urandom"); + acc_t acc; + + + for(unsigned int n=0; n < 100000; ++n) { + acc(dns_random(100000)/100000.0); + } + BOOST_CHECK_CLOSE(0.5, median(acc), 2.0); // within 2% + BOOST_CHECK_CLOSE(0.5, mean(acc), 2.0); + + // please add covariance tests, chi-square, Kolmogorov-Smirnov +} + +BOOST_AUTO_TEST_SUITE_END()