Skip to content

Commit bfad968

Browse files
committed
Test RDRAND and use_file implementations.
Signed-off-by: Joe Richey <[email protected]>
1 parent 71a2ab8 commit bfad968

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
toolchain: ${{ matrix.toolchain }}
3939
- uses: Swatinem/rust-cache@v2
4040
- run: cargo test
41-
# Make sure enabling the std and custom features don't break anything
42-
- run: cargo test --features=std,custom
41+
# Ensure enabling features works, and run feature-specific tests.
42+
- run: cargo test --features=std,custom,rdrand
4343
- run: cargo test --features=linux_disable_fallback
4444
- if: ${{ matrix.toolchain == 'nightly' }}
4545
run: cargo test --benches

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ mod util;
224224
mod custom;
225225
#[cfg(feature = "std")]
226226
mod error_impls;
227+
// If the rdrand feature is enabled, always bring in the rdrand module, so
228+
// that the RDRAND implementation can be tested.
229+
#[cfg(all(
230+
any(target_env = "sgx", feature = "rdrand"),
231+
any(target_arch = "x86_64", target_arch = "x86"),
232+
))]
233+
mod rdrand;
227234

228235
pub use crate::error::Error;
229236

@@ -330,10 +337,10 @@ cfg_if! {
330337
} else if #[cfg(windows)] {
331338
#[path = "windows.rs"] mod imp;
332339
} else if #[cfg(all(target_arch = "x86_64", target_env = "sgx"))] {
333-
#[path = "rdrand.rs"] mod imp;
340+
use rdrand as imp;
334341
} else if #[cfg(all(feature = "rdrand",
335342
any(target_arch = "x86_64", target_arch = "x86")))] {
336-
#[path = "rdrand.rs"] mod imp;
343+
use rdrand as imp;
337344
} else if #[cfg(all(feature = "js",
338345
any(target_arch = "wasm32", target_arch = "wasm64"),
339346
target_os = "unknown"))] {

src/rdrand.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn is_rdrand_good() -> bool {
9393
unsafe { self_test() }
9494
}
9595

96+
#[allow(dead_code)]
9697
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
9798
static RDRAND_GOOD: LazyBool = LazyBool::new();
9899
if !RDRAND_GOOD.unsync_init(is_rdrand_good) {
@@ -121,3 +122,8 @@ unsafe fn rdrand_exact(dest: &mut [MaybeUninit<u8>]) -> Option<()> {
121122
}
122123
Some(())
123124
}
125+
126+
#[cfg(test)]
127+
mod tests {
128+
crate::tests::define_tests!(super::getrandom_inner);
129+
}

src/use_file.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,8 @@ impl<F: FnMut()> Drop for DropGuard<F> {
174174
self.0()
175175
}
176176
}
177+
178+
#[cfg(test)]
179+
mod tests {
180+
crate::tests::define_tests!(super::getrandom_inner);
181+
}

0 commit comments

Comments
 (0)