Skip to content

Commit

Permalink
capsules: add capsule test error
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Feb 20, 2024
1 parent 394d0ff commit 9744072
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions capsules/core/src/test/capsule_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
//! Interface for running capsule tests.
//!
//! As Tock capsules are asynchronous, it is difficult for a test runner to
//! determine when a test when a test has finished. This interface provides a
//! `done()` callback to notify when the test is done.
//! determine when a test has finished. This interface provides a `done()`
//! callback used by the test implementation to notify when the test has
//! completed.
//!
//! A simple example of a test capsule using this interface:
//!
Expand Down Expand Up @@ -39,11 +40,26 @@
//! }
//! ```

use kernel::ErrorCode;

/// Errors for the result of a failed test.
pub enum CapsuleTestError {
/// The test computed some result (e.g., a checksum or hash) and the result
/// is not correct (e.g., it doesn't match the intended value, say the
/// correct checksum or hash).
IncorrectResult,

/// An error occurred while running the test, and the resulting `ErrorCode`
/// is provided.
ErrorCode(ErrorCode),
}

/// Client for receiving test done events.
pub trait CapsuleTestClient {
/// Called when the test is finished. If test was successful, `result` is
/// `Ok(())`. If test failed, `result` is `Err(())`.
fn done(&'static self, result: Result<(), ()>);
/// Called when the test is finished. If the test was successful, `result`
/// is `Ok(())`. If the test failed, `result` is `Err()` with a suitable
/// error.
fn done(&'static self, result: Result<(), CapsuleTestError>);
}

/// Identify a test as a capsule test. This is only used for setting the client
Expand Down

0 comments on commit 9744072

Please sign in to comment.