Skip to content

Commit 0f787bc

Browse files
authored
Test file fallback on Linux (#506)
Introduces new `getrandom_test_linux_fallback` configuration flag which forces `is_getrandom_available` to always return `false`. This flag is used in CI to test that file fallback works correctly in the `linux_android_with_fallback` backend.
1 parent 286e486 commit 0f787bc

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ jobs:
7171
- env:
7272
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="linux_getrandom"
7373
run: cargo test ${{ matrix.cargo_test_opts }} --target=${{ matrix.target }} --features=std
74+
- env:
75+
RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback
76+
run: cargo test --features=std
7477
- env:
7578
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
7679
run: cargo test --features=std

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ level = "warn"
4444
check-cfg = [
4545
'cfg(getrandom_backend, values("custom", "rdrand", "linux_getrandom", "wasm_js", "esp_idf"))',
4646
'cfg(getrandom_browser_test)',
47+
'cfg(getrandom_test_linux_fallback)',
4748
]
4849

4950
[package.metadata.docs.rs]

src/linux_android_with_fallback.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1919
}
2020

2121
fn is_getrandom_available() -> bool {
22-
if linux_android::getrandom_syscall(&mut []) < 0 {
22+
if cfg!(getrandom_test_linux_fallback) {
23+
false
24+
} else if linux_android::getrandom_syscall(&mut []) < 0 {
2325
match last_os_error().raw_os_error() {
2426
Some(libc::ENOSYS) => false, // No kernel support
2527
// The fallback on EPERM is intentionally not done on Android since this workaround

0 commit comments

Comments
 (0)