From 27ceb7d028241d9fa9170f42530e13735f275fa4 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 5 Sep 2024 15:09:42 -0300 Subject: [PATCH] Fix tests --- tests/execution.rs | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/tests/execution.rs b/tests/execution.rs index 20431324..1a1ca25a 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -41,6 +41,9 @@ macro_rules! test_interpreter_and_jit { .unwrap(); }; ($executable:expr, $mem:tt, $context_object:expr, $expected_result:expr $(,)?) => { + test_interpreter_and_jit!(true, $executable, $mem, $context_object, $expected_result) + }; + ($verify:literal, $executable:expr, $mem:tt, $context_object:expr, $expected_result:expr $(,)?) => { let expected_instruction_count = $context_object.get_remaining(); #[allow(unused_mut)] let mut context_object = $context_object; @@ -48,7 +51,9 @@ macro_rules! test_interpreter_and_jit { if !expected_result.contains("ExceededMaxInstructions") { context_object.remaining = INSTRUCTION_METER_BUDGET; } - $executable.verify::().unwrap(); + if $verify { + $executable.verify::().unwrap(); + } let (instruction_count_interpreter, interpreter_final_pc, _tracer_interpreter) = { let mut mem = $mem; let mem_region = MemoryRegion::new_writable(&mut mem, ebpf::MM_INPUT_START); @@ -159,7 +164,7 @@ macro_rules! test_interpreter_and_jit_asm { } macro_rules! test_interpreter_and_jit_elf { - ($source:tt, $config:tt, $mem:tt, ($($location:expr => $syscall_function:expr),* $(,)?), $context_object:expr, $expected_result:expr $(,)?) => { + ($verify:literal, $source:tt, $config:tt, $mem:tt, ($($location:expr => $syscall_function:expr),* $(,)?), $context_object:expr, $expected_result:expr $(,)?) => { let mut file = File::open($source).unwrap(); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); @@ -169,9 +174,12 @@ macro_rules! test_interpreter_and_jit_elf { $(test_interpreter_and_jit!(register, function_registry, $location => $syscall_function);)* let loader = Arc::new(BuiltinProgram::new_loader($config, function_registry)); let mut executable = Executable::::from_elf(&elf, loader).unwrap(); - test_interpreter_and_jit!(executable, $mem, $context_object, $expected_result); + test_interpreter_and_jit!($verify, executable, $mem, $context_object, $expected_result); } }; + ($source:tt, $config:tt, $mem:tt, ($($location:expr => $syscall_function:expr),* $(,)?), $context_object:expr, $expected_result:expr $(,)?) => { + test_interpreter_and_jit_elf!(true, $source, $config, $mem, ($($location => $syscall_function),*), $context_object, $expected_result); + }; ($source:tt, $mem:tt, ($($location:expr => $syscall_function:expr),* $(,)?), $context_object:expr, $expected_result:expr $(,)?) => { let config = Config { enable_instruction_tracing: true, @@ -2684,6 +2692,11 @@ fn test_err_instruction_count_syscall_capped() { #[test] fn test_non_terminate_early() { + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; + test_interpreter_and_jit_asm!( " mov64 r6, 0x0 @@ -2696,6 +2709,7 @@ fn test_non_terminate_early() { add64 r6, 0x1 ja -0x8 exit", + config.clone(), [], (), TestContextObject::new(7), @@ -2761,6 +2775,12 @@ fn test_err_capped_before_exception() { TestContextObject::new(4), ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); + + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; + test_interpreter_and_jit_asm!( " mov64 r1, 0x0 @@ -2770,6 +2790,7 @@ fn test_err_capped_before_exception() { syscall Unresolved add64 r0, 0x0 exit", + config.clone(), [], (), TestContextObject::new(4), @@ -2870,6 +2891,11 @@ fn test_symbol_relocation() { #[test] fn test_err_call_unresolved() { + let config = Config { + enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + ..Config::default() + }; + test_interpreter_and_jit_asm!( " mov r1, 1 @@ -2880,6 +2906,7 @@ fn test_err_call_unresolved() { syscall Unresolved mov64 r0, 0x0 exit", + config.clone(), [], (), TestContextObject::new(6), @@ -2933,8 +2960,15 @@ fn test_err_unresolved_syscall_reloc_64_32() { #[test] fn test_err_unresolved_syscall_static() { + let config = Config { + enable_instruction_tracing: true, + ..Config::default() + }; + // This case only works if we skip verification. test_interpreter_and_jit_elf!( + false, "tests/elfs/syscall_static.so", + config, [], (), TestContextObject::new(4),