From 24333963697e728c5977cd52e9c576fd0d2da42c Mon Sep 17 00:00:00 2001 From: allaun Date: Tue, 30 Jun 2026 18:31:18 -0500 Subject: [PATCH] fix(octave): restructure test to avoid subfunction scope issues --- octave/test_avm.m | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/octave/test_avm.m b/octave/test_avm.m index 9175f9dd..9ac22f1e 100644 --- a/octave/test_avm.m +++ b/octave/test_avm.m @@ -1,9 +1,12 @@ % AVM ISA v1 — Octave/MATLAB Test Harness % Run with: cd octave && octave --no-gui test_avm.m -function check(result, msg) - if result; fprintf(stdout, " ✅ %s\n", msg); - else; fprintf(stdout, " ❌ %s\n", msg); end +function test_avm() + test_basic_add(); + test_div(); + test_saturation(); + test_locals(); + fprintf(stdout, "\nAll Octave tests passed.\n"); end function test_basic_add() @@ -13,7 +16,8 @@ function test_basic_add() prog{3} = struct('op', AVM.OP_PRIM, 'arg', int32(AVM.PRIM_ADD_Q16), 'arg2', false); prog{4} = struct('op', AVM.OP_HALT, 'arg', int32(0), 'arg2', false); s = AVM.run(AVM.init_state(0), prog, 100); - check(s.stack{1}.i == 8*QS, 'basic_add: 5+3=8'); + if s.stack{1}.i == 8*QS; fprintf(stdout, " ✅ basic_add: 5+3=8\n"); + else; fprintf(stdout, " ❌ basic_add\n"); end end function test_div() @@ -24,7 +28,8 @@ function test_div() prog{4} = struct('op', AVM.OP_HALT, 'arg', int32(0), 'arg2', false); s = AVM.run(AVM.init_state(0), prog, 100); expected = idivide(int32(3*QS), int32(5*QS), 'floor') * int32(QS); - check(s.stack{1}.i == expected, 'div_q16: 3/5'); + if s.stack{1}.i == expected; fprintf(stdout, " ✅ div_q16: 3/5\n"); + else; fprintf(stdout, " ❌ div_q16\n"); end end function test_saturation() @@ -34,7 +39,8 @@ function test_saturation() prog{3} = struct('op', AVM.OP_PRIM, 'arg', int32(AVM.PRIM_ADD_Q16), 'arg2', false); prog{4} = struct('op', AVM.OP_HALT, 'arg', int32(0), 'arg2', false); s = AVM.run(AVM.init_state(0), prog, 100); - check(s.stack{1}.i == AVM.AVM_CLAMP_MAX, 'saturation'); + if s.stack{1}.i == AVM.AVM_CLAMP_MAX; fprintf(stdout, " ✅ saturation\n"); + else; fprintf(stdout, " ❌ saturation\n"); end end function test_locals() @@ -44,13 +50,10 @@ function test_locals() prog{3} = struct('op', AVM.OP_LOAD, 'arg', int32(0), 'arg2', false); prog{4} = struct('op', AVM.OP_HALT, 'arg', int32(0), 'arg2', false); s = AVM.run(AVM.init_state(1), prog, 100); - check(s.stack{1}.i == 42*QS, 'locals: store+load'); + if s.stack{1}.i == 42*QS; fprintf(stdout, " ✅ locals: store+load\n"); + else; fprintf(stdout, " ❌ locals\n"); end end fprintf(stdout, "AVM Octave Port — Test Harness\n"); fprintf(stdout, "===============================\n"); -test_basic_add(); -test_div(); -test_saturation(); -test_locals(); -fprintf(stdout, "\nAll Octave tests passed.\n"); +test_avm();