diff mbox series

[1/2] acpi: misc: add tests for ACPI MISC table (mantis 2297)

Message ID 20240111060228.243345-1-ivan.hu@canonical.com
State Accepted
Headers show
Series [1/2] acpi: misc: add tests for ACPI MISC table (mantis 2297) | expand

Commit Message

ivanhu Jan. 11, 2024, 6:02 a.m. UTC
BugLink: https://bugs.launchpad.net/fwts/+bug/2047212
The ACPI MISC(Miscellaneous GUIDed Table Entries) table was added to ACPI6.5,
add tests for the MISC table.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/Makefile.am             |  1 +
 src/acpi/misc/misc.c        | 88 +++++++++++++++++++++++++++++++++++++
 src/lib/include/fwts_acpi.h | 17 +++++++
 3 files changed, 106 insertions(+)
 create mode 100644 src/acpi/misc/misc.c
diff mbox series

Patch

diff --git a/src/Makefile.am b/src/Makefile.am
index 69204479..dde55098 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -114,6 +114,7 @@  fwts_SOURCES = main.c 				\
 	acpi/madt/madt.c			\
 	acpi/mcfg/mcfg.c 			\
 	acpi/mchi/mchi.c 			\
+        acpi/misc/misc.c                        \
 	acpi/mpam/mpam.c 			\
 	acpi/mpst/mpst.c 			\
 	acpi/msct/msct.c 			\
diff --git a/src/acpi/misc/misc.c b/src/acpi/misc/misc.c
new file mode 100644
index 00000000..44375424
--- /dev/null
+++ b/src/acpi/misc/misc.c
@@ -0,0 +1,88 @@ 
+/*
+ * Copyright (C) 2024 Canonical
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include "fwts.h"
+
+#if defined(FWTS_HAS_ACPI)
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+static fwts_acpi_table_info *table;
+acpi_table_init(MISC, &table)
+
+static int misc_test1(fwts_framework *fw)
+{
+	fwts_acpi_misc_guided_entry *entry;
+	bool passed = true;
+	uint32_t offset;
+
+	offset = sizeof(fwts_acpi_table_misc);
+	entry = (fwts_acpi_misc_guided_entry *)(table->data + offset);
+	while (offset < table->length) {
+		char guid_str[37];
+
+		if (fwts_acpi_structure_length_zero(fw, "MISC", entry->entry_len, offset)) {
+			passed = false;
+			break;
+		}
+
+		if ((offset + entry->entry_len) > table->length) {
+			fwts_failed(fw, LOG_LEVEL_HIGH,
+			"MISCOutOfRangeOffset",
+			"MISC GUIDed Entry Offset is out of range.");
+			passed = false;
+			break;
+		}
+
+		fwts_log_info_verbatim(fw, "Miscellaneous GUIDed Table Entries:");
+		fwts_guid_buf_to_str(entry->entry_guid, guid_str, sizeof(guid_str));
+		fwts_log_info_verbatim(fw, "  Entry GUID ID:     %s", guid_str);
+		fwts_log_info_simp_int(fw, "  Entry Length:      ", entry->entry_len);
+		fwts_log_info_simp_int(fw, "  Revision:          ", entry->revision);
+		fwts_log_info_simp_int(fw, "  Producer ID:       ", entry->producer_id);
+		fwts_log_info_verbatim(fw, "  Data:");
+		fwts_hexdump_data_prefix_all(fw, entry->data, "    ",
+				(entry->entry_len - sizeof(fwts_acpi_misc_guided_entry)));
+
+		/* Nothing else need to be checked currently */
+
+		offset += entry->entry_len;
+		entry = (fwts_acpi_misc_guided_entry *)(table->data + offset);
+		fwts_log_nl(fw);
+	}
+
+	if (passed)
+		fwts_passed(fw, "No issues found in MISC table.");
+
+	return FWTS_OK;
+}
+
+static fwts_framework_minor_test misc_tests[] = {
+	{ misc_test1, "Validate MISC table." },
+	{ NULL, NULL }
+};
+
+static fwts_framework_ops misc_ops = {
+	.description = "MISC Miscellaneous GUIDed Table Entries test.",
+	.init        = MISC_init,
+	.minor_tests = misc_tests
+};
+
+FWTS_REGISTER("misc", &misc_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_ACPI)
+
+#endif
diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
index 79763bab..a78aa577 100644
--- a/src/lib/include/fwts_acpi.h
+++ b/src/lib/include/fwts_acpi.h
@@ -2802,4 +2802,21 @@  typedef struct {
 	uint64_t		reserved;
 } __attribute__ ((packed)) fwts_acpi_table_viot;
 
+/*
+ * Miscellaneous GUIDed Table Entries
+ * ACPI6.5 5.2.33
+ */
+typedef struct {
+	uint8_t		entry_guid[16];
+	uint32_t	entry_len;
+	uint32_t	revision;
+	uint32_t	producer_id;
+	uint8_t		data[0];
+} __attribute__ ((packed)) fwts_acpi_misc_guided_entry;
+
+typedef struct {
+	fwts_acpi_table_header		header;
+	fwts_acpi_misc_guided_entry 	entry[0];
+} __attribute__ ((packed)) fwts_acpi_table_misc;
+
 #endif