Skip to content

Commit

Permalink
Merge pull request #1342 from nicholasbishop/bishop-convert-examples
Browse files Browse the repository at this point in the history
test-runner: Convert all examples to new style
  • Loading branch information
phip1611 authored Aug 23, 2024
2 parents 49eee3f + 70ad941 commit b5d1f7b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion uefi-test-runner/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use uefi::prelude::*;

// ANCHOR: entry
#[entry]
fn main(_image_handle: Handle, system_table: SystemTable<Boot>) -> Status {
fn main() -> Status {
// ANCHOR_END: entry
// ANCHOR: services
uefi::helpers::init().unwrap();
Expand Down
33 changes: 16 additions & 17 deletions uefi-test-runner/examples/loaded_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,44 @@
#![no_std]

use log::info;
use uefi::boot::{self, SearchType};
use uefi::prelude::*;
use uefi::proto::device_path::text::{
AllowShortcuts, DevicePathToText, DisplayOnly,
};
use uefi::proto::loaded_image::LoadedImage;
use uefi::table::boot::SearchType;
use uefi::{Identify, Result};

// ANCHOR: main
#[entry]
fn main(image_handle: Handle, system_table: SystemTable<Boot>) -> Status {
fn main() -> Status {
uefi::helpers::init().unwrap();
let boot_services = system_table.boot_services();

print_image_path(boot_services).unwrap();
print_image_path().unwrap();

boot_services.stall(10_000_000);
boot::stall(10_000_000);
Status::SUCCESS
}
// ANCHOR_END: main

// ANCHOR: print_image_path
fn print_image_path(boot_services: &BootServices) -> Result {
fn print_image_path() -> Result {
// ANCHOR_END: print_image_path
// ANCHOR: loaded_image
let loaded_image = boot_services
.open_protocol_exclusive::<LoadedImage>(boot_services.image_handle())?;
let loaded_image =
boot::open_protocol_exclusive::<LoadedImage>(boot::image_handle())?;
// ANCHOR_END: loaded_image

// ANCHOR: device_path
let device_path_to_text_handle = *boot_services
.locate_handle_buffer(SearchType::ByProtocol(&DevicePathToText::GUID))?
.first()
.expect("DevicePathToText is missing");

let device_path_to_text = boot_services
.open_protocol_exclusive::<DevicePathToText>(
device_path_to_text_handle,
)?;
let device_path_to_text_handle = *boot::locate_handle_buffer(
SearchType::ByProtocol(&DevicePathToText::GUID),
)?
.first()
.expect("DevicePathToText is missing");

let device_path_to_text = boot::open_protocol_exclusive::<DevicePathToText>(
device_path_to_text_handle,
)?;
// ANCHOR_END: device_path

// ANCHOR: text
Expand Down
2 changes: 1 addition & 1 deletion uefi-test-runner/examples/shell_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use alloc::vec::Vec;

// ANCHOR: entry
#[entry]
fn main(image_handle: Handle, system_table: SystemTable<Boot>) -> Status {
fn main() -> Status {
// ANCHOR_END: entry
// ANCHOR: services
uefi::helpers::init().unwrap();
Expand Down
17 changes: 8 additions & 9 deletions uefi-test-runner/examples/sierpinski.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::mem;
use uefi::prelude::*;
use uefi::proto::console::gop::{BltOp, BltPixel, BltRegion, GraphicsOutput};
use uefi::proto::rng::Rng;
use uefi::Result;
use uefi::{boot, Result};

#[derive(Clone, Copy)]
struct Point {
Expand Down Expand Up @@ -82,14 +82,14 @@ fn get_random_usize(rng: &mut Rng) -> usize {
usize::from_le_bytes(buf)
}

fn draw_sierpinski(bt: &BootServices) -> Result {
fn draw_sierpinski() -> Result {
// Open graphics output protocol.
let gop_handle = bt.get_handle_for_protocol::<GraphicsOutput>()?;
let mut gop = bt.open_protocol_exclusive::<GraphicsOutput>(gop_handle)?;
let gop_handle = boot::get_handle_for_protocol::<GraphicsOutput>()?;
let mut gop = boot::open_protocol_exclusive::<GraphicsOutput>(gop_handle)?;

// Open random number generator protocol.
let rng_handle = bt.get_handle_for_protocol::<Rng>()?;
let mut rng = bt.open_protocol_exclusive::<Rng>(rng_handle)?;
let rng_handle = boot::get_handle_for_protocol::<Rng>()?;
let mut rng = boot::open_protocol_exclusive::<Rng>(rng_handle)?;

// Create a buffer to draw into.
let (width, height) = gop.current_mode_info().resolution();
Expand Down Expand Up @@ -144,10 +144,9 @@ fn draw_sierpinski(bt: &BootServices) -> Result {
}

#[entry]
fn main(_handle: Handle, system_table: SystemTable<Boot>) -> Status {
fn main() -> Status {
uefi::helpers::init().unwrap();
let bt = system_table.boot_services();
draw_sierpinski(bt).unwrap();
draw_sierpinski().unwrap();
Status::SUCCESS
}
// ANCHOR_END: all
18 changes: 9 additions & 9 deletions uefi-test-runner/examples/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ extern crate alloc;
use log::{info, warn};

// ANCHOR: use
use uefi::boot;
use uefi::prelude::*;
use uefi::proto::misc::Timestamp;

// ANCHOR_END: use

// ANCHOR: entry
#[entry]
fn main(image_handle: Handle, system_table: SystemTable<Boot>) -> Status {
fn main() -> Status {
// ANCHOR_END: entry
// ANCHOR: services
uefi::helpers::init().unwrap();
let boot_services = system_table.boot_services();
// ANCHOR_END: services

// ANCHOR: params
test_timestamp(boot_services);
test_timestamp();
// ANCHOR_END: params

// ANCHOR: stall
boot_services.stall(10_000_000);
boot::stall(10_000_000);
// ANCHOR_END: stall

// ANCHOR: return
Expand All @@ -37,17 +37,17 @@ fn main(image_handle: Handle, system_table: SystemTable<Boot>) -> Status {
// ANCHOR_END: return

// ANCHOR: test_timestamp
pub fn test_timestamp(bt: &BootServices) {
pub fn test_timestamp() {
// ANCHOR_END: test_timestamp
info!("Running loaded Timestamp Protocol test");

let handle = bt.get_handle_for_protocol::<Timestamp>();
let handle = boot::get_handle_for_protocol::<Timestamp>();

match handle {
Ok(handle) => {
let timestamp_proto = bt
.open_protocol_exclusive::<Timestamp>(handle)
.expect("Founded Timestamp Protocol but open failed");
let timestamp_proto =
boot::open_protocol_exclusive::<Timestamp>(handle)
.expect("Founded Timestamp Protocol but open failed");
// ANCHOR: text
let timestamp = timestamp_proto.get_timestamp();
info!("Timestamp Protocol's timestamp: {:?}", timestamp);
Expand Down

0 comments on commit b5d1f7b

Please sign in to comment.