Skip to content

Commit d903bcb

Browse files
bors[bot]Johnathan Van Why
and
Johnathan Van Why
authored
Merge #304
304: Add a test that verifies `ErrorCode` includes every possible value. r=hudson-ayers a=jrvanwhy The syscalls TRD says an `ErrorCode` can have any value in [1, 1023]. This test uses Miri to confirm that the `ErrorCode` enum is not missing any of these values. I verified this test works by changing the `1023` to `1024`, which gave the following error: ``` error: Undefined Behavior: type validation failed: encountered 0x0400 at .<enum-tag>, but expected a valid enum tag --> platform/src/error_code_tests.rs:7:18 | 7 | unsafe { *(&value as *const u16 as *const crate::ErrorCode) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x0400 at .<enum-tag>, but expected a valid enum tag | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information ``` Co-authored-by: Johnathan Van Why <[email protected]>
2 parents 38915e1 + a496c7d commit d903bcb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

platform/src/error_code_tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Verifies that `ErrorCode` represents every valid value in the range
2+
// [1, 1023].
3+
#[cfg(miri)]
4+
#[test]
5+
fn error_code_range() {
6+
for value in 1..=1023u16 {
7+
unsafe { *(&value as *const u16 as *const crate::ErrorCode) };
8+
}
9+
}

platform/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ pub use yield_types::YieldNoWaitReturn;
2222

2323
#[cfg(test)]
2424
mod command_return_tests;
25+
26+
#[cfg(test)]
27+
mod error_code_tests;

0 commit comments

Comments
 (0)