Skip to content

Commit c6a1a13

Browse files
another test
1 parent 03dcc2f commit c6a1a13

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/src/helpers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ static inline void instrumented_allocator_new(instrumented_allocator_t* const se
147147
self->count_free = 0U;
148148
}
149149

150+
/// Resets the counters and generates a new canary.
151+
/// Will crash if there are outstanding allocations.
152+
static inline void instrumented_allocator_reset(instrumented_allocator_t* const self)
153+
{
154+
TEST_PANIC_UNLESS(self->allocated_fragments == 0U);
155+
TEST_PANIC_UNLESS(self->allocated_bytes == 0U);
156+
instrumented_allocator_new(self);
157+
}
158+
150159
static inline udpard_mem_resource_t instrumented_allocator_make_resource(const instrumented_allocator_t* const self)
151160
{
152161
return (udpard_mem_resource_t){ .user = (void*)self,

tests/src/test_intrusive_rx.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,48 @@ static void test_rx_fragment_tree_update_a(void)
8787
TEST_ASSERT_EQUAL_size_t(1, alloc_frag.count_free);
8888
TEST_ASSERT_EQUAL_size_t(0, alloc_payload.count_free); // bc payload empty
8989
}
90+
91+
instrumented_allocator_reset(&alloc_frag);
92+
instrumented_allocator_reset(&alloc_payload);
93+
94+
// Non-empty payload test with zero extent.
95+
{
96+
udpard_tree_t* root = NULL;
97+
size_t cov = 0;
98+
rx_fragment_tree_update_result_t res = rx_fragment_tree_not_done;
99+
//
100+
res = rx_fragment_tree_update(&root, //
101+
mem_frag,
102+
del_payload,
103+
make_frame_base(mem_payload, 0, "abc"),
104+
3,
105+
0,
106+
&cov);
107+
TEST_ASSERT_EQUAL(rx_fragment_tree_done, res);
108+
TEST_ASSERT_EQUAL_size_t(3, cov);
109+
TEST_ASSERT_NOT_NULL(root);
110+
TEST_ASSERT_EQUAL(1, tree_count(root));
111+
// Check the retained payload.
112+
TEST_ASSERT_EQUAL_size_t(0, fragment_at(root, 0)->offset);
113+
TEST_ASSERT_EQUAL_size_t(3, fragment_at(root, 0)->view.size);
114+
TEST_ASSERT_NULL(fragment_at(root, 1));
115+
// Check the heap.
116+
TEST_ASSERT_EQUAL_size_t(1, alloc_frag.allocated_fragments);
117+
TEST_ASSERT_EQUAL_size_t(1, alloc_payload.allocated_fragments);
118+
TEST_ASSERT_EQUAL_size_t(1, alloc_frag.count_alloc);
119+
TEST_ASSERT_EQUAL_size_t(1, alloc_payload.count_alloc);
120+
TEST_ASSERT_EQUAL_size_t(0, alloc_frag.count_free);
121+
TEST_ASSERT_EQUAL_size_t(0, alloc_payload.count_free);
122+
// Free the tree (as in freedom). The free tree is free to manifest its own destiny.
123+
udpard_fragment_free_all((udpard_fragment_t*)root, mem_frag);
124+
// Check the heap.
125+
TEST_ASSERT_EQUAL_size_t(0, alloc_frag.allocated_fragments);
126+
TEST_ASSERT_EQUAL_size_t(0, alloc_payload.allocated_fragments);
127+
TEST_ASSERT_EQUAL_size_t(1, alloc_frag.count_alloc);
128+
TEST_ASSERT_EQUAL_size_t(1, alloc_payload.count_alloc);
129+
TEST_ASSERT_EQUAL_size_t(1, alloc_frag.count_free);
130+
TEST_ASSERT_EQUAL_size_t(1, alloc_payload.count_free);
131+
}
90132
}
91133

92134
static void test_rx_transfer_id_forward_distance(void)

0 commit comments

Comments
 (0)