Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mozak-loader tests based on empty-elf #1049

Merged
merged 11 commits into from
Jan 10, 2024
1 change: 1 addition & 0 deletions runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ im = "15.1"
itertools = "0.12"
log = "0.4"
mimalloc = "0.1"
mozak-examples = { path = "../examples-builder", features = ["empty"] }
mozak-system = { path = "../system" }
plonky2 = "0.1"
proptest = { version = "1.4", optional = true }
Expand Down
66 changes: 64 additions & 2 deletions runner/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,7 @@ impl Program {

#[cfg(test)]
mod test {
use crate::elf::{MozakMemoryRegion, Program};

use crate::elf::{MozakMemory, MozakMemoryRegion, Program, RuntimeArguments};
#[test]
fn test_serialize_deserialize() {
let program = Program::default();
Expand Down Expand Up @@ -561,4 +560,67 @@ mod test {
assert_eq!(data[usize::try_from(*k).unwrap()], *v);
});
}
#[test]
fn test_empty_elf_with_empty_args() {
let mozak_ro_memory = Program::mozak_load_program(
mozak_examples::EMPTY_ELF,
&RuntimeArguments::new(&[], &[], &[]),
)
.unwrap()
.mozak_ro_memory
.unwrap();
assert_eq!(mozak_ro_memory.context_variables.data.len(), 0);
assert_eq!(mozak_ro_memory.io_tape_private.data.len(), 0);
assert_eq!(mozak_ro_memory.io_tape_public.data.len(), 0);
}
#[test]
fn test_empty_elf_with_args() {
let mozak_ro_memory = Program::mozak_load_program(
mozak_examples::EMPTY_ELF,
&RuntimeArguments::new(&[0], &[0, 1], &[0, 1, 2]),
)
.unwrap()
.mozak_ro_memory
.unwrap();
assert_eq!(mozak_ro_memory.context_variables.data.len(), 1);
assert_eq!(mozak_ro_memory.io_tape_private.data.len(), 2);
assert_eq!(mozak_ro_memory.io_tape_public.data.len(), 3);
}

#[test]
fn test_empty_elf_check_assumed_values() {
// This test ensures mozak-loader & mozak-linker-script is indeed aligned
let mozak_ro_memory = Program::mozak_load_program(
mozak_examples::EMPTY_ELF,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test only work for EMPTY_ELF? I think it should work for any ELF

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming it'd be more tedious to check every ELF that we have, since they might not all share (for eg.) similar run time args?

My understanding of this PR is that this ensures our loader is working as expected, and isn't necessarily a test for ELFs specifically, so an empty one would serve that purpose - we could have a followup PR if necessary?

&RuntimeArguments::new(&[], &[], &[]),
)
.unwrap()
.mozak_ro_memory
.unwrap();
let test_mozak_ro_memory = MozakMemory::default();
assert_eq!(
mozak_ro_memory.context_variables.capacity,
test_mozak_ro_memory.context_variables.capacity
);
assert_eq!(
mozak_ro_memory.context_variables.starting_address,
test_mozak_ro_memory.context_variables.starting_address
);
assert_eq!(
mozak_ro_memory.io_tape_private.capacity,
test_mozak_ro_memory.io_tape_private.capacity
);
assert_eq!(
mozak_ro_memory.io_tape_private.starting_address,
test_mozak_ro_memory.io_tape_private.starting_address
);
assert_eq!(
mozak_ro_memory.io_tape_public.capacity,
test_mozak_ro_memory.io_tape_public.capacity
);
assert_eq!(
mozak_ro_memory.io_tape_public.starting_address,
test_mozak_ro_memory.io_tape_public.starting_address
);
}
}