We actually had the stubs to implement this. The main pain is getting
the binary name into the program so we can validate the result.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
Makefile | 22 +++++++++++-----------
usertest.c | 24 ++++++++++++++++++++++++
2 files changed, 35 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..268a9d9 100644
--- a/usertest.c
+++ b/usertest.c
@@ -315,6 +315,26 @@ 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[0], sizeof(cmdline), &actual)) {
+ semi_write0("FAIL could recover command line\n");
+ return 1;
+ }
+
+ if (strcmp(&cmdline[0], BINARY_NAME) != 0) {
+ semi_write0("FAIL unexpected command line:");
+ semi_write0(&cmdline[0]);
+ }
+
+ semi_write0("PASS command line test\n");
+ return 0;
+}
+
int main(void)
{
void *bufp;
@@ -366,6 +386,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
On Mon, 13 May 2024 at 12:35, Alex Bennée <alex.bennee@linaro.org> wrote: > > We actually had the stubs to implement this. The main pain is getting > the binary name into the program so we can validate the result. Could you write the commit message so that it makes sense without reading the Subject line, please ? > index 5df95f3..268a9d9 100644 > --- a/usertest.c > +++ b/usertest.c > @@ -315,6 +315,26 @@ 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[0], sizeof(cmdline), &actual)) { > + semi_write0("FAIL could recover command line\n"); "couldn't", I guess. > + return 1; > + } > + > + if (strcmp(&cmdline[0], BINARY_NAME) != 0) { Why "&cmdline[0]" and not just "cmdline" ? > + semi_write0("FAIL unexpected command line:"); Space after the colon will make the error message a bit more neatly formatted. > + semi_write0(&cmdline[0]); Missing "return 1" ? > + } Is it worth testing that the length value returned by the semihosting function matches the length of the string? > + > + semi_write0("PASS command line test\n"); > + return 0; > +} > + > int main(void) > { > void *bufp; > @@ -366,6 +386,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 thanks -- PMM
Alex Bennée <alex.bennee@linaro.org> writes: > We actually had the stubs to implement this. The main pain is getting > the binary name into the program so we can validate the result. > > Signed-off-by: Alex Bennée <alex.bennee@linaro.org> > --- > Makefile | 22 +++++++++++----------- > usertest.c | 24 ++++++++++++++++++++++++ > 2 files changed, 35 insertions(+), 11 deletions(-) > > diff --git a/Makefile b/Makefile > index 59fd831..f77665f 100644 > --- a/Makefile > +++ b/Makefile <snip> > --- a/usertest.c > +++ b/usertest.c > @@ -315,6 +315,26 @@ 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[0], sizeof(cmdline), &actual)) { > + semi_write0("FAIL could recover command line\n"); > + return 1; > + } > + > + if (strcmp(&cmdline[0], BINARY_NAME) != 0) { > + semi_write0("FAIL unexpected command line:"); > + semi_write0(&cmdline[0]); oops need an error leg here. > + } > + > + semi_write0("PASS command line test\n"); > + return 0; > +} > + > int main(void) > { > void *bufp; > @@ -366,6 +386,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 */ -- Alex Bennée Virtualisation Tech Lead @ Linaro
© 2016 - 2024 Red Hat, Inc.