-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Create test_helpers crate to group all clint test code
The new crate can be extended in the future to hold more test helpers, such as macros to generate proper interrupt handlers. For now it is limited to clint functionalities and assumes the QEMU virt platform (it is not meant to be a general-purpose library).
- Loading branch information
Showing
15 changed files
with
94 additions
and
129 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "test_helpers" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Client utilities | ||
//! | ||
//! The functions exposed in this modules assumes the CLINT is located at the same addresses as on | ||
//! the QEMU virt platform, which we use for out tests. | ||
|
||
/// Clint base, assuming a QEMU virt-like layout. | ||
const CLINT_BASE: usize = 0x2000000; | ||
const MTIME_OFFSET: usize = 0xBFF8; | ||
const MTIMECMP_OFFSET: usize = 0x4000; | ||
|
||
/// Get the current mtime value | ||
pub fn read_mtime() -> usize { | ||
let mtime_ptr = (CLINT_BASE + MTIME_OFFSET) as *const usize; | ||
unsafe { mtime_ptr.read_volatile() } | ||
} | ||
|
||
/// Set mtimecmp deadline in the future | ||
pub fn set_mtimecmp_deadline(delta: usize, hart: usize) { | ||
let current_mtime = read_mtime(); | ||
let future_time = current_mtime.saturating_add(delta); | ||
|
||
let mtimecmp_ptr = (CLINT_BASE + MTIMECMP_OFFSET + 8 * hart) as *mut usize; | ||
unsafe { | ||
mtimecmp_ptr.write_volatile(future_time); | ||
} | ||
} | ||
|
||
/// Send an MSI to the given hart. | ||
pub fn send_msi(hart: usize) { | ||
let msip_ptr = (CLINT_BASE + 4 * hart) as *mut u32; | ||
unsafe { | ||
msip_ptr.write_volatile(1); | ||
} | ||
} | ||
|
||
/// Clear MSI for the given hart. | ||
pub fn clear_msi(hart: usize) { | ||
let msip_ptr = (CLINT_BASE + 4 * hart) as *mut u32; | ||
unsafe { | ||
msip_ptr.write_volatile(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//! Test helpers | ||
//! | ||
//! Utility functions, macros, and contants for the Miralis integration tests (firmware and | ||
//! payloads). | ||
|
||
#![no_std] | ||
|
||
pub mod clint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.