From 043f3397a9d0c126f0ad9642ff3131203e0bf9e8 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sat, 11 Nov 2023 00:06:55 +0100 Subject: tests/acpigen: Patch to allow moving buffers When a package length needs to be written, we used to always write three bytes for it, even when the length would fit into one or two bytes. To allow such compact package lengths, we have to move the written buffer data in case the length is smaller. This makes tracking the start of nested buffers harder, as they may be moved entirely later when a package length is written. So instead of tracking start addresses in test_acpigen_nested_ifs(), let's work with the generated AML alone. In this lucky case, we can simply search for the `if` operations. Change-Id: Id8557dd5d1be3878713ee0b6106c3e0975665e97 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/coreboot/+/79008 Tested-by: build bot (Jenkins) Reviewed-by: Felix Held --- tests/acpi/acpigen-test.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/acpi/acpigen-test.c b/tests/acpi/acpigen-test.c index 156b544095..0d261e22d9 100644 --- a/tests/acpi/acpigen-test.c +++ b/tests/acpi/acpigen-test.c @@ -76,37 +76,41 @@ static void test_acpigen_single_if(void **state) assert_int_equal(if_package_length, block_length); } -static void create_nested_ifs_recursive(char *stack_start[], char *stack_end[], u32 i, u32 n) +static void create_nested_ifs_recursive(size_t stack_len[], u32 i, u32 n) { if (i >= n) return; - stack_start[i] = acpigen_get_current(); + char *const start = acpigen_get_current(); acpigen_write_if_and(LOCAL0_OP, ZERO_OP); for (int k = 0; k < 3; ++k) acpigen_write_store_ops(ZERO_OP, LOCAL1_OP); - create_nested_ifs_recursive(stack_start, stack_end, i + 1, n); + create_nested_ifs_recursive(stack_len, i + 1, n); acpigen_pop_len(); - stack_end[i] = acpigen_get_current(); + stack_len[i] = acpigen_get_current() - start; } static void test_acpigen_nested_ifs(void **state) { char *acpigen_buf = *state; const size_t nesting_level = 8; - char *block_start[8] = {0}; - char *block_end[8] = {0}; + size_t block_len[8] = {0}; acpigen_set_current(acpigen_buf); - create_nested_ifs_recursive(block_start, block_end, 0, nesting_level); + create_nested_ifs_recursive(block_len, 0, nesting_level); - for (int i = 0; i < nesting_level; ++i) - assert_int_equal(decode_package_length(block_start[i]), - block_end[i] - block_start[i] - 1); + for (int i = 0, j = 0; i < nesting_level; ++i, ++j) { + /* Find next if op */ + for (; j < ACPIGEN_TEST_BUFFER_SZ; ++j) { + if ((u8)acpigen_buf[j] == IF_OP) + break; + } + assert_int_equal(decode_package_length(acpigen_buf + j), block_len[i] - 1); + } } static void test_acpigen_write_package(void **state) -- cgit v1.2.3