Skip to content

Commit dbdd174

Browse files
gabhijitalxiord
authored andcommitted
tests(doc): Fix example in src/lib.rs (#58)
Passing the reference to `boot_params` as per changed signature of `write_bootparams`. Also, removed the commented function calls for getting the Guest memory and the ELF image. Made implmenentation consistent with `test_load_bzImage` instead of using `include_bytes!`. Signed-off-by: Abhijit Gadgil <gabhijit@iitbombay.org>
1 parent 2855be1 commit dbdd174

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

coverage_config_x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 80.1,
2+
"coverage_score": 80.0,
33
"exclude_path": "",
44
"crate_features": "bzimage,elf",
55
"exclude_path": "benches/,loader_gen/"

src/lib.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,25 @@
2727
//! This example shows how to prepare a VM for booting with an ELF kernel, following the PVH
2828
//! boot protocol.
2929
//!
30-
//! ```rust,ignore
30+
//! ```rust
31+
//!
3132
//! # extern crate linux_loader;
3233
//! # extern crate vm_memory;
33-
//! # use std::io::Cursor;
34+
//! # use std::{io::{Cursor, Read}, fs::File};
3435
//! # use linux_loader::configurator::{BootConfigurator, BootParams};
36+
//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3537
//! # use linux_loader::configurator::pvh::PvhBootConfigurator;
38+
//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3639
//! # use linux_loader::loader::elf::start_info::{hvm_memmap_table_entry, hvm_start_info};
40+
//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3741
//! # use linux_loader::loader::elf::Elf;
3842
//! # use linux_loader::loader::KernelLoader;
3943
//! # use vm_memory::{Address, GuestAddress, GuestMemoryMmap};
4044
//! # const E820_RAM: u32 = 1;
4145
//! # const MEM_SIZE: usize = 0x100_0000;
4246
//! # const XEN_HVM_START_MAGIC_VALUE: u32 = 0x336ec578;
43-
//! # fn create_guest_memory() -> GuestMemoryMmap {
44-
//! # GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), MEM_SIZE)]).unwrap()
45-
//! # }
46-
//! # fn create_elf_pvh_image() -> Vec<u8> {
47-
//! # include_bytes!(concat!(
48-
//! # env!("CARGO_MANIFEST_DIR"), "/src/loader/x86_64/elf/test_elfnote.bin"
49-
//! # )).to_vec()
50-
//! # }
47+
//!
48+
//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5149
//! fn build_boot_params() -> (hvm_start_info, Vec<hvm_memmap_table_entry>) {
5250
//! let mut start_info = hvm_start_info::default();
5351
//! let memmap_entry = hvm_memmap_table_entry {
@@ -63,9 +61,16 @@
6361
//! (start_info, vec![memmap_entry])
6462
//! }
6563
//!
64+
//! # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6665
//! fn main() {
67-
//! let guest_mem = create_guest_memory();
68-
//! let elf_pvh_image = create_elf_pvh_image();
66+
//! let guest_mem =
67+
//! GuestMemoryMmap::from_ranges( &[(GuestAddress(0x0), MEM_SIZE)]) .unwrap();
68+
//!
69+
//! let mut elf_pvh_image = Vec::new();
70+
//! let path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/loader/x86_64/elf/test_elfnote.bin");
71+
//! let mut file = File::open(path).unwrap();
72+
//! file.read_to_end(&mut elf_pvh_image).unwrap();
73+
//!
6974
//! // Load the kernel image.
7075
//! let loader_result = Elf::load(
7176
//! &guest_mem, None, &mut Cursor::new(&elf_pvh_image), None
@@ -82,8 +87,12 @@
8287
//! // Write boot parameters in guest memory.
8388
//! let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
8489
//! boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
85-
//! PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(boot_params, &guest_mem).unwrap();
90+
//! PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_mem).unwrap();
8691
//! }
92+
//!
93+
//! # #[cfg(target_arch = "aarch64")]
94+
//! # fn main() {}
95+
//!
8796
//! ```
8897
//!
8998
//! [`BootConfigurator`]: trait.BootConfigurator.html

0 commit comments

Comments
 (0)