From c04d4816fb07640ce052e7b0da95a5f0e520dc4e Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 20 Jan 2013 14:03:05 -0800 Subject: [PATCH] Start adding tests --- Makefile.am | 3 ++- configure.ac | 5 +++-- test/Makefile.am | 18 ++++++++++++++++++ test/test-randombytes.c | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/Makefile.am create mode 100644 test/test-randombytes.c diff --git a/Makefile.am b/Makefile.am index 822cd2a7..4a608903 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,4 +6,5 @@ EXTRA_DIST = \ autogen.sh SUBDIRS = \ - src + src \ + test diff --git a/configure.ac b/configure.ac index 732b1b10..79e8077b 100644 --- a/configure.ac +++ b/configure.ac @@ -201,6 +201,7 @@ AC_CONFIG_FILES([Makefile src/Makefile src/libsodium/Makefile src/libsodium/include/Makefile - src/libsodium/include/sodium/version.h]) - + src/libsodium/include/sodium/version.h + test/Makefile + ]) AC_OUTPUT diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 00000000..4141182b --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,18 @@ + +AM_CPPFLAGS = \ + -I. \ + -I$(top_srcdir)/src/libsodium/include + +TESTS_TARGETS = \ + test-randombytes + +check_PROGRAMS = $(TESTS_TARGETS) + +TESTS = $(TESTS_TARGETS) + +TESTS_LDADD = $(top_srcdir)/src/libsodium/libsodium.la + +test_randombytes_SOURCES = test-randombytes.c +test_randombytes_LDADD = $(TESTS_LDADD) + +verify: check diff --git a/test/test-randombytes.c b/test/test-randombytes.c new file mode 100644 index 00000000..b4ff2774 --- /dev/null +++ b/test/test-randombytes.c @@ -0,0 +1,16 @@ +#include "sodium/randombytes.h" + +unsigned char x[65536]; +unsigned long long freq[256]; + +int main(void) +{ + unsigned long long i; + + randombytes(x,sizeof x); + for (i = 0;i < 256;++i) freq[i] = 0; + for (i = 0;i < sizeof x;++i) ++freq[255 & (int) x[i]]; + for (i = 0;i < 256;++i) if (!freq[i]) return 111; + + return 0; +}