cpu/tests: Test invalid instructions more exhaustively
This commit is contained in:
parent
c7226bf9cc
commit
33b6d0218e
@ -51,41 +51,42 @@ fn print_screen(bytes: &[u8]) {
|
|||||||
/// Unused instructions
|
/// Unused instructions
|
||||||
mod unimplemented {
|
mod unimplemented {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
macro_rules! invalid {
|
||||||
fn ins_5xyn() {
|
($(
|
||||||
|
$(#[$attr:meta])* // Preserve doc comments, etc.
|
||||||
|
$pub:vis test $name:ident { $($insn:literal),+$(,)? }
|
||||||
|
);+ $(;)?) => {
|
||||||
|
$( $(#[$attr])* #[test] $pub fn $name () {$(
|
||||||
let (mut cpu, mut bus) = setup_environment();
|
let (mut cpu, mut bus) = setup_environment();
|
||||||
cpu.screen.write(0x200u16, 0x500fu16);
|
cpu.mem.write(0x200u16, $insn as u16);
|
||||||
cpu.tick(&mut bus)
|
cpu.tick(&mut bus)
|
||||||
.expect_err("0x500f is not an instruction");
|
.expect_err(stringify!($insn is not an instruction));
|
||||||
|
)*} )+
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#[test]
|
|
||||||
fn ins_8xyn() {
|
invalid! {
|
||||||
let (mut cpu, mut bus) = setup_environment();
|
/// Invalid opcodes 5001, 0x5004-500f
|
||||||
cpu.screen.write(0x200u16, 0x800fu16);
|
test ins_5xyn {
|
||||||
cpu.tick(&mut bus)
|
0x5001,
|
||||||
.expect_err("0x800f is not an instruction");
|
0x5004, 0x5005, 0x5006, 0x5007, 0x5008, 0x5009,
|
||||||
}
|
0x500a, 0x500b, 0x500c, 0x500d, 0x500e, 0x500f,
|
||||||
#[test]
|
};
|
||||||
fn ins_9xyn() {
|
/// Invalid opcodes 8008-800d and 800f
|
||||||
let (mut cpu, mut bus) = setup_environment();
|
test ins_8xyn {
|
||||||
cpu.screen.write(0x200u16, 0x900fu16);
|
0x8008, 0x8009, 0x800a, 0x800b, 0x800c, 0x800d,
|
||||||
cpu.tick(&mut bus)
|
0x800f,
|
||||||
.expect_err("0x900f is not an instruction");
|
};
|
||||||
}
|
/// Invalid opcodes 9001-900f
|
||||||
#[test]
|
test ins_9xyn {
|
||||||
fn ins_exbb() {
|
0x9001, 0x9002, 0x9003, 0x9004, 0x9005,
|
||||||
let (mut cpu, mut bus) = setup_environment();
|
0x9006, 0x9007, 0x9008, 0x9009, 0x900a,
|
||||||
cpu.screen.write(0x200u16, 0xe00fu16);
|
0x900b, 0x900c, 0x900d, 0x900e, 0x900f,
|
||||||
cpu.tick(&mut bus)
|
};
|
||||||
.expect_err("0xe00f is not an instruction");
|
/// Invalid opcodes in e000 range
|
||||||
}
|
test ins_exbb { 0xe00f };
|
||||||
// Fxbb
|
/// Invalid opcodes in the 0xf000 range
|
||||||
#[test]
|
test ins_fxbb { 0xf001, 0xf00f };
|
||||||
fn ins_fxbb() {
|
|
||||||
let (mut cpu, mut bus) = setup_environment();
|
|
||||||
cpu.screen.write(0x200u16, 0xf00fu16);
|
|
||||||
cpu.tick(&mut bus)
|
|
||||||
.expect_err("0xf00f is not an instruction");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user