aboutsummaryrefslogtreecommitdiffstats
path: root/test/mppa/prng
diff options
context:
space:
mode:
authorCyril SIX <cyril.six@kalray.eu>2018-11-09 17:07:13 +0100
committerCyril SIX <cyril.six@kalray.eu>2018-11-09 17:07:13 +0100
commitf24d303df6cb125ca19b953bb364955cc6e8c246 (patch)
treee885cbb64c217ddec1b02a350679b3f2a29d6373 /test/mppa/prng
parent622a211d4ebd47feb4d2c7dfe590d10c6d6ae834 (diff)
downloadcompcert-kvx-f24d303df6cb125ca19b953bb364955cc6e8c246.tar.gz
compcert-kvx-f24d303df6cb125ca19b953bb364955cc6e8c246.zip
Fixed consistency between the different tests mmult, prng and sort
Diffstat (limited to 'test/mppa/prng')
-rw-r--r--test/mppa/prng/.gitignore2
-rw-r--r--test/mppa/prng/Makefile49
-rw-r--r--test/mppa/prng/README.md17
-rw-r--r--test/mppa/prng/prng.c41
-rw-r--r--test/mppa/prng/prng.h10
-rw-r--r--test/mppa/prng/types.h7
6 files changed, 126 insertions, 0 deletions
diff --git a/test/mppa/prng/.gitignore b/test/mppa/prng/.gitignore
new file mode 100644
index 00000000..1879eaee
--- /dev/null
+++ b/test/mppa/prng/.gitignore
@@ -0,0 +1,2 @@
+prng-test-k1c
+prng-test-x86
diff --git a/test/mppa/prng/Makefile b/test/mppa/prng/Makefile
new file mode 100644
index 00000000..481a3fca
--- /dev/null
+++ b/test/mppa/prng/Makefile
@@ -0,0 +1,49 @@
+K1CC ?= k1-mbr-gcc
+CC ?= gcc
+CCOMP ?= ccomp
+CFLAGS ?= -O2
+
+all: prng-test-gcc-x86 prng-test-gcc-k1c prng-test-ccomp-k1c
+
+prng-test-gcc-x86: prng.c
+ $(CC) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@
+
+prng-test-gcc-k1c: prng.c
+ $(K1CC) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@
+
+prng-test-ccomp-k1c: prng.c
+ $(CCOMP) -D__UNIT_TEST_PRNG__ $(CFLAGS) $< -o $@
+
+.PHONY:
+test: test-x86 test-k1c
+
+.PHONY:
+test-x86: prng-test-gcc-x86
+ @if ! ./$<; then\
+ >&2 echo "ERROR: $< failed";\
+ exit;\
+ else\
+ echo "$< Succeeded";\
+ fi
+
+.PHONY:
+test-k1c: prng-test-gcc-k1c
+ @if ! k1-cluster -- ./$<; then\
+ >&2 echo "ERROR: $< failed";\
+ exit;\
+ else\
+ echo "$< Succeeded";\
+ fi
+
+.PHONY:
+check: prng-test-ccomp-k1c
+ @if ! k1-cluster -- ./$<; then\
+ >&2 echo "ERROR: $< failed";\
+ exit;\
+ else\
+ echo "$< Succeeded";\
+ fi
+
+.PHONY:
+clean:
+ rm -f prng-test-gcc-x86 prng-test-gcc-k1c prng-test-ccomp-k1c
diff --git a/test/mppa/prng/README.md b/test/mppa/prng/README.md
new file mode 100644
index 00000000..b4c2279b
--- /dev/null
+++ b/test/mppa/prng/README.md
@@ -0,0 +1,17 @@
+PRNG
+====
+
+This is a simple Pseudo Random Number Generator.
+
+`prng.c` contains a simple unitary test that compares the sum of the "bytewise sum"
+of 1000 generated numbers to a hardcoded result, that is the one obtained with
+`gcc -O2` on a x86 processor, and returns 0 if the result is correct.
+
+The following commands can be run inside that folder:
+
+- `make`: produces the unitary test binaries
+ - `prng-test-gcc-x86` : binary from gcc on x86
+ - `prng-test-k1c-x86` : binary from gcc on k1c
+ - `prng-test-ccomp-x86` : binary from ccomp on k1c
+- `make test`: tests the return value of the binaries produced by gcc.
+- `make check`: tests the return value of the binary produced by CompCert.
diff --git a/test/mppa/prng/prng.c b/test/mppa/prng/prng.c
new file mode 100644
index 00000000..71de1dc3
--- /dev/null
+++ b/test/mppa/prng/prng.c
@@ -0,0 +1,41 @@
+// https://en.wikipedia.org/wiki/Linear_congruential_generator -> MMIX Donald Knuth
+// modulo 2^64 = no need to do it explicitly
+
+#include "types.h"
+
+#define MULTIPLIER 6364136223846793005LL
+#define INCREMENT 1442695040888963407LL
+
+static uint64_t current;
+
+void srand(uint64_t seed){
+ current = seed;
+}
+
+uint64_t randlong(void){
+ return (current = MULTIPLIER * current + INCREMENT);
+}
+
+#ifdef __UNIT_TEST_PRNG__
+char bytewise_sum(uint64_t to_check){
+ char sum = 0;
+ int i;
+
+ for (i = 0 ; i < 8 ; i++)
+ sum += (to_check & (uint64_t)(0xFFULL << i*8)) >> i*8;
+
+ return sum;
+}
+
+int main(void){
+ srand(42);
+ int i;
+
+ for (i = 0 ; i < 1000 ; i++)
+ randlong();
+
+ uint64_t last = randlong();
+
+ return !((unsigned char)bytewise_sum(last) == 155);
+}
+#endif // __UNIT_TEST_PRNG__
diff --git a/test/mppa/prng/prng.h b/test/mppa/prng/prng.h
new file mode 100644
index 00000000..6abdb45a
--- /dev/null
+++ b/test/mppa/prng/prng.h
@@ -0,0 +1,10 @@
+#ifndef __PRNG_H__
+#define __PRNG_H__
+
+#include "types.h"
+
+void srand(uint64_t seed);
+
+uint64_t randlong(void);
+
+#endif // __PRNG_H__
diff --git a/test/mppa/prng/types.h b/test/mppa/prng/types.h
new file mode 100644
index 00000000..584023e3
--- /dev/null
+++ b/test/mppa/prng/types.h
@@ -0,0 +1,7 @@
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+#define uint64_t unsigned long long
+#define int64_t signed long long
+
+#endif // __TYPES_H__