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>
---
v5
- drop asnprintf, just mix printf output
- don't use brk() but do sanity check
---
.../multiarch/arm-compat-semi/semihosting.c | 44 ++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/tests/tcg/multiarch/arm-compat-semi/semihosting.c b/tests/tcg/multiarch/arm-compat-semi/semihosting.c
index b3fd16cd12..8e9cfb578c 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,46 @@ 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);
+ } else if (info.heap_base != NULL && info.heap_limit != NULL) {
+ /* 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) {
+ printf("null stack: %p -> %p\n", info.stack_base, info.stack_limit);
+ exit(3);
+ } else if (info.stack_base != NULL && info.stack_limit != NULL) {
+ /* Error if stack base is below limit */
+ if ((uintptr_t) info.stack_base < (uintptr_t) info.stack_limit) {
+ printf("stack base %p < stack_limit %p\n",
+ info.stack_base, info.stack_limit);
+ exit(4);
+ }
+ }
+ 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
On Fri, 12 Mar 2021 at 10:31, Alex Bennée <alex.bennee@linaro.org> wrote: > > Query the SYS_HEAPINFO semicall and do some basic verification of the > information via libc calls. Are we both testing system emulation and linux-user, or just one of the two? (Not that I want to hold this up if we're only testing one, but coverage of both, including M-profile, seems like it would be useful; cf also https://bugs.launchpad.net/qemu/+bug/1918302 which is M-profile system-emulation SYS_HEAPINFO being broken in 5.2.) thanks -- PMM
Peter Maydell <peter.maydell@linaro.org> writes: > On Fri, 12 Mar 2021 at 10:31, Alex Benn=C3=A9e <alex.bennee@linaro.org> wro= > te: >> >> Query the SYS_HEAPINFO semicall and do some basic verification of the >> information via libc calls. > > Are we both testing system emulation and linux-user, or just one of the two= > ? Currently just linux-user. There is no inherent reason we couldn't add a system emulation test but I felt that was already reasonably exercised by your semihosting tests. > (Not that I want to hold this up if we're only testing one, but coverage > of both, including M-profile, seems like it would be useful; cf also > https://bugs.launchpad.net/qemu/+bug/1918302 which is M-profile system-emul= > ation > SYS_HEAPINFO being broken in 5.2.) > > thanks > -- PMM -- Alex Bennée
On Fri, 12 Mar 2021 at 11:24, Alex Bennée <alex.bennee@linaro.org> wrote: > > > Peter Maydell <peter.maydell@linaro.org> writes: > > > On Fri, 12 Mar 2021 at 10:31, Alex Benn=C3=A9e <alex.bennee@linaro.org> wro= > > te: > >> > >> Query the SYS_HEAPINFO semicall and do some basic verification of the > >> information via libc calls. > > > > Are we both testing system emulation and linux-user, or just one of the two= > > ? > > Currently just linux-user. There is no inherent reason we couldn't add a > system emulation test but I felt that was already reasonably exercised > by your semihosting tests. Do we run those automatically anywhere ? I agree that probably the best thing is to get those into the CI loop somehow (and then put a SYS_HEAPINFO test there.) -- PMM
Peter Maydell <peter.maydell@linaro.org> writes: > On Fri, 12 Mar 2021 at 11:24, Alex Benn=C3=A9e <alex.bennee@linaro.org> wro= > te: >> >> >> Peter Maydell <peter.maydell@linaro.org> writes: >> >> > On Fri, 12 Mar 2021 at 10:31, Alex Benn=3DC3=3DA9e <alex.bennee@linaro.= > org> wro=3D >> > te: >> >> >> >> Query the SYS_HEAPINFO semicall and do some basic verification of the >> >> information via libc calls. >> > >> > Are we both testing system emulation and linux-user, or just one of the= > two=3D >> > ? >> >> Currently just linux-user. There is no inherent reason we couldn't add a >> system emulation test but I felt that was already reasonably exercised >> by your semihosting tests. > > Do we run those automatically anywhere ? I agree that probably the > best thing is to get those into the CI loop somehow (and then put > a SYS_HEAPINFO test there.) Not currently. I have toyed with series that make integrate the building of external test suites into the source tree. There are a number that it would be useful to have a short "make" away including: kvm-unit-tests LTP diy7 (memory model testing) sbsa-ref tools and I guess the semihosting testd would be another good example. -- Alex Bennée
© 2016 - 2026 Red Hat, Inc.