From 0ef9fb21b7a2d723244c451b45c65301bbb2ca7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 12 Feb 2025 18:35:37 +0300 Subject: [PATCH] linux_android_with_fallback: add cfg to test that file fallback is not triggered --- .github/workflows/tests.yml | 4 ++++ Cargo.toml | 1 + src/backends/linux_android_with_fallback.rs | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4ba01e80..5363968f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -61,6 +61,10 @@ jobs: RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback RUSTDOCFLAGS: -Dwarnings --cfg getrandom_test_linux_fallback run: cargo test --features=std + - env: + RUSTFLAGS: -Dwarnings --cfg getrandom_test_linux_without_fallback + RUSTDOCFLAGS: -Dwarnings --cfg getrandom_test_linux_without_fallback + run: cargo test --features=std - env: RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand" RUSTDOCFLAGS: -Dwarnings --cfg getrandom_backend="rdrand" diff --git a/Cargo.toml b/Cargo.toml index 2942d31e..2441555b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,6 +84,7 @@ check-cfg = [ 'cfg(getrandom_backend, values("custom", "rdrand", "rndr", "linux_getrandom", "wasm_js"))', 'cfg(getrandom_msan)', 'cfg(getrandom_test_linux_fallback)', + 'cfg(getrandom_test_linux_without_fallback)', 'cfg(getrandom_test_netbsd_fallback)', ] diff --git a/src/backends/linux_android_with_fallback.rs b/src/backends/linux_android_with_fallback.rs index 379237c6..2ad8f0a4 100644 --- a/src/backends/linux_android_with_fallback.rs +++ b/src/backends/linux_android_with_fallback.rs @@ -60,6 +60,11 @@ fn init() -> NonNull { None => NOT_AVAILABLE, }; + #[cfg(getrandom_test_linux_without_fallback)] + if res_ptr == NOT_AVAILABLE { + panic!("Fallback is triggered with enabled `getrandom_test_linux_without_fallback`") + } + GETRANDOM_FN.store(res_ptr.as_ptr(), Ordering::Release); res_ptr }