From 8b8491aaf1177d6c6d6d91e785d9ffc6796edc45 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 10 Dec 2015 15:24:10 +0100 Subject: [PATCH] Port of the TestU01 test suite Library for statistical testing of uniform random number generators. http://simul.iro.umontreal.ca/testu01/tu01.html Fix #48 --- include/testu01/config.h | 99 +++++++++++++++++++++++++++++ include/testu01/gdefconf.h | 30 +++++++++ lib/import/import-testu01.mk | 3 + lib/mk/testu01.mk | 24 +++++++ ports/testu01.hash | 1 + ports/testu01.port | 40 ++++++++++++ src/lib/testu01/genode_chrono.cc | 106 +++++++++++++++++++++++++++++++ src/lib/testu01/genode_gdef.cc | 22 +++++++ 8 files changed, 325 insertions(+) create mode 100644 include/testu01/config.h create mode 100644 include/testu01/gdefconf.h create mode 100644 lib/import/import-testu01.mk create mode 100644 lib/mk/testu01.mk create mode 100644 ports/testu01.hash create mode 100644 ports/testu01.port create mode 100644 src/lib/testu01/genode_chrono.cc create mode 100644 src/lib/testu01/genode_gdef.cc diff --git a/include/testu01/config.h b/include/testu01/config.h new file mode 100644 index 0000000..92afbfa --- /dev/null +++ b/include/testu01/config.h @@ -0,0 +1,99 @@ +/* include/config.h. Generated from config.h.in by configure. */ +/* include/config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `erf' function. */ +#define HAVE_ERF 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_GMP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `lgamma' function. */ +#define HAVE_LGAMMA 1 + +/* Define to 1 if you have the `log1p' function. */ +#define HAVE_LOG1P 1 + +/* Define to 1 if the system has the type `long long'. */ +#define HAVE_LONG_LONG 1 + +/* Define when Mathematica is installed */ +#undef HAVE_MATHEMATICA + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `random' function. */ +#define HAVE_RANDOM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UTSNAME_H 1 + +/* Define to 1 if the system has the type `uint32_t'. */ +#define HAVE_UINT32_T 1 + +/* Define to 1 if the system has the type `uint8_t'. */ +#define HAVE_UINT8_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Name of package */ +#define PACKAGE "testu01" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "lecuyer@iro.umontreal.ca" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "TestU01" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "TestU01 1.2.3" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "testu01" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.2.3" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.2.3" + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ diff --git a/include/testu01/gdefconf.h b/include/testu01/gdefconf.h new file mode 100644 index 0000000..78ce266 --- /dev/null +++ b/include/testu01/gdefconf.h @@ -0,0 +1,30 @@ +/* include/gdefconf.h. Generated from gdefconf.h.in by configure. */ +/* gdef.h for ANSI C */ +#ifndef GDEFCONF_H +#define GDEFCONF_H + +/* #undef HAVE_LEBOOL */ + +#define HAVE_LONG_LONG 1 + +#define HAVE_ERF 1 + +#define HAVE_RANDOM 1 + +#define HAVE_LGAMMA 1 + +#define HAVE_GMP_H 1 + +#undef HAVE_MATHEMATICA + +#define HAVE_SYS_UTSNAME_H 1 + +#define HAVE_UNISTD_H 1 + +#define HAVE_STDINT_H 1 + +#define HAVE_UINT32_T 1 + +#define HAVE_UINT8_T 1 + +#endif diff --git a/lib/import/import-testu01.mk b/lib/import/import-testu01.mk new file mode 100644 index 0000000..19d4fd3 --- /dev/null +++ b/lib/import/import-testu01.mk @@ -0,0 +1,3 @@ +INC_DIR += \ + $(call select_from_ports,testu01)/include/testu01 \ + $(call select_from_repositories,include/testu01) diff --git a/lib/mk/testu01.mk b/lib/mk/testu01.mk new file mode 100644 index 0000000..3180ded --- /dev/null +++ b/lib/mk/testu01.mk @@ -0,0 +1,24 @@ +include $(call select_from_repositories,lib/import/import-testu01.mk) + +TESTU01_DIR = $(call select_from_ports,testu01) +TESTU01_SRC_DIR = $(TESTU01_DIR)/src/lib/testu01/TestU01-1.2.3 + +LIBS += libc + +CC_WARN += -Wno-unused-variable -Wno-maybe-uninitialized -Wno-return-type + +TESTU01_SRC_C = unif01.c ulcg.c umrg.c ucarry.c utaus.c ugfsr.c uinv.c uquad.c ucubic.c ulec.c utezuka.c umarsa.c uweyl.c uknuth.c uwu.c unumrec.c uvaria.c usoft.c ugranger.c ucrypto.c ufile.c udeng.c utouzin.c uautomata.c uxorshift.c ubrent.c rijndael-alg-fst.c tu01_sha1.c scatter.c swrite.c sres.c smultin.c sknuth.c smarsa.c sstring.c svaria.c snpair.c swalk.c sentrop.c sspectral.c scomp.c sspacings.c vectorsF2.c bbattery.c ffam.c fcong.c ffsr.c ftab.c fres.c fcho.c fmultin.c fmarsa.c fknuth.c fwalk.c fstring.c fspectral.c fvaria.c fnpair.c +PROBDIST_SRC_C = fmass.c fdist.c fbar.c finv.c gofs.c gofw.c statcoll.c wdist.c +MYLIB_SRC_C = addstr.c bitset.c mystr.c num.c num2.c tables.c util.c + +EXAMPLES_SRC_C = mrg32k3a.c xorshift.c + +SRC_C = $(TESTU01_SRC_C) $(PROBDIST_SRC_C) $(MYLIB_SRC_C) $(EXAMPLES_SRC_C) + +SRC_CC = genode_chrono.cc genode_gdef.cc + +vpath %.cc $(REP_DIR)/src/lib/testu01 +vpath %.c $(TESTU01_SRC_DIR)/testu01 +vpath %.c $(TESTU01_SRC_DIR)/probdist +vpath %.c $(TESTU01_SRC_DIR)/mylib +vpath %.c $(TESTU01_SRC_DIR)/examples diff --git a/ports/testu01.hash b/ports/testu01.hash new file mode 100644 index 0000000..72b626b --- /dev/null +++ b/ports/testu01.hash @@ -0,0 +1 @@ +ad8cc8e8b947a26e747f3089535e67c952926256 diff --git a/ports/testu01.port b/ports/testu01.port new file mode 100644 index 0000000..f3270ed --- /dev/null +++ b/ports/testu01.port @@ -0,0 +1,40 @@ +LICENSE := other +VERSION := 1.2.3 +DOWNLOADS := testu01.archive + +URL(testu01) := http://www.iro.umontreal.ca/~simardr/testu01/TestU01.zip +SHA(testu01) := f41af4bc71841e16dacc195930e6c3a191c9ab99 +DIR(testu01) := src/lib/testu01 + +TESTU01_DIR := src/lib/testu01/TestU01-1.2.3 + +testu01_includes = $(addprefix $(TESTU01_DIR)/testu01/,\ + unif01.h ulcg.h umrg.h ucarry.h utaus.h ugfsr.h uinv.h uquad.h ucubic.h ulec.h utezuka.h umarsa.h uweyl.h uknuth.h uwu.h unumrec.h uvaria.h usoft.h ugranger.h ucrypto.h ufile.h udeng.h utouzin.h uautomata.h uxorshift.h ubrent.h rijndael-alg-fst.h tu01_sha1.h scatter.h swrite.h sres.h smultin.h sknuth.h smarsa.h sstring.h svaria.h snpair.h swalk.h sentrop.h sspectral.h scomp.h sspacings.h vectorsF2.h bbattery.h ffam.h fcong.h ffsr.h ftab.h fres.h fcho.h fmultin.h fmarsa.h fknuth.h fwalk.h fstring.h fspectral.h fvaria.h fnpair.h) + +probdist_includes = $(addprefix $(TESTU01_DIR)/probdist/,\ + fmass.h fdist.h fbar.h finv.h gofs.h gofw.h statcoll.h wdist.h) + +mylib_includes = $(addprefix $(TESTU01_DIR)/mylib/,\ + gdef.h addstr.h bitset.h chrono.h mystr.h num.h num2.h tables.h util.h) + +DIRS := include/testu01 +DIR_CONTENT(include/testu01) = $(generated_headers) + +generated_headers = $(testu01_includes) $(probdist_includes) $(mylib_includes) + +_dirs: $(generated_headers) + +$(generated_headers): $(DOWNLOADS) + +%.h: %.tex tcode + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)mkdir -p include/testu01 + $(VERBOSE)./tcode $< $@ + +%.tex: $(DOWNLOADS) + +tcode: $(TESTU01_DIR)/mylib/tcode.c + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)$(CC) -o $@ $< + +tcode.c: $(DOWNLOADS) \ No newline at end of file diff --git a/src/lib/testu01/genode_chrono.cc b/src/lib/testu01/genode_chrono.cc new file mode 100644 index 0000000..fa96982 --- /dev/null +++ b/src/lib/testu01/genode_chrono.cc @@ -0,0 +1,106 @@ +#include +#include + +/* XXX: should be the CPU session time, but the timer works for now */ +static void Heure (unsigned long *tsec, unsigned long *tusec) +{ + static Timer::Connection timer; + + unsigned long ms = timer.elapsed_ms(); + + *tsec = ms / 1000; + *tusec = ms * 1000; +} + + +extern "C" { + +#include "chrono.h" +#include +#include + +void chrono_Init (chrono_Chrono *C) { + Heure(&C->second, &C->microsec); } + + +chrono_Chrono * chrono_Create (void) +{ + chrono_Chrono *C = new (Genode::env()->heap()) chrono_Chrono; + Heure(&C->second, &C->microsec); + return C; +} + + +void chrono_Delete (chrono_Chrono *C) { destroy(Genode::env()->heap(), C); } + + +double chrono_Val (chrono_Chrono *C, chrono_TimeFormat Unit) +{ + double temps; /* Time elapsed, in seconds */ + chrono_Chrono now; + Heure (&now.second, &now.microsec); + temps = (((double) now.microsec - (double) C->microsec) / 1.E+6 + + (double) now.second) - (double) C->second; + + switch (Unit) { + case chrono_sec: + return temps; + case chrono_min: + return temps * 1.666666667E-2; + case chrono_hours: + return temps * 2.777777778E-4; + case chrono_days: + return temps * 1.157407407E-5; + case chrono_hms: + util_Error ("chrono_Val : hms is a wrong arg for chrono_TimeUnit"); + } + return 0.0; +} + +void chrono_Write (chrono_Chrono * C, chrono_TimeFormat Form) +{ + long centieme; + long minute; + long heure; + long seconde; + double temps; + if (Form != chrono_hms) + temps = chrono_Val (C, Form); + else + temps = 0.0; + switch (Form) { + case chrono_sec: + num_WriteD (temps, 10, 2, 1); + printf (" seconds"); + break; + case chrono_min: + num_WriteD (temps, 10, 2, 1); + printf (" minutes"); + break; + case chrono_hours: + num_WriteD (temps, 10, 2, 1); + printf (" hours"); + break; + case chrono_days: + num_WriteD (temps, 10, 2, 1); + printf (" days"); + break; + case chrono_hms: + temps = chrono_Val (C, chrono_sec); + heure = (long) (temps * 2.777777778E-4); + if (heure > 0) + temps -= (double) (heure) * 3600.0; + minute = (long) (temps * 1.666666667E-2); + if (minute > 0) + temps -= (double) (minute) * 60.0; + seconde = (long) (temps); + centieme = (long) (100.0 * (temps - (double) (seconde))); + printf ("%02ld:", heure); + printf ("%02ld:", minute); + printf ("%02ld.", seconde); + printf ("%02ld", centieme); + break; + } +} + +} diff --git a/src/lib/testu01/genode_gdef.cc b/src/lib/testu01/genode_gdef.cc new file mode 100644 index 0000000..e791873 --- /dev/null +++ b/src/lib/testu01/genode_gdef.cc @@ -0,0 +1,22 @@ +#include + +extern "C" { + +#include + +void gdef_GetHostName (char machine[], int n) +{ + try { Genode::config()->xml_node().attribute("hostname").value(machine, n); } + catch (...) { Genode::strncpy(machine, "genode", n); } +} + +void gdef_WriteHostName (void) +{ + enum { MAXBYTES = 255 }; + + char machine[1 + MAXBYTES] = {'\0'}; + gdef_GetHostName(machine, MAXBYTES); + printf("%s\n", machine); +} + +} \ No newline at end of file