Skip to content

Commit

Permalink
Fix custom test
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Oct 7, 2024
1 parent 6dec774 commit db8b1e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ fn test_multithreading() {

#[cfg(getrandom_backend = "custom")]
mod custom {
use getrandom::Error;

struct Xoshiro128PlusPlus {
s: [u32; 4],
}
Expand Down Expand Up @@ -146,13 +148,13 @@ mod custom {
//
// WARNING: this custom implementation is for testing purposes ONLY!
#[no_mangle]
unsafe extern "Rust" fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
unsafe extern "Rust" fn __getrandom_custom(dest: *mut u8, len: usize) -> Result<(), Error> {
use std::time::{SystemTime, UNIX_EPOCH};

assert_ne!(len, 0);

if len == 142 {
return getrandom::Error::CUSTOM_START + 142;
return Err(Error::new_custom(142));
}

let dest_u32 = dest.cast::<u32>();
Expand All @@ -169,7 +171,7 @@ mod custom {
core::ptr::write_unaligned(dest.add(i), val as u8);
}
}
0
Ok(())
}

// Test that enabling the custom feature indeed uses the custom implementation
Expand Down

0 comments on commit db8b1e1

Please sign in to comment.