Tests: Minor simplification change

This commit is contained in:
Kedar Sovani 2023-01-06 07:43:34 +05:30
parent 13ea552280
commit 0822565383
5 changed files with 18 additions and 18 deletions

View file

@ -29,7 +29,7 @@ use matter::{
error::Error,
fabric::FabricMgr,
interaction_model::{core::OpCode, messages::ib::CmdPath, messages::msg, InteractionModel},
tlv::{TLVWriter, TagType, ToTLV},
tlv::{TLVArray, TLVWriter, TagType, ToTLV},
transport::packet::Packet,
transport::proto_demux::HandleProto,
transport::{
@ -124,7 +124,7 @@ impl ImEngine {
}
/// Run a transaction through the interaction model engine
pub fn process(&mut self, input: &ImInput, data_out: &mut [u8]) -> usize {
pub fn process<'a>(&mut self, input: &ImInput, data_out: &'a mut [u8]) -> (u8, &'a mut [u8]) {
let mut new_exch = Exchange::new(1, 0, exchange::Role::Responder);
// Choose whether to use a new exchange, or use the one from the ImEngine configuration
let mut exch = self.exch.as_mut().unwrap_or_else(|| &mut new_exch);
@ -163,16 +163,21 @@ impl ImEngine {
self.im.handle_proto_id(&mut ctx).unwrap();
let out_data_len = ctx.tx.as_borrow_slice().len();
data_out[..out_data_len].copy_from_slice(ctx.tx.as_borrow_slice());
out_data_len
let response = ctx.tx.get_proto_opcode();
(response, &mut data_out[..out_data_len])
}
}
// Create an Interaction Model, Data Model and run a rx/tx transaction through it
pub fn im_engine(action: OpCode, data_in: &[u8], data_out: &mut [u8]) -> (DataModel, usize) {
pub fn im_engine<'a>(
action: OpCode,
data_in: &[u8],
data_out: &'a mut [u8],
) -> (DataModel, u8, &'a mut [u8]) {
let mut engine = ImEngine::new();
let input = ImInput::new(action, data_in);
let output_len = engine.process(&input, data_out);
(engine.dm, output_len)
let (response, output) = engine.process(&input, data_out);
(engine.dm, response, output)
}
pub struct TestData<'a, 'b> {

View file

@ -73,8 +73,7 @@ fn gen_read_reqs_output<'a>(
let mut input = ImInput::new(OpCode::ReadRequest, wb.as_borrow_slice());
input.set_peer_node_id(peer_node_id);
let out_buf_len = im.process(&input, out_buf);
let out_buf = &out_buf[..out_buf_len];
let (_, out_buf) = im.process(&input, out_buf);
tlv::print_tlv_list(out_buf);
let root = tlv::get_root_node_struct(out_buf).unwrap();
@ -100,9 +99,8 @@ fn handle_write_reqs(
let mut input = ImInput::new(OpCode::WriteRequest, wb.as_borrow_slice());
input.set_peer_node_id(peer_node_id);
let out_buf_len = im.process(&input, &mut out_buf);
let (_, out_buf) = im.process(&input, &mut out_buf);
let out_buf = &out_buf[..out_buf_len];
tlv::print_tlv_list(out_buf);
let root = tlv::get_root_node_struct(out_buf).unwrap();

View file

@ -46,8 +46,7 @@ fn handle_write_reqs(input: &[AttrData], expected: &[AttrStatus]) -> DataModel {
let write_req = WriteReq::new(false, input);
write_req.to_tlv(&mut tw, TagType::Anonymous).unwrap();
let (dm, out_buf_len) = im_engine(OpCode::WriteRequest, wb.as_borrow_slice(), &mut out_buf);
let out_buf = &out_buf[..out_buf_len];
let (dm, _, out_buf) = im_engine(OpCode::WriteRequest, wb.as_borrow_slice(), &mut out_buf);
tlv::print_tlv_list(out_buf);
let root = tlv::get_root_node_struct(out_buf).unwrap();

View file

@ -54,8 +54,7 @@ fn gen_read_reqs_output<'a>(input: &[AttrPath], out_buf: &'a mut [u8]) -> Report
let read_req = ReadReq::new(true).set_attr_requests(input);
read_req.to_tlv(&mut tw, TagType::Anonymous).unwrap();
let (_, out_buf_len) = im_engine(OpCode::ReadRequest, wb.as_borrow_slice(), out_buf);
let out_buf = &out_buf[..out_buf_len];
let (_, _, out_buf) = im_engine(OpCode::ReadRequest, wb.as_borrow_slice(), out_buf);
tlv::print_tlv_list(out_buf);
let root = tlv::get_root_node_struct(out_buf).unwrap();
ReportDataMsg::from_tlv(&root).unwrap()
@ -73,12 +72,12 @@ fn handle_write_reqs(input: &[AttrData], expected: &[AttrStatus]) -> DataModel {
let write_req = WriteReq::new(false, input);
write_req.to_tlv(&mut tw, TagType::Anonymous).unwrap();
let (dm, out_buf_len) = im_engine(OpCode::WriteRequest, wb.as_borrow_slice(), &mut out_buf);
let out_buf = &out_buf[..out_buf_len];
let (dm, _, out_buf) = im_engine(OpCode::WriteRequest, wb.as_borrow_slice(), &mut out_buf);
tlv::print_tlv_list(out_buf);
let root = tlv::get_root_node_struct(out_buf).unwrap();
let mut index = 0;
let response_iter = root
.find_tag(msg::WriteRespTag::WriteResponses as u32)
.unwrap()

View file

@ -47,8 +47,7 @@ fn handle_commands(input: &[(CmdPath, Option<u8>)], expected: &[ExpectedInvResp]
td.commands(input).unwrap();
let (_, out_buf_len) = im_engine(OpCode::InvokeRequest, wb.as_borrow_slice(), &mut out_buf);
let out_buf = &out_buf[..out_buf_len];
let (_, _, out_buf) = im_engine(OpCode::InvokeRequest, wb.as_borrow_slice(), &mut out_buf);
tlv::print_tlv_list(out_buf);
let root = tlv::get_root_node_struct(out_buf).unwrap();