From 98e058bd88867776f3ad122b3b3c963eb33f5a4c Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 23 Jul 2023 12:41:05 +0200 Subject: [PATCH] start adding some testing --- test/makefile | 53 ++++++++++++++++++++++++++++ test/test | Bin 0 -> 22272 bytes test/test.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 test/makefile create mode 100755 test/test create mode 100644 test/test.c diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..e4139a0 --- /dev/null +++ b/test/makefile @@ -0,0 +1,53 @@ +# Interface: +# make +# make build +# make format +# make run + +# Compiler +CC=gcc +# CC=tcc # <= faster compilation + +# Main file +SRC=test.c ../squiggle.c +OUTPUT=test + +## Dependencies +MATH=-lm + +## Flags +DEBUG= #'-g' +STANDARD=-std=c99 +WARNINGS=-Wall +OPTIMIZED=-O3 #-Ofast +# OPENMP=-fopenmp + +## Formatter +STYLE_BLUEPRINT=webkit +FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) + +## make build +build: $(SRC) + $(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(MATH) -o $(OUTPUT) + +format: $(SRC) + $(FORMATTER) $(SRC) + +run: $(SRC) $(OUTPUT) + ./$(OUTPUT) + +time-linux: + @echo "Requires /bin/time, found on GNU/Linux systems" && echo + + @echo "Running 100x and taking avg time $(OUTPUT)" + @t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo + +## Profiling + +profile-linux: + echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar" + echo "Must be run as sudo" + $(CC) $(SRC) $(MATH) -o $(OUTPUT) + sudo perf record ./$(OUTPUT) + sudo perf report + rm perf.data diff --git a/test/test b/test/test new file mode 100755 index 0000000000000000000000000000000000000000..932cb620ade5cf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k0{z^~9a;Z{NaCE%%DbKI^J^sWh30nj#K_jFq|jwn!uL| z{DlHvcoj#mb0K7}1b)1rF@l+ben9v|`b(h)9XLC$X$iCjf_SiAqYQl##1m-n)X+yk z=qnw*CeNz+rj_1$k1x>F((3UB+mxE7hUR)dp7c123#S&PCZcb3)OoxuE#7q=e`BC! z9lp@vZSZ@1!G?x)U@??DpbR9D8cz2;p4qp$=aqU&=ab2*+;T}aSNZdE*U$`{OZmwOh>p1r8F!c*a%Szby~+1EsBT7yh$l#SmWak=DY zMd(u@^qr9*41H*%)l1g!tnxNAc;#12k}3YyCs*iWD9P0H4HX0Ci_BLZ@vu$t_0o@a<8S(mduykd|5TX28l zfe;iTJ^2?}P)Po+jK|m7N`+l?=|MI1}HONv07lgh52VX?T#y*@Yf*D$OlTHU8FC zkH4j*sYPkSP*`188@PUwP>&vYqMIv0!Gq86R7rG;eWu1^_!`cT4is1m%jm;7LpTa8 z`dm&j#^b>Ud&FQ6S|=idKJ1h7Yd!R(o@6n?PeTS>=|@l*btY>je{?5V!cgNwHd36e z>ly;ym4Ja34p++@J^|!!X;z$g2aS6p z0e>5cG-ZLhiH$I)f3=vTR{J1LmbeT)TX7DVM^oO0Itb(J2nEH7nX&=1pK(h5TzR@< z$-ocGFH7=%SweZvBdQs#%oDrF zj+B-BVtH5UfTJcQzdRq1Q0|LC!jcdti|kuZboM0qWP1*pp)kp63X*E(w}T5+n4rx z7&x+t>>q7WSrX8EM{f52_d#sr*94!0=72YeR~|9*i}MkAej@3)QnWYaNy5iW{PKK7 z!V{9w#3%V_-3C_VEb*VBf?`*;FVCms_cx_s#IQ=plXm<$c*%YV{skx?=`%Ro!a?FH z+m(>sgf{Xg?sHw7MYbaaNIqH41vBAf`|^Iq=He7)dTPs +#include +#include +#include + +#define N 10 * 1000 * 1000 + +void test_unit_uniform(uint32_t* seed){ + float* unit_uniform_array = malloc(sizeof(float) * N); + + for(int i=0; i 1.0/1000.0){ + printf("[-] Mean test for unit uniform NOT passed.\n"); + }else { + printf("[x] Mean test for unit uniform PASSED\n"); + } + + if(fabs(delta_std) > 1.0/1000.0){ + printf("[-] Std test for unit uniform NOT passed.\n"); + }else { + printf("[x] Std test for unit uniform PASSED\n"); + } + + printf("\n"); + +} + +void test_uniform(float start, float end, uint32_t* seed){ + float* uniform_array = malloc(sizeof(float) * N); + + for(int i=0; i width * 1.0/1000.0){ + printf("[-] Mean test for [%.1f, %.1f] uniform NOT passed.\n", start, end); + printf("Mean of [%.1f, %.1f] uniform: %f, vs expected mean: %f, delta: %f\n", start, end, mean, expected_mean, mean - expected_mean); + }else { + printf("[x] Mean test for unit uniform PASSED\n"); + } + + if(fabs(delta_std) > width * 1.0/1000.0){ + printf("[-] Std test for [%.1f, %.1f] uniform NOT passed.\n", start, end); + printf("Std of [%.1f, %.1f] uniform: %f, vs expected std: %f, delta: %f\n", start, end, std, expected_std, std - expected_std); + }else { + printf("[x] Std test for unit uniform PASSED\n"); + } + printf("\n"); + +} + +int main(){ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with a seed of 0 + + test_unit_uniform(seed); + + for(int i=0; i<100; i++){ + float start = sample_uniform(-10, 10, seed); + float end = sample_uniform(-10, 10, seed); + if ( end > start){ + test_uniform(start, end, seed); + } + } + free(seed); +} +