coreboot/tests
Yu-Ping Wu 23c41622a9 commonlib/list: Change to circular list
This is a reland of
commit c4be70f6ff ("commonlib/list: Support circular list").

In some use cases, we want to add items to the linked list and then
iterate over them with the insertion order. With the current API, the
call site needs to either use the inefficient list_append() function to
append items to the end of the list, or manually maintain a "tail"
node pointer.

To support that use case, add an internal helper function _list_init()
to initialize the list as a circular one with a placeholder head node.
_list_init() is automatically called within list_insert_after() and
list_append(). In list_insert_before(), an assertion is added to avoid
an insertion before the head node (which should be invalid). The
implementation ensures that the list is initialized as a circular one
whenever the first element is added. That also allows all call sites to
be auto-upgraded to the "circular list" implementation without any
modification.

Modify list_for_each() to support circular lists, and improve
list_append() efficiency by inserting the new node before the
placeholder head node. Also add a few assertions in the implementation.

Add a new test case to test iterating over an empty list.

Note that '(uintptr_t)ptr + (uintptr_t)offsetof(typeof(*(ptr)), member)'
was used instead of the simpler '&((ptr)->member)' because GCC9+ assumes
that the address can never be NULL. See commit 88991caf00
("include/list.h: Add support for GCC9+") for details. Now, with the
new list_for_each() implementation, that pointer value can never be
NULL.

Change-Id: Idc22887cce71284c9028dce10eeef9cc16669028
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/90962
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jakub "Kuba" Czapiga <czapiga@google.com>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
2026-02-13 15:17:00 +00:00
..
acpi tests: Rename Makefiles from .inc to .mk 2024-01-26 12:43:08 +00:00
commonlib commonlib/list: Change to circular list 2026-02-13 15:17:00 +00:00
console tests: Rename Makefiles from .inc to .mk 2024-01-26 12:43:08 +00:00
data/lib tests/imd: Fix invalid NULL comparison on uintptr_t 2025-09-30 11:55:53 +00:00
device tests: Replace 'unsigned long int' by 'unsigned long' 2025-01-12 04:52:30 +00:00
drivers tests/drivers/efivars: Remove duplicated <limits.h> 2024-07-03 20:21:06 +00:00
helpers tests/lib: Factor out file related functions 2024-05-21 13:44:39 +00:00
include include/fmap.h: Require FMAP_FLASH_SIZE == CONFIG_ROM_SIZE 2026-01-23 18:54:11 +00:00
lib tests/lib/coreboot_table-test.c: Add lb_string_platform_blob_version 2026-01-23 21:38:33 +00:00
mock tests: Fix tests code and comments style 2022-01-14 14:29:29 +00:00
stubs tree: Use <stdio.h> for snprintf 2024-05-29 10:33:54 +00:00
Makefile.common include/fmap.h: Require FMAP_FLASH_SIZE == CONFIG_ROM_SIZE 2026-01-23 18:54:11 +00:00
Makefile.mk tests: Disable generation of lcov HTML 2025-12-22 14:35:20 +00:00