From 18c202dceec08e2628cf85a21df5c53257576c88 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 28 Mar 2022 22:56:32 +0800 Subject: [PATCH] start of testing code for the PDDB --- services/pddb/src/api.rs | 3 +++ services/pddb/src/lib.rs | 6 ++++++ services/pddb/src/main.rs | 6 ++++++ services/shellchat/Cargo.toml | 3 ++- services/shellchat/src/cmds/pddb_cmd.rs | 18 ++++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/services/pddb/src/api.rs b/services/pddb/src/api.rs index 758c1a650..6e03d4dac 100644 --- a/services/pddb/src/api.rs +++ b/services/pddb/src/api.rs @@ -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 { diff --git a/services/pddb/src/lib.rs b/services/pddb/src/lib.rs index 55b7941fd..a7495b089 100644 --- a/services/pddb/src/lib.rs +++ b/services/pddb/src/lib.rs @@ -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 { diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 470aab54d..459343039 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -1088,6 +1088,12 @@ fn xmain() -> ! { } modals.show_notification(¬e).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( diff --git a/services/shellchat/Cargo.toml b/services/shellchat/Cargo.toml index 009d30bd1..dd32ec230 100644 --- a/services/shellchat/Cargo.toml +++ b/services/shellchat/Cargo.toml @@ -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 = "*" diff --git a/services/shellchat/src/cmds/pddb_cmd.rs b/services/shellchat/src/cmds/pddb_cmd.rs index 132309827..d89b92377 100644 --- a/services/shellchat/src/cmds/pddb_cmd.rs +++ b/services/shellchat/src/cmds/pddb_cmd.rs @@ -18,7 +18,10 @@ impl<'a> ShellCmdApi<'a> for PddbCmd { fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result>, 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:: + ).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(); }