From 3bfcce9a069be0c9f3405ee943cb987892012e39 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 31 Jan 2024 03:52:32 +0800 Subject: [PATCH] split out sha tests and upgrade api to 0.10 in shellchat --- services/shellchat/Cargo.toml | 3 ++- services/shellchat/src/cmds.rs | 12 ++++++------ services/shellchat/src/cmds/sha.rs | 15 +++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/services/shellchat/Cargo.toml b/services/shellchat/Cargo.toml index b0dd95795..befc77c75 100644 --- a/services/shellchat/Cargo.toml +++ b/services/shellchat/Cargo.toml @@ -121,6 +121,7 @@ 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. +hashtest = [] aestests = [] # adds AES tests tts = [] # adds text to speech plugin pddbtest = ["rand_chacha"] @@ -146,4 +147,4 @@ extra-tests = [] mass-storage = [] locktests = [ ] # for debugging some specific `std` tests cherry-picked out of the test suite -default = [] # "debugprint" +default = ["hashtest"] # "debugprint" diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index 7ab78a566..e6d0e821d 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -144,9 +144,9 @@ use tts::*; mod engine; #[cfg(feature = "benchmarks")] use engine::*; -#[cfg(feature = "benchmarks")] +#[cfg(feature = "hashtest")] mod sha; -#[cfg(feature = "benchmarks")] +#[cfg(feature = "hashtest")] use sha::*; #[cfg(feature = "aestests")] mod aes_cmd; @@ -183,7 +183,7 @@ pub struct CmdEnv { #[cfg(feature = "tts")] tts_cmd: Tts, - #[cfg(feature = "benchmarks")] + #[cfg(feature = "hashtest")] sha_cmd: Sha, #[cfg(feature = "aestests")] aes_cmd: Aes, @@ -229,7 +229,7 @@ impl CmdEnv { event_csr: AtomicCsr::new(event1_csr.as_mut_ptr() as *mut u32), }; //let fcc = Fcc::new(&mut common); - #[cfg(feature = "benchmarks")] + #[cfg(feature = "hashtest")] let sha = Sha::new(&xns, &mut _common); #[cfg(feature = "aestests")] let aes = Aes::new(&xns, &mut _common); @@ -321,7 +321,7 @@ impl CmdEnv { #[cfg(feature = "tts")] tts_cmd: Tts::new(&xns), - #[cfg(feature = "benchmarks")] + #[cfg(feature = "hashtest")] sha_cmd: sha, #[cfg(feature = "aestests")] aes_cmd: aes, @@ -371,7 +371,7 @@ impl CmdEnv { &mut self.test_cmd, #[cfg(feature = "tts")] &mut self.tts_cmd, - #[cfg(feature = "benchmarks")] + #[cfg(feature = "hashtest")] &mut self.sha_cmd, #[cfg(feature = "aestests")] &mut self.aes_cmd, diff --git a/services/shellchat/src/cmds/sha.rs b/services/shellchat/src/cmds/sha.rs index 0ce9da132..3930673af 100644 --- a/services/shellchat/src/cmds/sha.rs +++ b/services/shellchat/src/cmds/sha.rs @@ -1,8 +1,7 @@ use core::sync::atomic::{AtomicU32, Ordering}; -use digest::Digest; use num_traits::*; -use sha2::*; +use sha2::Digest; use xous_ipc::String; use crate::{CommonEnv, ShellCmdApi}; @@ -25,7 +24,7 @@ const TEST_ITERS: usize = 1000; const TEST_MAX_LEN: usize = 8192; const TEST_FIXED_LEN: bool = true; /* -benchamrk notes: +benchmark notes: TEST_MAX_LEN = 16384 (fixed length) / TEST_ITERS = 1000: hw 25.986ms/hash, sw 155.11ms/hash TEST_MAX_LEN = 16384 (random length) / TEST_ITERS = 1000: hw 15.262ms/hash, sw 80.053ms/hash TEST_MAX_LEN = 256 (random length) / TEST_ITERS = 1000: hw 6.968ms/hash, sw 3.987ms/hash @@ -72,9 +71,10 @@ pub fn benchmark_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { let mut hasher = match FromPrimitive::from_usize(msg.body.id()) { Some(BenchOp::StartSha512Sw) => { hw_mode = false; - sha2::Sha512::new_with_strategy(FallbackStrategy::SoftwareOnly) + // should be software-only, but we can't specify that with the lastest API... + sha2::Sha512::new() } - _ => sha2::Sha512::new_with_strategy(FallbackStrategy::WaitForHardware), + _ => sha2::Sha512::new(), // should be "wait for hardware"... }; let mut accumulator = [0 as u8; 64]; for i in 0..TEST_ITERS { @@ -190,7 +190,7 @@ impl<'a> ShellCmdApi<'a> for Sha { ]; let mut pass: bool = true; - let mut hasher = sha2::Sha512::new_with_strategy(FallbackStrategy::WaitForHardware); + let mut hasher = sha2::Sha512::new(); hasher.update(K_DATA); let digest = hasher.finalize(); @@ -217,8 +217,7 @@ impl<'a> ShellCmdApi<'a> for Sha { ]; let mut pass: bool = true; - let mut hasher = - sha2::Sha512Trunc256::new_with_strategy(FallbackStrategy::WaitForHardware); + let mut hasher = sha2::Sha512_256::new(); hasher.update(K_DATA); let digest = hasher.finalize();