-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test Linux fallback paths without use of cfg()s #628
base: master
Are you sure you want to change the base?
Conversation
This PR changes our Linux fallback tests to test the "real" fallback paths rather than using various `cfg()`s within the implementation. As these tests require being run sequentally and only work on Linux, they are configured to require manual invocation. Also renames `tests/mod.rs` to `tests/common.rs` to reuse our tests. Actually testing the netbsd fallback is harder, so that's best left for a future PR. Signed-off-by: Joe Richey <[email protected]>
path.to_str() == Some("/dev/urandom") | ||
} | ||
let mut dir = read_dir("/proc/self/fd").expect("/proc/self exists"); | ||
assert!(dir.any(|path| is_urandom(path.expect("entry exists")))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply inline the is_urandom
function?
let has_open_urandom = read_dir("/proc/self/fd")
.expect("/proc/self exists")
.any(|dir_entry| {
let path = dir_entry.expect("entry exists").path();
let path = path.canonicalize().expect("entry is valid");
path.to_str() == Some("/dev/urandom")
});
assert!(has_open_urandom);
// Override libc::getrandom to simulate failure | ||
#[export_name = "getrandom"] | ||
pub unsafe extern "C" fn fake_getrandom(_: *mut c_void, _: size_t, _: c_uint) -> ssize_t { | ||
FAKE_GETRANDOM_CALLED.store(true, Ordering::SeqCst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think AcqRel
should be sufficient here?
@@ -53,6 +53,8 @@ jobs: | |||
targets: ${{ matrix.target }} | |||
- uses: Swatinem/rust-cache@v2 | |||
- run: cargo test --target=${{ matrix.target }} --features=std | |||
- run: cargo test --test linux_no_fallback -- --test-threads 1 | |||
- run: cargo test --test linux_force_fallback -- --test-threads 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that the order of tests is guaranteed?
Overall, it's an interesting approach, but I am not sure if it's simpler than the |
This PR changes our Linux fallback tests to test the "real" fallback paths rather than using various
cfg()
s within the implementation.As these tests require being run sequentally and only work on Linux, they are configured to require manual invocation.
Also renames
tests/mod.rs
totests/common.rs
to reuse our tests.Actually testing the netbsd fallback is harder, so that's best left for a future PR.