From 36d5b8f9d8c851e8c83d8da832bba38a032473b6 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 2 Apr 2022 18:20:18 +0300 Subject: [PATCH] tests --- src/README.md | 7 +------ test/README.md | 11 ++++++++++ test/cmp.bqn | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ test/equal.bqn | 44 ++++++++++++++++++++++++++++++++++++++++ test/mainCfgs.sh | 5 +++++ test/moreCfgs.sh | 26 ++++++++++++++++++++++++ test/x86Cfgs.sh | 6 ++++++ 7 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 test/README.md create mode 100644 test/cmp.bqn create mode 100644 test/equal.bqn create mode 100755 test/mainCfgs.sh create mode 100755 test/moreCfgs.sh create mode 100755 test/x86Cfgs.sh diff --git a/src/README.md b/src/README.md index 60a7e929..ce875515 100644 --- a/src/README.md +++ b/src/README.md @@ -97,12 +97,7 @@ A heap-allocated object from type `B` can be cast to a `Value*` with `v(x)`, to The reference count of any `B` object can be incremented/decremented with `inc(x)`/`dec(x)`, and any subtype of `Value*` can use `ptr_inc(x)`/`ptr_dec(x)`. `inc(x)` and `ptr_inc(x)` will return the argument, so you can use it inline. `dec(x)` and `ptr_dec(x)` will return the object to the memory manager if the refcount as a result goes to zero. -Since reference counting is hard, there's `make heapverify` that verifies that any code executed does it right (and screams unreadable messages when it doesn't). After any changes, I'd suggest running: -```bash -#!/usr/bin/env bash -make rtverify && echo 'rtverify:' && ./BQN -M 1000 path/to/mlochbaum/BQN/test/this.bqn -make heapverify && echo 'heapverify:' && ./BQN -M 1000 path/to/mlochbaum/BQN/test/this.bqn -noerr bytecode header identity literal namespace prim simple syntax token under undo -``` +Since reference counting is hard, there's `make heapverify` that verifies that any code executed does it right (and screams unreadable messages when it doesn't). After any changes, I'd suggest running `test/mainCfgs.sh path/to/mlochbaum/BQN`, which'll run a couple primary configurations, including said `heapverify`. Temporary allocations can be made with `utils/talloc.h`: ```C diff --git a/test/README.md b/test/README.md new file mode 100644 index 00000000..8cb82d1f --- /dev/null +++ b/test/README.md @@ -0,0 +1,11 @@ +## Tests + +Must be run from the projects root directory. + +``` C +test/mainCfgs.sh path/to/mlochbaum/BQN // run the test suite for a couple primary configurations +test/x86Cfgs.sh path/to/mlochbaum/BQN // run the test suite for x86-64-specific configurations, including singeli; 32-bit build is "supposed" to fail one test involving ⋆⁼ +test/moreCfgs.sh path/to/mlochbaum/BQN // run "2+2" in a bunch of configurations +./BQN test/cmp.bqn // fuzz-test scalar comparison functions =≠<≤>≥ +./BQN test/equal.bqn // fuzz-test 𝕨≡𝕩 +``` \ No newline at end of file diff --git a/test/cmp.bqn b/test/cmp.bqn new file mode 100644 index 00000000..836e2a74 --- /dev/null +++ b/test/cmp.bqn @@ -0,0 +1,52 @@ +noerr←≠•args +•Out⍟noerr "Not executing tests that would error" +fns ← =‿≠‿<‿≤‿>‿≥ +n ← 0÷0 +nn ← -n +arrs ← •internal.Squeeze¨ ⟨ + "hello","{⍉⍵}","{⍉𝕩}" + @+0‿1‿2‿126‿127 + @+0‿1‿2‿126‿127‿128‿129 + @+0‿1‿2‿65533‿65534‿65535 + "",↕0 + 1‿2‿3 ⋄ ¯1‿0‿1 ⋄ ↕10 ⋄ ¯5+↕10 ⋄ 1‿1.5‿0‿0‿4‿π ⋄ -1‿1.5‿0‿0‿4‿π ⋄ n‿nn‿n‿n‿nn∾(-0‿2‿π)∾1‿2‿5‿0‿0÷0‿0‿3‿5‿0 + ¯128‿¯1‿0‿1‿127 + ¯32768‿¯1‿0‿1‿32767 + ¯2147483648‿¯1‿0‿1‿2147483647 + ¯2147483648‿¯1‿0‿1‿2147483648 + 63 (•MakeRand 2).Range 2 + 64 (•MakeRand 2).Range 2 + 65 (•MakeRand 2).Range 2 + 90 (•MakeRand 2).Range 2 +⟩ +atms ← 1‿¯1‿0‿¯0‿∞‿¯∞‿n‿nn‿@‿'l'‿'⍉'‿'𝕩'‿{a⇐1} +atms∾↩ -⊸∾ 10⋆↕20 +atms∾↩ -⊸∾ ⥊(⥊¯0.9‿¯0.1‿0‿0.1‿0.9+⌜2-↕5) +⌜ 2⋆↕35 +atms∾↩ @+⥊128‿65536+⌜2-↕5 + +LV ← •internal.ListVariations +V ← •internal.Variation +ElType ← •internal.ElType + +NEas ← ((⊑¨∊=‿≠˙) ∨ 8≠·ElType 2⊑¨⊢)⊸/ + +•Out "AS" +{ +fn‿arr‿atm: + ∧´(⊏≡¨⊢) {(𝕩 V arr) Fn⎊"err" atm}¨ LV arr?0; +fn‿arr‿atm: + •Out "Fail:" + •Show arr + •Show fn + •Show atm + •Show ⍉(LV arr)≍{(𝕩 V arr) Fn⎊"err" atm}¨ LV arr + •Exit 1 +}¨ NEas⍟noerr ⥊(<⟨⟩)<⊸∾⌜´ fns‿arrs‿atms + +•Out "AA" +{ +fn‿l‿r: + lr←(⌈´≠¨l‿r)↑¨l‿r + ∧´(⊏≡¨⊢) {fn⎊"err"˝𝕩 V¨ lr}¨ ⥊≍○<⌜´ LV¨lr?0; + 𝕩!0 +}¨ (⥊(<⟨⟩)<⊸∾⌜´ ⟨fns⟩ ∾ 2⥊< (0<≠¨)⊸/arrs) ∾ ⥊(<⟨⟩)<⊸∾⌜´ ⟨fns⟩ ∾ 2⥊<⟨"" ⋄ ↕0 ⋄ ⟨⟩⟩ \ No newline at end of file diff --git a/test/equal.bqn b/test/equal.bqn new file mode 100644 index 00000000..13dfee66 --- /dev/null +++ b/test/equal.bqn @@ -0,0 +1,44 @@ +⟨ListVariations, ClearRefs, Variation, Squeeze, Info⟩ ← •internal +u ← •UnixTime@ +# u ↩ 1648896733 + +r ← •MakeRand •Show u + +TestVars ← { w𝕊a‿b: + n ← ¬w + (ListVariations a) { + ¬⍟n (𝕨 Variation a) ≡ (𝕩 Variation b)? @; + •Out ∾"fail for "‿𝕨‿"/"‿𝕩‿", expected "‿(w⊑"0"‿"1")‿":" + •Out •Repr a + •Out •Repr b + •Out •Repr a≠b + •Exit 1 + }⌜ ListVariations b + ClearRefs@ +} + +(1 TestVars ⋈˜)¨ ⟨⟨⟩ ⋄ "" ⋄ ↕0⟩ + +# types: u1,i8,i16,i32,f64,c8,c16,c32 +szs ← 2∾(2⋆8‿16‿32)∾0∾(2⋆8‿16)∾1114111 +off ← 0∾(2⋆7‿15‿31)∾¯0.5∾0‿0‿0 +chr ← 0‿0‿0‿0‿0‿1‿1‿1 +RandVal ← { + Squeeze @+⍟(𝕩⊑chr) (𝕨 r.Range 𝕩⊑szs) - 𝕩⊑off +} + +Do ← { 𝕊: + at ← r.Range 8 + l ← 1 + r.Range (at=0)⊑100‿700 + a ← l RandVal at + 1 TestVars a‿a + { 𝕊: + p ← r.Range l + v ← RandVal ⊢◶⟨r.Range∘5 ⋄ 5+r.Range∘3⟩ at≥5 + exp ← v = p⊑a + b ← Squeeze v⌾(p⊸⊑) a + exp TestVars a‿b + }⍟100 @ +} + +@∘Do⍟1000 @ \ No newline at end of file diff --git a/test/mainCfgs.sh b/test/mainCfgs.sh new file mode 100755 index 00000000..93860353 --- /dev/null +++ b/test/mainCfgs.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +make heapverify && echo 'heapverify:' && ./BQN -M 1000 "$1/test/this.bqn" -noerr bytecode header identity literal namespace prim simple syntax token under undo unhead || exit +make rtverify && echo 'rtverify:' && ./BQN -M 1000 "$1/test/this.bqn" || exit +echo 'gcc:';make CC=gcc t='gcc_basic' c && ./BQN -M 1000 "$1/test/this.bqn" || exit + diff --git a/test/moreCfgs.sh b/test/moreCfgs.sh new file mode 100755 index 00000000..a74cade1 --- /dev/null +++ b/test/moreCfgs.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +make && ./BQN -p 2+2 || exit +make single-debug && ./BQN -p 2+2 || exit +make heapverify && ./BQN -p 2+2 || exit +make rtverify && ./BQN -p 2+2 || exit +make rtperf && ./BQN -p 2+2 | head -2 || exit +make t=mc_vmdbg f='-DDEBUG -DDEBUG_VM' c && ./BQN -p 2+2 | tail -2 || exit +make t=mc_mm0 f='-DMM=0 -DENABLE_GC=0' c && ./BQN -p 2+2 || exit +make t=mc_mm1 f='-DMM=1' c && ./BQN -p 2+2 || exit +make t=mc_mm2 f='-DMM=2' c && ./BQN -p 2+2 || exit +make t=mc_tyar0 f='-DTYPED_ARITH=0' c && ./BQN -p 2+2 || exit +make t=mc_frt f='-DFAKE_RUNTIME' c && ./BQN -p 2+2 || exit +make t=mc_allr0 f='-DALL_R0' c && ./BQN -p 2+2 || exit +make t=mc_allr1 f='-DALL_R1' c && ./BQN -p 2+2 || exit +make t=mc_allr01 f='-DALL_R0 -DALL_R1' c && ./BQN -p 2+2 || exit +make t=mc_nosff f='-DSFNS_FILLS=0' c && ./BQN -p 2+2 || exit +make t=mc_nofmt f='-DFORMATTER=0' c && ./BQN -p 2+2 || exit +make t=mc_novmpos f='-DVMPOS=0' c && ./BQN -p 2+2 || exit +make t=mc_dontfree f='-DDONT_FREE' c && ./BQN -p 2+2 || exit +make t=mc_objctr f='-DOBJ_COUNTER' c && ./BQN -p 2+2 || exit +make t=mc_nort f='-DNO_RT' c || exit +./precompiled.bqn "$1" "$PATH" '2+2' || exit +make t=mc_nortpre f='-DNO_RT -DPRECOMP' c && ./BQN || exit +make t=mc_loggc f='-DLOG_GC' c && ./BQN -p 2+2 || exit +make t=mc_writeasm f='-DWRITE_ASM' c && ./BQN -p 2+2 || exit +make t=mc_useperf f='-DUSE_PERF' c && ./BQN -p 2+2 || exit diff --git a/test/x86Cfgs.sh b/test/x86Cfgs.sh new file mode 100755 index 00000000..489e8ed3 --- /dev/null +++ b/test/x86Cfgs.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +make f='-DDEBUG -DHEAP_VERIFY -DJIT_START=0' single-c +echo 'alljit+heapverify:' && ./BQN -M 1000 "$1/test/this.bqn" -noerr bytecode header identity literal namespace prim simple syntax token under undo unhead || exit +echo 'singeli:';make o3n-singeli && ./BQN -M 1000 "$1/test/this.bqn" || exit +echo 'singeli vfy:';make heapverifyn-singeli && ./BQN -M 1000 "$1/test/this.bqn" -noerr bytecode header identity literal namespace prim simple syntax token under undo unhead || exit +echo '32-bit:';make f='-DDEBUG -m32' single-c && ./BQN -M 1000 "$1/test/this.bqn" || exit