mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
retrofit the seed into an atomicu64 so we can set it elsewhere
This commit is contained in:
parent
809dbbdbc2
commit
dd14dfc4c6
7 changed files with 14 additions and 11 deletions
|
|
@ -65,7 +65,7 @@ pub fn set_send_addr(send_addr: Sender<SocketAddr>) {
|
|||
#[cfg(not(test))]
|
||||
use core::sync::atomic::{AtomicU64, Ordering};
|
||||
#[cfg(not(test))]
|
||||
static LOCAL_RNG_STATE: AtomicU64 = AtomicU64::new(xous_kernel::TESTING_RNG_SEED + 2);
|
||||
static LOCAL_RNG_STATE: AtomicU64 = AtomicU64::new(2);
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn generate_pid_key() -> [u8; 16] {
|
||||
|
|
@ -73,7 +73,7 @@ fn generate_pid_key() -> [u8; 16] {
|
|||
use rand_chacha::ChaCha8Rng;
|
||||
|
||||
let mut process_key = [0u8; 16];
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(LOCAL_RNG_STATE.load(Ordering::SeqCst));
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(LOCAL_RNG_STATE.load(Ordering::SeqCst) + xous_kernel::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst));
|
||||
for b in process_key.iter_mut() {
|
||||
*b = rng.gen();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ static GLOBAL: &StatsAlloc<std::alloc::System> = &INSTRUMENTED_SYSTEM;
|
|||
const SERVER_SPEC: &str = "127.0.0.1:0";
|
||||
|
||||
use core::sync::atomic::{AtomicU64, Ordering};
|
||||
static RNG_LOCAL_STATE: AtomicU64 = AtomicU64::new(xous::TESTING_RNG_SEED + 1);
|
||||
static RNG_LOCAL_STATE: AtomicU64 = AtomicU64::new(1);
|
||||
|
||||
fn start_kernel(server_spec: &str) -> JoinHandle<()> {
|
||||
assert!(
|
||||
|
|
@ -32,7 +32,7 @@ fn start_kernel(server_spec: &str) -> JoinHandle<()> {
|
|||
use rand::prelude::*;
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
let mut pid1_key = [0u8; 16];
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(RNG_LOCAL_STATE.load(Ordering::SeqCst));
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(RNG_LOCAL_STATE.load(Ordering::SeqCst) + xous::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst));
|
||||
for b in pid1_key.iter_mut() {
|
||||
*b = rng.gen();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -437,7 +437,7 @@ fn xmain() -> ! {
|
|||
const EXTRA_BASIS_PW: &'static str = "some password blah blah";
|
||||
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::info!("Seed for this run: {}", xous::TESTING_RNG_SEED);
|
||||
log::info!("Seed for this run: {}", xous::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst));
|
||||
|
||||
pddb_os.test_reset();
|
||||
log::info!("Creating `basecase1e`");
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ use std::collections::BTreeSet;
|
|||
const UPPER_BOUND: usize = 9000;
|
||||
const LOWER_BOUND: usize = 12; // needs to be big enough to compute murmur3 hash + hold checksum
|
||||
|
||||
static RNG_LOCAL_STATE: AtomicU64 = AtomicU64::new(xous::TESTING_RNG_SEED + 3);
|
||||
static RNG_LOCAL_STATE: AtomicU64 = AtomicU64::new(3);
|
||||
|
||||
fn gen_key(dictname: &str, keynum: usize, lower_size_bound: usize, upper_size_bound: usize) -> (String, Vec::<u8>) {
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(RNG_LOCAL_STATE.load(Ordering::SeqCst));
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(RNG_LOCAL_STATE.load(Ordering::SeqCst) + xous::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst));
|
||||
// we want roughly half our keys to be in the small bin, and half in the large bin
|
||||
let keylen = if rng.gen_bool(0.5) {
|
||||
rng.gen_range(lower_size_bound..VPAGE_SIZE)
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ impl Drop for Spinor {
|
|||
use core::sync::atomic::AtomicU64;
|
||||
|
||||
#[cfg(test)]
|
||||
static TEST_RNG_STATE: AtomicU64 = AtomicU64::new(xous::TESTING_RNG_SEED + 4);
|
||||
static TEST_RNG_STATE: AtomicU64 = AtomicU64::new(4);
|
||||
|
||||
// run with `cargo test -- --nocapture --test-threads=1`:
|
||||
// --nocapture to see the print output (while debugging)
|
||||
|
|
@ -419,7 +419,7 @@ mod tests {
|
|||
fn flash_fill_rand() {
|
||||
use rand::prelude::*;
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(TEST_RNG_STATE.load(Ordering::SeqCst));;
|
||||
let mut rng = ChaCha8Rng::seed_from_u64(TEST_RNG_STATE.load(Ordering::SeqCst) + xous::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst));
|
||||
for byte in EMU_FLASH.lock().unwrap().iter_mut() {
|
||||
*byte = rng.gen::<u8>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -480,7 +480,7 @@ mod implementation {
|
|||
impl Trng {
|
||||
pub fn new(_xns: &xous_names::XousNames) -> Trng {
|
||||
Trng {
|
||||
rng: ChaCha8Rng::seed_from_u64(xous::TESTING_RNG_SEED),
|
||||
rng: ChaCha8Rng::seed_from_u64(xous::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst)),
|
||||
seed: 0x1afe_cafe,
|
||||
msgcount: 0,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,10 @@ pub const PDDB_LOC: u32 = 0x0100_0000; // PDDB start
|
|||
pub const PDDB_LEN: u32 = EC_REGION_LOC - PDDB_LOC;
|
||||
|
||||
#[cfg(all(any(windows, unix), not(feature = "processes-as-threads")))]
|
||||
pub const TESTING_RNG_SEED: u64 = 8; // 0, 1, 2, 3, 4, 7, 8 "works"; 5 "oom"; 6 "key space oom"
|
||||
use core::sync::atomic::AtomicU64;
|
||||
|
||||
#[cfg(all(any(windows, unix), not(feature = "processes-as-threads")))]
|
||||
pub const TESTING_RNG_SEED: AtomicU64 = AtomicU64::new(0); // 0, 1, 2, 3, 4, 7, 8 "works"; 5 "oom"; 6 "key space oom"
|
||||
|
||||
pub mod exceptions;
|
||||
pub use exceptions::*;
|
||||
|
|
|
|||
Loading…
Reference in a new issue