Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup - Adds test_utils::assert_error!() #446

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 37 additions & 38 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,13 +1200,13 @@ mod test {
consts::{ELFCLASS32, ELFDATA2MSB, ET_REL},
types::{Elf64Ehdr, Elf64Shdr},
},
error::EbpfError,
fuzz::fuzz,
syscalls,
vm::{ProgramResult, TestContextObject},
};
use rand::{distributions::Uniform, Rng};
use std::{fs::File, io::Read};
use test_utils::assert_error;
type ElfExecutable = Executable<TestContextObject>;

fn loader() -> Arc<BuiltInProgram<TestContextObject>> {
Expand Down Expand Up @@ -1784,12 +1784,11 @@ mod test {
));

// one byte past the ro section is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(
address
)) if address == ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size
);
}

#[test]
Expand Down Expand Up @@ -1830,12 +1829,11 @@ mod test {
));

// one byte past the ro section is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(
address
)) if address == ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size
);
}

#[test]
Expand Down Expand Up @@ -1867,16 +1865,18 @@ mod test {
// s1 starts at sh_addr=10 so [MM_PROGRAM_START..MM_PROGRAM_START + 10] is not mappable

// the low bound of the initial gap is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(address)) if address == ebpf::MM_PROGRAM_START,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START
);

// the hi bound of the initial gap is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START + s1.sh_addr - 1, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(address)) if address == ebpf::MM_PROGRAM_START + 9,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START + 9
);

// [s1.sh_addr..s3.sh_addr + s3.sh_size] is the valid ro memory area
assert!(matches!(
Expand All @@ -1888,12 +1888,11 @@ mod test {
));

// one byte past the ro section is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(
address
)) if address == ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size
);
}

#[test]
Expand Down Expand Up @@ -1973,12 +1972,11 @@ mod test {
));

// one byte past the ro section is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START + s2.sh_addr + s2.sh_size, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(
address
)) if address == ebpf::MM_PROGRAM_START + s2.sh_addr + s2.sh_size,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START + s2.sh_addr + s2.sh_size
);
}

#[test]
Expand All @@ -2004,16 +2002,18 @@ mod test {
// s2 starts at sh_addr=10 so [0..10] is not mappable

// the low bound of the initial gap is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(address)) if address == ebpf::MM_PROGRAM_START,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START
);

// the hi bound of the initial gap is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START + s2.sh_addr - 1, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(address)) if address == ebpf::MM_PROGRAM_START + 9,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START + 9
);

// [s2.sh_addr..s3.sh_addr + s3.sh_size] is the valid ro memory area
assert!(matches!(
Expand All @@ -2025,12 +2025,11 @@ mod test {
));

// one byte past the ro section is not mappable
assert!(matches!(
assert_error!(
ro_region.vm_to_host(ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size, 1),
ProgramResult::Err(EbpfError::InvalidVirtualAddress(
address
)) if address == ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size,
));
"InvalidVirtualAddress({})",
ebpf::MM_PROGRAM_START + s3.sh_addr + s3.sh_size
);
}

#[test]
Expand Down
Loading