Skip to content

Commit 074b15b

Browse files
authored
linux_android_with_fallback: add cfg to test that fallback is not triggered (#605)
The test is needed to prevent potential regressions like #600.
1 parent b75db5c commit 074b15b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

.github/workflows/tests.yml

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ jobs:
6161
RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback
6262
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback
6363
run: cargo test --features=std
64+
- env:
65+
RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_without_fallback
66+
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_test_linux_without_fallback
67+
run: cargo test --features=std
6468
- env:
6569
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
6670
RUSTDOCFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ check-cfg = [
8484
'cfg(getrandom_backend, values("custom", "rdrand", "rndr", "linux_getrandom", "wasm_js"))',
8585
'cfg(getrandom_msan)',
8686
'cfg(getrandom_test_linux_fallback)',
87+
'cfg(getrandom_test_linux_without_fallback)',
8788
'cfg(getrandom_test_netbsd_fallback)',
8889
]
8990

src/backends/linux_android_with_fallback.rs

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ fn init() -> NonNull<c_void> {
6060
None => NOT_AVAILABLE,
6161
};
6262

63+
#[cfg(getrandom_test_linux_without_fallback)]
64+
if res_ptr == NOT_AVAILABLE {
65+
panic!("Fallback is triggered with enabled `getrandom_test_linux_without_fallback`")
66+
}
67+
6368
GETRANDOM_FN.store(res_ptr.as_ptr(), Ordering::Release);
6469
res_ptr
6570
}

0 commit comments

Comments
 (0)