mirror of
https://github.com/allaunthefox/SilverSight.git
synced 2026-07-31 01:25:21 +00:00
fix(octave): restructure test to avoid subfunction scope issues
This commit is contained in:
parent
249179d922
commit
2433396369
1 changed files with 15 additions and 12 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue