-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
414: Implement the driver registration API in `doc/UnitTestOwnership.md`. r=jrvanwhy a=jrvanwhy As described in #355, I intend to remove the use of thread-local storage in `libtock_unittest`. That requires giving `fake::SyscallDriver` implementations a reference that allows them to schedule upcalls. This PR adds that reference, and updates the `fake::SyscallDrivers` to use it. Co-authored-by: Johnathan Van Why <[email protected]>
- Loading branch information
Showing
18 changed files
with
405 additions
and
317 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/// Information that a `fake::SyscallDriver` provides to the `fake::Kernel` | ||
/// during registration. This may be expanded over time as new features are | ||
/// added to Tock. | ||
#[non_exhaustive] | ||
pub struct DriverInfo { | ||
// All constructors of DriverInfo require the driver to specify | ||
// `driver_num`. | ||
pub(crate) driver_num: u32, | ||
|
||
/// The maximum number of subscriptions to support. The maximum subscribe | ||
/// number supported will be one less than `upcall_count`. | ||
pub upcall_count: u32, | ||
} | ||
|
||
impl DriverInfo { | ||
/// Creates a new `DriverInfo` with the given driver number. `upcall_count` | ||
/// will be initialized to zero. | ||
pub fn new(driver_num: u32) -> Self { | ||
Self { | ||
driver_num, | ||
upcall_count: 0, | ||
} | ||
} | ||
|
||
/// Sets `upcall_count` and returns `self`. Used similar to a builder. | ||
/// | ||
/// # Example | ||
/// ``` | ||
/// use libtock_platform::CommandReturn; | ||
/// use libtock_unittest::{DriverInfo, fake}; | ||
/// struct FooDriver; | ||
/// impl fake::SyscallDriver for FooDriver { | ||
/// fn info(&self) -> DriverInfo { | ||
/// DriverInfo::new(3).upcall_count(2) | ||
/// } | ||
/// fn command(&self, _: u32, _: u32, _: u32) -> CommandReturn { | ||
/// unimplemented!("Example code"); | ||
/// } | ||
/// } | ||
/// ``` | ||
pub fn upcall_count(mut self, upcall_count: u32) -> Self { | ||
self.upcall_count = upcall_count; | ||
self | ||
} | ||
} |
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.