Fix no_std errors

This commit is contained in:
ivmarkov 2023-05-04 05:26:13 +00:00
parent 5fc3d2d510
commit 86fb8ce1f0
9 changed files with 60 additions and 48 deletions

View file

@ -44,19 +44,14 @@ use matter::{
transport::packet::Packet, transport::packet::Packet,
transport::{ transport::{
exchange::{self, Exchange, ExchangeCtx}, exchange::{self, Exchange, ExchangeCtx},
network::Address, network::{Address, IpAddr, Ipv4Addr, SocketAddr},
packet::MAX_RX_BUF_SIZE, packet::MAX_RX_BUF_SIZE,
proto_ctx::ProtoCtx, proto_ctx::ProtoCtx,
session::{CaseDetails, CloneData, NocCatIds, SessionMgr, SessionMode}, session::{CaseDetails, CloneData, NocCatIds, SessionMgr, SessionMode},
}, },
utils::{ utils::{rand::dummy_rand, writebuf::WriteBuf},
epoch::{sys_epoch, sys_utc_calendar},
rand::dummy_rand,
writebuf::WriteBuf,
},
Matter, Matter,
}; };
use std::net::{Ipv4Addr, SocketAddr};
use super::echo_cluster::EchoCluster; use super::echo_cluster::EchoCluster;
@ -109,14 +104,17 @@ impl<'a> ImInput<'a> {
pub type DmHandler<'a> = handler_chain_type!(OnOffCluster, EchoCluster, DescriptorCluster, EchoCluster | RootEndpointHandler<'a>); pub type DmHandler<'a> = handler_chain_type!(OnOffCluster, EchoCluster, DescriptorCluster, EchoCluster | RootEndpointHandler<'a>);
pub fn matter(mdns: &mut dyn Mdns) -> Matter<'_> { pub fn matter(mdns: &mut dyn Mdns) -> Matter<'_> {
Matter::new( #[cfg(feature = "std")]
&BASIC_INFO, use matter::utils::epoch::sys_epoch as epoch;
mdns, #[cfg(feature = "std")]
sys_epoch, use matter::utils::epoch::sys_utc_calendar as utc_calendar;
dummy_rand,
sys_utc_calendar, #[cfg(not(feature = "std"))]
5540, use matter::utils::epoch::dummy_epoch as epoch;
) #[cfg(not(feature = "std"))]
use matter::utils::epoch::dummy_utc_calendar as utc_calendar;
Matter::new(&BASIC_INFO, mdns, epoch, dummy_rand, utc_calendar, 5540)
} }
/// An Interaction Model Engine to facilitate easy testing /// An Interaction Model Engine to facilitate easy testing
@ -203,7 +201,7 @@ impl<'a> ImEngine<'a> {
10, 10,
30, 30,
Address::Udp(SocketAddr::new( Address::Udp(SocketAddr::new(
std::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
5542, 5542,
)), )),
SessionMode::Case(CaseDetails::new(1, &input.cat_ids)), SessionMode::Case(CaseDetails::new(1, &input.cat_ids)),

View file

@ -20,3 +20,10 @@ pub mod commands;
pub mod echo_cluster; pub mod echo_cluster;
pub mod handlers; pub mod handlers;
pub mod im_engine; pub mod im_engine;
pub fn init_env_logger() {
#[cfg(feature = "std")]
{
let _ = env_logger::try_init();
}
}

View file

@ -36,6 +36,7 @@ use crate::{
attributes::*, attributes::*,
echo_cluster::{self, ATTR_WRITE_DEFAULT_VALUE}, echo_cluster::{self, ATTR_WRITE_DEFAULT_VALUE},
im_engine::{matter, ImEngine}, im_engine::{matter, ImEngine},
init_env_logger,
}, },
}; };
@ -43,7 +44,7 @@ use crate::{
/// Ensure that wildcard read attributes don't include error response /// Ensure that wildcard read attributes don't include error response
/// and silently drop the data when access is not granted /// and silently drop the data when access is not granted
fn wc_read_attribute() { fn wc_read_attribute() {
let _ = env_logger::try_init(); init_env_logger();
let wc_att1 = GenericPath::new( let wc_att1 = GenericPath::new(
None, None,
@ -101,7 +102,7 @@ fn wc_read_attribute() {
/// Ensure that exact read attribute includes error response /// Ensure that exact read attribute includes error response
/// when access is not granted /// when access is not granted
fn exact_read_attribute() { fn exact_read_attribute() {
let _ = env_logger::try_init(); init_env_logger();
let wc_att1 = GenericPath::new( let wc_att1 = GenericPath::new(
Some(0), Some(0),
@ -139,7 +140,7 @@ fn exact_read_attribute() {
/// Ensure that an write attribute with a wildcard either performs the operation, /// Ensure that an write attribute with a wildcard either performs the operation,
/// if allowed, or silently drops the request /// if allowed, or silently drops the request
fn wc_write_attribute() { fn wc_write_attribute() {
let _ = env_logger::try_init(); init_env_logger();
let val0 = 10; let val0 = 10;
let val1 = 20; let val1 = 20;
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {
@ -228,7 +229,7 @@ fn wc_write_attribute() {
/// Ensure that an write attribute without a wildcard returns an error when the /// Ensure that an write attribute without a wildcard returns an error when the
/// ACL disallows the access, and returns success once access is granted /// ACL disallows the access, and returns success once access is granted
fn exact_write_attribute() { fn exact_write_attribute() {
let _ = env_logger::try_init(); init_env_logger();
let val0 = 10; let val0 = 10;
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {
let _ = t.u16(tag, val0); let _ = t.u16(tag, val0);
@ -278,7 +279,7 @@ fn exact_write_attribute() {
/// ACL disallows the access, and returns success once access is granted to the CAT ID /// ACL disallows the access, and returns success once access is granted to the CAT ID
/// The Accessor CAT version is one more than that in the ACL /// The Accessor CAT version is one more than that in the ACL
fn exact_write_attribute_noc_cat() { fn exact_write_attribute_noc_cat() {
let _ = env_logger::try_init(); init_env_logger();
let val0 = 10; let val0 = 10;
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {
let _ = t.u16(tag, val0); let _ = t.u16(tag, val0);
@ -330,7 +331,7 @@ fn exact_write_attribute_noc_cat() {
#[test] #[test]
/// Ensure that a write attribute with insufficient permissions is rejected /// Ensure that a write attribute with insufficient permissions is rejected
fn insufficient_perms_write() { fn insufficient_perms_write() {
let _ = env_logger::try_init(); init_env_logger();
let val0 = 10; let val0 = 10;
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {
let _ = t.u16(tag, val0); let _ = t.u16(tag, val0);
@ -379,7 +380,7 @@ fn insufficient_perms_write() {
/// - Write Attr to ACL Cluster (allowed, this ACL also grants universal access) /// - Write Attr to ACL Cluster (allowed, this ACL also grants universal access)
/// - Write Attr to Echo Cluster again (successful this time) /// - Write Attr to Echo Cluster again (successful this time)
fn write_with_runtime_acl_add() { fn write_with_runtime_acl_add() {
let _ = env_logger::try_init(); init_env_logger();
let peer = 98765; let peer = 98765;
let mut mdns = DummyMdns {}; let mut mdns = DummyMdns {};
let matter = matter(&mut mdns); let matter = matter(&mut mdns);
@ -446,7 +447,7 @@ fn test_read_data_ver() {
// 1 Attr Read Requests // 1 Attr Read Requests
// - wildcard endpoint, att1 // - wildcard endpoint, att1
// - 2 responses are expected // - 2 responses are expected
let _ = env_logger::try_init(); init_env_logger();
let peer = 98765; let peer = 98765;
let mut mdns = DummyMdns {}; let mut mdns = DummyMdns {};
let matter = matter(&mut mdns); let matter = matter(&mut mdns);
@ -549,7 +550,7 @@ fn test_write_data_ver() {
// 1 Attr Read Requests // 1 Attr Read Requests
// - wildcard endpoint, att1 // - wildcard endpoint, att1
// - 2 responses are expected // - 2 responses are expected
let _ = env_logger::try_init(); init_env_logger();
let peer = 98765; let peer = 98765;
let mut mdns = DummyMdns {}; let mut mdns = DummyMdns {};
let matter = matter(&mut mdns); let matter = matter(&mut mdns);

View file

@ -29,6 +29,7 @@ use matter::{
use crate::common::{ use crate::common::{
echo_cluster::{self, TestChecker}, echo_cluster::{self, TestChecker},
im_engine::{matter, ImEngine}, im_engine::{matter, ImEngine},
init_env_logger,
}; };
// Helper for handling Write Attribute sequences // Helper for handling Write Attribute sequences
@ -40,7 +41,7 @@ fn attr_list_ops() {
let val1: u16 = 15; let val1: u16 = 15;
let tc_handle = TestChecker::get().unwrap(); let tc_handle = TestChecker::get().unwrap();
let _ = env_logger::try_init(); init_env_logger();
let delete_item = EncodeValue::Closure(&|tag, t| { let delete_item = EncodeValue::Closure(&|tag, t| {
let _ = t.null(tag); let _ = t.null(tag);

View file

@ -35,6 +35,7 @@ use crate::{
attributes::*, attributes::*,
echo_cluster, echo_cluster,
im_engine::{matter, ImEngine}, im_engine::{matter, ImEngine},
init_env_logger,
}, },
}; };
@ -44,7 +45,7 @@ fn test_read_success() {
// - first on endpoint 0, att1 // - first on endpoint 0, att1
// - second on endpoint 1, att2 // - second on endpoint 1, att2
// - third on endpoint 1, attcustom a custom attribute // - third on endpoint 1, attcustom a custom attribute
let _ = env_logger::try_init(); init_env_logger();
let ep0_att1 = GenericPath::new( let ep0_att1 = GenericPath::new(
Some(0), Some(0),
@ -86,7 +87,7 @@ fn test_read_unsupported_fields() {
// - attribute doesn't exist - UnsupportedAttribute // - attribute doesn't exist - UnsupportedAttribute
// - attribute doesn't exist and endpoint is wildcard - Silently ignore // - attribute doesn't exist and endpoint is wildcard - Silently ignore
// - attribute doesn't exist and cluster is wildcard - Silently ignore // - attribute doesn't exist and cluster is wildcard - Silently ignore
let _ = env_logger::try_init(); init_env_logger();
let invalid_endpoint = GenericPath::new( let invalid_endpoint = GenericPath::new(
Some(2), Some(2),
@ -129,7 +130,7 @@ fn test_read_wc_endpoint_all_have_clusters() {
// 1 Attr Read Requests // 1 Attr Read Requests
// - wildcard endpoint, att1 // - wildcard endpoint, att1
// - 2 responses are expected // - 2 responses are expected
let _ = env_logger::try_init(); init_env_logger();
let wc_ep_att1 = GenericPath::new( let wc_ep_att1 = GenericPath::new(
None, None,
@ -160,7 +161,7 @@ fn test_read_wc_endpoint_only_1_has_cluster() {
// 1 Attr Read Requests // 1 Attr Read Requests
// - wildcard endpoint, on/off Cluster OnOff Attribute // - wildcard endpoint, on/off Cluster OnOff Attribute
// - 1 response are expected // - 1 response are expected
let _ = env_logger::try_init(); init_env_logger();
let wc_ep_onoff = GenericPath::new( let wc_ep_onoff = GenericPath::new(
None, None,
@ -185,7 +186,7 @@ fn test_read_wc_endpoint_wc_attribute() {
// 1 Attr Read Request // 1 Attr Read Request
// - wildcard endpoint, wildcard attribute // - wildcard endpoint, wildcard attribute
// - 8 responses are expected, 1+3 attributes on endpoint 0, 1+3 on endpoint 1 // - 8 responses are expected, 1+3 attributes on endpoint 0, 1+3 on endpoint 1
let _ = env_logger::try_init(); init_env_logger();
let wc_ep_wc_attr = GenericPath::new(None, Some(echo_cluster::ID), None); let wc_ep_wc_attr = GenericPath::new(None, Some(echo_cluster::ID), None);
let input = &[AttrPath::new(&wc_ep_wc_attr)]; let input = &[AttrPath::new(&wc_ep_wc_attr)];
@ -294,7 +295,7 @@ fn test_write_success() {
// - second on endpoint 1, AttWrite // - second on endpoint 1, AttWrite
let val0 = 10; let val0 = 10;
let val1 = 15; let val1 = 15;
let _ = env_logger::try_init(); init_env_logger();
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {
let _ = t.u16(tag, val0); let _ = t.u16(tag, val0);
}; };
@ -342,7 +343,7 @@ fn test_write_wc_endpoint() {
// 1 Attr Write Request // 1 Attr Write Request
// - wildcard endpoint, AttWrite // - wildcard endpoint, AttWrite
let val0 = 10; let val0 = 10;
let _ = env_logger::try_init(); init_env_logger();
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {
let _ = t.u16(tag, val0); let _ = t.u16(tag, val0);
}; };
@ -390,7 +391,7 @@ fn test_write_unsupported_fields() {
// - attribute doesn't exist and endpoint is wildcard - Silently ignore // - attribute doesn't exist and endpoint is wildcard - Silently ignore
// - cluster is wildcard - Cluster cannot be wildcard - UnsupportedCluster // - cluster is wildcard - Cluster cannot be wildcard - UnsupportedCluster
// - attribute is wildcard - Attribute cannot be wildcard - UnsupportedAttribute // - attribute is wildcard - Attribute cannot be wildcard - UnsupportedAttribute
let _ = env_logger::try_init(); init_env_logger();
let val0 = 50; let val0 = 50;
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {

View file

@ -21,6 +21,7 @@ use crate::{
commands::*, commands::*,
echo_cluster, echo_cluster,
im_engine::{matter, ImEngine}, im_engine::{matter, ImEngine},
init_env_logger,
}, },
echo_req, echo_resp, echo_req, echo_resp,
}; };
@ -39,7 +40,7 @@ fn test_invoke_cmds_success() {
// 2 echo Requests // 2 echo Requests
// - one on endpoint 0 with data 5, // - one on endpoint 0 with data 5,
// - another on endpoint 1 with data 10 // - another on endpoint 1 with data 10
let _ = env_logger::try_init(); init_env_logger();
let input = &[echo_req!(0, 5), echo_req!(1, 10)]; let input = &[echo_req!(0, 5), echo_req!(1, 10)];
let expected = &[echo_resp!(0, 10), echo_resp!(1, 30)]; let expected = &[echo_resp!(0, 10), echo_resp!(1, 30)];
@ -54,7 +55,7 @@ fn test_invoke_cmds_unsupported_fields() {
// - cluster doesn't exist and endpoint is wildcard - UnsupportedCluster // - cluster doesn't exist and endpoint is wildcard - UnsupportedCluster
// - command doesn't exist - UnsupportedCommand // - command doesn't exist - UnsupportedCommand
// - command doesn't exist and endpoint is wildcard - UnsupportedCommand // - command doesn't exist and endpoint is wildcard - UnsupportedCommand
let _ = env_logger::try_init(); init_env_logger();
let invalid_endpoint = CmdPath::new( let invalid_endpoint = CmdPath::new(
Some(2), Some(2),
@ -105,7 +106,7 @@ fn test_invoke_cmds_unsupported_fields() {
fn test_invoke_cmd_wc_endpoint_all_have_clusters() { fn test_invoke_cmd_wc_endpoint_all_have_clusters() {
// 1 echo Request with wildcard endpoint // 1 echo Request with wildcard endpoint
// should generate 2 responses from the echo clusters on both // should generate 2 responses from the echo clusters on both
let _ = env_logger::try_init(); init_env_logger();
let path = CmdPath::new( let path = CmdPath::new(
None, None,
Some(echo_cluster::ID), Some(echo_cluster::ID),
@ -120,7 +121,7 @@ fn test_invoke_cmd_wc_endpoint_all_have_clusters() {
fn test_invoke_cmd_wc_endpoint_only_1_has_cluster() { fn test_invoke_cmd_wc_endpoint_only_1_has_cluster() {
// 1 on command for on/off cluster with wildcard endpoint // 1 on command for on/off cluster with wildcard endpoint
// should generate 1 response from the on-off cluster // should generate 1 response from the on-off cluster
let _ = env_logger::try_init(); init_env_logger();
let target = CmdPath::new( let target = CmdPath::new(
None, None,

View file

@ -34,7 +34,7 @@ use matter::{
tlv::{self, ElementType, FromTLV, TLVElement, TagType, ToTLV}, tlv::{self, ElementType, FromTLV, TLVElement, TagType, ToTLV},
transport::{ transport::{
exchange::{self, Exchange}, exchange::{self, Exchange},
udp::MAX_RX_BUF_SIZE, packet::MAX_RX_BUF_SIZE,
}, },
Matter, Matter,
}; };
@ -45,6 +45,7 @@ use crate::{
attributes::*, attributes::*,
echo_cluster as echo, echo_cluster as echo,
im_engine::{matter, ImEngine, ImInput}, im_engine::{matter, ImEngine, ImInput},
init_env_logger,
}, },
}; };
@ -251,7 +252,7 @@ fn wildcard_read_resp(part: u8) -> Vec<AttrResp<'static>> {
#[test] #[test]
fn test_long_read_success() { fn test_long_read_success() {
// Read the entire attribute database, which requires 2 reads to complete // Read the entire attribute database, which requires 2 reads to complete
let _ = env_logger::try_init(); init_env_logger();
let mut mdns = DummyMdns; let mut mdns = DummyMdns;
let matter = matter(&mut mdns); let matter = matter(&mut mdns);
let mut lr = LongRead::new(&matter); let mut lr = LongRead::new(&matter);
@ -285,7 +286,7 @@ fn test_long_read_success() {
#[test] #[test]
fn test_long_read_subscription_success() { fn test_long_read_subscription_success() {
// Subscribe to the entire attribute database, which requires 2 reads to complete // Subscribe to the entire attribute database, which requires 2 reads to complete
let _ = env_logger::try_init(); init_env_logger();
let mut mdns = DummyMdns; let mut mdns = DummyMdns;
let matter = matter(&mut mdns); let matter = matter(&mut mdns);
let mut lr = LongRead::new(&matter); let mut lr = LongRead::new(&matter);

View file

@ -32,6 +32,7 @@ use crate::{
echo_cluster, echo_cluster,
handlers::{TimedInvResponse, WriteResponse}, handlers::{TimedInvResponse, WriteResponse},
im_engine::{matter, ImEngine}, im_engine::{matter, ImEngine},
init_env_logger,
}, },
echo_req, echo_resp, echo_req, echo_resp,
}; };
@ -41,7 +42,7 @@ fn test_timed_write_fail_and_success() {
// - 1 Timed Attr Write Transaction should fail due to timeout // - 1 Timed Attr Write Transaction should fail due to timeout
// - 1 Timed Attr Write Transaction should succeed // - 1 Timed Attr Write Transaction should succeed
let val0 = 10; let val0 = 10;
let _ = env_logger::try_init(); init_env_logger();
let attr_data0 = |tag, t: &mut TLVWriter| { let attr_data0 = |tag, t: &mut TLVWriter| {
let _ = t.u16(tag, val0); let _ = t.u16(tag, val0);
}; };
@ -98,7 +99,7 @@ fn test_timed_write_fail_and_success() {
#[test] #[test]
fn test_timed_cmd_success() { fn test_timed_cmd_success() {
// A timed request that works // A timed request that works
let _ = env_logger::try_init(); init_env_logger();
let input = &[echo_req!(0, 5), echo_req!(1, 10)]; let input = &[echo_req!(0, 5), echo_req!(1, 10)];
let expected = &[echo_resp!(0, 10), echo_resp!(1, 30)]; let expected = &[echo_resp!(0, 10), echo_resp!(1, 30)];
@ -115,7 +116,7 @@ fn test_timed_cmd_success() {
#[test] #[test]
fn test_timed_cmd_timeout() { fn test_timed_cmd_timeout() {
// A timed request that is executed after t imeout // A timed request that is executed after t imeout
let _ = env_logger::try_init(); init_env_logger();
let input = &[echo_req!(0, 5), echo_req!(1, 10)]; let input = &[echo_req!(0, 5), echo_req!(1, 10)];
ImEngine::new_with_timed_commands( ImEngine::new_with_timed_commands(
@ -131,7 +132,7 @@ fn test_timed_cmd_timeout() {
#[test] #[test]
fn test_timed_cmd_timedout_mismatch() { fn test_timed_cmd_timedout_mismatch() {
// A timed request with timeout mismatch // A timed request with timeout mismatch
let _ = env_logger::try_init(); init_env_logger();
let input = &[echo_req!(0, 5), echo_req!(1, 10)]; let input = &[echo_req!(0, 5), echo_req!(1, 10)];
ImEngine::new_with_timed_commands( ImEngine::new_with_timed_commands(

View file

@ -24,6 +24,9 @@ use matter::interaction_model::core::Transaction;
use matter::transport::exchange::Exchange; use matter::transport::exchange::Exchange;
use matter::transport::exchange::ExchangeCtx; use matter::transport::exchange::ExchangeCtx;
use matter::transport::network::Address; use matter::transport::network::Address;
use matter::transport::network::IpAddr;
use matter::transport::network::Ipv4Addr;
use matter::transport::network::SocketAddr;
use matter::transport::packet::Packet; use matter::transport::packet::Packet;
use matter::transport::packet::MAX_RX_BUF_SIZE; use matter::transport::packet::MAX_RX_BUF_SIZE;
use matter::transport::packet::MAX_TX_BUF_SIZE; use matter::transport::packet::MAX_TX_BUF_SIZE;
@ -31,8 +34,6 @@ use matter::transport::proto_ctx::ProtoCtx;
use matter::transport::session::SessionMgr; use matter::transport::session::SessionMgr;
use matter::utils::epoch::dummy_epoch; use matter::utils::epoch::dummy_epoch;
use matter::utils::rand::dummy_rand; use matter::utils::rand::dummy_rand;
use std::net::Ipv4Addr;
use std::net::SocketAddr;
struct Node { struct Node {
pub endpoint: u16, pub endpoint: u16,
@ -95,7 +96,7 @@ fn handle_data(action: OpCode, data_in: &[u8], data_out: &mut [u8]) -> (DataMode
.get_or_add( .get_or_add(
0, 0,
Address::Udp(SocketAddr::new( Address::Udp(SocketAddr::new(
std::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
5542, 5542,
)), )),
None, None,