start of testing code for the PDDB

This commit is contained in:
bunnie 2022-03-28 22:56:32 +08:00
parent 874a5ac20e
commit 18c202dcee
5 changed files with 35 additions and 1 deletions

View file

@ -118,6 +118,9 @@ pub(crate) enum Opcode {
SuspendResume,
/// quit the server
Quit,
/// Write debug dump (only available in hosted mode)
#[cfg(not(any(target_os = "none", target_os = "xous")))]
DbgDump,
}
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum PollOp {

View file

@ -583,6 +583,12 @@ impl Pddb {
}
Ok(dict_list)
}
#[cfg(not(any(target_os = "none", target_os = "xous")))]
pub fn dbg_dump(&self, name: &str) -> Result<()> {
let ipc_str = xous_ipc::String::<128>::from_str(name);
ipc_str.send(self.conn).expect("couldn't initiate debug dump");
Ok(())
}
}
impl Drop for Pddb {

View file

@ -1088,6 +1088,12 @@ fn xmain() -> ! {
}
modals.show_notification(&note).expect("couldn't show basis list");
},
#[cfg(not(any(target_os = "none", target_os = "xous")))]
Some(Opcode::DbgDump) => {
let dumpname = xous_ipc::String::<128>::from_message(msg.body.memory_message().unwrap()).unwrap();
log::info!("dumping {}", dumpname);
pddb_os.dbg_dump(Some(dumpname.as_str().unwrap().to_string()), None);
}
Some(Opcode::Quit) => {
log::warn!("quitting the PDDB server");
send_message(

View file

@ -83,7 +83,8 @@ debugprint = []
spinortest = [] # for spinor testing. contra-indicated with PDDB, as it steals memory from the PDDB.
benchmarks = [] # adds the benchmark routines. Left off normally to free up code and memory space.
tts = [] # adds text to speech plugin
default = [] # "debugprint"
pddbtest = []
default = ["pddbtest"] # "debugprint"
[target.'cfg(any(windows,unix))'.dependencies]
debug-here = "*"

View file

@ -18,7 +18,10 @@ impl<'a> ShellCmdApi<'a> for PddbCmd {
fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
use core::fmt::Write;
let mut ret = String::<1024>::new();
#[cfg(not(feature="pddbtest"))]
let helpstring = "pddb [basislist] [dictlist] [keylist] [query] [dictdelete] [keydelete]";
#[cfg(feature="pddbtest")]
let helpstring = "pddb [basislist] [dictlist] [keylist] [query] [dictdelete] [keydelete] [test]";
let mut tokens = args.as_str().unwrap().split(' ');
if let Some(sub_cmd) = tokens.next() {
@ -164,6 +167,21 @@ impl<'a> ShellCmdApi<'a> for PddbCmd {
Err(_) => write!(ret, "Error encountered listing dictionaries").ok().unwrap_or(()),
}
}
// note that this feature only works in hosted mode
#[cfg(feature="pddbtest")]
"test" => {
let mut test_handle = pddb::Pddb::new();
let test_key = test_handle.get(
"test",
"zerolength",
None, true, true,
Some(8),
None::<fn()>
).expect("couldn't build empty key");
// test_handle.sync().expect("couldn't sync");
self.pddb.dbg_dump("std_test1").unwrap();
write!(ret, "dumped std_test1").unwrap();
}
_ => {
write!(ret, "{}", helpstring).unwrap();
}