aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2021-06-15 17:58:00 +0100
committerPeter Maydell <peter.maydell@linaro.org>2021-06-18 11:03:49 +0100
commit8dffe179656d930b34f8c2c6af63d1f2c846391b (patch)
treea183ab91d39fdb6951b927901f2474d4ead977b2
parente56d22bbf8112c04d9554883e78357c82c8cf046 (diff)
tests/tcg: port SYS_HEAPINFO to a system test
This allows us to check our new SYS_HEAPINFO implementation generates sane values. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-id: 20210615165800.23265-3-alex.bennee@linaro.org
-rw-r--r--tests/tcg/aarch64/system/semiheap.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/tcg/aarch64/system/semiheap.c b/tests/tcg/aarch64/system/semiheap.c
new file mode 100644
index 0000000000..d5613dca59
--- /dev/null
+++ b/tests/tcg/aarch64/system/semiheap.c
@@ -0,0 +1,74 @@
+/*
+ * Semihosting System HEAPINFO Test
+ *
+ * Copyright (c) 2021 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <inttypes.h>
+#include <stddef.h>
+#include <minilib.h>
+
+#define SYS_HEAPINFO 0x16
+
+uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
+{
+ register uintptr_t t asm("x0") = type;
+ register uintptr_t a0 asm("x1") = arg0;
+ asm("hlt 0xf000"
+ : "=r" (t)
+ : "r" (t), "r" (a0));
+
+ return t;
+}
+
+int main(int argc, char *argv[argc])
+{
+ struct {
+ void *heap_base;
+ void *heap_limit;
+ void *stack_base;
+ void *stack_limit;
+ } info;
+ void *ptr_to_info = (void *) &info;
+
+ ml_printf("Semihosting Heap Info Test\n");
+
+ /* memset(&info, 0, sizeof(info)); */
+ __semi_call(SYS_HEAPINFO, (uintptr_t) &ptr_to_info);
+
+ if (info.heap_base == NULL || info.heap_limit == NULL) {
+ ml_printf("null heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ return -1;
+ }
+
+ /* Error if heap base is above limit */
+ if ((uintptr_t) info.heap_base >= (uintptr_t) info.heap_limit) {
+ ml_printf("heap base %p >= heap_limit %p\n",
+ info.heap_base, info.heap_limit);
+ return -2;
+ }
+
+ if (info.stack_base == NULL) {
+ ml_printf("null stack: %p -> %p\n", info.stack_base, info.stack_limit);
+ return -3;
+ }
+
+ /*
+ * We don't check our local variables are inside the reported
+ * stack because the runtime may select a different stack area (as
+ * our boot.S code does). However we can check we don't clash with
+ * the heap.
+ */
+ if (ptr_to_info > info.heap_base && ptr_to_info < info.heap_limit) {
+ ml_printf("info appears to be inside the heap: %p in %p:%p\n",
+ ptr_to_info, info.heap_base, info.heap_limit);
+ return -4;
+ }
+
+ ml_printf("heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ ml_printf("stack: %p <- %p\n", info.stack_limit, info.stack_base);
+ ml_printf("Passed HeapInfo checks\n");
+ return 0;
+}