diff --git a/tests/execution.rs b/tests/execution.rs index 204313249..6286d2d81 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, @@ -179,6 +187,7 @@ macro_rules! test_interpreter_and_jit_elf { }; test_interpreter_and_jit_elf!($source, config, $mem, ($($location => $syscall_function),*), $context_object, $expected_result); }; + } // BPF_ALU : Arithmetic and Logic @@ -2684,6 +2693,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 +2710,7 @@ fn test_non_terminate_early() { add64 r6, 0x1 ja -0x8 exit", + config.clone(), [], (), TestContextObject::new(7), @@ -2761,6 +2776,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 +2791,7 @@ fn test_err_capped_before_exception() { syscall Unresolved add64 r0, 0x0 exit", + config.clone(), [], (), TestContextObject::new(4), @@ -2870,6 +2892,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 +2907,7 @@ fn test_err_call_unresolved() { syscall Unresolved mov64 r0, 0x0 exit", + config.clone(), [], (), TestContextObject::new(6), @@ -2933,8 +2961,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),