[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/22] tests/tcg: add HeapInfo checking to semihosting test
From: |
Alex Bennée |
Subject: |
[PULL 09/22] tests/tcg: add HeapInfo checking to semihosting test |
Date: |
Wed, 24 Mar 2021 14:30:08 +0000 |
Query the SYS_HEAPINFO semicall and do some basic verification of the
information via libc calls.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20210323165308.15244-10-alex.bennee@linaro.org>
diff --git a/tests/tcg/multiarch/arm-compat-semi/semihosting.c
b/tests/tcg/multiarch/arm-compat-semi/semihosting.c
index b3fd16cd12..8627eee3cf 100644
--- a/tests/tcg/multiarch/arm-compat-semi/semihosting.c
+++ b/tests/tcg/multiarch/arm-compat-semi/semihosting.c
@@ -8,9 +8,13 @@
*/
#define SYS_WRITE0 0x04
+#define SYS_HEAPINFO 0x16
#define SYS_REPORTEXC 0x18
#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
#include "semicall.h"
int main(int argc, char *argv[argc])
@@ -21,8 +25,57 @@ int main(int argc, char *argv[argc])
uintptr_t exit_block[2] = {0x20026, 0};
uintptr_t exit_code = (uintptr_t) &exit_block;
#endif
+ struct {
+ void *heap_base;
+ void *heap_limit;
+ void *stack_base;
+ void *stack_limit;
+ } info;
+ void *ptr_to_info = (void *) &info;
- __semi_call(SYS_WRITE0, (uintptr_t) "Hello World");
+ __semi_call(SYS_WRITE0, (uintptr_t) "Checking HeapInfo\n");
+
+ memset(&info, 0, sizeof(info));
+ __semi_call(SYS_HEAPINFO, (uintptr_t) &ptr_to_info);
+
+ if (info.heap_base == NULL || info.heap_limit == NULL) {
+ printf("null heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ exit(1);
+ }
+
+ /* Error if heap base is above limit */
+ if ((uintptr_t) info.heap_base >= (uintptr_t) info.heap_limit) {
+ printf("heap base %p >= heap_limit %p\n",
+ info.heap_base, info.heap_limit);
+ exit(2);
+ }
+
+ if (info.stack_base == NULL || info.stack_limit) {
+ printf("null stack: %p -> %p\n", info.stack_base, info.stack_limit);
+ exit(3);
+ }
+
+ /* check our local variables are indeed inside the reported stack */
+ if (ptr_to_info > info.stack_base) {
+ printf("info appears to be above stack: %p > %p\n", ptr_to_info,
+ info.stack_base);
+ exit(4);
+ } else if (ptr_to_info < info.stack_limit) {
+ printf("info appears to be outside stack: %p < %p\n", ptr_to_info,
+ info.stack_limit);
+ exit(5);
+ }
+
+ if (ptr_to_info > info.heap_base && ptr_to_info < info.heap_limit) {
+ printf("info appears to be inside the heap: %p in %p:%p\n",
+ ptr_to_info, info.heap_base, info.heap_limit);
+ exit(6);
+ }
+
+ printf("heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ printf("stack: %p -> %p\n", info.stack_base, info.stack_limit);
+
+ __semi_call(SYS_WRITE0, (uintptr_t) "Passed HeapInfo checks");
__semi_call(SYS_REPORTEXC, exit_code);
/* if we get here we failed */
return -1;
--
2.20.1
- [PULL 04/22] tools/virtiofsd: include --socket-group in help, (continued)
- [PULL 04/22] tools/virtiofsd: include --socket-group in help, Alex Bennée, 2021/03/24
- [PULL 07/22] semihosting/arm-compat-semi: don't use SET_ARG to report SYS_HEAPINFO, Alex Bennée, 2021/03/24
- [PULL 05/22] semihosting: move semihosting tests to multiarch, Alex Bennée, 2021/03/24
- [PULL 06/22] semihosting/arm-compat-semi: unify GET/SET_ARG helpers, Alex Bennée, 2021/03/24
- [PULL 11/22] configure: Don't use the __atomic_*_16 functions for testing 128-bit support, Alex Bennée, 2021/03/24
- [PULL 13/22] utils: Tighter tests for qemu_strtosz, Alex Bennée, 2021/03/24
- [PULL 10/22] gitlab-ci.yml: Merge the trace-backend testing into other jobs, Alex Bennée, 2021/03/24
- [PULL 08/22] linux-user/riscv: initialise the TaskState heap/stack info, Alex Bennée, 2021/03/24
- [PULL 14/22] utils: Work around mingw strto*l bug with 0x, Alex Bennée, 2021/03/24
- [PULL 12/22] cirrus.yml: Update the FreeBSD task to version 12.2, Alex Bennée, 2021/03/24
- [PULL 09/22] tests/tcg: add HeapInfo checking to semihosting test,
Alex Bennée <=
- [PULL 18/22] blockdev: with -drive if=virtio, use generic virtio-blk, Alex Bennée, 2021/03/24
- [PULL 20/22] iotests: test m68k with the virt machine, Alex Bennée, 2021/03/24
- [PULL 16/22] qdev: define list of archs with virtio-pci or virtio-ccw, Alex Bennée, 2021/03/24
- [PULL 19/22] iotests: Revert "iotests: use -ccw on s390x for 040, 139, and 182", Alex Bennée, 2021/03/24
- [PULL 21/22] iotests: iothreads need ioeventfd, Alex Bennée, 2021/03/24
- [PULL 17/22] m68k: add the virtio devices aliases, Alex Bennée, 2021/03/24
- [PULL 15/22] gitlab: extend timeouts for CFI builds, Alex Bennée, 2021/03/24
- [PULL 22/22] gitlab: default to not building the documentation, Alex Bennée, 2021/03/24
- Re: [PULL for 6.0 00/22] various fixes (kernel-doc, semihosting, testing), no-reply, 2021/03/24
- Re: [PULL for 6.0 00/22] various fixes (kernel-doc, semihosting, testing), Peter Maydell, 2021/03/24