diff --git a/services/bao-console/Cargo.toml b/services/bao-console/Cargo.toml index 47de6f88f..5521d7c8f 100644 --- a/services/bao-console/Cargo.toml +++ b/services/bao-console/Cargo.toml @@ -23,6 +23,10 @@ modals = { path = "../modals", default-features = false } ux-api = { path = "../../libs/ux-api", optional = true } pddb = { path = "../pddb", features = ["gen2"] } +# pddb testing +rand = { version = "0.8.5", features = ["getrandom"], optional = true } +rand_chacha = { version = "0.3.1", optional = true } + [features] cramium-soc = [ "utralib/cramium-soc", @@ -41,11 +45,12 @@ hosted-baosec = [ "usb-cramium/hosted-baosec", "cramium-emu", "pddb/hosted-baosec", + "cramium-hal/hosted-baosec", ] usb = [] pddbtest = [] test-rekey = [] -autobasis = [] +autobasis = ["rand_chacha", "rand"] modal-testing = ["ux-api", "modals/modal-testing"] test-scrollbars = [] -default = [] +default = ["pddbtest"] diff --git a/services/bao-console/src/cmds/pddb.rs b/services/bao-console/src/cmds/pddb.rs index 9c4398830..8f969c0ef 100644 --- a/services/bao-console/src/cmds/pddb.rs +++ b/services/bao-console/src/cmds/pddb.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use String; #[cfg(all(feature = "pddbtest", feature = "autobasis"))] -const PDDB_A_LEN: usize = cramium_emu::PDDB_LEN as usize; +const PDDB_A_LEN: usize = cramium_hal::board::PDDB_LEN as usize; use crate::{CommonEnv, ShellCmdApi}; @@ -1184,7 +1184,7 @@ impl<'a> ShellCmdApi<'a> for PddbCmd { for i in 0..20 { let mut testkey = self .pddb - .get("wlan.networks", "testkey", None, false, true, None, None::) + .get("wlan.networks", "testkey", None, true, true, None, None::) .expect("couldn't make test key"); testdata.push_str(&i.to_string()); // testkey.seek(SeekFrom::Start(0)).ok(); @@ -1249,3 +1249,53 @@ fn join_tokens<'a>(buf: &mut String, tokens: impl Iterator) { } } } + +#[cfg(all(feature = "pddbtest", feature = "autobasis"))] +enum VectorType { + Small(usize), + Large(usize), + Junk, +} +#[cfg(all(feature = "pddbtest", feature = "autobasis"))] +const SMALL_SIZE: usize = 2011; +#[cfg(all(feature = "pddbtest", feature = "autobasis"))] +const LARGE_SIZE: usize = 28813; +#[cfg(all(feature = "pddbtest", feature = "autobasis"))] +const JUNK_SIZE: usize = 128 * 1024 - 2; +#[cfg(all(feature = "pddbtest", feature = "autobasis"))] +fn make_vector(basis_number: usize, vtype: VectorType) -> Vec { + use rand::prelude::*; + use rand_chacha::ChaCha8Rng; + + let mut vector = Vec::::new(); + // seed format: + // bottom 0xFFFF is reserved for the basis_number + // next 0xFFF is resrved for the vector number + // 0x8000_0000 when set means small, not set means large + let typemod = match vtype { + VectorType::Small(n) => 0x1_0000 * (n as u64) + 0x8000_0000, + VectorType::Large(n) => 0x1_0000 * (n as u64) + 0x0000_0000, + VectorType::Junk => 0x1_0000_000, + }; + let mut rng = ChaCha8Rng::seed_from_u64(basis_number as u64 + typemod); + match vtype { + VectorType::Small(n) => { + // multiply the vector number by some odd value so the vectors are not same-sized + for _ in 0..SMALL_SIZE + 7 * n + basis_number { + vector.push(rng.gen()); + } + } + VectorType::Large(n) => { + // multiply the vector number by some odd value so the vectors are not same-sized + for _ in 0..LARGE_SIZE + 1117 * n + basis_number { + vector.push(rng.gen()); + } + } + VectorType::Junk => { + for _ in 0..JUNK_SIZE + basis_number { + vector.push(rng.gen()); + } + } + } + vector +}