aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-07-07 21:32:15 -0600
committerBin Meng <bmeng.cn@gmail.com>2020-07-17 14:32:24 +0800
commitbb6772c3ffb0b2df22fd22cfe8d17276823af06d (patch)
treec5bcb11fd822d78b1f94a3815b993d0600673662 /test
parent91c2f9c32ed76269b9786a6c506233e9b91bdfce (diff)
downloadu-boot-bb6772c3ffb0b2df22fd22cfe8d17276823af06d.zip
u-boot-bb6772c3ffb0b2df22fd22cfe8d17276823af06d.tar.gz
u-boot-bb6772c3ffb0b2df22fd22cfe8d17276823af06d.tar.bz2
acpi: Support writing named values
Allow writing named integers and strings to the generated ACPI code. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> [bmeng: Fix the "new blank line at EOF" warning] Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/dm/acpigen.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index cea1a62..14a758d 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -1020,3 +1020,80 @@ static int dm_test_acpi_device(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_acpi_device, 0);
+
+/* Test writing named values */
+static int dm_test_acpi_write_name(struct unit_test_state *uts)
+{
+ const char *name = "\\_SB." ACPI_TEST_DEV_NAME;
+ struct acpi_ctx *ctx;
+ u8 *ptr;
+
+ ut_assertok(alloc_context(&ctx));
+ ptr = acpigen_get_current(ctx);
+
+ acpigen_write_name_zero(ctx, name);
+ acpigen_write_name_one(ctx, name);
+ acpigen_write_name_byte(ctx, name, TEST_INT8);
+ acpigen_write_name_word(ctx, name, TEST_INT16);
+ acpigen_write_name_dword(ctx, name, TEST_INT32);
+ acpigen_write_name_qword(ctx, name, TEST_INT64);
+ acpigen_write_name_integer(ctx, name, TEST_INT64 + 1);
+ acpigen_write_name_string(ctx, name, "baldrick");
+ acpigen_write_name_string(ctx, name, NULL);
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ut_asserteq_strn("\\._SB_ABCD", (char *)ptr);
+ ptr += 10;
+ ut_asserteq(ZERO_OP, *ptr++);
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(ONE_OP, *ptr++);
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(BYTE_PREFIX, *ptr++);
+ ut_asserteq(TEST_INT8, *ptr++);
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(WORD_PREFIX, *ptr++);
+ ut_asserteq(TEST_INT16, get_unaligned((u16 *)ptr));
+ ptr += 2;
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(DWORD_PREFIX, *ptr++);
+ ut_asserteq(TEST_INT32, get_unaligned((u32 *)ptr));
+ ptr += 4;
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(QWORD_PREFIX, *ptr++);
+ ut_asserteq_64(TEST_INT64, get_unaligned((u64 *)ptr));
+ ptr += 8;
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(QWORD_PREFIX, *ptr++);
+ ut_asserteq_64(TEST_INT64 + 1, get_unaligned((u64 *)ptr));
+ ptr += 8;
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(STRING_PREFIX, *ptr++);
+ ut_asserteq_str("baldrick", (char *)ptr)
+ ptr += 9;
+
+ ut_asserteq(NAME_OP, *ptr++);
+ ptr += 10;
+ ut_asserteq(STRING_PREFIX, *ptr++);
+ ut_asserteq('\0', *ptr++);
+
+ ut_asserteq_ptr(ptr, ctx->current);
+
+ free_context(&ctx);
+
+ return 0;
+}
+DM_TEST(dm_test_acpi_write_name, 0);