use super::{BIOS_DATE, MODEL_BYTE, RESET_VECTOR, SEGMENT, SIZE, image};
#[test]
fn the_image_is_byte_identical_across_builds() {
assert_eq!(image(), image());
assert_eq!(image().len(), SIZE);
}
#[test]
fn the_reset_vector_is_a_far_jump_into_this_segment() {
let rom = image();
let at = RESET_VECTOR as usize;
assert_eq!(rom[at], 0xea, "the reset vector is not a far jump");
let target = u16::from_le_bytes([rom[at + 1], rom[at + 2]]);
let segment = u16::from_le_bytes([rom[at + 3], rom[at + 4]]);
assert_eq!(segment, SEGMENT);
assert!(
(target as usize) < RESET_VECTOR as usize,
"the far jump targets {target:#06x}, which is not code"
);
}
#[test]
fn the_identification_bytes_are_where_software_looks_for_them() {
let rom = image();
assert_eq!(&rom[0xfff5..0xfffd], BIOS_DATE);
assert_eq!(rom[0xfffe], MODEL_BYTE);
}
#[test]
fn the_whole_image_sums_to_zero() {
let sum = image().iter().fold(0u8, |acc, &b| acc.wrapping_add(b));
assert_eq!(sum, 0);
}
#[test]
fn the_code_fits_below_the_reset_vector() {
let rom = image();
let used = rom[..RESET_VECTOR as usize]
.iter()
.rposition(|&b| b != 0xff)
.expect("the image is not empty");
#[cfg(feature = "std")]
std::println!("the firmware occupies {used:#06x} bytes of its 64 KiB segment");
assert!(
used < RESET_VECTOR as usize,
"the code reaches {used:#06x}, which collides with the reset vector"
);
assert!(
used < 0x4000,
"the image is unexpectedly large: {used:#06x}"
);
}