From c740492e7a5c14a524c31bbc769a07af2e2ac6be Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Tue, 17 Apr 2018 09:59:42 +0200 Subject: MPPA - Added uint64_t types to the tests + k1c test --- test/mppa/lib/Makefile | 18 +++++++++++++++--- test/mppa/lib/prng.c | 14 ++++++++------ test/mppa/lib/prng.h | 6 ++++-- test/mppa/lib/types.h | 7 +++++++ 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 test/mppa/lib/types.h (limited to 'test/mppa') diff --git a/test/mppa/lib/Makefile b/test/mppa/lib/Makefile index 10f40f23..e6a75707 100644 --- a/test/mppa/lib/Makefile +++ b/test/mppa/lib/Makefile @@ -1,8 +1,11 @@ prng-test-x86: prng.c gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@ +prng-test-k1c: prng.c + k1-gcc -D__UNIT_TEST__ -O2 -std=c99 $< -o $@ + .PHONY: -test: test-x86 +test: test-x86 test-k1c .PHONY: test-x86: prng-test-x86 @@ -10,9 +13,18 @@ test-x86: prng-test-x86 >&2 echo "ERROR: $< failed";\ exit;\ else\ - echo "Test Succeeded";\ + echo "x86: Test Succeeded";\ + fi + +.PHONY: +test-k1c: prng-test-k1c + @if ! k1-cluster -- ./$<; then\ + >&2 echo "ERROR: $< failed";\ + exit;\ + else\ + echo "k1c: Test Succeeded";\ fi .PHONY: clean: - rm -f prng-test-x86 + rm -f prng-test-x86 prng-test-k1c diff --git a/test/mppa/lib/prng.c b/test/mppa/lib/prng.c index 5846038c..bfc38678 100644 --- a/test/mppa/lib/prng.c +++ b/test/mppa/lib/prng.c @@ -1,25 +1,27 @@ // 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 unsigned long long current; +static uint64_t current; -void srand(long long seed){ +void srand(uint64_t seed){ seed = current; } -unsigned long long randlong(void){ +uint64_t randlong(void){ return (current = MULTIPLIER * current + INCREMENT); } #ifdef __UNIT_TEST__ -char bytewise_sum(unsigned long long to_check){ +char bytewise_sum(uint64_t to_check){ char sum = 0; for (int i = 0 ; i < 8 ; i++) - sum += (to_check & (unsigned long long)(0xFFULL << i*8)) >> i*8; + sum += (to_check & (uint64_t)(0xFFULL << i*8)) >> i*8; return sum; } @@ -33,7 +35,7 @@ int main(void){ for (int i = 0 ; i < 1000 ; i++) randlong(); - unsigned long long last = randlong(); + uint64_t last = randlong(); return !((unsigned char)bytewise_sum(last) == 251); } diff --git a/test/mppa/lib/prng.h b/test/mppa/lib/prng.h index fee8c865..6abdb45a 100644 --- a/test/mppa/lib/prng.h +++ b/test/mppa/lib/prng.h @@ -1,8 +1,10 @@ #ifndef __PRNG_H__ #define __PRNG_H__ -void srand(long long seed); +#include "types.h" -long long randlong(void); +void srand(uint64_t seed); + +uint64_t randlong(void); #endif // __PRNG_H__ diff --git a/test/mppa/lib/types.h b/test/mppa/lib/types.h new file mode 100644 index 00000000..584023e3 --- /dev/null +++ b/test/mppa/lib/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__ -- cgit