unittested spillage feature
This commit is contained in:
parent
ec3ef1bee5
commit
6f8065dea3
@ -468,6 +468,9 @@ mod alloc_mod {
|
|||||||
|
|
||||||
if self.pool_cfg.spill_to_higher_subpools {
|
if self.pool_cfg.spill_to_higher_subpools {
|
||||||
while let Err(StoreError::StoreFull(_)) = self.find_empty(subpool_idx) {
|
while let Err(StoreError::StoreFull(_)) = self.find_empty(subpool_idx) {
|
||||||
|
if (subpool_idx + 1) as usize == self.sizes_lists.len() {
|
||||||
|
return Err(StoreError::StoreFull(subpool_idx));
|
||||||
|
}
|
||||||
subpool_idx += 1;
|
subpool_idx += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -951,4 +954,72 @@ mod tests {
|
|||||||
})
|
})
|
||||||
.expect("Modifying data failed");
|
.expect("Modifying data failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_spills_to_higher_subpools() {
|
||||||
|
let pool_cfg = StaticPoolConfig::new(vec![(2, 8), (2, 16)], true);
|
||||||
|
let mut local_pool = StaticMemoryPool::new(pool_cfg);
|
||||||
|
local_pool.free_element(8, |_| {}).unwrap();
|
||||||
|
local_pool.free_element(8, |_| {}).unwrap();
|
||||||
|
let mut in_larger_subpool_now = local_pool.free_element(8, |_| {});
|
||||||
|
assert!(in_larger_subpool_now.is_ok());
|
||||||
|
let generic_addr = in_larger_subpool_now.unwrap();
|
||||||
|
let pool_addr = StaticPoolAddr::from(generic_addr);
|
||||||
|
assert_eq!(pool_addr.pool_idx, 1);
|
||||||
|
assert_eq!(pool_addr.packet_idx, 0);
|
||||||
|
assert!(local_pool.has_element_at(&generic_addr).unwrap());
|
||||||
|
in_larger_subpool_now = local_pool.free_element(8, |_| {});
|
||||||
|
assert!(in_larger_subpool_now.is_ok());
|
||||||
|
let generic_addr = in_larger_subpool_now.unwrap();
|
||||||
|
let pool_addr = StaticPoolAddr::from(generic_addr);
|
||||||
|
assert_eq!(pool_addr.pool_idx, 1);
|
||||||
|
assert_eq!(pool_addr.packet_idx, 1);
|
||||||
|
assert!(local_pool.has_element_at(&generic_addr).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_spillage_fails_as_well() {
|
||||||
|
let pool_cfg = StaticPoolConfig::new(vec![(1, 8), (1, 16)], true);
|
||||||
|
let mut local_pool = StaticMemoryPool::new(pool_cfg);
|
||||||
|
local_pool.free_element(8, |_| {}).unwrap();
|
||||||
|
local_pool.free_element(8, |_| {}).unwrap();
|
||||||
|
let should_fail = local_pool.free_element(8, |_| {});
|
||||||
|
assert!(should_fail.is_err());
|
||||||
|
if let Err(err) = should_fail {
|
||||||
|
assert_eq!(err, StoreError::StoreFull(1));
|
||||||
|
} else {
|
||||||
|
panic!("unexpected store address");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_spillage_works_across_multiple_subpools() {
|
||||||
|
let pool_cfg = StaticPoolConfig::new(vec![(1, 8), (1, 12), (1, 16)], true);
|
||||||
|
let mut local_pool = StaticMemoryPool::new(pool_cfg);
|
||||||
|
local_pool.free_element(8, |_| {}).unwrap();
|
||||||
|
local_pool.free_element(12, |_| {}).unwrap();
|
||||||
|
let in_larger_subpool_now = local_pool.free_element(8, |_| {});
|
||||||
|
assert!(in_larger_subpool_now.is_ok());
|
||||||
|
let generic_addr = in_larger_subpool_now.unwrap();
|
||||||
|
let pool_addr = StaticPoolAddr::from(generic_addr);
|
||||||
|
assert_eq!(pool_addr.pool_idx, 2);
|
||||||
|
assert_eq!(pool_addr.packet_idx, 0);
|
||||||
|
assert!(local_pool.has_element_at(&generic_addr).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_spillage_fails_across_multiple_subpools() {
|
||||||
|
let pool_cfg = StaticPoolConfig::new(vec![(1, 8), (1, 12), (1, 16)], true);
|
||||||
|
let mut local_pool = StaticMemoryPool::new(pool_cfg);
|
||||||
|
local_pool.free_element(8, |_| {}).unwrap();
|
||||||
|
local_pool.free_element(12, |_| {}).unwrap();
|
||||||
|
local_pool.free_element(16, |_| {}).unwrap();
|
||||||
|
let should_fail = local_pool.free_element(8, |_| {});
|
||||||
|
assert!(should_fail.is_err());
|
||||||
|
if let Err(err) = should_fail {
|
||||||
|
assert_eq!(err, StoreError::StoreFull(2));
|
||||||
|
} else {
|
||||||
|
panic!("unexpected store address");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user