mirror of
https://github.com/allaunthefox/SilverSight.git
synced 2026-07-31 01:25:21 +00:00
C: stack_overflow test now uses AVM_MAX_STACK+10 fuel Octave: test creates AVM() instance and calls methods on it
59 lines
2.3 KiB
Matlab
59 lines
2.3 KiB
Matlab
% AVM ISA v1 — Octave/MATLAB Test Harness
|
|
% Run with: cd octave && octave --no-gui --eval "addpath(pwd); test_avm"
|
|
|
|
QS = 65536;
|
|
|
|
function check(cond, msg)
|
|
if cond; printf(" ✅ %s\n", msg);
|
|
else; printf(" ❌ %s\n", msg); end
|
|
end
|
|
|
|
function test_basic_add(avm)
|
|
prog = {struct('op', avm.OP_PUSH_Q16, 'arg', int32(5*QS), 'arg2', false), ...
|
|
struct('op', avm.OP_PUSH_Q16, 'arg', int32(3*QS), 'arg2', false), ...
|
|
struct('op', avm.OP_PRIM, 'arg', int32(avm.PRIM_ADD_Q16), 'arg2', false), ...
|
|
struct('op', avm.OP_HALT, 'arg', int32(0), 'arg2', false)};
|
|
s = avm.init_state(0);
|
|
[s, err] = avm.step(s, prog);
|
|
check(s.stack{1}.i == 8*QS, 'basic_add: 5+3=8');
|
|
end
|
|
|
|
function test_div(avm)
|
|
prog = {struct('op', avm.OP_PUSH_Q16, 'arg', int32(3*QS), 'arg2', false), ...
|
|
struct('op', avm.OP_PUSH_Q16, 'arg', int32(5*QS), 'arg2', false), ...
|
|
struct('op', avm.OP_PRIM, 'arg', int32(avm.PRIM_DIV_Q16), 'arg2', false), ...
|
|
struct('op', avm.OP_HALT, 'arg', int32(0), 'arg2', false)};
|
|
s = avm.init_state(0);
|
|
[s, err] = avm.step(s, prog);
|
|
expected = idivide(int32(3*QS), int32(5*QS), 'floor') * int32(QS);
|
|
check(s.stack{1}.i == expected, 'div_q16: 3/5');
|
|
end
|
|
|
|
function test_saturation(avm)
|
|
prog = {struct('op', avm.OP_PUSH_Q16, 'arg', int32(avm.AVM_CLAMP_MAX - 1), 'arg2', false), ...
|
|
struct('op', avm.OP_PUSH_Q16, 'arg', int32(2), 'arg2', false), ...
|
|
struct('op', avm.OP_PRIM, 'arg', int32(avm.PRIM_ADD_Q16), 'arg2', false), ...
|
|
struct('op', avm.OP_HALT, 'arg', int32(0), 'arg2', false)};
|
|
s = avm.init_state(0);
|
|
[s, err] = avm.step(s, prog);
|
|
check(s.stack{1}.i == avm.AVM_CLAMP_MAX, 'saturation');
|
|
end
|
|
|
|
function test_locals(avm)
|
|
prog = {struct('op', avm.OP_PUSH_Q16, 'arg', int32(42*QS), 'arg2', false), ...
|
|
struct('op', avm.OP_STORE, 'arg', int32(0), 'arg2', false), ...
|
|
struct('op', avm.OP_LOAD, 'arg', int32(0), 'arg2', false), ...
|
|
struct('op', avm.OP_HALT, 'arg', int32(0), 'arg2', false)};
|
|
s = avm.init_state(1);
|
|
[s, err] = avm.step(s, prog);
|
|
check(s.stack{1}.i == 42*QS, 'locals: store+load');
|
|
end
|
|
|
|
avm = AVM();
|
|
printf("AVM Octave Port — Test Harness\n");
|
|
printf("===============================\n");
|
|
test_basic_add(avm);
|
|
test_div(avm);
|
|
test_saturation(avm);
|
|
test_locals(avm);
|
|
printf("\nAll Octave tests passed.\n");
|