forked from AbleOS/holey-bytes
add in test cases
This commit is contained in:
parent
e3277e99a7
commit
49a45d62c6
|
@ -444,15 +444,26 @@ F5-F9 {:016X} {:016X} {:016X} {:016X} {:016X}",
|
|||
|
||||
(255, int) => {
|
||||
trace!("Enviroment Call {}", int);
|
||||
let ret = self.enviroment_call_table[int as usize](self);
|
||||
match ret {
|
||||
Ok(eng) => {
|
||||
trace!("Resuming execution at {}", eng.index);
|
||||
let ecall = self.enviroment_call_table[int as usize];
|
||||
|
||||
match ecall {
|
||||
Some(call) => {
|
||||
let ret = call(self);
|
||||
|
||||
match ret {
|
||||
Ok(eng) => {
|
||||
trace!("Resuming execution at {}", eng.index);
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(HostError(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(HostError(err));
|
||||
None => {
|
||||
return Err(InvalidSystemCall(int));
|
||||
}
|
||||
}
|
||||
|
||||
self.index += 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ use {
|
|||
super::Engine,
|
||||
crate::{HaltStatus, RuntimeErrors},
|
||||
alloc::vec,
|
||||
RuntimeErrors::*,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -30,7 +31,7 @@ fn jump_out_of_bounds() {
|
|||
let prog = vec![JUMP as u8, 0, 0, 0, 0, 0, 0, 1, 0];
|
||||
let mut eng = Engine::new(prog);
|
||||
let ret = eng.run();
|
||||
assert_eq!(ret, Err(RuntimeErrors::InvalidJumpAddress(256)));
|
||||
assert_eq!(ret, Err(InvalidJumpAddress(256)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -38,5 +39,44 @@ fn invalid_system_call() {
|
|||
let prog = vec![255, 0];
|
||||
let mut eng = Engine::new(prog);
|
||||
let ret = eng.run();
|
||||
// assert_eq!(ret, );
|
||||
assert_eq!(ret, Err(InvalidSystemCall(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_u8() {
|
||||
use crate::engine::{Operations::ADD, SubTypes::EightBit};
|
||||
|
||||
let prog = vec![ADD as u8, EightBit as u8, 1, 1, 0xA0];
|
||||
let mut eng = Engine::new(prog);
|
||||
let _ = eng.run();
|
||||
assert_eq!(eng.registers.a0, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_u8() {
|
||||
use crate::engine::{Operations::SUB, SubTypes::EightBit};
|
||||
|
||||
let prog = vec![SUB as u8, EightBit as u8, 2, 1, 0xA0];
|
||||
let mut eng = Engine::new(prog);
|
||||
let _ = eng.run();
|
||||
assert_eq!(eng.registers.a0, 1);
|
||||
}
|
||||
#[test]
|
||||
fn mul_u8() {
|
||||
use crate::engine::{Operations::MUL, SubTypes::EightBit};
|
||||
|
||||
let prog = vec![MUL as u8, EightBit as u8, 1, 1, 0xA0];
|
||||
let mut eng = Engine::new(prog);
|
||||
let _ = eng.run();
|
||||
assert_eq!(eng.registers.a0, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn div_u8() {
|
||||
use crate::engine::{Operations::DIV, SubTypes::EightBit};
|
||||
|
||||
let prog = vec![DIV as u8, EightBit as u8, 1, 1, 0xA0];
|
||||
let mut eng = Engine::new(prog);
|
||||
let _ = eng.run();
|
||||
assert_eq!(eng.registers.a0, 2);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ pub enum RuntimeErrors {
|
|||
HostError(u64),
|
||||
PageNotMapped(u64),
|
||||
InvalidJumpAddress(u64),
|
||||
InvalidSystemCall(u8),
|
||||
}
|
||||
|
||||
// If you solve the halting problem feel free to remove this
|
||||
|
|
|
@ -7,28 +7,28 @@ use hbvm::{
|
|||
fn main() -> Result<(), RuntimeErrors> {
|
||||
#[rustfmt::skip]
|
||||
let prog: Vec<u8> = vec![
|
||||
NOP as u8, NOP as u8,
|
||||
255, 10,
|
||||
// NOP as u8, NOP as u8,
|
||||
// 255, 10,
|
||||
ADD as u8, EightBit as u8, 100, 20, 0xA7,
|
||||
ADD as u8,
|
||||
EightBit as u8, 1, 0, 0xB0,
|
||||
ADD as u8,
|
||||
SixtyFourBit as u8,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 2, 0xD0,
|
||||
SUB as u8, EightBit as u8, 255, 0, 0xA7,
|
||||
DIV as u8, EightBit as u8, 12, 5, 0xA8,
|
||||
ADD as u8, Register8 as u8, 0xA7, 0xB0, 0xA7,
|
||||
LOAD as u8, AddrToReg as u8,
|
||||
0, 0, 0, 0, 0, 0, 0, 2,
|
||||
0xA0,
|
||||
JUMP as u8, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
// ADD as u8,
|
||||
// EightBit as u8, 1, 0, 0xB0,
|
||||
// ADD as u8,
|
||||
// SixtyFourBit as u8,
|
||||
// 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
// 0, 0, 0, 0, 0, 0, 0, 2, 0xD0,
|
||||
// SUB as u8, EightBit as u8, 255, 0, 0xA7,
|
||||
// DIV as u8, EightBit as u8, 12, 5, 0xA8,
|
||||
// ADD as u8, Register8 as u8, 0xA7, 0xB0, 0xA7,
|
||||
// LOAD as u8, AddrToReg as u8,
|
||||
// 0, 0, 0, 0, 0, 0, 0, 2,
|
||||
// 0xA0,
|
||||
// JUMP as u8, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
];
|
||||
|
||||
let mut eng = Engine::new(prog);
|
||||
// eng.set_timer_callback(time);
|
||||
eng.enviroment_call_table[10] = print_fn;
|
||||
eng.enviroment_call_table[10] = Some(print_fn);
|
||||
eng.run()?;
|
||||
eng.dump();
|
||||
println!("{:#?}", eng.registers);
|
||||
|
|
Loading…
Reference in a new issue