From f464e34eef1600ea0a0e57c200493f5fefb66a2e Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 11 Jan 2022 18:29:12 +0800 Subject: [PATCH] debug the test oqc integration --- services/shellchat/Cargo.toml | 3 ++- services/shellchat/src/cmds.rs | 5 +++- services/shellchat/src/cmds/test.rs | 42 ++++++++++++++++++----------- services/shellchat/src/oqc_test.rs | 17 ++++++++---- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/services/shellchat/Cargo.toml b/services/shellchat/Cargo.toml index 8537465b2..8928920d4 100644 --- a/services/shellchat/Cargo.toml +++ b/services/shellchat/Cargo.toml @@ -72,7 +72,8 @@ utralib = {path = "../../utralib"} [features] debugprint = [] spinortest = [] # for spinor testing. contra-indicated with PDDB, as it steals memory from the PDDB. -default = [] # "debugprint" +benchmarks = [] # adds the benchmark routines. Left off normally to free up code and memory space. +default = ["benchmarks"] # "debugprint" [target.'cfg(any(windows,unix))'.dependencies] debug-here = "*" diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index 52ce2e007..f368f978e 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -94,7 +94,6 @@ mod backlight; use backlight::*; mod accel; use accel::*; mod sha; use sha::*; mod ecup; use ecup::*; -mod aes_cmd; use aes_cmd::*; mod trng_cmd; use trng_cmd::*; mod engine; use engine::*; mod console; use console::*; @@ -105,6 +104,10 @@ mod jtag_cmd; use jtag_cmd::*; mod net_cmd; use net_cmd::*; mod pddb_cmd; use pddb_cmd::*; +#[cfg(feature="benchmarks")] +mod aes_cmd; +#[cfg(feature="benchmarks")] +use aes_cmd::*; //mod fcc; use fcc::*; //mod pds; // dependency of the FCC file diff --git a/services/shellchat/src/cmds/test.rs b/services/shellchat/src/cmds/test.rs index 28844bd48..558860a1e 100644 --- a/services/shellchat/src/cmds/test.rs +++ b/services/shellchat/src/cmds/test.rs @@ -34,6 +34,7 @@ pub struct Test { end_time: Option, start_elapsed: Option, end_elapsed: Option, + oqc_cid: Option, oqc_start: u64, #[cfg(any(target_os = "none", target_os = "xous"))] jtag: jtag::Jtag, @@ -68,6 +69,7 @@ impl Test { end_time: None, start_elapsed: None, end_elapsed: None, + oqc_cid: None, oqc_start: 0, #[cfg(any(target_os = "none", target_os = "xous"))] jtag: jtag::Jtag::new(&xns).unwrap(), @@ -398,24 +400,32 @@ impl<'a> ShellCmdApi<'a> for Test { log::info!("{}|ASTOP|", SENTINEL); } "oqc" => { - let oqc_cid = Arc::new(AtomicU32::new(0)); - // start the OQC thread - let _ = std::thread::spawn({ - let oqc_cid = oqc_cid.clone(); - move || { - crate::oqc_test::oqc_test(oqc_cid); - } - }); - // wait until the OQC thread has connected itself - while oqc_cid.load(Ordering::SeqCst) == 0 { - env.ticktimer.sleep_ms(200).unwrap(); - } - if ((env.llio.adc_vbus().unwrap() as f64) * 0.005033) > 1.5 { // if power is plugged in, deny powerdown request write!(ret, "Can't run OQC test while charging. Unplug charging cable and try again.").unwrap(); return Ok(Some(ret)); } + // start the server if it isn't started already, but only allow it to start once. Note that the CID stays the same between calls, + // because the SID is stable between calls and we're calling from the same process each time. + let oqc_cid = if let Some(oc) = self.oqc_cid { + oc + } else { + let oqc_cid = Arc::new(AtomicU32::new(0)); + // start the OQC thread + let _ = std::thread::spawn({ + let oqc_cid = oqc_cid.clone(); + move || { + crate::oqc_test::oqc_test(oqc_cid); + } + }); + // wait until the OQC thread has connected itself + while oqc_cid.load(Ordering::SeqCst) == 0 { + env.ticktimer.sleep_ms(200).unwrap(); + } + self.oqc_cid = Some(oqc_cid.load(Ordering::SeqCst)); + oqc_cid.load(Ordering::SeqCst) + }; + let susres = susres::Susres::new_without_hook(&env.xns).unwrap(); env.llio.wfi_override(true).unwrap(); // activate SSID scanning while the test runs @@ -446,13 +456,13 @@ impl<'a> ShellCmdApi<'a> for Test { susres.initiate_suspend().unwrap(); env.ticktimer.sleep_ms(1000).unwrap(); // pause for the suspend/resume cycle - let timeout = 60_0000; - xous::send_message(oqc_cid.load(Ordering::SeqCst), + let timeout = 60_000; + xous::send_message(oqc_cid, xous::Message::new_blocking_scalar(OqcOp::Trigger.to_usize().unwrap(), timeout, 0, 0, 0,) ).expect("couldn't trigger self test"); loop { - match oqc_status(oqc_cid.load(Ordering::SeqCst)) { + match oqc_status(oqc_cid) { Some(true) => { let ssid_str = env.com.ssid_fetch_as_string().unwrap(); use std::str::FromStr; diff --git a/services/shellchat/src/oqc_test.rs b/services/shellchat/src/oqc_test.rs index 881b23d73..283651347 100644 --- a/services/shellchat/src/oqc_test.rs +++ b/services/shellchat/src/oqc_test.rs @@ -1,7 +1,7 @@ use num_traits::*; use gam::modal::*; use keyboard::{RowCol, KeyRawStates}; -use core::sync::atomic::{AtomicU32, Ordering}; +use core::sync::atomic::{AtomicU32, Ordering, AtomicBool}; use std::sync::Arc; pub(crate) const SERVER_NAME_OQC: &str = "_Outgoing Quality Check Test Program_"; @@ -18,7 +18,14 @@ pub(crate) enum OqcOp { Quit, } +static SERVER_STARTED: AtomicBool = AtomicBool::new(false); pub(crate) fn oqc_test(oqc_cid: Arc) { + // only start the server once! + if SERVER_STARTED.load(Ordering::SeqCst) { + return + } + SERVER_STARTED.store(true, Ordering::SeqCst); + let xns = xous_names::XousNames::new().unwrap(); // we allow any connections because this server is not spawned until it is needed let oqc_sid = xns.register_name(SERVER_NAME_OQC, None).expect("can't register server"); @@ -190,10 +197,11 @@ pub(crate) fn oqc_test(oqc_cid: Arc) { Some(OqcOp::ModalDrop) => { log::error!("test modal quit unexpectedly"); } - Some(OqcOp::Quit) => { + Some(OqcOp::Quit) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { log::warn!("Quit received on OQC"); + xous::return_scalar(msg.sender, 1).unwrap(); break; - } + }), None => { log::error!("couldn't convert OqcOp: {:?}", msg); } @@ -203,8 +211,7 @@ pub(crate) fn oqc_test(oqc_cid: Arc) { log::trace!("main loop exit, destroying servers"); xns.unregister_server(oqc_sid).unwrap(); xous::destroy_server(oqc_sid).unwrap(); - log::trace!("quitting"); - xous::terminate_process(0) + log::trace!("quitting oqc server"); } fn populate_vectors() -> Vec::<(RowCol, bool)> {