Skip to content

Commit

Permalink
Revert testing changes
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr committed Oct 19, 2022
1 parent 7dad584 commit 107743e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::getrandom_impl;
use core::mem::{self, MaybeUninit};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand All @@ -10,16 +9,16 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[test]
fn test_zero() {
// Test that APIs are happy with zero-length requests
getrandom_impl(unsafe { slice_as_uninit_mut(&mut [0u8; 0]) }).unwrap();
getrandom_impl(&mut [0u8; 0]).unwrap();
}

#[test]
fn test_diff() {
let mut v1 = [0u8; 1000];
getrandom_impl(unsafe { slice_as_uninit_mut(&mut v1) }).unwrap();
getrandom_impl(&mut v1).unwrap();

let mut v2 = [0u8; 1000];
getrandom_impl(unsafe { slice_as_uninit_mut(&mut v2) }).unwrap();
getrandom_impl(&mut v2).unwrap();

let mut n_diff_bits = 0;
for i in 0..v1.len() {
Expand All @@ -33,7 +32,7 @@ fn test_diff() {
#[test]
fn test_huge() {
let mut huge = [0u8; 100_000];
getrandom_impl(unsafe { slice_as_uninit_mut(&mut huge) }).unwrap();
getrandom_impl(&mut huge).unwrap();
}

// On WASM, the thread API always fails/panics
Expand All @@ -52,9 +51,9 @@ fn test_multithreading() {
// wait until all the tasks are ready to go.
rx.recv().unwrap();
let mut v = [0u8; 1000];
let y = unsafe { slice_as_uninit_mut(&mut v) };

for _ in 0..100 {
getrandom_impl(y).unwrap();
getrandom_impl(&mut v).unwrap();
thread::yield_now();
}
});
Expand All @@ -65,9 +64,3 @@ fn test_multithreading() {
tx.send(()).unwrap();
}
}

#[inline(always)]
unsafe fn slice_as_uninit_mut<T>(slice: &mut [T]) -> &mut [MaybeUninit<T>] {
// SAFETY: `MaybeUninit<T>` is guaranteed to be layout-compatible with `T`.
mem::transmute(slice)
}
2 changes: 1 addition & 1 deletion tests/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
)))]

// Use the normal getrandom implementation on this architecture.
use getrandom::getrandom_uninit as getrandom_impl;
use getrandom::getrandom as getrandom_impl;
mod common;

0 comments on commit 107743e

Please sign in to comment.