Skip to content

Commit 9237719

Browse files
CYFS3Rbb666
authored andcommitted
[docs][utest]:Add standardized utest documentation block for slab_tc
1 parent b532938 commit 9237719

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/utest/slab_tc.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2021-10-14 tyx the first version
9+
* 2025-11-13 CYFS Add standardized utest documentation block
10+
*/
11+
12+
/**
13+
* Test Case Name: Kernel Core Slab Memory Management Test
14+
*
15+
* Test Objectives:
16+
* - Validate RT-Thread slab allocator behavior under deterministic and randomized workloads
17+
* - Verify core APIs: rt_slab_init, rt_slab_alloc, rt_slab_free, rt_slab_realloc, rt_slab_detach
18+
*
19+
* Test Scenarios:
20+
* - **Scenario 1 (Random Allocation Stress Test / slab_alloc_test):**
21+
* 1. Initialize a 1 MB slab pool backed by dynamic memory.
22+
* 2. Perform mixed random-sized allocations with ~60% allocation probability.
23+
* 3. Reclaim half the outstanding allocations when the pool exhausts resources.
24+
* 4. Validate slab payload integrity using magic bytes before every free.
25+
* 5. Drain remaining allocations, ensuring list bookkeeping reaches zero.
26+
* - **Scenario 2 (Random Reallocation Stress Test / slab_realloc_test):**
27+
* 1. Initialize the slab pool and allocate a context table within it.
28+
* 2. Randomly reallocate tracked blocks with size adjustments between 0 and 5 units.
29+
* 3. On realloc failures, free random existing blocks to relieve pressure.
30+
* 4. Confirm in-place data integrity after size changes using magic byte comparisons.
31+
* 5. Reallocate to zero size to validate free semantics, then release all resources.
32+
*
33+
* Verification Metrics:
34+
* - **Scenario 1:** Allocations return aligned pointers; data regions retain magic patterns until freed; head.count returns to 0 before teardown.
35+
* - **Scenario 2:** Reallocated blocks preserve prior data up to the min(old, new) length; zero-size realloc frees memory; final sweep leaves no outstanding allocations.
36+
*
37+
* Dependencies:
38+
* - Requires dynamic memory support (rt_malloc/rt_free) to back the slab pool.
39+
* - `RT_USING_UTEST` enabled with test registered under `core.slab`.
40+
* - System tick (`rt_tick_get`) and random number generator (`rand`) available for timing and stochastic operations.
41+
*
42+
* Expected Results:
43+
* - Test case completes without assertion failures.
44+
* - Console prints progress markers (`#`) during stress loops and `[ PASSED ] [ result ] testcase (core.slab)` when run via `utest_run core.slab`.
945
*/
1046

1147
#include <rtthread.h>

0 commit comments

Comments
 (0)