From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>
Subject: [Semihosting Tests PATCH v2 3/3] add SYS_GET_CMDLINE test
Date: Thu, 30 May 2024 12:23:32 +0100 [thread overview]
Message-ID: <20240530112332.1439238-4-alex.bennee@linaro.org> (raw)
In-Reply-To: <20240530112332.1439238-1-alex.bennee@linaro.org>
Adds a new test case for the semihosting SYS_GET_CMDLINE call. We can
use the existing previously unused semi_get_cmdline helper and we then
verify:
- the call succeeds
- the call returns the expected length string
- the call returns the expected binary name as arg0
The most fiddly bit was exposing the binary name into the program so
we can validate the result.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- add return leg on failing test
- check returned length is sane
- s/could/couldn't/
- just let array reference decay to the pointer
- rewrite the commit message to be less terse
---
Makefile | 22 +++++++++++-----------
usertest.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index 59fd831..f77665f 100644
--- a/Makefile
+++ b/Makefile
@@ -85,37 +85,37 @@ systest-srcs = start.S string.c $(usertest-srcs)
microbit-systest-srcs = start-microbit.S string.c $(usertest-srcs)
usertest-a32: $(usertest-srcs)
- $(A32GCC) --static -o $@ $^
+ $(A32GCC) -DBINARY_NAME="\"$@\"" --static -o $@ $^
usertest-t32: $(usertest-srcs)
- $(T32GCC) --static -o $@ $^
+ $(T32GCC) -DBINARY_NAME="\"$@\"" --static -o $@ $^
usertest-a32-hlt: $(usertest-srcs)
- $(A32GCC) -DUSE_HLT --static -o $@ $^
+ $(A32GCC) -DBINARY_NAME="\"$@\"" -DUSE_HLT --static -o $@ $^
usertest-t32-hlt: $(usertest-srcs)
- $(T32GCC) -DUSE_HLT --static -o $@ $^
+ $(T32GCC) -DBINARY_NAME="\"$@\"" -DUSE_HLT --static -o $@ $^
usertest-a64: $(usertest-srcs)
- $(A64GCC) --static -o $@ $^
+ $(A64GCC) -DBINARY_NAME="\"$@\"" --static -o $@ $^
systest-a32.axf: $(systest-srcs)
- $(A32GCC) -o $@ $^ $(A32LINKOPTS)
+ $(A32GCC) -DBINARY_NAME="\"$@\"" -o $@ $^ $(A32LINKOPTS)
systest-t32.axf: $(systest-srcs)
- $(T32GCC) -o $@ $^ $(A32LINKOPTS)
+ $(T32GCC) -DBINARY_NAME="\"$@\"" -o $@ $^ $(A32LINKOPTS)
systest-a32-hlt.axf: $(systest-srcs)
- $(A32GCC) -DUSE_HLT -o $@ $^ $(A32LINKOPTS)
+ $(A32GCC) -DBINARY_NAME="\"$@\"" -DUSE_HLT -o $@ $^ $(A32LINKOPTS)
systest-t32-hlt.axf: $(systest-srcs)
- $(T32GCC) -DUSE_HLT -o $@ $^ $(A32LINKOPTS)
+ $(T32GCC) -DBINARY_NAME="\"$@\"" -DUSE_HLT -o $@ $^ $(A32LINKOPTS)
systest-t32-bkpt.axf: $(microbit-systest-srcs)
- $(V7MGCC) -DUSE_BKPT -o $@ $^ $(AV7MLINKOPTS)
+ $(V7MGCC) -DBINARY_NAME="\"$@\"" -DUSE_BKPT -o $@ $^ $(AV7MLINKOPTS)
systest-a64.axf: $(systest-srcs)
- $(A64GCC) -nostdlib -o $@ $^ $(A64LINKOPTS)
+ $(A64GCC) -DBINARY_NAME="\"$@\"" -nostdlib -o $@ $^ $(A64LINKOPTS)
run-usertest-a32: usertest-a32
$(QEMU_ARM) usertest-a32
diff --git a/usertest.c b/usertest.c
index 5df95f3..7a12896 100644
--- a/usertest.c
+++ b/usertest.c
@@ -315,6 +315,33 @@ static int test_feature_detect(void)
return 0;
}
+static int test_cmdline(void)
+{
+ char cmdline[256];
+ int actual;
+ const char *s, *c;
+
+ if (semi_get_cmdline(cmdline, sizeof(cmdline), &actual)) {
+ semi_write0("FAIL couldn't recover command line\n");
+ return 1;
+ }
+
+ if (strlen(BINARY_NAME) != actual) {
+ semi_write0("FAIL cmdline length not what expected: ");
+ semi_write0(cmdline);
+ return 1;
+ }
+
+ if (strcmp(cmdline, BINARY_NAME) != 0) {
+ semi_write0("FAIL unexpected command line: ");
+ semi_write0(cmdline);
+ return 1;
+ }
+
+ semi_write0("PASS command line test\n");
+ return 0;
+}
+
int main(void)
{
void *bufp;
@@ -366,6 +393,10 @@ int main(void)
return 1;
}
+ if (test_cmdline()) {
+ return 1;
+ }
+
semi_write0("ALL TESTS PASSED\n");
/* If we have EXIT_EXTENDED then use it */
--
2.39.2
next prev parent reply other threads:[~2024-05-30 11:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 11:23 [Semihosting Tests PATCH v2 0/3] add SYS_GET_CMDLINE test Alex Bennée
2024-05-30 11:23 ` [Semihosting Tests PATCH v2 1/3] .editorconfig: add code conventions for tooling Alex Bennée
2024-05-30 15:22 ` Brian Cain
2024-05-31 8:54 ` Alex Bennée
2024-05-31 10:05 ` Peter Maydell
2024-05-30 11:23 ` [Semihosting Tests PATCH v2 2/3] update includes for bare metal compiling Alex Bennée
2024-05-30 11:23 ` Alex Bennée [this message]
2024-05-30 14:31 ` [Semihosting Tests PATCH v2 0/3] add SYS_GET_CMDLINE test Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240530112332.1439238-4-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).