From 52e7e9fe23e7dec7be0623661d1be2307bb90f28 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 18 Feb 2020 22:45:51 -0800 Subject: [PATCH] tests: Test CPU-based RNG on all x86 targets This allows us to verify the RDRAND implementation on Linux. Signed-off-by: Joe Richey --- .travis.yml | 4 ++-- src/lib.rs | 2 ++ src/test_cpu.rs | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/test_cpu.rs diff --git a/.travis.yml b/.travis.yml index 4d58a143..916dcb30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -122,11 +122,11 @@ jobs: script: # We test that getrandom builds for all targets - echo $STD_TARGETS | xargs -t -n1 cargo build --target - - echo $NO_STD_TARGETS | xargs -t -n1 cargo xbuild --target + - echo $NO_STD_TARGETS | xargs -t -n1 cargo xbuild --features=cpu --target # also test minimum dependency versions are usable - cargo generate-lockfile -Z minimal-versions - echo $STD_TARGETS | xargs -t -n1 cargo build --target - - echo $NO_STD_TARGETS | xargs -t -n1 cargo xbuild --target + - echo $NO_STD_TARGETS | xargs -t -n1 cargo xbuild --features=cpu --target # Trust cross-built/emulated targets. We must repeat all non-default values. - name: "Linux (MIPS, big-endian)" diff --git a/src/lib.rs b/src/lib.rs index f579d9ae..98dcff67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -217,3 +217,5 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> { #[cfg(test)] mod test_common; +#[cfg(test)] +mod test_cpu; diff --git a/src/test_cpu.rs b/src/test_cpu.rs new file mode 100644 index 00000000..efcb1c83 --- /dev/null +++ b/src/test_cpu.rs @@ -0,0 +1,8 @@ +// We only test the CPU-based RNG source on supported architectures. +#![cfg(target_arch = "x86_64")] + +#[path = "rdrand.rs"] +mod rdrand; +use rdrand::getrandom_inner as getrandom; +#[path = "test_common.rs"] +mod test_common;