everything seems to work
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
c996b1d5aa
commit
5d7672e9c2
@ -196,9 +196,40 @@ impl Error for StoreError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait PoolProvider {
|
||||||
|
/// Add new data to the pool. The provider should attempt to reserve a memory block with the
|
||||||
|
/// appropriate size and then copy the given data to the block. Yields a [StoreAddr] which can
|
||||||
|
/// be used to access the data stored in the pool
|
||||||
|
fn add(&mut self, data: &[u8]) -> Result<StoreAddr, StoreError>;
|
||||||
|
|
||||||
|
/// The provider should attempt to reserve a free memory block with the appropriate size and
|
||||||
|
/// then return a mutable reference to it. Yields a [StoreAddr] which can be used to access
|
||||||
|
/// the data stored in the pool
|
||||||
|
fn free_element(&mut self, len: usize) -> Result<(StoreAddr, &mut [u8]), StoreError>;
|
||||||
|
|
||||||
|
/// Modify data added previously using a given [StoreAddr] by yielding a mutable reference
|
||||||
|
/// to it
|
||||||
|
fn modify(&mut self, addr: &StoreAddr) -> Result<&mut [u8], StoreError>;
|
||||||
|
|
||||||
|
/// Read data by yielding a read-only reference given a [StoreAddr]
|
||||||
|
fn read(&self, addr: &StoreAddr) -> Result<&[u8], StoreError>;
|
||||||
|
|
||||||
|
/// Delete data inside the pool given a [StoreAddr]
|
||||||
|
fn delete(&mut self, addr: StoreAddr) -> Result<(), StoreError>;
|
||||||
|
fn has_element_at(&self, addr: &StoreAddr) -> Result<bool, StoreError>;
|
||||||
|
|
||||||
|
/// Retrieve the length of the data at the given store address.
|
||||||
|
fn len_of_data(&self, addr: &StoreAddr) -> Result<usize, StoreError> {
|
||||||
|
if !self.has_element_at(addr)? {
|
||||||
|
return Err(StoreError::DataDoesNotExist(*addr));
|
||||||
|
}
|
||||||
|
Ok(self.read(addr)?.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
mod alloc_mod {
|
mod alloc_mod {
|
||||||
use super::StaticPoolAddr;
|
use super::{StaticPoolAddr, PoolProvider};
|
||||||
use crate::pool::{NumBlocks, StoreAddr, StoreError, StoreIdError};
|
use crate::pool::{NumBlocks, StoreAddr, StoreError, StoreIdError};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
@ -208,7 +239,7 @@ mod alloc_mod {
|
|||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub type ShareablePoolProvider = Box<dyn PoolProvider + Send + Sync>;
|
pub type ShareablePoolProvider = Box<dyn PoolProviderWithGuards + Send + Sync>;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub type SharedPool = Arc<RwLock<ShareablePoolProvider>>;
|
pub type SharedPool = Arc<RwLock<ShareablePoolProvider>>;
|
||||||
|
|
||||||
@ -223,13 +254,13 @@ mod alloc_mod {
|
|||||||
/// * `cfg`: Vector of tuples which represent a subpool. The first entry in the tuple specifies the
|
/// * `cfg`: Vector of tuples which represent a subpool. The first entry in the tuple specifies the
|
||||||
/// number of memory blocks in the subpool, the second entry the size of the blocks
|
/// number of memory blocks in the subpool, the second entry the size of the blocks
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PoolCfg {
|
pub struct StaticPoolConfig {
|
||||||
cfg: Vec<(NumBlocks, usize)>,
|
cfg: Vec<(NumBlocks, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PoolCfg {
|
impl StaticPoolConfig {
|
||||||
pub fn new(cfg: Vec<(NumBlocks, usize)>) -> Self {
|
pub fn new(cfg: Vec<(NumBlocks, usize)>) -> Self {
|
||||||
PoolCfg { cfg }
|
StaticPoolConfig { cfg }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cfg(&self) -> &Vec<(NumBlocks, usize)> {
|
pub fn cfg(&self) -> &Vec<(NumBlocks, usize)> {
|
||||||
@ -309,34 +340,7 @@ mod alloc_mod {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PoolProvider {
|
pub trait PoolProviderWithGuards: PoolProvider {
|
||||||
/// Add new data to the pool. The provider should attempt to reserve a memory block with the
|
|
||||||
/// appropriate size and then copy the given data to the block. Yields a [StoreAddr] which can
|
|
||||||
/// be used to access the data stored in the pool
|
|
||||||
fn add(&mut self, data: &[u8]) -> Result<StoreAddr, StoreError>;
|
|
||||||
|
|
||||||
/// The provider should attempt to reserve a free memory block with the appropriate size and
|
|
||||||
/// then return a mutable reference to it. Yields a [StoreAddr] which can be used to access
|
|
||||||
/// the data stored in the pool
|
|
||||||
fn free_element(&mut self, len: usize) -> Result<(StoreAddr, &mut [u8]), StoreError>;
|
|
||||||
|
|
||||||
/// Modify data added previously using a given [StoreAddr] by yielding a mutable reference
|
|
||||||
/// to it
|
|
||||||
fn modify(&mut self, addr: &StoreAddr) -> Result<&mut [u8], StoreError>;
|
|
||||||
|
|
||||||
/// This function behaves like [Self::modify], but consumes the provided address and returns a
|
|
||||||
/// RAII conformant guard object.
|
|
||||||
///
|
|
||||||
/// Unless the guard [PoolRwGuard::release] method is called, the data for the
|
|
||||||
/// given address will be deleted automatically when the guard is dropped.
|
|
||||||
/// This can prevent memory leaks. Users can read (and modify) the data and release the guard
|
|
||||||
/// if the data in the store is valid for further processing. If the data is faulty, no
|
|
||||||
/// manual deletion is necessary when returning from a processing function prematurely.
|
|
||||||
fn modify_with_guard(&mut self, addr: StoreAddr) -> PoolRwGuard;
|
|
||||||
|
|
||||||
/// Read data by yielding a read-only reference given a [StoreAddr]
|
|
||||||
fn read(&self, addr: &StoreAddr) -> Result<&[u8], StoreError>;
|
|
||||||
|
|
||||||
/// This function behaves like [Self::read], but consumes the provided address and returns a
|
/// This function behaves like [Self::read], but consumes the provided address and returns a
|
||||||
/// RAII conformant guard object.
|
/// RAII conformant guard object.
|
||||||
///
|
///
|
||||||
@ -347,23 +351,21 @@ mod alloc_mod {
|
|||||||
/// manual deletion is necessary when returning from a processing function prematurely.
|
/// manual deletion is necessary when returning from a processing function prematurely.
|
||||||
fn read_with_guard(&mut self, addr: StoreAddr) -> PoolGuard;
|
fn read_with_guard(&mut self, addr: StoreAddr) -> PoolGuard;
|
||||||
|
|
||||||
/// Delete data inside the pool given a [StoreAddr]
|
/// This function behaves like [Self::modify], but consumes the provided address and returns a
|
||||||
fn delete(&mut self, addr: StoreAddr) -> Result<(), StoreError>;
|
/// RAII conformant guard object.
|
||||||
fn has_element_at(&self, addr: &StoreAddr) -> Result<bool, StoreError>;
|
///
|
||||||
|
/// Unless the guard [PoolRwGuard::release] method is called, the data for the
|
||||||
/// Retrieve the length of the data at the given store address.
|
/// given address will be deleted automatically when the guard is dropped.
|
||||||
fn len_of_data(&self, addr: &StoreAddr) -> Result<usize, StoreError> {
|
/// This can prevent memory leaks. Users can read (and modify) the data and release the guard
|
||||||
if !self.has_element_at(addr)? {
|
/// if the data in the store is valid for further processing. If the data is faulty, no
|
||||||
return Err(StoreError::DataDoesNotExist(*addr));
|
/// manual deletion is necessary when returning from a processing function prematurely.
|
||||||
}
|
fn modify_with_guard(&mut self, addr: StoreAddr) -> PoolRwGuard;
|
||||||
Ok(self.read(addr)?.len())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pool implementation providing sub-pools with fixed size memory blocks. More details in
|
/// Pool implementation providing sub-pools with fixed size memory blocks. More details in
|
||||||
/// the [module documentation][crate::pool]
|
/// the [module documentation][crate::pool]
|
||||||
pub struct StaticMemoryPool {
|
pub struct StaticMemoryPool {
|
||||||
pool_cfg: PoolCfg,
|
pool_cfg: StaticPoolConfig,
|
||||||
pool: Vec<Vec<u8>>,
|
pool: Vec<Vec<u8>>,
|
||||||
sizes_lists: Vec<Vec<PoolSize>>,
|
sizes_lists: Vec<Vec<PoolSize>>,
|
||||||
}
|
}
|
||||||
@ -371,7 +373,7 @@ mod alloc_mod {
|
|||||||
impl StaticMemoryPool {
|
impl StaticMemoryPool {
|
||||||
/// Create a new local pool from the [given configuration][PoolCfg]. This function will sanitize
|
/// Create a new local pool from the [given configuration][PoolCfg]. This function will sanitize
|
||||||
/// the given configuration as well.
|
/// the given configuration as well.
|
||||||
pub fn new(mut cfg: PoolCfg) -> StaticMemoryPool {
|
pub fn new(mut cfg: StaticPoolConfig) -> StaticMemoryPool {
|
||||||
let subpools_num = cfg.sanitize();
|
let subpools_num = cfg.sanitize();
|
||||||
let mut local_pool = StaticMemoryPool {
|
let mut local_pool = StaticMemoryPool {
|
||||||
pool_cfg: cfg,
|
pool_cfg: cfg,
|
||||||
@ -503,10 +505,6 @@ mod alloc_mod {
|
|||||||
Ok(block)
|
Ok(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_with_guard(&mut self, addr: StoreAddr) -> PoolRwGuard {
|
|
||||||
PoolRwGuard::new(self, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read(&self, addr: &StoreAddr) -> Result<&[u8], StoreError> {
|
fn read(&self, addr: &StoreAddr) -> Result<&[u8], StoreError> {
|
||||||
let addr = StaticPoolAddr::from(*addr);
|
let addr = StaticPoolAddr::from(*addr);
|
||||||
let curr_size = self.addr_check(&addr)?;
|
let curr_size = self.addr_check(&addr)?;
|
||||||
@ -516,10 +514,6 @@ mod alloc_mod {
|
|||||||
Ok(block)
|
Ok(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_with_guard(&mut self, addr: StoreAddr) -> PoolGuard {
|
|
||||||
PoolGuard::new(self, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete(&mut self, addr: StoreAddr) -> Result<(), StoreError> {
|
fn delete(&mut self, addr: StoreAddr) -> Result<(), StoreError> {
|
||||||
let addr = StaticPoolAddr::from(addr);
|
let addr = StaticPoolAddr::from(addr);
|
||||||
self.addr_check(&addr)?;
|
self.addr_check(&addr)?;
|
||||||
@ -545,34 +539,43 @@ mod alloc_mod {
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl PoolProviderWithGuards for StaticMemoryPool {
|
||||||
|
fn modify_with_guard(&mut self, addr: StoreAddr) -> PoolRwGuard {
|
||||||
|
PoolRwGuard::new(self, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_with_guard(&mut self, addr: StoreAddr) -> PoolGuard {
|
||||||
|
PoolGuard::new(self, addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::pool::{
|
use crate::pool::{
|
||||||
PoolCfg, PoolGuard, PoolProvider, PoolRwGuard, StaticMemoryPool, StaticPoolAddr, StoreAddr,
|
PoolGuard, PoolProvider, PoolRwGuard, StaticMemoryPool, StaticPoolAddr, StaticPoolConfig,
|
||||||
StoreError, StoreIdError, POOL_MAX_SIZE,
|
StoreAddr, StoreError, StoreIdError, POOL_MAX_SIZE,
|
||||||
};
|
};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
fn basic_small_pool() -> StaticMemoryPool {
|
fn basic_small_pool() -> StaticMemoryPool {
|
||||||
// 4 buckets of 4 bytes, 2 of 8 bytes and 1 of 16 bytes
|
// 4 buckets of 4 bytes, 2 of 8 bytes and 1 of 16 bytes
|
||||||
let pool_cfg = PoolCfg::new(vec![(4, 4), (2, 8), (1, 16)]);
|
let pool_cfg = StaticPoolConfig::new(vec![(4, 4), (2, 8), (1, 16)]);
|
||||||
StaticMemoryPool::new(pool_cfg)
|
StaticMemoryPool::new(pool_cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cfg() {
|
fn test_cfg() {
|
||||||
// Values where number of buckets is 0 or size is too large should be removed
|
// Values where number of buckets is 0 or size is too large should be removed
|
||||||
let mut pool_cfg = PoolCfg::new(vec![(0, 0), (1, 0), (2, POOL_MAX_SIZE)]);
|
let mut pool_cfg = StaticPoolConfig::new(vec![(0, 0), (1, 0), (2, POOL_MAX_SIZE)]);
|
||||||
pool_cfg.sanitize();
|
pool_cfg.sanitize();
|
||||||
assert_eq!(*pool_cfg.cfg(), vec![(1, 0)]);
|
assert_eq!(*pool_cfg.cfg(), vec![(1, 0)]);
|
||||||
// Entries should be ordered according to bucket size
|
// Entries should be ordered according to bucket size
|
||||||
pool_cfg = PoolCfg::new(vec![(16, 6), (32, 3), (8, 12)]);
|
pool_cfg = StaticPoolConfig::new(vec![(16, 6), (32, 3), (8, 12)]);
|
||||||
pool_cfg.sanitize();
|
pool_cfg.sanitize();
|
||||||
assert_eq!(*pool_cfg.cfg(), vec![(32, 3), (16, 6), (8, 12)]);
|
assert_eq!(*pool_cfg.cfg(), vec![(32, 3), (16, 6), (8, 12)]);
|
||||||
// Unstable sort is used, so order of entries with same block length should not matter
|
// Unstable sort is used, so order of entries with same block length should not matter
|
||||||
pool_cfg = PoolCfg::new(vec![(12, 12), (14, 16), (10, 12)]);
|
pool_cfg = StaticPoolConfig::new(vec![(12, 12), (14, 16), (10, 12)]);
|
||||||
pool_cfg.sanitize();
|
pool_cfg.sanitize();
|
||||||
assert!(
|
assert!(
|
||||||
*pool_cfg.cfg() == vec![(12, 12), (10, 12), (14, 16)]
|
*pool_cfg.cfg() == vec![(12, 12), (10, 12), (14, 16)]
|
||||||
|
@ -712,7 +712,7 @@ pub mod alloc_mod {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::pool::{
|
use crate::pool::{
|
||||||
PoolCfg, PoolProvider, StaticMemoryPool, StaticPoolAddr, StoreAddr, StoreError,
|
PoolProvider, StaticMemoryPool, StaticPoolAddr, StaticPoolConfig, StoreAddr, StoreError,
|
||||||
};
|
};
|
||||||
use alloc::collections::btree_map::Range;
|
use alloc::collections::btree_map::Range;
|
||||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
|
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
|
||||||
@ -808,7 +808,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reset() {
|
fn reset() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
@ -960,7 +960,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn release_basic() {
|
fn release_basic() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
@ -1023,7 +1023,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn release_multi_with_same_time() {
|
fn release_multi_with_same_time() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
@ -1080,7 +1080,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn release_with_scheduler_disabled() {
|
fn release_with_scheduler_disabled() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
@ -1148,7 +1148,7 @@ mod tests {
|
|||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None);
|
let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None);
|
||||||
|
|
||||||
@ -1194,7 +1194,7 @@ mod tests {
|
|||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
|
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
let tc = scheduled_tc(UnixTimestamp::new_only_seconds(100), &mut buf);
|
let tc = scheduled_tc(UnixTimestamp::new_only_seconds(100), &mut buf);
|
||||||
@ -1240,7 +1240,7 @@ mod tests {
|
|||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
|
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
let tc = wrong_tc_service(UnixTimestamp::new_only_seconds(100), &mut buf);
|
let tc = wrong_tc_service(UnixTimestamp::new_only_seconds(100), &mut buf);
|
||||||
@ -1261,7 +1261,7 @@ mod tests {
|
|||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
|
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
let tc = wrong_tc_subservice(UnixTimestamp::new_only_seconds(100), &mut buf);
|
let tc = wrong_tc_subservice(UnixTimestamp::new_only_seconds(100), &mut buf);
|
||||||
@ -1281,7 +1281,7 @@ mod tests {
|
|||||||
fn insert_wrapped_tc_faulty_app_data() {
|
fn insert_wrapped_tc_faulty_app_data() {
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let tc = invalid_time_tagged_cmd();
|
let tc = invalid_time_tagged_cmd();
|
||||||
let insert_res = scheduler.insert_wrapped_tc::<cds::TimeProvider>(&tc, &mut pool);
|
let insert_res = scheduler.insert_wrapped_tc::<cds::TimeProvider>(&tc, &mut pool);
|
||||||
assert!(insert_res.is_err());
|
assert!(insert_res.is_err());
|
||||||
@ -1296,7 +1296,7 @@ mod tests {
|
|||||||
fn insert_doubly_wrapped_time_tagged_cmd() {
|
fn insert_doubly_wrapped_time_tagged_cmd() {
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut buf: [u8; 64] = [0; 64];
|
let mut buf: [u8; 64] = [0; 64];
|
||||||
let tc = double_wrapped_time_tagged_tc(UnixTimestamp::new_only_seconds(50), &mut buf);
|
let tc = double_wrapped_time_tagged_tc(UnixTimestamp::new_only_seconds(50), &mut buf);
|
||||||
let insert_res = scheduler.insert_wrapped_tc::<cds::TimeProvider>(&tc, &mut pool);
|
let insert_res = scheduler.insert_wrapped_tc::<cds::TimeProvider>(&tc, &mut pool);
|
||||||
@ -1332,7 +1332,7 @@ mod tests {
|
|||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
|
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
|
|
||||||
@ -1352,7 +1352,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_store_error_propagation_release() {
|
fn test_store_error_propagation_release() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
@ -1386,7 +1386,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_store_error_propagation_reset() {
|
fn test_store_error_propagation_reset() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
@ -1410,7 +1410,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_delete_by_req_id_simple_retrieve_addr() {
|
fn test_delete_by_req_id_simple_retrieve_addr() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
@ -1429,7 +1429,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_delete_by_req_id_simple_delete_all() {
|
fn test_delete_by_req_id_simple_delete_all() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
@ -1448,7 +1448,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_delete_by_req_id_complex() {
|
fn test_delete_by_req_id_complex() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
@ -1495,7 +1495,7 @@ mod tests {
|
|||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
|
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(1, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(1, 64)]));
|
||||||
|
|
||||||
let mut buf: [u8; 32] = [0; 32];
|
let mut buf: [u8; 32] = [0; 32];
|
||||||
// Store is full after this.
|
// Store is full after this.
|
||||||
@ -1534,7 +1534,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_time_window_retrieval_select_all() {
|
fn test_time_window_retrieval_select_all() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
@ -1565,7 +1565,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_time_window_retrieval_select_from_stamp() {
|
fn test_time_window_retrieval_select_from_stamp() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
@ -1596,7 +1596,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_time_window_retrieval_select_to_time() {
|
fn test_time_window_retrieval_select_to_time() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
@ -1627,7 +1627,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_time_window_retrieval_select_from_time_to_time() {
|
fn test_time_window_retrieval_select_from_time_to_time() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
@ -1662,7 +1662,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deletion_all() {
|
fn test_deletion_all() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
@ -1689,7 +1689,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deletion_from_start_time() {
|
fn test_deletion_from_start_time() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
@ -1710,7 +1710,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deletion_to_end_time() {
|
fn test_deletion_to_end_time() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let cmd_0_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
let cmd_0_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
@ -1732,7 +1732,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deletion_from_start_time_to_end_time() {
|
fn test_deletion_from_start_time_to_end_time() {
|
||||||
let mut pool = StaticMemoryPool::new(PoolCfg::new(vec![(10, 32), (5, 64)]));
|
let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)]));
|
||||||
let mut scheduler =
|
let mut scheduler =
|
||||||
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5));
|
||||||
let cmd_out_of_range_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
let cmd_out_of_range_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50);
|
||||||
|
@ -1325,7 +1325,7 @@ mod std_mod {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::pool::{PoolCfg, StaticMemoryPool};
|
use crate::pool::{StaticMemoryPool, StaticPoolConfig};
|
||||||
use crate::pus::tests::CommonTmInfo;
|
use crate::pus::tests::CommonTmInfo;
|
||||||
use crate::pus::verification::{
|
use crate::pus::verification::{
|
||||||
EcssTmSenderCore, EcssTmtcError, FailParams, FailParamsWithStep, RequestId, TcStateNone,
|
EcssTmSenderCore, EcssTmtcError, FailParams, FailParamsWithStep, RequestId, TcStateNone,
|
||||||
@ -1487,7 +1487,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mpsc_verif_send_sync() {
|
fn test_mpsc_verif_send_sync() {
|
||||||
let pool = StaticMemoryPool::new(PoolCfg::new(vec![(8, 8)]));
|
let pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(8, 8)]));
|
||||||
let tm_store = Box::new(pool);
|
let tm_store = Box::new(pool);
|
||||||
let shared_tm_store = SharedTmStore::new(tm_store);
|
let shared_tm_store = SharedTmStore::new(tm_store);
|
||||||
let (tx, _) = mpsc::channel();
|
let (tx, _) = mpsc::channel();
|
||||||
@ -2154,7 +2154,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
// TODO: maybe a bit more extensive testing, all I have time for right now
|
// TODO: maybe a bit more extensive testing, all I have time for right now
|
||||||
fn test_seq_count_increment() {
|
fn test_seq_count_increment() {
|
||||||
let pool_cfg = PoolCfg::new(vec![(10, 32), (10, 64), (10, 128), (10, 1024)]);
|
let pool_cfg = StaticPoolConfig::new(vec![(10, 32), (10, 64), (10, 128), (10, 1024)]);
|
||||||
let tm_pool = Box::new(StaticMemoryPool::new(pool_cfg.clone()));
|
let tm_pool = Box::new(StaticMemoryPool::new(pool_cfg.clone()));
|
||||||
let shared_tm_store = SharedTmStore::new(tm_pool);
|
let shared_tm_store = SharedTmStore::new(tm_pool);
|
||||||
let shared_tm_pool = shared_tm_store.clone_backing_pool();
|
let shared_tm_pool = shared_tm_store.clone_backing_pool();
|
||||||
|
@ -29,7 +29,7 @@ use satrs_core::event_man::{
|
|||||||
};
|
};
|
||||||
use satrs_core::events::EventU32;
|
use satrs_core::events::EventU32;
|
||||||
use satrs_core::hk::HkRequest;
|
use satrs_core::hk::HkRequest;
|
||||||
use satrs_core::pool::{PoolCfg, StaticMemoryPool};
|
use satrs_core::pool::{StaticMemoryPool, StaticPoolConfig};
|
||||||
use satrs_core::pus::event_man::{
|
use satrs_core::pus::event_man::{
|
||||||
DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken,
|
DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken,
|
||||||
PusEventDispatcher,
|
PusEventDispatcher,
|
||||||
@ -68,7 +68,7 @@ use std::time::Duration;
|
|||||||
fn main() {
|
fn main() {
|
||||||
setup_logger().expect("setting up logging with fern failed");
|
setup_logger().expect("setting up logging with fern failed");
|
||||||
println!("Running OBSW example");
|
println!("Running OBSW example");
|
||||||
let tm_pool = StaticMemoryPool::new(PoolCfg::new(vec![
|
let tm_pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![
|
||||||
(30, 32),
|
(30, 32),
|
||||||
(15, 64),
|
(15, 64),
|
||||||
(15, 128),
|
(15, 128),
|
||||||
@ -78,7 +78,7 @@ fn main() {
|
|||||||
]));
|
]));
|
||||||
let shared_tm_store = SharedTmStore::new(Box::new(tm_pool));
|
let shared_tm_store = SharedTmStore::new(Box::new(tm_pool));
|
||||||
let tm_store_event = shared_tm_store.clone();
|
let tm_store_event = shared_tm_store.clone();
|
||||||
let tc_pool = StaticMemoryPool::new(PoolCfg::new(vec![
|
let tc_pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![
|
||||||
(30, 32),
|
(30, 32),
|
||||||
(15, 64),
|
(15, 64),
|
||||||
(15, 128),
|
(15, 128),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user