// SPDX-License-Identifier: GPL-2.0+ /* * Tests for ACPI code generation * * Copyright 2019 Google LLC * Written by Simon Glass */ #include #include #include #include #include #include #include #include /* Maximum size of the ACPI context needed for most tests */ #define ACPI_CONTEXT_SIZE 150 static int alloc_context(struct acpi_ctx **ctxp) { struct acpi_ctx *ctx; *ctxp = NULL; ctx = malloc(sizeof(*ctx)); if (!ctx) return -ENOMEM; ctx->base = malloc(ACPI_CONTEXT_SIZE); if (!ctx->base) { free(ctx); return -ENOMEM; } ctx->current = ctx->base; *ctxp = ctx; return 0; } static void free_context(struct acpi_ctx **ctxp) { free((*ctxp)->base); free(*ctxp); *ctxp = NULL; } /* Test emitting simple types and acpigen_get_current() */ static int dm_test_acpi_emit_simple(struct unit_test_state *uts) { struct acpi_ctx *ctx; u8 *ptr; ut_assertok(alloc_context(&ctx)); ptr = acpigen_get_current(ctx); acpigen_emit_byte(ctx, 0x23); ut_asserteq(1, acpigen_get_current(ctx) - ptr); ut_asserteq(0x23, *(u8 *)ptr); acpigen_emit_word(ctx, 0x1234); ut_asserteq(3, acpigen_get_current(ctx) - ptr); ut_asserteq(0x1234, get_unaligned((u16 *)(ptr + 1))); acpigen_emit_dword(ctx, 0x87654321); ut_asserteq(7, acpigen_get_current(ctx) - ptr); ut_asserteq(0x87654321, get_unaligned((u32 *)(ptr + 3))); free_context(&ctx); return 0; } DM_TEST(dm_test_acpi_emit_simple, 0);