This commit is contained in:
dzaima 2022-04-02 18:20:18 +03:00
parent b329ddee1d
commit 36d5b8f9d8
7 changed files with 145 additions and 6 deletions

View File

@ -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

11
test/README.md Normal file
View File

@ -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 𝕨≡𝕩
```

52
test/cmp.bqn Normal file
View File

@ -0,0 +1,52 @@
noerr•args
•Outnoerr "Not executing tests that would error"
fns =<>
n 0÷0
nn -n
arrs •internal.Squeeze¨
"hello","{⍉⍵}","{⍉𝕩}"
@+012126127
@+012126127128129
@+012655336553465535
"",0
123 ¯101 10 ¯5+10 11.5004π -11.5004π nnnnnnn(-02π)12500÷00350
¯128¯101127
¯32768¯10132767
¯2147483648¯1012147483647
¯2147483648¯1012147483648
63 (•MakeRand 2).Range 2
64 (•MakeRand 2).Range 2
65 (•MakeRand 2).Range 2
90 (•MakeRand 2).Range 2
atms 1¯10¯0¯∞nnn@'l''⍉''𝕩'{a1}
atms - 1020
atms - (¯0.9¯0.100.10.9+2-5) + 235
atms @+12865536+2-5
LV •internal.ListVariations
V •internal.Variation
ElType •internal.ElType
NEas ((¨=˙) 8·ElType 2¨)/
•Out "AS"
{
fnarratm:
´(¨) {(𝕩 V arr) Fn"err" atm}¨ LV arr?0;
fnarratm:
•Out "Fail:"
•Show arr
•Show fn
•Show atm
•Show (LV arr){(𝕩 V arr) Fn"err" atm}¨ LV arr
•Exit 1
}¨ NEasnoerr (<)<´ fnsarrsatms
•Out "AA"
{
fnlr:
lr(´¨lr)¨lr
´(¨) {fn"err"˝𝕩 V¨ lr}¨ <´ LV¨lr?0;
𝕩!0
}¨ ((<)<´ fns 2< (0<¨)/arrs) (<)<´ fns 2<"" 0

44
test/equal.bqn Normal file
View File

@ -0,0 +1,44 @@
ListVariations, ClearRefs, Variation, Squeeze, Info •internal
u •UnixTime@
# u ↩ 1648896733
r •MakeRand •Show u
TestVars { w𝕊ab:
n ¬w
(ListVariations a) {
¬n (𝕨 Variation a) (𝕩 Variation b)? @;
•Out "fail for "𝕨"/"𝕩", expected "(w"0""1")":"
•Out •Repr a
•Out •Repr b
•Out •Repr ab
•Exit 1
} ListVariations b
ClearRefs@
}
(1 TestVars ˜)¨ "" 0
# types: u1,i8,i16,i32,f64,c8,c16,c32
szs 2(281632)0(2816)1114111
off 0(271531)¯0.5000
chr 00000111
RandVal {
Squeeze @+(𝕩chr) (𝕨 r.Range 𝕩szs) - 𝕩off
}
Do { 𝕊:
at r.Range 8
l 1 + r.Range (at=0)100700
a l RandVal at
1 TestVars aa
{ 𝕊:
p r.Range l
v RandVal r.Range5 5+r.Range3 at5
exp v = pa
b Squeeze v(p) a
exp TestVars ab
}100 @
}
@Do1000 @

5
test/mainCfgs.sh Executable file
View File

@ -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

26
test/moreCfgs.sh Executable file
View File

@ -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

6
test/x86Cfgs.sh Executable file
View File

@ -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