diff options
author | Julius Werner <jwerner@chromium.org> | 2022-11-30 16:18:01 -0800 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2022-12-22 15:34:28 +0000 |
commit | 9a9b2778a1f04ba5d570de154f4b6f38f3b5807a (patch) | |
tree | ce5c6fcc45240198711ab0f159a543bab6d629b6 /tests/lib/coreboot_table-test.c | |
parent | ad6c407927a2aa05cb7ecb47c833b230c227db36 (diff) |
coreboot_tables: Make existing alignment conventions more explicit
There seem to be some recurring vague concerns about the alignment of
coreboot table entries. While the existing implementation has been
producing tables with a well-defined alignment (4 bytes) for a long
time, the code doesn't always make it very clear. This patch adds an
explicit constant to codify that alignment, assertions to check it after
each entry, and adds explicit padding to the few entry structures that
were relying on compiler padding to return a correct sizeof() value.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Iaeef29ef255047a855066469e03b5481812e5975
Reviewed-on: https://review.coreboot.org/c/coreboot/+/70158
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Peter Stuge <peter@stuge.se>
Diffstat (limited to 'tests/lib/coreboot_table-test.c')
-rw-r--r-- | tests/lib/coreboot_table-test.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/tests/lib/coreboot_table-test.c b/tests/lib/coreboot_table-test.c index aa10f6534b..9547ee07a6 100644 --- a/tests/lib/coreboot_table-test.c +++ b/tests/lib/coreboot_table-test.c @@ -109,7 +109,8 @@ static void test_lb_new_record(void **state) accumulated_size = sizeof(struct lb_record); for (i = 0; i < entries; ++i) { curr = lb_new_record(header); - curr->size = sizeof(struct lb_record) + ((i + 2) * 7) % 32; + curr->size = sizeof(struct lb_record) + + ALIGN_UP(((i + 2) * 7) % 32, LB_ENTRY_ALIGN); assert_int_equal(entries_offset + (i + 1), header->table_entries); assert_int_equal(accumulated_size, header->table_bytes); @@ -359,31 +360,31 @@ static void test_write_tables(void **state) assert_int_equal(ALIGN_UP(sizeof(struct lb_mainboard) + ARRAY_SIZE(mainboard_vendor) + ARRAY_SIZE(mainboard_part_number), - 8), + LB_ENTRY_ALIGN), record->size); break; case LB_TAG_VERSION: assert_int_equal(ALIGN_UP(sizeof(struct lb_string) + ARRAY_SIZE(coreboot_version), - 8), + LB_ENTRY_ALIGN), record->size); break; case LB_TAG_EXTRA_VERSION: assert_int_equal(ALIGN_UP(sizeof(struct lb_string) + ARRAY_SIZE(coreboot_extra_version), - 8), + LB_ENTRY_ALIGN), record->size); break; case LB_TAG_BUILD: assert_int_equal( ALIGN_UP(sizeof(struct lb_string) + ARRAY_SIZE(coreboot_build), - 8), + LB_ENTRY_ALIGN), record->size); break; case LB_TAG_COMPILE_TIME: assert_int_equal(ALIGN_UP(sizeof(struct lb_string) + ARRAY_SIZE(coreboot_compile_time), - 8), + LB_ENTRY_ALIGN), record->size); break; case LB_TAG_SERIAL: |