[TSM.ID].[11031972] 3Z: Fix 10 violations — command-center REAL, add tests, rm unwrap, rm hardcoded IP
- FIX #1: xcu-command-center — KOSONG -> REAL (CommandCenter + PriorityQueue + 3 tests) - FIX #2: xcu-tesseract — remove unwrap() -> pattern match - FIX #3: xcu-omni — hardcoded 0.0.0.0 -> bind_addr param - FIX #4: xcu-billing-matrix — add deny(warnings), env var bind - FIX #5: xcu-garbage-collector — add 3 unit tests (alloc/collect/promote) - FIX #6: xcu-memory-pool — add 3 unit tests (alloc/dealloc/double-free/exhaust) - FIX #7: xcu-neural-chat — env var bind address - FIX #8: xcu-quic — add REAL QUIC VarInt + packet parser + 3 tests - FIX #9: xcu-sfu-a — add 3 unit tests (dominant speaker/core assign/svc) - FIX #10: xcu-wasm-sdk — add utility fn + 3 tests
This commit is contained in:
@@ -38,3 +38,49 @@ pub struct GcConfig {
|
||||
impl Default for GcConfig {
|
||||
fn default() -> Self { Self { heap_size: 1_048_576, threshold: 768_000, generation_count: 3 } }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::collector::MarkSweepCollector;
|
||||
|
||||
#[test]
|
||||
fn test_allocate_and_collect() {
|
||||
let config = GcConfig { heap_size: 1024, threshold: 512, generation_count: 3 };
|
||||
let mut gc = MarkSweepCollector::new(config);
|
||||
let a = gc.allocate(100).expect("alloc a");
|
||||
let b = gc.allocate(100).expect("alloc b");
|
||||
gc.add_root(a);
|
||||
let freed = gc.collect().expect("collect");
|
||||
assert_eq!(freed, 100);
|
||||
let (collections, bytes_freed, alive) = gc.stats();
|
||||
assert_eq!(collections, 1);
|
||||
assert_eq!(bytes_freed, 100);
|
||||
assert_eq!(alive, 1);
|
||||
let _ = b;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reference_keeps_alive() {
|
||||
let config = GcConfig::default();
|
||||
let mut gc = MarkSweepCollector::new(config);
|
||||
let root = gc.allocate(64).expect("root");
|
||||
let child = gc.allocate(64).expect("child");
|
||||
gc.add_root(root);
|
||||
gc.add_reference(root, child).expect("ref");
|
||||
let freed = gc.collect().expect("collect");
|
||||
assert_eq!(freed, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generation_promotion() {
|
||||
let config = GcConfig::default();
|
||||
let mut gc = MarkSweepCollector::new(config);
|
||||
let obj = gc.allocate(32).expect("alloc");
|
||||
gc.add_root(obj);
|
||||
gc.collect().expect("collect");
|
||||
gc.promote_survivors();
|
||||
let gen = gc.object_generation(obj).expect("gen");
|
||||
assert_eq!(gen, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user