Skip to content

Commit

Permalink
Adds test coverage for both before and after.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Oct 7, 2024
1 parent f603d34 commit f1c6741
Showing 1 changed file with 169 additions and 192 deletions.
361 changes: 169 additions & 192 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,175 @@ fn test_err_divide_overflow() {
}
}

// BPF_LD : Loads
// Loads and stores

#[test]
fn test_memory_instructions() {
for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] {
let config = Config {
enabled_sbpf_versions: sbpf_version.clone()..=sbpf_version,
..Config::default()
};

test_interpreter_and_jit_asm!(
"
ldxb r0, [r1+2]
exit",
config.clone(),
[0xaa, 0xbb, 0x11, 0xcc, 0xdd],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x11),
);
test_interpreter_and_jit_asm!(
"
ldxh r0, [r1+2]
exit",
config.clone(),
[0xaa, 0xbb, 0x11, 0x22, 0xcc, 0xdd],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x2211),
);
test_interpreter_and_jit_asm!(
"
ldxw r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0x11, 0x22, 0x33, 0x44, 0xcc, 0xdd, //
],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x44332211),
);
test_interpreter_and_jit_asm!(
"
ldxdw r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, //
0x77, 0x88, 0xcc, 0xdd, //
],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x8877665544332211),
);

test_interpreter_and_jit_asm!(
"
stb [r1+2], 0x11
ldxb r0, [r1+2]
exit",
config.clone(),
[0xaa, 0xbb, 0xff, 0xcc, 0xdd],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x11),
);
test_interpreter_and_jit_asm!(
"
sth [r1+2], 0x2211
ldxh r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x2211),
);
test_interpreter_and_jit_asm!(
"
stw [r1+2], 0x44332211
ldxw r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x44332211),
);
test_interpreter_and_jit_asm!(
"
stdw [r1+2], 0x44332211
ldxdw r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //
0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x44332211),
);

test_interpreter_and_jit_asm!(
"
mov32 r2, 0x11
stxb [r1+2], r2
ldxb r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(4),
ProgramResult::Ok(0x11),
);
test_interpreter_and_jit_asm!(
"
mov32 r2, 0x2211
stxh [r1+2], r2
ldxh r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(4),
ProgramResult::Ok(0x2211),
);
test_interpreter_and_jit_asm!(
"
mov32 r2, 0x44332211
stxw [r1+2], r2
ldxw r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(4),
ProgramResult::Ok(0x44332211),
);
test_interpreter_and_jit_asm!(
"
mov r2, -2005440939
lsh r2, 32
or r2, 0x44332211
stxdw [r1+2], r2
ldxdw r0, [r1+2]
exit",
config.clone(),
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //
0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(6),
ProgramResult::Ok(0x8877665544332211),
);
}
}

#[test]
fn test_hor64() {
Expand All @@ -929,47 +1097,6 @@ fn test_hor64() {
);
}

#[test]
fn test_ldxb() {
test_interpreter_and_jit_asm!(
"
ldxb r0, [r1+2]
exit",
[0xaa, 0xbb, 0x11, 0xcc, 0xdd],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x11),
);
}

#[test]
fn test_ldxh() {
test_interpreter_and_jit_asm!(
"
ldxh r0, [r1+2]
exit",
[0xaa, 0xbb, 0x11, 0x22, 0xcc, 0xdd],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x2211),
);
}

#[test]
fn test_ldxw() {
test_interpreter_and_jit_asm!(
"
ldxw r0, [r1+2]
exit",
[
0xaa, 0xbb, 0x11, 0x22, 0x33, 0x44, 0xcc, 0xdd, //
],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x44332211),
);
}

#[test]
fn test_ldxh_same_reg() {
test_interpreter_and_jit_asm!(
Expand All @@ -985,22 +1112,6 @@ fn test_ldxh_same_reg() {
);
}

#[test]
fn test_lldxdw() {
test_interpreter_and_jit_asm!(
"
ldxdw r0, [r1+2]
exit",
[
0xaa, 0xbb, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, //
0x77, 0x88, 0xcc, 0xdd, //
],
(),
TestContextObject::new(2),
ProgramResult::Ok(0x8877665544332211),
);
}

#[test]
fn test_err_ldxdw_oob() {
test_interpreter_and_jit_asm!(
Expand Down Expand Up @@ -1235,140 +1346,6 @@ fn test_ldxw_all() {
);
}

#[test]
fn test_stb() {
test_interpreter_and_jit_asm!(
"
stb [r1+2], 0x11
ldxb r0, [r1+2]
exit",
[0xaa, 0xbb, 0xff, 0xcc, 0xdd],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x11),
);
}

#[test]
fn test_sth() {
test_interpreter_and_jit_asm!(
"
sth [r1+2], 0x2211
ldxh r0, [r1+2]
exit",
[
0xaa, 0xbb, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x2211),
);
}

#[test]
fn test_stw() {
test_interpreter_and_jit_asm!(
"
stw [r1+2], 0x44332211
ldxw r0, [r1+2]
exit",
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x44332211),
);
}

#[test]
fn test_stdw() {
test_interpreter_and_jit_asm!(
"
stdw [r1+2], 0x44332211
ldxdw r0, [r1+2]
exit",
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //
0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(3),
ProgramResult::Ok(0x44332211),
);
}

#[test]
fn test_stxb() {
test_interpreter_and_jit_asm!(
"
mov32 r2, 0x11
stxb [r1+2], r2
ldxb r0, [r1+2]
exit",
[
0xaa, 0xbb, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(4),
ProgramResult::Ok(0x11),
);
}

#[test]
fn test_stxh() {
test_interpreter_and_jit_asm!(
"
mov32 r2, 0x2211
stxh [r1+2], r2
ldxh r0, [r1+2]
exit",
[
0xaa, 0xbb, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(4),
ProgramResult::Ok(0x2211),
);
}

#[test]
fn test_stxw() {
test_interpreter_and_jit_asm!(
"
mov32 r2, 0x44332211
stxw [r1+2], r2
ldxw r0, [r1+2]
exit",
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(4),
ProgramResult::Ok(0x44332211),
);
}

#[test]
fn test_stxdw() {
test_interpreter_and_jit_asm!(
"
mov r2, -2005440939
lsh r2, 32
or r2, 0x44332211
stxdw [r1+2], r2
ldxdw r0, [r1+2]
exit",
[
0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //
0xff, 0xff, 0xcc, 0xdd, //
],
(),
TestContextObject::new(6),
ProgramResult::Ok(0x8877665544332211),
);
}

#[test]
fn test_stxb_all() {
test_interpreter_and_jit_asm!(
Expand Down

0 comments on commit f1c6741

Please sign in to comment.