Skip to content

Commit a721452

Browse files
committed
Fix tests
1 parent 4f6fe12 commit a721452

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

src/ebpf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ pub const MM_INPUT_START: u64 = MM_REGION_SIZE * 4;
5454
/// Virtual address of the scratch pad area
5555
pub const MM_SCRATCHPAD_AREA: u64 = MM_REGION_SIZE * 5;
5656
/// Virtual address of the instruction area
57-
pub const MM_INSTRUCTION_AREA: u64 = MM_REGION_SIZE * 6;
57+
pub const MM_TX_INSTRUCTION_AREA: u64 = MM_REGION_SIZE * 6;
5858
/// Virtual address of the instruction input payload
59-
pub const MM_INSTRUCTION_INPUT: u64 = MM_REGION_SIZE * 7;
59+
pub const MM_TX_INSTRUCTION_INPUT: u64 = MM_REGION_SIZE * 7;
6060
/// Virtual address of the accounts payload area
6161
pub const MM_ACCOUNTS_AREA: u64 = MM_REGION_SIZE * 8;
6262

src/memory_region.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@ fn generate_access_violation(
867867
ebpf::MM_STACK_START => "stack",
868868
ebpf::MM_HEAP_START => "heap",
869869
ebpf::MM_INPUT_START => "input",
870+
ebpf::MM_SCRATCHPAD_AREA if sbpf_version >= SBPFVersion::V4 => "scratchpad",
871+
ebpf::MM_TX_INSTRUCTION_AREA if sbpf_version >= SBPFVersion::V4 => "tx instruction",
872+
ebpf::MM_TX_INSTRUCTION_INPUT if sbpf_version >= SBPFVersion::V4 => {
873+
"tx instruction input"
874+
}
875+
addr if addr >= ebpf::MM_ACCOUNTS_AREA && sbpf_version >= SBPFVersion::V4 => "accounts",
870876
_ => "unknown",
871877
};
872878
ProgramResult::Err(EbpfError::AccessViolation(

test_utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ macro_rules! test_syscall_asm {
431431
enable_instruction_tracing: true,
432432
..Config::default()
433433
};
434-
for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] {
434+
for sbpf_version in [SBPFVersion::V0, SBPFVersion::V4] {
435435
config.enabled_sbpf_versions = sbpf_version..=sbpf_version;
436436
let mut loader = BuiltinProgram::new_loader(config.clone());
437437
$(test_syscall_asm!(register, loader, $syscall_name => $syscall_function);)*

tests/execution.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ fn test_err_dynamic_stack_out_of_bound() {
18871887
AccessType::Store,
18881888
ebpf::MM_STACK_START - 1,
18891889
1,
1890-
"program"
1890+
"rodata"
18911891
)),
18921892
);
18931893

@@ -1931,7 +1931,7 @@ fn test_err_dynamic_stack_ptr_overflow() {
19311931
AccessType::Store,
19321932
u64::MAX - 63,
19331933
1,
1934-
"unknown"
1934+
"accounts"
19351935
)),
19361936
);
19371937
}
@@ -2096,7 +2096,12 @@ fn test_err_mem_access_out_of_bound() {
20962096
prog[16] = ebpf::ST_1B_IMM;
20972097
prog[24] = ebpf::RETURN;
20982098
let loader = Arc::new(BuiltinProgram::new_mock());
2099-
for address in [0x2u64, 0x8002u64, 0x80000002u64, 0x8000000000000002u64] {
2099+
for (address, area) in [
2100+
(0x2u64, "program"),
2101+
(0x8002u64, "program"),
2102+
(0x80000002u64, "program"),
2103+
(0x8000000000000002u64, "accounts"),
2104+
] {
21002105
LittleEndian::write_u32(&mut prog[4..], address as u32);
21012106
LittleEndian::write_u32(&mut prog[12..], (address >> 32) as u32);
21022107
#[allow(unused_mut)]
@@ -2115,7 +2120,7 @@ fn test_err_mem_access_out_of_bound() {
21152120
AccessType::Store,
21162121
address,
21172122
1,
2118-
"unknown"
2123+
area
21192124
)),
21202125
);
21212126
}
@@ -2440,16 +2445,18 @@ fn test_call_save() {
24402445
fn test_err_syscall_string() {
24412446
test_syscall_asm!(
24422447
"
2443-
mov64 r1, 0x0
2448+
mov64 r1, 0x3
2449+
lsh64 r1, 32
2450+
add64 r1, 0xffff
24442451
syscall bpf_syscall_string
24452452
mov64 r0, 0x0
24462453
exit",
24472454
[72, 101, 108, 108, 111],
24482455
(
24492456
"bpf_syscall_string" => syscalls::SyscallString::vm,
24502457
),
2451-
TestContextObject::new(2),
2452-
ProgramResult::Err(EbpfError::SyscallError(Box::new(EbpfError::AccessViolation(AccessType::Load, 0, 0, "unknown")))),
2458+
TestContextObject::new(4),
2459+
ProgramResult::Err(EbpfError::SyscallError(Box::new(EbpfError::AccessViolation(AccessType::Load, 0x30000FFFF, 0, "heap")))),
24532460
);
24542461
}
24552462

0 commit comments

Comments
 (0)