]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add rudimentary testing of our random generator. I've hooked up boost::accumulator...
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 12 May 2013 11:35:47 +0000 (13:35 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 12 May 2013 11:35:47 +0000 (13:35 +0200)
pdns/Makefile.am
pdns/test-dns_random_hh.cc [new file with mode: 0644]

index fee70cd5d0cefaca453b778e91e2f0b50cfeada3..a0bfbed146d6751ec84055f4272916ce573430f6 100644 (file)
@@ -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 (file)
index 0000000..8f0a7c0
--- /dev/null
@@ -0,0 +1,42 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_NO_MAIN
+#include <boost/test/unit_test.hpp>
+#include <boost/assign/std/map.hpp>
+#include <boost/foreach.hpp>
+#include <boost/accumulators/statistics/median.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+
+#include "dns_random.hh"
+#include "namespaces.hh"
+
+using namespace boost;
+using namespace boost::accumulators;
+
+typedef accumulator_set<
+  double
+  , stats<boost::accumulators::tag::median(with_p_square_quantile),
+         boost::accumulators::tag::mean(immediate)
+         >
+  > 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()