Skip to content

Commit

Permalink
sedeve-kit, remove unused dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ybbh committed Jun 28, 2024
1 parent 842f4ac commit 1f28851
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 328 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ substring = "1.4.5"
tracing = "0.1.37"
tracing-subscriber = "0.3.14"
log = "0.4.17"
tree-sitter = { git = "https://github.com/scuptio/tree-sitter" }
project-root = "0.2.2"
bincode = "2.0.0-rc.3"
serde = { version = "1.0.197", features = ["derive", "rc"] }
Expand Down
8 changes: 6 additions & 2 deletions src/action/action_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ mod test {

#[test]
fn test_action_map_order() {
println!("test_action_map_order");
let s1 = r#"
{
"Input":{
Expand Down Expand Up @@ -230,11 +231,14 @@ mod test {
let v2 = serde_json::from_str(s2).unwrap();
let a1 = ActionJson::from_json_value(v1).unwrap();
let a2 = ActionJson::from_json_value(v2).unwrap();
assert_eq!(a1, a2);
assert_eq!(a1, a2, "test_action_map_order action value not equal {:?} /= {:?}",
a1.to_serde_json_string(),
a2.to_serde_json_string());
let mut h1 = DefaultHasher::new();
let mut h2 = DefaultHasher::new();
a1.hash(&mut h1);
a2.hash(&mut h2);
assert_eq!(h1.finish(), h2.finish());
assert_eq!(h1.finish(), h2.finish(), "test_action_map_order hash value not equal");
println!("end test_action_map_order");
}
}
14 changes: 0 additions & 14 deletions src/action/action_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ Encode,
pub enum ActionMessage<
Payload: MsgTrait + 'static,
> {
/// Check the state correctness of a node, used for asserting invariants
#[serde(bound = "Payload: MsgTrait")]
Check(Message<Payload>),

/// Set up and initializes the state of a node
#[serde(bound = "Payload: MsgTrait")]
Setup(Message<Payload>),

/// Represent a node receiving an input message, from a network endpoint or a terminal, for example.
/// When check_all_begin_end disable, the driver would expected to send only end input action.
#[serde(bound = "Payload: MsgTrait")]
Expand All @@ -57,8 +49,6 @@ impl<Payload: MsgTrait + 'static> ActionMessage<Payload> {
/// Build an ActionMessage through ActionType and Message struct.
pub fn from_message(action_type: ActionType, message: Message<Payload>) -> Self {
match action_type {
ActionType::Check => { ActionMessage::Check(message) }
ActionType::Setup => { ActionMessage::Setup(message) }
ActionType::Input => { ActionMessage::Input(message) }
ActionType::Internal => { ActionMessage::Internal(message) }
ActionType::Output => { ActionMessage::Output(message) }
Expand Down Expand Up @@ -91,8 +81,6 @@ impl<Payload: MsgTrait + 'static> ActionMessage<Payload> {
/// Action type
pub fn action_type(&self) -> ActionType {
match self {
ActionMessage::Check(_) => { ActionType::Check }
ActionMessage::Setup(_) => { ActionType::Setup }
ActionMessage::Input(_) => { ActionType::Input }
ActionMessage::Output(_) => { ActionType::Output }
ActionMessage::Internal(_) => { ActionType::Internal }
Expand All @@ -102,8 +90,6 @@ impl<Payload: MsgTrait + 'static> ActionMessage<Payload> {
fn fn_message<F, R>(&self, f: F) -> Res<R>
where F: Fn(&Message<Payload>) -> Res<R> {
match self {
ActionMessage::Check(m) => { f(m) }
ActionMessage::Setup(m) => { f(m) }
ActionMessage::Input(m) => { f(m) }
ActionMessage::Output(m) => { f(m) }
ActionMessage::Internal(m) => { f(m) }
Expand Down
23 changes: 7 additions & 16 deletions src/action/action_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,15 @@ Decode,
Encode,
)]
pub enum ActionType {
/// Set up and initializes the state of a node
Setup = 0,

/// Check the state correctness of a node, used for asserting invariants
Check = 1,

/// Represent a node receiving an input message, from a network endpoint or a terminal, for example
Input = 2,
Input = 1,

/// Represent a node sending an output message, to a network endpoint or a terminal, for example
Output = 3,
Output = 2,

/// Represent an internal event in a node
Internal = 4,
Internal = 3,
}

#[derive(
Expand All @@ -71,8 +66,8 @@ impl ActionType {
constant::ACTION_TYPE_OUTPUT => { ActionType::Output }
constant::ACTION_TYPE_INPUT => { ActionType::Input }
constant::ACTION_TYPE_INTERNAL => { ActionType::Internal }
constant::ACTION_TYPE_SETUP => { ActionType::Setup }
constant::ACTION_TYPE_CHECK => { ActionType::Check }
constant::ACTION_TYPE_SETUP => { ActionType::Input }
constant::ACTION_TYPE_CHECK => { ActionType::Input }
_ => { panic!("unknown TLA+ action type error") }
}
}
Expand All @@ -82,16 +77,14 @@ impl ActionType {
constant::SERDE_ACTION_TYPE_OUTPUT => { ActionType::Output }
constant::SERDE_ACTION_TYPE_INPUT => { ActionType::Input }
constant::SERDE_ACTION_TYPE_INTERNAL => { ActionType::Internal }
constant::SERDE_ACTION_TYPE_SETUP => { ActionType::Setup }
constant::SERDE_ACTION_TYPE_CHECK => { ActionType::Check }
constant::SERDE_ACTION_TYPE_SETUP => { ActionType::Input }
constant::SERDE_ACTION_TYPE_CHECK => { ActionType::Input }
_ => { panic!("unknown serde action type error") }
}
}

pub fn action_message<P: MsgTrait + 'static>(&self, m: Message<P>) -> ActionMessage<P> {
match self {
ActionType::Check => { ActionMessage::Check(m) }
ActionType::Setup => { ActionMessage::Setup(m) }
ActionType::Input => { ActionMessage::Input(m) }
ActionType::Internal => { ActionMessage::Internal(m) }
ActionType::Output => { ActionMessage::Output(m) }
Expand All @@ -100,8 +93,6 @@ impl ActionType {

pub fn to_string(&self) -> String {
let s = match self {
ActionType::Check => { constant::SERDE_ACTION_TYPE_CHECK.to_string() }
ActionType::Setup => { constant::SERDE_ACTION_TYPE_SETUP.to_string() }
ActionType::Input => { constant::SERDE_ACTION_TYPE_INPUT.to_string() }
ActionType::Internal => { constant::SERDE_ACTION_TYPE_INTERNAL.to_string() }
ActionType::Output => { constant::SERDE_ACTION_TYPE_OUTPUT.to_string() }
Expand Down
1 change: 1 addition & 0 deletions src/action/panic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::backtrace::Backtrace;
use std::panic;

/// DO NOT set panic hook when testing should_panic
pub fn set_panic_hook() {
panic::set_hook(Box::new(|info| {
let stacktrace = Backtrace::force_capture();
Expand Down
47 changes: 0 additions & 47 deletions src/action/serde_json_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@ use scupt_util::res::Res;
use serde_json::{Map, Value};
use tracing::error;

pub fn json_util_empty_to_null(value: Value) -> Value {
match value {
Value::Object(map) => {
if map.is_empty() {
Value::Null
} else {
Value::Object(map)
}
}
Value::Array(vec) => {
if vec.is_empty() {
Value::Null
} else {
Value::Array(vec)
}
}
_ => {
value
}
}
}


pub fn json_util_map_get_value(map: &Map<String, Value>, key: &str) -> Res<Value> {
match map.get(key) {
None => {
Expand Down Expand Up @@ -72,27 +49,3 @@ pub fn json_util_map_get_i64(map: &Map<String, Value>, key: &str) -> Res<i64> {
}
}

pub fn json_util_map_get_object(map: &Map<String, Value>, key: &str) -> Res<Map<String, Value>> {
let v = json_util_map_get_value(map, key)?;
let obj_map = match v {
Value::Null => {
Map::new()
}
Value::Array(array) => {
if array.is_empty() {
Map::new()
} else {
error!("array is not a object");
return Err(ET::NoneOption);
}
}
Value::Object(map) => {
map.clone()
}
x => {
error!("{:?} is not a object", x);
return Err(ET::NoneOption);
}
};
Ok(obj_map)
}
2 changes: 1 addition & 1 deletion src/action/test_tla_typed_value.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod tests {
mod test {
use serde_json::Value;

use crate::action::constant;
Expand Down
31 changes: 16 additions & 15 deletions src/data/path.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#[cfg(test)]
pub mod test {
use log::error;
pub mod _test {
use std::path::Path;

use project_root::get_project_root;
use scupt_util::error_type::ET;
use scupt_util::res::Res;
use scupt_util::res_of::res_io;

pub fn test_data_path(file_name: String) -> Res<String> {
let mut path_buf = res_io(get_project_root())?;
pub fn _test_data_path(file_name: String) -> String {
let mut path_buf = res_io(get_project_root()).unwrap();
path_buf = path_buf
.join("src/data")
.join(file_name);
let s = match path_buf.as_path().to_str() {
Some(s) => s.to_string(),
None => {
error!("build path error");
return Err(ET::NoneOption);
}
};
Ok(s)
let s = path_buf.as_path().to_str().unwrap().to_string();
if !Path::new(&s).exists() {
panic!("no exist such file {}", s);
}
s
}

#[test]
#[should_panic]
fn _test_non_exist_data_file() {
let _s = _test_data_path("file.non_exist_data_file_name".to_string());
}
}
8 changes: 2 additions & 6 deletions src/dtm/action_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ impl ActionExecutor {
let action_type = action.action_type()?;
let msg = action.serde_json_value_ref();
match action_type {
ActionType::Input |
ActionType::Setup |
ActionType::Check
ActionType::Input
=> {
trace!("INPUT: notify case file input {:?}", msg);
self.inner.node_wait_input.add_action(action).await?;
Expand Down Expand Up @@ -161,9 +159,7 @@ impl ActionExecutor {
trace!("enter, SIMULATOR: receive Action {:?}, {}", action, begin);
let action_type = action.action_type()?;
match action_type {
ActionType::Input |
ActionType::Setup |
ActionType::Check => {
ActionType::Input => {
if begin {
if self.inner.wait_both_begin_and_end_action {
trace!("RECEIVE: notify case file {:?}", action);
Expand Down
15 changes: 9 additions & 6 deletions src/dtm/action_input_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ mod test {
use std::fs::read_to_string;
use std::sync::Arc;

use crate::data::path::test::test_data_path;
use crate::data::path::_test::_test_data_path;
use crate::dtm::action_incoming::ActionIncoming;
use crate::dtm::action_incoming_factory::ActionIncomingFactory;
use crate::dtm::action_input_json::ActionInputJson;

#[test]
fn test() {
let path = test_data_path("trace1.json".to_string()).unwrap();
let incoming1: Arc<dyn ActionIncoming> = Arc::new(ActionInputJson::from_file(path.clone()).unwrap());
fn test_read_trace_json() {
let path = _test_data_path("trace1.json".to_string());
let incoming1: Arc<dyn ActionIncoming> =
ActionIncomingFactory::action_incoming_from_json_file(path.clone()).unwrap();
let string = read_to_string(path).unwrap();
let incoming2: Arc<dyn ActionIncoming> = Arc::new(ActionInputJson::from_json_string(string).unwrap());
let incoming2: Arc<dyn ActionIncoming> =
ActionIncomingFactory::action_incoming_from_string(string).unwrap();

let path = test_data_path("trace2.json".to_string()).unwrap();
let path = _test_data_path("trace2.json".to_string());
let incoming3: Arc<dyn ActionIncoming> = Arc::new(ActionInputJson::from_file(path.clone()).unwrap());
let string = read_to_string(path).unwrap();
let incoming4: Arc<dyn ActionIncoming> = Arc::new(ActionInputJson::from_json_string(string).unwrap());
Expand Down
57 changes: 0 additions & 57 deletions src/dtm/automata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,34 +201,6 @@ macro_rules! action_end {
};
}

/// End a Setup action , alias of `setup_end`
#[macro_export]
macro_rules! setup {
($automata_name:expr, $message:expr) => {
{
$crate::action_end!(
$automata_name,
$crate::action::action_type::ActionType::Setup,
$message
)
}
};
}

/// End a Check action , alias of `check_end`
#[macro_export]
macro_rules! check {
($automata_name:expr, $message:expr) => {
{
$crate::action_end!(
$automata_name,
$crate::action::action_type::ActionType::Check,
$message
);
}
};
}

/// End an Input action , alias of `input_end`
#[macro_export]
macro_rules! input {
Expand Down Expand Up @@ -285,35 +257,6 @@ macro_rules! setup_end {
};
}

/// Begin a Check action
#[macro_export]
macro_rules! check_begin {
($automata_name:expr, $message:expr) => {
{
$crate::action_begin!(
$automata_name,
$crate::action::action_type::ActionType::Check,
$message
)
}
};
}


/// End a Check action
#[macro_export]
macro_rules! check_end {
($automata_name:expr, $message:expr) => {
{
$crate::action_end!(
$automata_name,
$crate::action::action_type::ActionType::Check,
$message
)
}
};
}

/// Begin an Input action
#[macro_export]
macro_rules! input_begin {
Expand Down
6 changes: 1 addition & 5 deletions src/dtm/dtm_server_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ impl DTMServerHandler {
let action_type = v.action_type()?;

let nid = match action_type {
ActionType::Input |
ActionType::Setup |
ActionType::Check => {
ActionType::Input => {
v.dest_nid()?
}
ActionType::Internal => {
Expand Down Expand Up @@ -333,8 +331,6 @@ impl DTMServerHandler {
let action_type = value.action_type()?;
let need_send_message_to_node = if
action_type == ActionType::Input
|| action_type == ActionType::Setup
|| action_type == ActionType::Check
{
if action_type == ActionType::Input {
let dest_nid = value.dest_nid()?;
Expand Down
Loading

0 comments on commit 1f28851

Please sign in to comment.