Skip to content

Commit 9a3ae61

Browse files
tmlemanlgirdwood
authored andcommitted
test: Add UT case for list_relink function
Add ztest coverage for list_relink function that was missing from the unit test suite. The test validates both empty list and non-empty list relinking scenarios. The test covers: - Empty list relinking ensuring proper initialization - Non-empty list relinking verifying that item back-references to the list head are correctly updated when the head structure is moved - List integrity validation after relinking operations This completes the test coverage for all list.h functions and ensures the list_relink functionality is properly validated in the ztest framework. Signed-off-by: Tomasz Leman <[email protected]>
1 parent 1b89844 commit 9a3ae61

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/ztest/unit/list/test_list_ztest.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,56 @@ ZTEST(sof_list_suite, test_list_item_is_last)
162162
"item2 should be the last item in the list");
163163
}
164164

165+
/**
166+
* @brief Test list_relink functionality
167+
*
168+
* Tests that list_relink correctly updates references when a list head is moved
169+
*/
170+
ZTEST(sof_list_suite, test_list_relink)
171+
{
172+
struct list_item old_head;
173+
struct list_item new_head;
174+
struct list_item item1;
175+
struct list_item item2;
176+
177+
/* Test case 1: Empty list relinking */
178+
list_init(&old_head);
179+
new_head = old_head; /* Copy the old head structure */
180+
181+
list_relink(&new_head, &old_head);
182+
183+
/* After relinking empty list, new_head should be properly initialized */
184+
zassert_equal(&new_head, new_head.next,
185+
"Empty list: new_head->next should point to itself");
186+
zassert_equal(&new_head, new_head.prev,
187+
"Empty list: new_head->prev should point to itself");
188+
189+
/* Test case 2: Non-empty list relinking */
190+
list_init(&old_head);
191+
list_item_append(&item1, &old_head);
192+
list_item_append(&item2, &old_head);
193+
194+
/* Verify initial state - items point to old_head */
195+
zassert_equal(&old_head, item1.prev, "Initial: item1 prev should point to old_head");
196+
zassert_equal(&old_head, item2.next, "Initial: item2 next should point to old_head");
197+
198+
/* Simulate moving list to new location by copying head structure */
199+
new_head = old_head;
200+
/* Now new_head.next points to item1, new_head.prev points to item2 */
201+
/* But item1.prev and item2.next still point to &old_head */
202+
203+
/* Perform the relinking */
204+
list_relink(&new_head, &old_head);
205+
206+
/* After relinking, items should now point to new_head instead of old_head */
207+
zassert_equal(&new_head, item1.prev, "After relink: item1 prev should point to new_head");
208+
zassert_equal(&new_head, item2.next, "After relink: item2 next should point to new_head");
209+
zassert_equal(&item1, new_head.next, "After relink: new_head next should point to item1");
210+
zassert_equal(&item2, new_head.prev, "After relink: new_head prev should point to item2");
211+
212+
/* Verify list integrity - items should still be properly linked */
213+
zassert_equal(&item2, item1.next, "After relink: item1 next should point to item2");
214+
zassert_equal(&item1, item2.prev, "After relink: item2 prev should point to item1");
215+
}
216+
165217
ZTEST_SUITE(sof_list_suite, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)