From 7fb8da4ce1b22c8f077e6d4fe6e0d88e3fd9206d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 7 Jul 2020 13:11:45 -0600 Subject: acpi: Support string output Add support for output of strings and streams of bytes. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner Reviewed-by: Bin Meng --- test/dm/acpigen.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/dm/acpigen.c') diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c index a4adfbfdf8..26d1b76db4 100644 --- a/test/dm/acpigen.c +++ b/test/dm/acpigen.c @@ -20,6 +20,9 @@ /* Maximum size of the ACPI context needed for most tests */ #define ACPI_CONTEXT_SIZE 150 +#define TEST_STRING "frogmore" +#define TEST_STREAM2 "\xfa\xde" + static int alloc_context(struct acpi_ctx **ctxp) { struct acpi_ctx *ctx; @@ -73,6 +76,45 @@ static int dm_test_acpi_emit_simple(struct unit_test_state *uts) } DM_TEST(dm_test_acpi_emit_simple, 0); +/* Test emitting a stream */ +static int dm_test_acpi_emit_stream(struct unit_test_state *uts) +{ + struct acpi_ctx *ctx; + u8 *ptr; + + ut_assertok(alloc_context(&ctx)); + + ptr = acpigen_get_current(ctx); + acpigen_emit_stream(ctx, TEST_STREAM2, 2); + ut_asserteq(2, acpigen_get_current(ctx) - ptr); + ut_asserteq((u8)TEST_STREAM2[0], ptr[0]); + ut_asserteq((u8)TEST_STREAM2[1], ptr[1]); + + free_context(&ctx); + + return 0; +} +DM_TEST(dm_test_acpi_emit_stream, 0); + +/* Test emitting a string */ +static int dm_test_acpi_emit_string(struct unit_test_state *uts) +{ + struct acpi_ctx *ctx; + u8 *ptr; + + ut_assertok(alloc_context(&ctx)); + + ptr = acpigen_get_current(ctx); + acpigen_emit_string(ctx, TEST_STRING); + ut_asserteq(sizeof(TEST_STRING), acpigen_get_current(ctx) - ptr); + ut_asserteq_str(TEST_STRING, (char *)ptr); + + free_context(&ctx); + + return 0; +} +DM_TEST(dm_test_acpi_emit_string, 0); + /* Test emitting an interrupt descriptor */ static int dm_test_acpi_interrupt(struct unit_test_state *uts) { -- cgit