mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add ability to re-run pddb test cases in hosted mode for more test automation
This commit is contained in:
parent
26736c09b6
commit
61b5aeba98
4 changed files with 101 additions and 90 deletions
|
|
@ -54,6 +54,12 @@ impl EmuStorage {
|
||||||
pub fn as_mut_slice(&mut self) -> &mut [u8] {
|
pub fn as_mut_slice(&mut self) -> &mut [u8] {
|
||||||
flashmem().memory.as_mut_slice()
|
flashmem().memory.as_mut_slice()
|
||||||
}
|
}
|
||||||
|
/// used to reset the storage for repeated test case generation
|
||||||
|
pub fn reset(&mut self) {
|
||||||
|
for b in flashmem().memory.as_mut_slice() {
|
||||||
|
*b = 0xFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn dump_fs(&self, name: &Option<String>) {
|
pub fn dump_fs(&self, name: &Option<String>) {
|
||||||
let defaultname = String::from("pddb");
|
let defaultname = String::from("pddb");
|
||||||
let rootname = name.as_ref().unwrap_or(&defaultname);
|
let rootname = name.as_ref().unwrap_or(&defaultname);
|
||||||
|
|
|
||||||
|
|
@ -96,18 +96,10 @@ pub(crate) struct PddbOs {
|
||||||
entropy: Rc<RefCell<TrngPool>>,
|
entropy: Rc<RefCell<TrngPool>>,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/// virtual to physical page map. It's the reverse mapping of the physical page table on disk.
|
|
||||||
v2p_map: HashMap<String, HashMap<VirtAddr, PhysPage>>,
|
|
||||||
/// keys to non-system basis that may or may not be mounted
|
/// keys to non-system basis that may or may not be mounted
|
||||||
/// We don't blend the System basis into this one because we need to refer to the System basis specifically
|
/// We don't blend the System basis into this one because we need to refer to the System basis specifically
|
||||||
/// for decrypting management structures like the FSCB.
|
/// for decrypting management structures like the FSCB.
|
||||||
basis_keys: Vec::<[u8; AES_KEYSIZE]>,
|
basis_keys: Vec::<[u8; AES_KEYSIZE]>,
|
||||||
/// An in-memory "priority vector" of Basis root data that have been unlocked. Right now, we keep all data resident.
|
|
||||||
/// Basis root data should be fairly compact -- it's just the directory data to find the keys and
|
|
||||||
/// dictionaries, so unless you create 1k's of dictionaries and keys, it'll probably all fit in RAM.
|
|
||||||
/// When searching for dictionaries and keys, the search always starts with the LAST item added to the
|
|
||||||
/// basis_cache.
|
|
||||||
basis_cache: Vec::<BasisCacheEntry>,
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,14 +135,11 @@ impl PddbOs {
|
||||||
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
||||||
system_basis_key: None,
|
system_basis_key: None,
|
||||||
cipher_ecb: None,
|
cipher_ecb: None,
|
||||||
//v2p_map: HashMap::<String, HashMap<VirtAddr, PhysPage>>::new(),
|
|
||||||
fspace_cache: HashSet::<PhysPage>::new(),
|
fspace_cache: HashSet::<PhysPage>::new(),
|
||||||
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
||||||
fspace_log_next_addr: None,
|
fspace_log_next_addr: None,
|
||||||
dna: llio.soc_dna().unwrap(),
|
dna: llio.soc_dna().unwrap(),
|
||||||
entropy: trngpool,
|
entropy: trngpool,
|
||||||
//basis_keys: Vec::new(),
|
|
||||||
//basis_cache: Vec::<BasisCacheEntry>::new(),
|
|
||||||
};
|
};
|
||||||
// emulated
|
// emulated
|
||||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
|
|
@ -167,14 +156,11 @@ impl PddbOs {
|
||||||
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
data_phys_base: PageAlignedPa::from(fscb_phys_base.as_u32() + FSCB_PAGES as u32 * PAGE_SIZE as u32),
|
||||||
system_basis_key: None,
|
system_basis_key: None,
|
||||||
cipher_ecb: None,
|
cipher_ecb: None,
|
||||||
//v2p_map: HashMap::<String, HashMap<VirtAddr, PhysPage>>::new(),
|
|
||||||
fspace_cache: HashSet::<PhysPage>::new(),
|
fspace_cache: HashSet::<PhysPage>::new(),
|
||||||
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
fspace_log_addrs: Vec::<PageAlignedPa>::new(),
|
||||||
fspace_log_next_addr: None,
|
fspace_log_next_addr: None,
|
||||||
dna: llio.soc_dna().unwrap(),
|
dna: llio.soc_dna().unwrap(),
|
||||||
entropy: trngpool,
|
entropy: trngpool,
|
||||||
//basis_keys: Vec::new(),
|
|
||||||
//basis_cache: Vec::<BasisCacheEntry>::new(),
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ret
|
ret
|
||||||
|
|
@ -203,6 +189,16 @@ impl PddbOs {
|
||||||
pub fn dbg_dump(&self, _name: Option<String>) {
|
pub fn dbg_dump(&self, _name: Option<String>) {
|
||||||
// placeholder
|
// placeholder
|
||||||
}
|
}
|
||||||
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
|
/// used to reset the hardware structure for repeated runs of testing within a single invocation
|
||||||
|
pub fn test_reset(&mut self) {
|
||||||
|
self.fspace_cache = HashSet::<PhysPage>::new();
|
||||||
|
self.fspace_log_addrs = Vec::<PageAlignedPa>::new();
|
||||||
|
self.system_basis_key = None;
|
||||||
|
self.cipher_ecb = None;
|
||||||
|
self.fspace_log_next_addr = None;
|
||||||
|
self.pddb_mr.reset();
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn nonce_gen(&mut self) -> Nonce {
|
pub(crate) fn nonce_gen(&mut self) -> Nonce {
|
||||||
let nonce_array = self.entropy.borrow_mut().get_nonce();
|
let nonce_array = self.entropy.borrow_mut().get_nonce();
|
||||||
|
|
|
||||||
|
|
@ -369,93 +369,45 @@ fn xmain() -> ! {
|
||||||
// shared entropy cache across all process-local services (it's more efficient to request entropy in blocks from the TRNG)
|
// shared entropy cache across all process-local services (it's more efficient to request entropy in blocks from the TRNG)
|
||||||
let entropy = Rc::new(RefCell::new(TrngPool::new()));
|
let entropy = Rc::new(RefCell::new(TrngPool::new()));
|
||||||
|
|
||||||
// OS-specific PDDB driver
|
|
||||||
log::info!("creating PddbOs structure");
|
|
||||||
let mut pddb_os = PddbOs::new(Rc::clone(&entropy));
|
|
||||||
|
|
||||||
/*
|
// OS-specific PDDB driver
|
||||||
|
let mut pddb_os = PddbOs::new(Rc::clone(&entropy));
|
||||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
{
|
{
|
||||||
|
log::info!("Creating `basecase1`");
|
||||||
create_testcase(&mut pddb_os, None, None, None);
|
create_testcase(&mut pddb_os, None, None, None);
|
||||||
pddb_os.dbg_dump(Some("basecase1".to_string()));
|
pddb_os.dbg_dump(Some("basecase1".to_string()));
|
||||||
}*/
|
|
||||||
|
|
||||||
log::info!("Initializing disk...");
|
|
||||||
pddb_os.pddb_format().unwrap();
|
|
||||||
log::info!("Done initializing disk");
|
|
||||||
|
|
||||||
// it's a vector because order is important: by default access to keys/dicts go into the latest entry first, and then recurse to the earliest
|
|
||||||
let mut basis_cache = BasisCache::new();
|
|
||||||
|
|
||||||
log::info!("Attempting to mount the PDDB");
|
|
||||||
if let Some(sys_basis) = pddb_os.pddb_mount() {
|
|
||||||
log::info!("PDDB mount operation finished successfully");
|
|
||||||
basis_cache.basis_add(sys_basis);
|
|
||||||
} else {
|
|
||||||
log::info!("PDDB did not mount; did you remember to format the PDDB region?");
|
|
||||||
}
|
}
|
||||||
log::info!("size of vpage: {}", VPAGE_SIZE);
|
{ // a simple case that could be run directly on the hardware
|
||||||
|
log::info!("Running `manual` test case");
|
||||||
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
|
pddb_os.test_reset();
|
||||||
|
|
||||||
// add a "system settings" dictionary to the default basis
|
manual_testcase(&mut pddb_os);
|
||||||
log::info!("adding 'system settings' dictionary");
|
|
||||||
basis_cache.dict_add(&mut pddb_os, "system settings", None).expect("couldn't add system settings dictionary");
|
log::info!("Re-mount the PDDB");
|
||||||
basis_cache.key_update(&mut pddb_os, "system settings", "wifi/wpa_keys/Kosagi", "my_wpa_key_here".as_bytes(), None, None, None, false).expect("couldn't add a key");
|
let mut basis_cache = BasisCache::new();
|
||||||
let mut readback = [0u8; 15];
|
if let Some(sys_basis) = pddb_os.pddb_mount() {
|
||||||
match basis_cache.key_read(&mut pddb_os, "system settings", "wifi/wpa_keys/Kosagi", &mut readback, None, None) {
|
log::info!("PDDB mount operation finished successfully");
|
||||||
Ok(readsize) => {
|
basis_cache.basis_add(sys_basis);
|
||||||
log::info!("read back {} bytes", readsize);
|
} else {
|
||||||
log::info!("read data: {}", String::from_utf8_lossy(&readback));
|
log::info!("PDDB did not mount; did you remember to format the PDDB region?");
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
log::info!("couldn't read data: {:?}", e);
|
|
||||||
}
|
}
|
||||||
}
|
log::info!("test readback of wifi/wpa_keys/e4200");
|
||||||
basis_cache.key_update(&mut pddb_os, "system settings", "wifi/wpa_keys/e4200", "12345678".as_bytes(), None, None, None, false).expect("couldn't add a key");
|
let mut readback = [0u8; 16]; // this buffer is bigger than the data in the key, but that's alright...
|
||||||
|
match basis_cache.key_read(&mut pddb_os, "system settings", "wifi/wpa_keys/e4200", &mut readback, None, None) {
|
||||||
// add a "big" key
|
Ok(readsize) => {
|
||||||
let mut bigdata = [0u8; 5000];
|
log::info!("read back {} bytes", readsize);
|
||||||
for (i, d) in bigdata.iter_mut().enumerate() {
|
log::info!("read data: {}", String::from_utf8_lossy(&readback));
|
||||||
*d = i as u8;
|
},
|
||||||
}
|
Err(e) => {
|
||||||
basis_cache.key_update(&mut pddb_os, "system settings", "big_pool1", &bigdata, None, None, None, false).expect("couldn't add a key");
|
log::info!("couldn't read data: {:?}", e);
|
||||||
|
}
|
||||||
basis_cache.dict_add(&mut pddb_os, "test_dict_2", None).expect("couldn't add test dictionary 2");
|
|
||||||
basis_cache.key_update(&mut pddb_os, "test_dict_2", "test key in dict 2", "some data".as_bytes(), None, Some(128), None, false).expect("couldn't add a key to second dict");
|
|
||||||
|
|
||||||
basis_cache.key_update(&mut pddb_os, "system settings", "wifi/wpa_keys/e4200", "ABC".as_bytes(), Some(2), None, None, false).expect("couldn't update e4200 key");
|
|
||||||
|
|
||||||
log::info!("test readback of wifi/wpa_keys/e4200");
|
|
||||||
match basis_cache.key_read(&mut pddb_os, "system settings", "wifi/wpa_keys/e4200", &mut readback, None, None) {
|
|
||||||
Ok(readsize) => {
|
|
||||||
log::info!("read back {} bytes", readsize);
|
|
||||||
log::info!("read data: {}", String::from_utf8_lossy(&readback));
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
log::info!("couldn't read data: {:?}", e);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
pddb_os.dbg_dump(Some("basic1".to_string()));
|
pddb_os.dbg_dump(Some("manual".to_string()));
|
||||||
|
|
||||||
log::info!("Re-mount the PDDB");
|
|
||||||
if let Some(sys_basis) = pddb_os.pddb_mount() {
|
|
||||||
log::info!("PDDB mount operation finished successfully");
|
|
||||||
basis_cache.basis_add(sys_basis);
|
|
||||||
} else {
|
|
||||||
log::info!("PDDB did not mount; did you remember to format the PDDB region?");
|
|
||||||
}
|
}
|
||||||
log::info!("test readback of wifi/wpa_keys/e4200");
|
|
||||||
match basis_cache.key_read(&mut pddb_os, "system settings", "wifi/wpa_keys/e4200", &mut readback, None, None) {
|
|
||||||
Ok(readsize) => {
|
|
||||||
log::info!("read back {} bytes", readsize);
|
|
||||||
log::info!("read data: {}", String::from_utf8_lossy(&readback));
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
log::info!("couldn't read data: {:?}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* list of test cases:
|
/* list of test cases:
|
||||||
genenral integrity: allocate 4 dictionaries, each with 34 keys of various sizes ranging from 1k-9k.
|
genenral integrity: allocate 4 dictionaries, each with 34 keys of various sizes ranging from 1k-9k.
|
||||||
delete/add consistency: general integrity, delete a dictionary, then add a dictionary.
|
delete/add consistency: general integrity, delete a dictionary, then add a dictionary.
|
||||||
|
|
|
||||||
|
|
@ -49,4 +49,61 @@ pub(crate) fn create_testcase(hw: &mut PddbOs,
|
||||||
basis_cache.key_update(hw, &dictname, &keyname, &keydata, None, None, None, false).unwrap();
|
basis_cache.key_update(hw, &dictname, &keyname, &keydata, None, None, None, false).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn manual_testcase(hw: &mut PddbOs) {
|
||||||
|
log::info!("Initializing disk...");
|
||||||
|
hw.pddb_format().unwrap();
|
||||||
|
log::info!("Done initializing disk");
|
||||||
|
|
||||||
|
// it's a vector because order is important: by default access to keys/dicts go into the latest entry first, and then recurse to the earliest
|
||||||
|
let mut basis_cache = BasisCache::new();
|
||||||
|
|
||||||
|
log::info!("Attempting to mount the PDDB");
|
||||||
|
if let Some(sys_basis) = hw.pddb_mount() {
|
||||||
|
log::info!("PDDB mount operation finished successfully");
|
||||||
|
basis_cache.basis_add(sys_basis);
|
||||||
|
} else {
|
||||||
|
log::info!("PDDB did not mount; did you remember to format the PDDB region?");
|
||||||
|
}
|
||||||
|
log::info!("size of vpage: {}", VPAGE_SIZE);
|
||||||
|
|
||||||
|
// add a "system settings" dictionary to the default basis
|
||||||
|
log::info!("adding 'system settings' dictionary");
|
||||||
|
basis_cache.dict_add(hw, "system settings", None).expect("couldn't add system settings dictionary");
|
||||||
|
basis_cache.key_update(hw, "system settings", "wifi/wpa_keys/Kosagi", "my_wpa_key_here".as_bytes(), None, None, None, false).expect("couldn't add a key");
|
||||||
|
let mut readback = [0u8; 15];
|
||||||
|
match basis_cache.key_read(hw, "system settings", "wifi/wpa_keys/Kosagi", &mut readback, None, None) {
|
||||||
|
Ok(readsize) => {
|
||||||
|
log::info!("read back {} bytes", readsize);
|
||||||
|
log::info!("read data: {}", String::from_utf8_lossy(&readback));
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
log::info!("couldn't read data: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
basis_cache.key_update(hw, "system settings", "wifi/wpa_keys/e4200", "12345678".as_bytes(), None, None, None, false).expect("couldn't add a key");
|
||||||
|
|
||||||
|
// add a "big" key
|
||||||
|
let mut bigdata = [0u8; 5000];
|
||||||
|
for (i, d) in bigdata.iter_mut().enumerate() {
|
||||||
|
*d = i as u8;
|
||||||
|
}
|
||||||
|
basis_cache.key_update(hw, "system settings", "big_pool1", &bigdata, None, None, None, false).expect("couldn't add a key");
|
||||||
|
|
||||||
|
basis_cache.dict_add(hw, "test_dict_2", None).expect("couldn't add test dictionary 2");
|
||||||
|
basis_cache.key_update(hw, "test_dict_2", "test key in dict 2", "some data".as_bytes(), None, Some(128), None, false).expect("couldn't add a key to second dict");
|
||||||
|
|
||||||
|
basis_cache.key_update(hw, "system settings", "wifi/wpa_keys/e4200", "ABC".as_bytes(), Some(2), None, None, false).expect("couldn't update e4200 key");
|
||||||
|
|
||||||
|
log::info!("test readback of wifi/wpa_keys/e4200");
|
||||||
|
match basis_cache.key_read(hw, "system settings", "wifi/wpa_keys/e4200", &mut readback, None, None) {
|
||||||
|
Ok(readsize) => {
|
||||||
|
log::info!("read back {} bytes", readsize);
|
||||||
|
log::info!("read data: {}", String::from_utf8_lossy(&readback));
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
log::info!("couldn't read data: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue