acpigen: Support writing a package
A package collects together several elements. Add an easy way of writing
a package header and updating its length later.
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index c756847..aaffc6a 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -404,3 +404,30 @@
return 0;
}
DM_TEST(dm_test_acpi_len, 0);
+
+/* Test writing a package */
+static int dm_test_acpi_package(struct unit_test_state *uts)
+{
+ struct acpi_ctx *ctx;
+ char *num_elements;
+ u8 *ptr;
+
+ ut_assertok(alloc_context(&ctx));
+
+ ptr = acpigen_get_current(ctx);
+
+ num_elements = acpigen_write_package(ctx, 3);
+ ut_asserteq_ptr(num_elements, ptr + 4);
+
+ /* For ease of testing, just emit a byte, not valid package contents */
+ acpigen_emit_byte(ctx, 0x23);
+ acpigen_pop_len(ctx);
+ ut_asserteq(PACKAGE_OP, ptr[0]);
+ ut_asserteq(5, get_length(ptr + 1));
+ ut_asserteq(3, ptr[4]);
+
+ free_context(&ctx);
+
+ return 0;
+}
+DM_TEST(dm_test_acpi_package, 0);