* [Semihosting Tests PATCH 0/3] add SYS_GET_CMDLINE test
@ 2024-05-13 11:35 Alex Bennée
2024-05-13 11:35 ` [Semihosting Tests PATCH 1/3] .editorconfig: add code conventions for tooling Alex Bennée
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Alex Bennée @ 2024-05-13 11:35 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, Alex Bennée
Hi Peter,
Looking at bug #2322 I wanted to make sure SYS_GET_CMDLINE works as I
expected. While at it I needed to fix a compile error with headers
which I guess we got away with on earlier compilers.
I've added an editorconfig for good measure.
Alex Bennée (3):
.editorconfig: add code conventions for tooling
update includes for bare metal compiling
add SYS_GET_CMDLINE test
.editorconfig | 28 ++++++++++++++++++++++++++++
Makefile | 22 +++++++++++-----------
semihosting.c | 4 ++--
semihosting.h | 2 +-
string.c | 2 +-
usertest.c | 26 +++++++++++++++++++++++++-
6 files changed, 68 insertions(+), 16 deletions(-)
create mode 100644 .editorconfig
--
2.39.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Semihosting Tests PATCH 1/3] .editorconfig: add code conventions for tooling
2024-05-13 11:35 [Semihosting Tests PATCH 0/3] add SYS_GET_CMDLINE test Alex Bennée
@ 2024-05-13 11:35 ` Alex Bennée
2024-05-20 15:06 ` Peter Maydell
2024-05-13 11:35 ` [Semihosting Tests PATCH 2/3] update includes for bare metal compiling Alex Bennée
2024-05-13 11:35 ` [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test Alex Bennée
2 siblings, 1 reply; 8+ messages in thread
From: Alex Bennée @ 2024-05-13 11:35 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, Alex Bennée
It's a pain when you come back to a code base you haven't touched in a
while and realise whatever indent settings you were using having
carried over. Add an editorconfig and be done with it.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
.editorconfig | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
create mode 100644 .editorconfig
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..e1540ae
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,28 @@
+# EditorConfig is a file format and collection of text editor plugins
+# for maintaining consistent coding styles between different editors
+# and IDEs. Most popular editors support this either natively or via
+# plugin.
+#
+# Check https://editorconfig.org for details.
+#
+# Emacs: you need https://github.com/10sr/editorconfig-custom-majormode-el
+# to automatically enable the appropriate major-mode for your files
+# that aren't already caught by your existing config.
+#
+
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+charset = utf-8
+
+[Makefile*]
+indent_style = tab
+indent_size = 8
+emacs_mode = makefile
+
+[*.{c,h}]
+indent_style = space
+indent_size = 4
+emacs_mode = c
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Semihosting Tests PATCH 2/3] update includes for bare metal compiling
2024-05-13 11:35 [Semihosting Tests PATCH 0/3] add SYS_GET_CMDLINE test Alex Bennée
2024-05-13 11:35 ` [Semihosting Tests PATCH 1/3] .editorconfig: add code conventions for tooling Alex Bennée
@ 2024-05-13 11:35 ` Alex Bennée
2024-05-20 15:07 ` Peter Maydell
2024-05-13 11:35 ` [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test Alex Bennée
2 siblings, 1 reply; 8+ messages in thread
From: Alex Bennée @ 2024-05-13 11:35 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, Alex Bennée
We shouldn't use <string.h> for our own implementation. Also the base
types we need live in <stdint.h> as <inttypes.h> doesn't exist for the
bare metal compilers.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
semihosting.c | 4 ++--
semihosting.h | 2 +-
string.c | 2 +-
usertest.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/semihosting.c b/semihosting.c
index 7a0ee0c..27dafbe 100644
--- a/semihosting.c
+++ b/semihosting.c
@@ -16,8 +16,8 @@
* from this software without specific prior written permission.
*/
-#include <inttypes.h>
-#include <string.h>
+#include <stdint.h>
+#include "string.h"
#include "semihosting.h"
int semi_open(char const *filename, int mode)
diff --git a/semihosting.h b/semihosting.h
index 06cda8d..68344fb 100644
--- a/semihosting.h
+++ b/semihosting.h
@@ -19,7 +19,7 @@
#ifndef SEMIHOSTING_H
#define SEMIHOSTING_H
-#include <inttypes.h>
+#include <stdint.h>
#define SYS_OPEN 1
#define OPEN_RDONLY 1
diff --git a/string.c b/string.c
index 045d71b..c289aa1 100644
--- a/string.c
+++ b/string.c
@@ -16,7 +16,7 @@
* from this software without specific prior written permission.
*/
-#include <string.h>
+#include "string.h"
static void *__memmove_down(void *__dest, __const void *__src, size_t __n)
{
diff --git a/usertest.c b/usertest.c
index ce0f61d..5df95f3 100644
--- a/usertest.c
+++ b/usertest.c
@@ -20,7 +20,7 @@
* from this software without specific prior written permission.
*/
-#include <stdio.h>
+#include "string.h"
#include "semihosting.h"
#include "printf/printf.h"
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test
2024-05-13 11:35 [Semihosting Tests PATCH 0/3] add SYS_GET_CMDLINE test Alex Bennée
2024-05-13 11:35 ` [Semihosting Tests PATCH 1/3] .editorconfig: add code conventions for tooling Alex Bennée
2024-05-13 11:35 ` [Semihosting Tests PATCH 2/3] update includes for bare metal compiling Alex Bennée
@ 2024-05-13 11:35 ` Alex Bennée
2024-05-13 12:36 ` Alex Bennée
2024-05-20 15:17 ` Peter Maydell
2 siblings, 2 replies; 8+ messages in thread
From: Alex Bennée @ 2024-05-13 11:35 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, Alex Bennée
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test
2024-05-13 11:35 ` [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test Alex Bennée
@ 2024-05-13 12:36 ` Alex Bennée
2024-05-20 15:17 ` Peter Maydell
1 sibling, 0 replies; 8+ messages in thread
From: Alex Bennée @ 2024-05-13 12:36 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Semihosting Tests PATCH 1/3] .editorconfig: add code conventions for tooling
2024-05-13 11:35 ` [Semihosting Tests PATCH 1/3] .editorconfig: add code conventions for tooling Alex Bennée
@ 2024-05-20 15:06 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2024-05-20 15:06 UTC (permalink / raw)
To: Alex Bennée; +Cc: qemu-devel
On Mon, 13 May 2024 at 12:35, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> It's a pain when you come back to a code base you haven't touched in a
> while and realise whatever indent settings you were using having
> carried over. Add an editorconfig and be done with it.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> .editorconfig | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
> create mode 100644 .editorconfig
>
> diff --git a/.editorconfig b/.editorconfig
> new file mode 100644
> index 0000000..e1540ae
> --- /dev/null
> +++ b/.editorconfig
> @@ -0,0 +1,28 @@
> +# EditorConfig is a file format and collection of text editor plugins
> +# for maintaining consistent coding styles between different editors
> +# and IDEs. Most popular editors support this either natively or via
> +# plugin.
> +#
> +# Check https://editorconfig.org for details.
> +#
> +# Emacs: you need https://github.com/10sr/editorconfig-custom-majormode-el
> +# to automatically enable the appropriate major-mode for your files
> +# that aren't already caught by your existing config.
> +#
> +
> +root = true
> +
> +[*]
> +end_of_line = lf
> +insert_final_newline = true
> +charset = utf-8
> +
> +[Makefile*]
> +indent_style = tab
> +indent_size = 8
> +emacs_mode = makefile
> +
> +[*.{c,h}]
> +indent_style = space
> +indent_size = 4
> +emacs_mode = c
The QEMU .editorconfig has a stanza for .s/.S files too:
[*.{s,S}]
indent_style = tab
indent_size = 8
emacs_mode = asm
thanks
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Semihosting Tests PATCH 2/3] update includes for bare metal compiling
2024-05-13 11:35 ` [Semihosting Tests PATCH 2/3] update includes for bare metal compiling Alex Bennée
@ 2024-05-20 15:07 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2024-05-20 15:07 UTC (permalink / raw)
To: Alex Bennée; +Cc: qemu-devel
On Mon, 13 May 2024 at 12:35, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> We shouldn't use <string.h> for our own implementation. Also the base
> types we need live in <stdint.h> as <inttypes.h> doesn't exist for the
> bare metal compilers.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test
2024-05-13 11:35 ` [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test Alex Bennée
2024-05-13 12:36 ` Alex Bennée
@ 2024-05-20 15:17 ` Peter Maydell
1 sibling, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2024-05-20 15:17 UTC (permalink / raw)
To: Alex Bennée; +Cc: qemu-devel
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-05-20 15:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-13 11:35 [Semihosting Tests PATCH 0/3] add SYS_GET_CMDLINE test Alex Bennée
2024-05-13 11:35 ` [Semihosting Tests PATCH 1/3] .editorconfig: add code conventions for tooling Alex Bennée
2024-05-20 15:06 ` Peter Maydell
2024-05-13 11:35 ` [Semihosting Tests PATCH 2/3] update includes for bare metal compiling Alex Bennée
2024-05-20 15:07 ` Peter Maydell
2024-05-13 11:35 ` [Semihosting Tests PATCH 3/3] add SYS_GET_CMDLINE test Alex Bennée
2024-05-13 12:36 ` Alex Bennée
2024-05-20 15:17 ` Peter Maydell
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).