Skip to content

Commit

Permalink
tests: add simple test case for ARM64 Image loader
Browse files Browse the repository at this point in the history
The test_image.bin is a cut of the first 4096 bytes of a pre-compiled
linux kernel ARM64 Image.

Signed-off-by: Qiu Wenbo <[email protected]>
  • Loading branch information
crab2313 committed Mar 9, 2020
1 parent 02ad394 commit 23338de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ impl KernelLoader for Image {
#[cfg(test)]
mod test {
use super::*;
#[cfg(any(feature = "elf", feature = "bzimage"))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(any(feature = "elf", feature = "bzimage", feature = "image"))]
use std::io::Cursor;
use vm_memory::{Address, GuestAddress, GuestMemoryMmap};

Expand All @@ -541,6 +540,15 @@ mod test {
v
}

// first 4096 bytes of a precompiled ARM64 kernel Image.
#[cfg(feature = "image")]
#[cfg(target_arch = "aarch64")]
fn make_image_bin() -> Vec<u8> {
let mut v = Vec::new();
v.extend_from_slice(include_bytes!("test_image.bin"));
v
}

#[allow(safe_packed_borrows)]
#[allow(non_snake_case)]
#[test]
Expand Down Expand Up @@ -663,6 +671,19 @@ mod test {
);
}

#[test]
#[cfg(feature = "image")]
#[cfg(target_arch = "aarch64")]
fn load_image() {
let gm = create_guest_mem();
let image = make_image_bin();
let kernel_addr = GuestAddress(0x200000);

let loader_result =
Image::load(&gm, Some(kernel_addr), &mut Cursor::new(&image), None).unwrap();
assert_eq!(loader_result.kernel_load.raw_value(), 0x280000);
}

#[test]
fn cmdline_overflow() {
let gm = create_guest_mem();
Expand Down
Binary file added src/loader/test_image.bin
Binary file not shown.

0 comments on commit 23338de

Please sign in to comment.