Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Fix tests (part 4)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Oct 8, 2024
1 parent 654146f commit 43ae800
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ pub fn disassemble_instruction<C: ContextObject>(
desc = format!("{name} {function_name}");
},
ebpf::CALL_REG => { name = "callx"; desc = format!("{} r{}", name, if sbpf_version.callx_uses_src_reg() { insn.src } else { insn.imm as u8 }); },
ebpf::EXIT => { name = "exit"; desc = name.to_string(); }
ebpf::RETURN => { name = "return"; desc = name.to_string(); }
ebpf::EXIT => { name = "exit"; desc = name.to_string(); },
ebpf::RETURN => { name = "return"; desc = name.to_string(); },

_ => { name = "unknown"; desc = format!("{} opcode={:#x}", name, insn.opc); },
};
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> {
if self.vm.call_depth == 0 {
if config.enable_instruction_meter && self.vm.due_insn_count > self.vm.previous_instruction_meter {
throw_error!(self, EbpfError::ExceededMaxInstructions);
}
}
self.vm.program_result = ProgramResult::Ok(self.reg[0]);
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ mod tests {
}

fn create_mockup_executable(config: Config, program: &[u8]) -> Executable<TestContextObject> {
let sbpf_version = config.enabled_sbpf_versions.end().clone();
let sbpf_version = *config.enabled_sbpf_versions.clone().end();
let mut function_registry =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry
Expand Down Expand Up @@ -1739,7 +1739,7 @@ mod tests {
let empty_program_machine_code_length = {
let config = Config {
noop_instruction_rate: 0,
enabled_sbpf_versions: sbpf_version.clone()..=sbpf_version.clone(),
enabled_sbpf_versions: sbpf_version..=sbpf_version,
..Config::default()
};
let mut executable = create_mockup_executable(config, &prog[0..0]);
Expand All @@ -1750,7 +1750,7 @@ mod tests {
.machine_code_length()
};
assert!(empty_program_machine_code_length <= MAX_EMPTY_PROGRAM_MACHINE_CODE_LENGTH);
empty_program_machine_code_length_per_version[sbpf_version.clone() as usize] =
empty_program_machine_code_length_per_version[sbpf_version as usize] =
empty_program_machine_code_length;
}

Expand Down Expand Up @@ -1784,7 +1784,7 @@ mod tests {

for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] {
let empty_program_machine_code_length =
empty_program_machine_code_length_per_version[sbpf_version.clone() as usize];
empty_program_machine_code_length_per_version[sbpf_version as usize];

for mut opcode in 0x00..=0xFF {
let (registers, immediate) = match opcode {
Expand All @@ -1811,7 +1811,7 @@ mod tests {
}
let config = Config {
noop_instruction_rate: 0,
enabled_sbpf_versions: sbpf_version.clone()..=sbpf_version.clone(),
enabled_sbpf_versions: sbpf_version..=sbpf_version,
..Config::default()
};
let mut executable = create_mockup_executable(config, &prog);
Expand Down
4 changes: 2 additions & 2 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ macro_rules! test_interpreter_and_jit {
None
);
match compilation_result {
Err(err) => assert_eq!(
format!("{:?}", err),
Err(_) => assert_eq!(
format!("{:?}", compilation_result),
expected_result,
"Unexpected result for JIT compilation"
),
Expand Down
14 changes: 9 additions & 5 deletions tests/exercise_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@ fn test_ins(v1: bool, ins: String, prng: &mut SmallRng, cu: u64) {

prng.fill_bytes(&mut input);

let mut config = Config::default();
let final_instr = if v1 {
config.enabled_sbpf_versions = SBPFVersion::V1..=SBPFVersion::V1;
"exit"
} else {
"return"
};

let asm = format!(
"
ldxdw r9, [r1+72]
Expand All @@ -535,12 +543,8 @@ fn test_ins(v1: bool, ins: String, prng: &mut SmallRng, cu: u64) {
xor64 r0, r7
xor64 r0, r8
xor64 r0, r9
exit"
{final_instr}"
);

let mut config = Config::default();
if v1 {
config.enabled_sbpf_versions = SBPFVersion::V1..=SBPFVersion::V1;
}
test_interpreter_and_jit_asm!(asm.as_str(), config, input, (), TestContextObject::new(cu));
}

0 comments on commit 43ae800

Please sign in to comment.