* [PATCH 01/17] kbuild: add install target
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 02/17] kbuild: add ARCH={i386, x86_64} as aliases for x86 Ahmad Fatoum
` (15 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
For CI, it could be useful to have the barebox build install the
artifacts into a directory. Add an install target that does this.
Example usage: make install INSTALL_PATH=install/
Unlike Linux, we don't set INSTALL_PATH to a default value, because
most barebox-enabled boards don't have barebox in a file system.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 14 ++++++++++++++
images/Makefile | 5 +++++
2 files changed, 19 insertions(+)
diff --git a/Makefile b/Makefile
index e80584b9c9dd..a13f1e792549 100644
--- a/Makefile
+++ b/Makefile
@@ -880,6 +880,20 @@ ifndef CONFIG_PBL_IMAGE
$(call cmd,check_file_size,$@,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
endif
+install:
+ifeq ($(INSTALL_PATH),)
+ @echo 'error: INSTALL_PATH undefined' >&2
+ @exit 1
+endif
+ifdef CONFIG_PBL_IMAGE
+ $(Q)$(MAKE) $(build)=images __images_install
+ @install -t "$(INSTALL_PATH)" barebox.bin
+else
+ @install -t "$(INSTALL_PATH)" $(KBUILD_IMAGE)
+endif
+
+PHONY += install
+
# By default the uImage load address is 2MB below CONFIG_TEXT_BASE,
# leaving space for the compressed PBL image at 1MB below CONFIG_TEXT_BASE.
UIMAGE_BASE ?= $(shell printf "0x%08x" $$(($(CONFIG_TEXT_BASE) - 0x200000)))
diff --git a/images/Makefile b/images/Makefile
index ee1347f6b6bd..c185982c17ed 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -204,6 +204,11 @@ images: $(image-y-path) $(flash-link) $(flash-list) FORCE
@echo "images built:"
@for i in $(image-y); do echo $$i; done
+__images_install: images
+ @for i in $(image-y-path); do install -t "$(INSTALL_PATH)" $$i; done
+
+PHONY += __images_install
+
$(flash-link): $(link-dest) FORCE
$(call if_changed,ln)
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 02/17] kbuild: add ARCH={i386, x86_64} as aliases for x86
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 01/17] kbuild: add install target Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 03/17] kbuild: add ARCH=um alias for sandbox Ahmad Fatoum
` (14 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
Linux already does this. Follow suit so we can interoperate with tools
that assume Linux-like Kbuild structure.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Makefile b/Makefile
index a13f1e792549..387f46b587d4 100644
--- a/Makefile
+++ b/Makefile
@@ -343,6 +343,14 @@ ifeq ($(ARCH),arm64)
SRCARCH := arm
endif
+ifeq ($(ARCH),i386)
+ SRCARCH := x86
+endif
+
+ifeq ($(ARCH),x86_64)
+ SRCARCH := x86
+endif
+
# Support ARCH=ppc for backward compatibility
ifeq ($(ARCH),ppc)
SRCARCH := powerpc
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 03/17] kbuild: add ARCH=um alias for sandbox
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 01/17] kbuild: add install target Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 02/17] kbuild: add ARCH={i386, x86_64} as aliases for x86 Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 04/17] MIPS: qemu-malta: generate swapped image as part of multi-image build Ahmad Fatoum
` (13 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
ARCH=um (User Mode) is the Linux kernel counterpart to our sandbox
architecture. Add um as an alias, so we can interoperate with tools that
handle ARCH=um specially.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Makefile b/Makefile
index 387f46b587d4..f6c0c4817046 100644
--- a/Makefile
+++ b/Makefile
@@ -356,6 +356,10 @@ ifeq ($(ARCH),ppc)
SRCARCH := powerpc
endif
+ifeq ($(ARCH),um)
+ SRCARCH := sandbox
+endif
+
KCONFIG_CONFIG ?= .config
export KCONFIG_CONFIG
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 04/17] MIPS: qemu-malta: generate swapped image as part of multi-image build
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (2 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 03/17] kbuild: add ARCH=um alias for sandbox Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 9:27 ` Jules Maselbas
2021-04-12 7:16 ` [PATCH 05/17] MIPS: qemu-malta: replace board code with syscon-reboot Ahmad Fatoum
` (12 subsequent siblings)
16 siblings, 1 reply; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
Having to manually swap the words in the MIPS Malta image for QEMU
little endian emulation is annoying.
Have the multi-image build for Malta generate a second .swapped
image that can be readily used if needed.
Cc: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Documentation/boards/mips/qemu-malta.rst | 16 ++---
images/.gitignore | 1 +
images/Makefile | 2 +-
images/Makefile.malta | 8 ++-
scripts/Makefile | 1 +
scripts/bswap.c | 83 ++++++++++++++++++++++++
6 files changed, 97 insertions(+), 14 deletions(-)
create mode 100644 scripts/bswap.c
diff --git a/Documentation/boards/mips/qemu-malta.rst b/Documentation/boards/mips/qemu-malta.rst
index e188ae8c642a..fd37d5edb229 100644
--- a/Documentation/boards/mips/qemu-malta.rst
+++ b/Documentation/boards/mips/qemu-malta.rst
@@ -10,31 +10,23 @@ QEMU run string:
qemu-system-mips -nodefaults -M malta -m 256 \
-device VGA -serial stdio -monitor null \
- -bios barebox-flash-image
+ -bios ./images/barebox-qemu-malta.img
Little-endian mode
------------------
-Running little-endian Malta is a bit tricky.
In little-endian mode the 32bit words in the boot flash image are swapped,
a neat trick which allows bi-endian firmware.
-You have to swap words of ``zbarebox.bin`` image, e.g.:
-
-.. code-block:: sh
-
- echo arch/mips/pbl/zbarebox.bin \
- | cpio --create \
- | cpio --extract --swap --unconditional
-
-QEMU run string:
+The barebox build generates a second ``./images/barebox-qemu-malta.img.swapped``
+image that can be used in this case, e.g.:
.. code-block:: sh
qemu-system-mipsel -nodefaults -M malta -m 256 \
-device VGA -serial stdio -monitor null \
- -bios barebox-flash-image
+ -bios ./images/barebox-qemu-malta.img.swapped
Using GXemul
diff --git a/images/.gitignore b/images/.gitignore
index eafdb44b5bdd..3a9a77dad16e 100644
--- a/images/.gitignore
+++ b/images/.gitignore
@@ -32,3 +32,4 @@ barebox.sum
*.mvebu1img
*.stm32
*.nmon
+*.swapped
diff --git a/images/Makefile b/images/Makefile
index c185982c17ed..cc330d957597 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -218,5 +218,5 @@ $(flash-list): $(image-y-path)
clean-files := *.pbl *.pblb *.map start_*.imximg *.img barebox.z start_*.kwbimg \
start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \
*.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd \
- start_*.simximg start_*.usimximg *.zynqimg *.image
+ start_*.simximg start_*.usimximg *.zynqimg *.image *.swapped
clean-files += pbl.lds
diff --git a/images/Makefile.malta b/images/Makefile.malta
index 5739ec464092..ce7b4424b63b 100644
--- a/images/Makefile.malta
+++ b/images/Makefile.malta
@@ -1,3 +1,9 @@
+quiet_cmd_bswap32_image = BSWAP4 $@
+ cmd_bswap32_image = scripts/bswap -B 4 $< > $@
+
+$(obj)/%.img.swapped: $(obj)/%.img FORCE
+ $(call if_changed,bswap32_image)
+
pblb-$(CONFIG_BOARD_QEMU_MALTA) += start_qemu_malta
FILE_barebox-qemu-malta.img = start_qemu_malta.pblb
-image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img
+image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img barebox-qemu-malta.img.swapped
diff --git a/scripts/Makefile b/scripts/Makefile
index 2d322fd1c923..57861fa9b2f8 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -16,6 +16,7 @@ hostprogs-always-$(CONFIG_KALLSYMS) += kallsyms
hostprogs-always-$(CONFIG_MIPS) += mips-relocs
hostprogs-always-$(CONFIG_MVEBU_HOSTTOOLS) += kwbimage kwboot mvebuimg
hostprogs-always-$(CONFIG_ARCH_OMAP) += omap_signGP mk-omap-image
+hostprogs-always-$(CONFIG_BOARD_QEMU_MALTA) += bswap
hostprogs-always-$(CONFIG_ARCH_S5PCxx) += s5p_cksum
hostprogs-always-$(CONFIG_ARCH_DAVINCI) += mkublheader
HOSTCFLAGS_zynq_mkimage.o = -I$(srctree) -I$(srctree)/arch/arm/mach-zynq/include
diff --git a/scripts/bswap.c b/scripts/bswap.c
new file mode 100644
index 000000000000..e87d30cfe51e
--- /dev/null
+++ b/scripts/bswap.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2012 Jan Luebbe <j.luebbe@pengutronix.de>
+
+#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <endian.h>
+
+static void usage(char *prgname)
+{
+ printf("usage: %s [OPTION] FILE > IMAGE\n"
+ "\n"
+ "options:\n"
+ " -B number of bytes to swap each time\n",
+ prgname);
+}
+
+int main(int argc, char *argv[])
+{
+ FILE *input;
+ int opt;
+ size_t size;
+ unsigned long bytes = 0;
+ uint32_t temp_u32;
+
+ while((opt = getopt(argc, argv, "B:")) != -1) {
+ switch (opt) {
+ case 'B':
+ bytes = strtoul(optarg, NULL, 0);
+ break;
+ }
+ }
+
+ if (optind >= argc) {
+ usage(argv[0]);
+ return 1;
+ }
+
+ if (bytes != 4) {
+ fprintf(stderr, "-B %s unsupported\n", optarg);
+ return 1;
+ }
+
+ input = fopen(argv[optind], "r");
+ if (input == NULL) {
+ perror("fopen");
+ return 1;
+ }
+
+ for (;;) {
+ size = fread(&temp_u32, 1, sizeof(uint32_t), input);
+ if (!size)
+ break;
+ if (size < 4 && !feof(input)) {
+ perror("fread");
+ return 1;
+ }
+
+ temp_u32 = htobe32(le32toh(temp_u32));
+ if (fwrite(&temp_u32, 1, sizeof(uint32_t), stdout) != 4) {
+ perror("fwrite");
+ return 1;
+ }
+ }
+
+ if (fclose(input) != 0) {
+ perror("fclose");
+ return 1;
+ }
+
+ return 0;
+}
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 04/17] MIPS: qemu-malta: generate swapped image as part of multi-image build
2021-04-12 7:16 ` [PATCH 04/17] MIPS: qemu-malta: generate swapped image as part of multi-image build Ahmad Fatoum
@ 2021-04-12 9:27 ` Jules Maselbas
2021-04-12 9:45 ` Ahmad Fatoum
0 siblings, 1 reply; 21+ messages in thread
From: Jules Maselbas @ 2021-04-12 9:27 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox, rcz
Hi Ahmad,
Just in case you didn't know, the byte swap can be done
without a writting C program but with a simple shell script.
You can use objcopy to create a byte swapped image:
objcopy -I binary --reverse-bytes=4 barebox barebox.swapped
You can use truncate to make sure the file size is multiple of 4 bytes:
truncate -s %4 file
bswap32 script could be implemented like this:
cp $in $out
truncate -s %4 $out
objcopy -I binary --reverse-byte=4 $out
Best,
Jules
On Mon, Apr 12, 2021 at 09:16:38AM +0200, Ahmad Fatoum wrote:
> Having to manually swap the words in the MIPS Malta image for QEMU
> little endian emulation is annoying.
>
> Have the multi-image build for Malta generate a second .swapped
> image that can be readily used if needed.
>
> Cc: Antony Pavlov <antonynpavlov@gmail.com>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Documentation/boards/mips/qemu-malta.rst | 16 ++---
> images/.gitignore | 1 +
> images/Makefile | 2 +-
> images/Makefile.malta | 8 ++-
> scripts/Makefile | 1 +
> scripts/bswap.c | 83 ++++++++++++++++++++++++
> 6 files changed, 97 insertions(+), 14 deletions(-)
> create mode 100644 scripts/bswap.c
>
> diff --git a/Documentation/boards/mips/qemu-malta.rst b/Documentation/boards/mips/qemu-malta.rst
> index e188ae8c642a..fd37d5edb229 100644
> --- a/Documentation/boards/mips/qemu-malta.rst
> +++ b/Documentation/boards/mips/qemu-malta.rst
> @@ -10,31 +10,23 @@ QEMU run string:
>
> qemu-system-mips -nodefaults -M malta -m 256 \
> -device VGA -serial stdio -monitor null \
> - -bios barebox-flash-image
> + -bios ./images/barebox-qemu-malta.img
>
>
> Little-endian mode
> ------------------
>
> -Running little-endian Malta is a bit tricky.
> In little-endian mode the 32bit words in the boot flash image are swapped,
> a neat trick which allows bi-endian firmware.
>
> -You have to swap words of ``zbarebox.bin`` image, e.g.:
> -
> -.. code-block:: sh
> -
> - echo arch/mips/pbl/zbarebox.bin \
> - | cpio --create \
> - | cpio --extract --swap --unconditional
> -
> -QEMU run string:
> +The barebox build generates a second ``./images/barebox-qemu-malta.img.swapped``
> +image that can be used in this case, e.g.:
>
> .. code-block:: sh
>
> qemu-system-mipsel -nodefaults -M malta -m 256 \
> -device VGA -serial stdio -monitor null \
> - -bios barebox-flash-image
> + -bios ./images/barebox-qemu-malta.img.swapped
>
>
> Using GXemul
> diff --git a/images/.gitignore b/images/.gitignore
> index eafdb44b5bdd..3a9a77dad16e 100644
> --- a/images/.gitignore
> +++ b/images/.gitignore
> @@ -32,3 +32,4 @@ barebox.sum
> *.mvebu1img
> *.stm32
> *.nmon
> +*.swapped
> diff --git a/images/Makefile b/images/Makefile
> index c185982c17ed..cc330d957597 100644
> --- a/images/Makefile
> +++ b/images/Makefile
> @@ -218,5 +218,5 @@ $(flash-list): $(image-y-path)
> clean-files := *.pbl *.pblb *.map start_*.imximg *.img barebox.z start_*.kwbimg \
> start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \
> *.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd \
> - start_*.simximg start_*.usimximg *.zynqimg *.image
> + start_*.simximg start_*.usimximg *.zynqimg *.image *.swapped
> clean-files += pbl.lds
> diff --git a/images/Makefile.malta b/images/Makefile.malta
> index 5739ec464092..ce7b4424b63b 100644
> --- a/images/Makefile.malta
> +++ b/images/Makefile.malta
> @@ -1,3 +1,9 @@
> +quiet_cmd_bswap32_image = BSWAP4 $@
> + cmd_bswap32_image = scripts/bswap -B 4 $< > $@
> +
> +$(obj)/%.img.swapped: $(obj)/%.img FORCE
> + $(call if_changed,bswap32_image)
> +
> pblb-$(CONFIG_BOARD_QEMU_MALTA) += start_qemu_malta
> FILE_barebox-qemu-malta.img = start_qemu_malta.pblb
> -image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img
> +image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img barebox-qemu-malta.img.swapped
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 2d322fd1c923..57861fa9b2f8 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -16,6 +16,7 @@ hostprogs-always-$(CONFIG_KALLSYMS) += kallsyms
> hostprogs-always-$(CONFIG_MIPS) += mips-relocs
> hostprogs-always-$(CONFIG_MVEBU_HOSTTOOLS) += kwbimage kwboot mvebuimg
> hostprogs-always-$(CONFIG_ARCH_OMAP) += omap_signGP mk-omap-image
> +hostprogs-always-$(CONFIG_BOARD_QEMU_MALTA) += bswap
> hostprogs-always-$(CONFIG_ARCH_S5PCxx) += s5p_cksum
> hostprogs-always-$(CONFIG_ARCH_DAVINCI) += mkublheader
> HOSTCFLAGS_zynq_mkimage.o = -I$(srctree) -I$(srctree)/arch/arm/mach-zynq/include
> diff --git a/scripts/bswap.c b/scripts/bswap.c
> new file mode 100644
> index 000000000000..e87d30cfe51e
> --- /dev/null
> +++ b/scripts/bswap.c
> @@ -0,0 +1,83 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +// SPDX-FileCopyrightText: 2012 Jan Luebbe <j.luebbe@pengutronix.de>
> +
> +#define _BSD_SOURCE
> +#define _DEFAULT_SOURCE
> +
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <stdint.h>
> +#include <limits.h>
> +#include <errno.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <getopt.h>
> +#include <endian.h>
> +
> +static void usage(char *prgname)
> +{
> + printf("usage: %s [OPTION] FILE > IMAGE\n"
> + "\n"
> + "options:\n"
> + " -B number of bytes to swap each time\n",
> + prgname);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + FILE *input;
> + int opt;
> + size_t size;
> + unsigned long bytes = 0;
> + uint32_t temp_u32;
> +
> + while((opt = getopt(argc, argv, "B:")) != -1) {
> + switch (opt) {
> + case 'B':
> + bytes = strtoul(optarg, NULL, 0);
> + break;
> + }
> + }
> +
> + if (optind >= argc) {
> + usage(argv[0]);
> + return 1;
> + }
> +
> + if (bytes != 4) {
> + fprintf(stderr, "-B %s unsupported\n", optarg);
> + return 1;
> + }
> +
> + input = fopen(argv[optind], "r");
> + if (input == NULL) {
> + perror("fopen");
> + return 1;
> + }
> +
> + for (;;) {
> + size = fread(&temp_u32, 1, sizeof(uint32_t), input);
> + if (!size)
> + break;
> + if (size < 4 && !feof(input)) {
> + perror("fread");
> + return 1;
> + }
> +
> + temp_u32 = htobe32(le32toh(temp_u32));
> + if (fwrite(&temp_u32, 1, sizeof(uint32_t), stdout) != 4) {
> + perror("fwrite");
> + return 1;
> + }
> + }
> +
> + if (fclose(input) != 0) {
> + perror("fclose");
> + return 1;
> + }
> +
> + return 0;
> +}
> --
> 2.29.2
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 04/17] MIPS: qemu-malta: generate swapped image as part of multi-image build
2021-04-12 9:27 ` Jules Maselbas
@ 2021-04-12 9:45 ` Ahmad Fatoum
0 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 9:45 UTC (permalink / raw)
To: Jules Maselbas; +Cc: barebox, rcz
Hello Jules,
On 12.04.21 11:27, Jules Maselbas wrote:
> Hi Ahmad,
>
> Just in case you didn't know, the byte swap can be done
> without a writting C program but with a simple shell script.
>
> You can use objcopy to create a byte swapped image:
> objcopy -I binary --reverse-bytes=4 barebox barebox.swapped
>
> You can use truncate to make sure the file size is multiple of 4 bytes:
> truncate -s %4 file
>
> bswap32 script could be implemented like this:
> cp $in $out
> truncate -s %4 $out
> objcopy -I binary --reverse-byte=4 $out
I did not know that objcopy can be used for that. Will try it out and
send a fixup.
Thanks!
Ahmad
>
> Best,
> Jules
>
> On Mon, Apr 12, 2021 at 09:16:38AM +0200, Ahmad Fatoum wrote:
>> Having to manually swap the words in the MIPS Malta image for QEMU
>> little endian emulation is annoying.
>>
>> Have the multi-image build for Malta generate a second .swapped
>> image that can be readily used if needed.
>>
>> Cc: Antony Pavlov <antonynpavlov@gmail.com>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> Documentation/boards/mips/qemu-malta.rst | 16 ++---
>> images/.gitignore | 1 +
>> images/Makefile | 2 +-
>> images/Makefile.malta | 8 ++-
>> scripts/Makefile | 1 +
>> scripts/bswap.c | 83 ++++++++++++++++++++++++
>> 6 files changed, 97 insertions(+), 14 deletions(-)
>> create mode 100644 scripts/bswap.c
>>
>> diff --git a/Documentation/boards/mips/qemu-malta.rst b/Documentation/boards/mips/qemu-malta.rst
>> index e188ae8c642a..fd37d5edb229 100644
>> --- a/Documentation/boards/mips/qemu-malta.rst
>> +++ b/Documentation/boards/mips/qemu-malta.rst
>> @@ -10,31 +10,23 @@ QEMU run string:
>>
>> qemu-system-mips -nodefaults -M malta -m 256 \
>> -device VGA -serial stdio -monitor null \
>> - -bios barebox-flash-image
>> + -bios ./images/barebox-qemu-malta.img
>>
>>
>> Little-endian mode
>> ------------------
>>
>> -Running little-endian Malta is a bit tricky.
>> In little-endian mode the 32bit words in the boot flash image are swapped,
>> a neat trick which allows bi-endian firmware.
>>
>> -You have to swap words of ``zbarebox.bin`` image, e.g.:
>> -
>> -.. code-block:: sh
>> -
>> - echo arch/mips/pbl/zbarebox.bin \
>> - | cpio --create \
>> - | cpio --extract --swap --unconditional
>> -
>> -QEMU run string:
>> +The barebox build generates a second ``./images/barebox-qemu-malta.img.swapped``
>> +image that can be used in this case, e.g.:
>>
>> .. code-block:: sh
>>
>> qemu-system-mipsel -nodefaults -M malta -m 256 \
>> -device VGA -serial stdio -monitor null \
>> - -bios barebox-flash-image
>> + -bios ./images/barebox-qemu-malta.img.swapped
>>
>>
>> Using GXemul
>> diff --git a/images/.gitignore b/images/.gitignore
>> index eafdb44b5bdd..3a9a77dad16e 100644
>> --- a/images/.gitignore
>> +++ b/images/.gitignore
>> @@ -32,3 +32,4 @@ barebox.sum
>> *.mvebu1img
>> *.stm32
>> *.nmon
>> +*.swapped
>> diff --git a/images/Makefile b/images/Makefile
>> index c185982c17ed..cc330d957597 100644
>> --- a/images/Makefile
>> +++ b/images/Makefile
>> @@ -218,5 +218,5 @@ $(flash-list): $(image-y-path)
>> clean-files := *.pbl *.pblb *.map start_*.imximg *.img barebox.z start_*.kwbimg \
>> start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \
>> *.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd \
>> - start_*.simximg start_*.usimximg *.zynqimg *.image
>> + start_*.simximg start_*.usimximg *.zynqimg *.image *.swapped
>> clean-files += pbl.lds
>> diff --git a/images/Makefile.malta b/images/Makefile.malta
>> index 5739ec464092..ce7b4424b63b 100644
>> --- a/images/Makefile.malta
>> +++ b/images/Makefile.malta
>> @@ -1,3 +1,9 @@
>> +quiet_cmd_bswap32_image = BSWAP4 $@
>> + cmd_bswap32_image = scripts/bswap -B 4 $< > $@
>> +
>> +$(obj)/%.img.swapped: $(obj)/%.img FORCE
>> + $(call if_changed,bswap32_image)
>> +
>> pblb-$(CONFIG_BOARD_QEMU_MALTA) += start_qemu_malta
>> FILE_barebox-qemu-malta.img = start_qemu_malta.pblb
>> -image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img
>> +image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img barebox-qemu-malta.img.swapped
>> diff --git a/scripts/Makefile b/scripts/Makefile
>> index 2d322fd1c923..57861fa9b2f8 100644
>> --- a/scripts/Makefile
>> +++ b/scripts/Makefile
>> @@ -16,6 +16,7 @@ hostprogs-always-$(CONFIG_KALLSYMS) += kallsyms
>> hostprogs-always-$(CONFIG_MIPS) += mips-relocs
>> hostprogs-always-$(CONFIG_MVEBU_HOSTTOOLS) += kwbimage kwboot mvebuimg
>> hostprogs-always-$(CONFIG_ARCH_OMAP) += omap_signGP mk-omap-image
>> +hostprogs-always-$(CONFIG_BOARD_QEMU_MALTA) += bswap
>> hostprogs-always-$(CONFIG_ARCH_S5PCxx) += s5p_cksum
>> hostprogs-always-$(CONFIG_ARCH_DAVINCI) += mkublheader
>> HOSTCFLAGS_zynq_mkimage.o = -I$(srctree) -I$(srctree)/arch/arm/mach-zynq/include
>> diff --git a/scripts/bswap.c b/scripts/bswap.c
>> new file mode 100644
>> index 000000000000..e87d30cfe51e
>> --- /dev/null
>> +++ b/scripts/bswap.c
>> @@ -0,0 +1,83 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +// SPDX-FileCopyrightText: 2012 Jan Luebbe <j.luebbe@pengutronix.de>
>> +
>> +#define _BSD_SOURCE
>> +#define _DEFAULT_SOURCE
>> +
>> +#include <stdio.h>
>> +#include <sys/types.h>
>> +#include <sys/stat.h>
>> +#include <fcntl.h>
>> +#include <unistd.h>
>> +#include <stdint.h>
>> +#include <limits.h>
>> +#include <errno.h>
>> +#include <stdlib.h>
>> +#include <string.h>
>> +#include <getopt.h>
>> +#include <endian.h>
>> +
>> +static void usage(char *prgname)
>> +{
>> + printf("usage: %s [OPTION] FILE > IMAGE\n"
>> + "\n"
>> + "options:\n"
>> + " -B number of bytes to swap each time\n",
>> + prgname);
>> +}
>> +
>> +int main(int argc, char *argv[])
>> +{
>> + FILE *input;
>> + int opt;
>> + size_t size;
>> + unsigned long bytes = 0;
>> + uint32_t temp_u32;
>> +
>> + while((opt = getopt(argc, argv, "B:")) != -1) {
>> + switch (opt) {
>> + case 'B':
>> + bytes = strtoul(optarg, NULL, 0);
>> + break;
>> + }
>> + }
>> +
>> + if (optind >= argc) {
>> + usage(argv[0]);
>> + return 1;
>> + }
>> +
>> + if (bytes != 4) {
>> + fprintf(stderr, "-B %s unsupported\n", optarg);
>> + return 1;
>> + }
>> +
>> + input = fopen(argv[optind], "r");
>> + if (input == NULL) {
>> + perror("fopen");
>> + return 1;
>> + }
>> +
>> + for (;;) {
>> + size = fread(&temp_u32, 1, sizeof(uint32_t), input);
>> + if (!size)
>> + break;
>> + if (size < 4 && !feof(input)) {
>> + perror("fread");
>> + return 1;
>> + }
>> +
>> + temp_u32 = htobe32(le32toh(temp_u32));
>> + if (fwrite(&temp_u32, 1, sizeof(uint32_t), stdout) != 4) {
>> + perror("fwrite");
>> + return 1;
>> + }
>> + }
>> +
>> + if (fclose(input) != 0) {
>> + perror("fclose");
>> + return 1;
>> + }
>> +
>> + return 0;
>> +}
>> --
>> 2.29.2
>>
>>
>> _______________________________________________
>> barebox mailing list
>> barebox@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox
>>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 05/17] MIPS: qemu-malta: replace board code with syscon-reboot
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (3 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 04/17] MIPS: qemu-malta: generate swapped image as part of multi-image build Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 06/17] MIPS: configs: qemu-malta: enable Virt I/O Ahmad Fatoum
` (11 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
We got two identical implementations of system controller reset,
one in mach-malta and another in mach-bcm47xx.
For the Malta board, Linux represents this as syscon-reboot nodes,
do likewise. This could probably done for the dlink-dir-320, but
would increase code size. This is not done here, because inability to
test.
Tested on Qemu Malta board.
Cc: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/mips/dts/qemu-malta.dts | 13 ++++++++
arch/mips/mach-malta/Kconfig | 1 +
arch/mips/mach-malta/Makefile | 1 -
arch/mips/mach-malta/include/mach/hardware.h | 6 ----
arch/mips/mach-malta/reset.c | 31 --------------------
5 files changed, 14 insertions(+), 38 deletions(-)
delete mode 100644 arch/mips/mach-malta/reset.c
diff --git a/arch/mips/dts/qemu-malta.dts b/arch/mips/dts/qemu-malta.dts
index 32e473cac0d2..926806e587c1 100644
--- a/arch/mips/dts/qemu-malta.dts
+++ b/arch/mips/dts/qemu-malta.dts
@@ -46,6 +46,19 @@
status = "disabled";
};
+ fpga_regs: system-controller@1f000000 {
+ compatible = "mti,malta-fpga", "syscon", "simple-mfd";
+ reg = <0x1f000000 0x1000>;
+ native-endian;
+
+ reboot {
+ compatible = "syscon-reboot";
+ regmap = <&fpga_regs>;
+ offset = <0x500>;
+ mask = <0x42>;
+ };
+ };
+
uart2: serial@1f000900 {
compatible = "ns16550a";
reg = <0x1f000900 0x40>;
diff --git a/arch/mips/mach-malta/Kconfig b/arch/mips/mach-malta/Kconfig
index 467107514006..7aad8242baf7 100644
--- a/arch/mips/mach-malta/Kconfig
+++ b/arch/mips/mach-malta/Kconfig
@@ -4,6 +4,7 @@ config BOARD_QEMU_MALTA
bool "qemu malta"
select HAVE_PBL_IMAGE
select HAVE_IMAGE_COMPRESSION
+ select POWER_RESET_SYSCON
select HAS_NMON
endif
diff --git a/arch/mips/mach-malta/Makefile b/arch/mips/mach-malta/Makefile
index 0c5a7018d45a..7d56f215b034 100644
--- a/arch/mips/mach-malta/Makefile
+++ b/arch/mips/mach-malta/Makefile
@@ -1,2 +1 @@
-obj-y += reset.o
obj-$(CONFIG_PCI) += pci.o
diff --git a/arch/mips/mach-malta/include/mach/hardware.h b/arch/mips/mach-malta/include/mach/hardware.h
index 1176b08b6a9a..c816f412053c 100644
--- a/arch/mips/mach-malta/include/mach/hardware.h
+++ b/arch/mips/mach-malta/include/mach/hardware.h
@@ -11,10 +11,4 @@
#define MALTA_CBUS_UART 0xbf000900
#define MALTA_CBUS_UART_SHIFT 3
-/*
- * Reset register.
- */
-#define SOFTRES_REG 0xbf000500
-#define GORESET 0x42
-
#endif /* __INCLUDE_ARCH_HARDWARE_H__ */
diff --git a/arch/mips/mach-malta/reset.c b/arch/mips/mach-malta/reset.c
deleted file mode 100644
index ad0de2741b05..000000000000
--- a/arch/mips/mach-malta/reset.c
+++ /dev/null
@@ -1,31 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (C) 2011 Antony Pavlov <antonynpavlov@gmail.com>
- */
-
-/**
- * @file
- * @brief Resetting an malta board
- */
-
-#include <common.h>
-#include <io.h>
-#include <init.h>
-#include <restart.h>
-#include <mach/hardware.h>
-
-static void __noreturn malta_restart_soc(struct restart_handler *rst)
-{
- __raw_writel(GORESET, (char *)SOFTRES_REG);
-
- hang();
- /*NOTREACHED*/
-}
-
-static int restart_register_feature(void)
-{
- restart_handler_register_fn("soc", malta_restart_soc);
-
- return 0;
-}
-coredevice_initcall(restart_register_feature);
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 06/17] MIPS: configs: qemu-malta: enable Virt I/O
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (4 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 05/17] MIPS: qemu-malta: replace board code with syscon-reboot Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 07/17] openrisc: set default KBUILD_IMAGE Ahmad Fatoum
` (10 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
Virt I/O over PCI is usable on both the MIPS little- and big-endian
Malta boards emulated by QEMU. Enable Virt I/O PCI and their
dependencies.
Cc: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/mips/configs/qemu-malta_defconfig | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/mips/configs/qemu-malta_defconfig b/arch/mips/configs/qemu-malta_defconfig
index b9994f392c47..3ef2fc302a20 100644
--- a/arch/mips/configs/qemu-malta_defconfig
+++ b/arch/mips/configs/qemu-malta_defconfig
@@ -1,5 +1,6 @@
CONFIG_BOARD_QEMU_MALTA=y
CONFIG_IMAGE_COMPRESSION_XZKERN=y
+CONFIG_MMU=y
CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x400000
CONFIG_STACK_SIZE=0x7000
CONFIG_EXPERIMENTAL=y
@@ -10,13 +11,14 @@ CONFIG_AUTO_COMPLETE=y
CONFIG_MENU=y
CONFIG_BOOTM_SHOW_TYPE=y
CONFIG_CONSOLE_ALLOW_COLOR=y
-CONFIG_PARTITION=y
CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_BTHREAD=y
CONFIG_CMD_DMESG=y
CONFIG_LONGHELP=y
CONFIG_CMD_IOMEM=y
CONFIG_CMD_IMD=y
CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_BTHREAD=y
CONFIG_CMD_GO=y
CONFIG_CMD_LOADB=y
CONFIG_CMD_LOADY=y
@@ -59,6 +61,7 @@ CONFIG_NET_NFS=y
CONFIG_NET_NETCONSOLE=y
CONFIG_OFDEVICE=y
CONFIG_OF_BAREBOX_DRIVERS=y
+CONFIG_VIRTIO_CONSOLE=y
CONFIG_DRIVER_NET_RTL8139=y
# CONFIG_SPI is not set
CONFIG_I2C=y
@@ -69,12 +72,19 @@ CONFIG_DRIVER_CFI=y
# CONFIG_DRIVER_CFI_BANK_WIDTH_1 is not set
# CONFIG_DRIVER_CFI_BANK_WIDTH_2 is not set
CONFIG_CFI_BUFFER_WRITE=y
+CONFIG_DISK=y
+CONFIG_DISK_WRITE=y
+CONFIG_VIRTIO_BLK=y
CONFIG_VIDEO=y
CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_DRIVER_VIDEO_BOCHS_PCI=y
+CONFIG_VIRTIO_INPUT=y
+CONFIG_HWRNG=y
+CONFIG_HW_RANDOM_VIRTIO=y
CONFIG_GPIO_MALTA_FPGA_I2C=y
CONFIG_PCI=y
CONFIG_PCI_DEBUG=y
+CONFIG_VIRTIO_PCI=y
CONFIG_FS_CRAMFS=y
CONFIG_FS_TFTP=y
CONFIG_FS_FAT=y
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 07/17] openrisc: set default KBUILD_IMAGE
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (5 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 06/17] MIPS: configs: qemu-malta: enable Virt I/O Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 08/17] Documentation: boards: RISC-V: update TinyEMU support Ahmad Fatoum
` (9 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Stafford Horne, Ahmad Fatoum, rcz
For non-multi-image configuration, KBUILD_IMAGE is taken as the image to
install. It was so far not set for openRISC. Define it, so it can be
used with the new install target. This could be later used to package
artifacts in CI.
Cc: Stafford Horne <shorne@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/openrisc/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/openrisc/Makefile b/arch/openrisc/Makefile
index 72d7fa3d53fe..1776f56df97b 100644
--- a/arch/openrisc/Makefile
+++ b/arch/openrisc/Makefile
@@ -28,3 +28,5 @@ dts := arch/openrisc/dts
%.dtb: scripts
$(Q)$(MAKE) $(build)=$(dts) $(dts)/$@
+
+KBUILD_IMAGE := barebox
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 08/17] Documentation: boards: RISC-V: update TinyEMU support
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (6 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 07/17] openrisc: set default KBUILD_IMAGE Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 09/17] test: add basic barebox self-test infrastructure Ahmad Fatoum
` (8 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
Adding the tinyemu files as separate files and including them has the
nice benefit that temu users can just use these files directly instead
of copy pasting. While at it, update the section as input, as support
was added meanwhile.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Documentation/boards/riscv.rst | 20 +++++++++----------
Documentation/boards/riscv/barebox-virt32.cfg | 7 +++++++
Documentation/boards/riscv/barebox-virt64.cfg | 7 +++++++
3 files changed, 24 insertions(+), 10 deletions(-)
create mode 100644 Documentation/boards/riscv/barebox-virt32.cfg
create mode 100644 Documentation/boards/riscv/barebox-virt64.cfg
diff --git a/Documentation/boards/riscv.rst b/Documentation/boards/riscv.rst
index 59cdc00a99e6..955a6fbb6bd1 100644
--- a/Documentation/boards/riscv.rst
+++ b/Documentation/boards/riscv.rst
@@ -41,25 +41,25 @@ TinyEMU
-------
TinyEMU can emulate a qemu-virt like machine with a RISC-V 32-, 64-
-and 128-bit CPU. It can run barebox with this sample configuration::
+and 128-bit CPU. It can run 32-bit barebox with this sample configuration:
- /* temu barebox-virt64.cfg */
- {
- version: 1,
- machine: "riscv64",
- memory_size: 256,
- bios: "bbl64.bin",
- kernel: "./images/barebox-dt-2nd.img",
- }
+.. literalinclude:: riscv/barebox-virt32.cfg
+
+as well as 64-bit barebox with this configuration:
+
+.. literalinclude:: riscv/barebox-virt64.cfg
``barebox-dt-2nd.img`` can be generated like with Qemu. Graphical
-output is also supported, but virtio input support is still missing.
+output and input are also supported.
To activate add::
display0: { device: "simplefb", width: 800, height: 600 },
+ input_device: "virtio",
into the config file.
+See https://barebox.org/jsbarebox/?graphic=1 for a live example.
+
Erizo
-----
diff --git a/Documentation/boards/riscv/barebox-virt32.cfg b/Documentation/boards/riscv/barebox-virt32.cfg
new file mode 100644
index 000000000000..5f0eb34eee9c
--- /dev/null
+++ b/Documentation/boards/riscv/barebox-virt32.cfg
@@ -0,0 +1,7 @@
+{
+ version: 1,
+ machine: "riscv32",
+ memory_size: 256,
+ bios: "bbl32.bin",
+ kernel: "images/barebox-dt-2nd.img",
+}
diff --git a/Documentation/boards/riscv/barebox-virt64.cfg b/Documentation/boards/riscv/barebox-virt64.cfg
new file mode 100644
index 000000000000..45e1cd830802
--- /dev/null
+++ b/Documentation/boards/riscv/barebox-virt64.cfg
@@ -0,0 +1,7 @@
+{
+ version: 1,
+ machine: "riscv64",
+ memory_size: 256,
+ bios: "bbl64.bin",
+ kernel: "images/barebox-dt-2nd.img",
+}
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 09/17] test: add basic barebox self-test infrastructure
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (7 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 08/17] Documentation: boards: RISC-V: update TinyEMU support Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 10:12 ` Jules Maselbas
2021-04-12 7:16 ` [PATCH 10/17] test: self: port Linux printf kselftest Ahmad Fatoum
` (7 subsequent siblings)
16 siblings, 1 reply; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
Self tests is code written to run within barebox to exercise
functionality. They offer flexibility to test specific units of barebox
instead of the program as a whole. Add a very simple infrastructure
for registering and executing self-tests. THis is based on the Linux
kselftest modules. We don't utilize modules for this, however, because
we only have module support on ARM, but we need a generic solution.
Selftests can be enabled individually and even tested without shell
support to allow tests to happen for size-restricted barebox images
as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Kconfig | 1 +
Makefile | 2 +-
commands/Makefile | 1 +
commands/selftest.c | 88 +++++++++++++++++++++++++++++++++++++++++++++
include/bselftest.h | 70 ++++++++++++++++++++++++++++++++++++
test/Kconfig | 8 +++++
test/Makefile | 1 +
test/self/Kconfig | 33 +++++++++++++++++
test/self/Makefile | 3 ++
test/self/core.c | 39 ++++++++++++++++++++
10 files changed, 245 insertions(+), 1 deletion(-)
create mode 100644 commands/selftest.c
create mode 100644 include/bselftest.h
create mode 100644 test/Kconfig
create mode 100644 test/Makefile
create mode 100644 test/self/Kconfig
create mode 100644 test/self/Makefile
create mode 100644 test/self/core.c
diff --git a/Kconfig b/Kconfig
index 29c32463fb43..7c4cf36881b4 100644
--- a/Kconfig
+++ b/Kconfig
@@ -15,3 +15,4 @@ source "lib/Kconfig"
source "crypto/Kconfig"
source "firmware/Kconfig"
source "scripts/Kconfig"
+source "test/Kconfig"
diff --git a/Makefile b/Makefile
index f6c0c4817046..0a93915cf347 100644
--- a/Makefile
+++ b/Makefile
@@ -581,7 +581,7 @@ endif
include $(srctree)/scripts/Makefile.lib
# Objects we will link into barebox / subdirs we need to visit
-common-y := common/ drivers/ commands/ lib/ crypto/ net/ fs/ firmware/
+common-y := common/ drivers/ commands/ lib/ crypto/ net/ fs/ firmware/ test/
include $(srctree)/arch/$(SRCARCH)/Makefile
diff --git a/commands/Makefile b/commands/Makefile
index 447349fd157d..4b45d266fd56 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -130,5 +130,6 @@ obj-$(CONFIG_CMD_SEED) += seed.o
obj-$(CONFIG_CMD_IP_ROUTE_GET) += ip-route-get.o
obj-$(CONFIG_CMD_BTHREAD) += bthread.o
obj-$(CONFIG_CMD_UBSAN) += ubsan.o
+obj-$(CONFIG_CMD_SELFTEST) += selftest.o
UBSAN_SANITIZE_ubsan.o := y
diff --git a/commands/selftest.c b/commands/selftest.c
new file mode 100644
index 000000000000..de5d100de04a
--- /dev/null
+++ b/commands/selftest.c
@@ -0,0 +1,88 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#define pr_fmt(fmt) "selftest: " fmt
+
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <bselftest.h>
+#include <complete.h>
+
+static int run_selftest(const char *match, bool list)
+{
+ struct selftest *test;
+ int matches = 0;
+ int err = 0;
+
+ list_for_each_entry(test, &selftests, list) {
+ if (list) {
+ printf("%s\n", test->name);
+ matches++;
+ continue;
+ }
+
+ if (match && strcmp(test->name, match))
+ continue;
+
+ err |= test->func();
+ matches++;
+ }
+
+ if (!matches) {
+ if (match)
+ printf("No tests matching '%s' found.\n", match);
+ else
+ printf("No matching tests found.\n");
+
+ return -EINVAL;
+ }
+
+ return err;
+}
+
+static int do_selftest(int argc, char *argv[])
+{
+ bool list = false;
+ int i, err = 0;
+ int opt;
+
+ while((opt = getopt(argc, argv, "l")) > 0) {
+ switch(opt) {
+ case 'l':
+ list = true;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (optind == argc) {
+ err = run_selftest(NULL, list);
+ } else {
+ for (i = optind; i < argc; i++) {
+ err = run_selftest(argv[i], list);
+ if (err)
+ goto out;
+ }
+ }
+
+out:
+ return err ? COMMAND_ERROR : COMMAND_SUCCESS;
+}
+
+BAREBOX_CMD_HELP_START(selftest)
+BAREBOX_CMD_HELP_TEXT("Run enabled barebox self-tests")
+BAREBOX_CMD_HELP_TEXT("If run without arguments, all tests are run")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-l", "list available tests")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(selftest)
+ .cmd = do_selftest,
+ BAREBOX_CMD_DESC("Run selftests")
+ BAREBOX_CMD_OPTS("[-l] [tests..]")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_COMPLETE(empty_complete)
+ BAREBOX_CMD_HELP(cmd_selftest_help)
+BAREBOX_CMD_END
diff --git a/include/bselftest.h b/include/bselftest.h
new file mode 100644
index 000000000000..9a639608e35b
--- /dev/null
+++ b/include/bselftest.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+#ifndef __BSELFTEST_H
+#define __BSELFTEST_H
+
+#include <linux/compiler.h>
+#include <linux/list.h>
+#include <init.h>
+
+enum bselftest_group {
+ BSELFTEST_core
+};
+
+struct selftest {
+ enum bselftest_group group;
+ const char *name;
+ int (*func)(void);
+ struct list_head list;
+};
+
+static inline int selftest_report(unsigned int total_tests, unsigned int failed_tests,
+ unsigned int skipped_tests)
+{
+ if (failed_tests == 0) {
+ if (skipped_tests) {
+ pr_info("skipped %u tests\n", skipped_tests);
+ pr_info("remaining %u tests passed\n", total_tests);
+ } else
+ pr_info("all %u tests passed\n", total_tests);
+ } else
+ pr_err("failed %u out of %u tests\n", failed_tests, total_tests);
+
+ return failed_tests ? -EINVAL : 0;
+}
+
+extern struct list_head selftests;
+
+#define BSELFTEST_GLOBALS() \
+static unsigned int total_tests __initdata; \
+static unsigned int failed_tests __initdata; \
+static unsigned int skipped_tests __initdata
+
+#ifdef CONFIG_SELFTEST
+#define __bselftest_initcall(func) late_initcall(func)
+#else
+#define __bselftest_initcall(func)
+#endif
+
+#define bselftest(_group, _func) \
+ static int __bselftest_##_func(void) \
+ { \
+ total_tests = failed_tests = skipped_tests = 0; \
+ _func(); \
+ return selftest_report(total_tests, \
+ failed_tests, \
+ skipped_tests); \
+ } \
+ static __maybe_unused \
+ int __init _func##_bselftest_register(void) \
+ { \
+ static struct selftest this = { \
+ .group = BSELFTEST_##_group, \
+ .name = KBUILD_MODNAME, \
+ .func = __bselftest_##_func, \
+ }; \
+ list_add_tail(&this.list, &selftests); \
+ return 0; \
+ } \
+ __bselftest_initcall(_func##_bselftest_register);
+
+#endif
diff --git a/test/Kconfig b/test/Kconfig
new file mode 100644
index 000000000000..eece702e68aa
--- /dev/null
+++ b/test/Kconfig
@@ -0,0 +1,8 @@
+menuconfig TEST
+ bool "Testing"
+
+if TEST
+
+source "test/self/Kconfig"
+
+endif
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 000000000000..1b9eb2171a82
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1 @@
+obj-y += self/
diff --git a/test/self/Kconfig b/test/self/Kconfig
new file mode 100644
index 000000000000..720abeffc51b
--- /dev/null
+++ b/test/self/Kconfig
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config SELFTEST
+ bool "Self-tests"
+ help
+ Configures support for in-barebox testing
+
+if SELFTEST
+
+config CMD_SELFTEST
+ bool "selftest command"
+ depends on COMMAND_SUPPORT
+ help
+ Command to run enabled barebox self-tests.
+ If run without arguments, all tests are run
+
+ Usage: selftest [-l] [tests...]
+
+ Options:
+ -l list available tests
+
+config SELFTEST_AUTORUN
+ bool "Run self-tests on startup"
+ help
+ Self tests are run automatically after initcalls are done,
+ but before barebox_main (shell or board-specific startup).
+
+config SELFTEST_ENABLE_ALL
+ bool "Enable all self-tests"
+ help
+ Selects all self-tests compatible with current configuration
+
+endif
diff --git a/test/self/Makefile b/test/self/Makefile
new file mode 100644
index 000000000000..78f738c8e210
--- /dev/null
+++ b/test/self/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_SELFTEST) += core.o
diff --git a/test/self/core.c b/test/self/core.c
new file mode 100644
index 000000000000..d8c6e5d271ba
--- /dev/null
+++ b/test/self/core.c
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#define pr_fmt(fmt) "bselftest: " fmt
+
+#include <common.h>
+#include <bselftest.h>
+
+LIST_HEAD(selftests);
+
+static int (*old_main)(void);
+
+static int run_selftests(void)
+{
+ struct selftest *test;
+ int err = 0;
+
+ pr_notice("Configured tests will run now\n");
+
+ list_for_each_entry(test, &selftests, list)
+ err |= test->func();
+
+ if (err)
+ pr_err("Some selftests failed\n");
+
+ barebox_main = old_main;
+ return barebox_main();
+}
+
+static int init_selftests(void)
+{
+ if (!IS_ENABLED(CONFIG_SELFTEST_AUTORUN))
+ return 0;
+
+ old_main = barebox_main;
+ barebox_main = run_selftests;
+
+ return 0;
+}
+postenvironment_initcall(init_selftests);
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 09/17] test: add basic barebox self-test infrastructure
2021-04-12 7:16 ` [PATCH 09/17] test: add basic barebox self-test infrastructure Ahmad Fatoum
@ 2021-04-12 10:12 ` Jules Maselbas
0 siblings, 0 replies; 21+ messages in thread
From: Jules Maselbas @ 2021-04-12 10:12 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox, rcz
Hi Ahmad,
This looks nice, I can't wait to try it out :]
On Mon, Apr 12, 2021 at 09:16:43AM +0200, Ahmad Fatoum wrote:
> Self tests is code written to run within barebox to exercise
> functionality. They offer flexibility to test specific units of barebox
> instead of the program as a whole. Add a very simple infrastructure
> for registering and executing self-tests. THis is based on the Linux
> kselftest modules. We don't utilize modules for this, however, because
> we only have module support on ARM, but we need a generic solution.
>
> Selftests can be enabled individually and even tested without shell
> support to allow tests to happen for size-restricted barebox images
> as well.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Kconfig | 1 +
> Makefile | 2 +-
> commands/Makefile | 1 +
> commands/selftest.c | 88 +++++++++++++++++++++++++++++++++++++++++++++
> include/bselftest.h | 70 ++++++++++++++++++++++++++++++++++++
> test/Kconfig | 8 +++++
> test/Makefile | 1 +
> test/self/Kconfig | 33 +++++++++++++++++
> test/self/Makefile | 3 ++
> test/self/core.c | 39 ++++++++++++++++++++
> 10 files changed, 245 insertions(+), 1 deletion(-)
> create mode 100644 commands/selftest.c
> create mode 100644 include/bselftest.h
> create mode 100644 test/Kconfig
> create mode 100644 test/Makefile
> create mode 100644 test/self/Kconfig
> create mode 100644 test/self/Makefile
> create mode 100644 test/self/core.c
>
> diff --git a/Kconfig b/Kconfig
> index 29c32463fb43..7c4cf36881b4 100644
> --- a/Kconfig
> +++ b/Kconfig
> @@ -15,3 +15,4 @@ source "lib/Kconfig"
> source "crypto/Kconfig"
> source "firmware/Kconfig"
> source "scripts/Kconfig"
> +source "test/Kconfig"
> diff --git a/Makefile b/Makefile
> index f6c0c4817046..0a93915cf347 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -581,7 +581,7 @@ endif
> include $(srctree)/scripts/Makefile.lib
>
> # Objects we will link into barebox / subdirs we need to visit
> -common-y := common/ drivers/ commands/ lib/ crypto/ net/ fs/ firmware/
> +common-y := common/ drivers/ commands/ lib/ crypto/ net/ fs/ firmware/ test/
>
> include $(srctree)/arch/$(SRCARCH)/Makefile
>
> diff --git a/commands/Makefile b/commands/Makefile
> index 447349fd157d..4b45d266fd56 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -130,5 +130,6 @@ obj-$(CONFIG_CMD_SEED) += seed.o
> obj-$(CONFIG_CMD_IP_ROUTE_GET) += ip-route-get.o
> obj-$(CONFIG_CMD_BTHREAD) += bthread.o
> obj-$(CONFIG_CMD_UBSAN) += ubsan.o
> +obj-$(CONFIG_CMD_SELFTEST) += selftest.o
>
> UBSAN_SANITIZE_ubsan.o := y
> diff --git a/commands/selftest.c b/commands/selftest.c
> new file mode 100644
> index 000000000000..de5d100de04a
> --- /dev/null
> +++ b/commands/selftest.c
> @@ -0,0 +1,88 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#define pr_fmt(fmt) "selftest: " fmt
> +
> +#include <common.h>
> +#include <command.h>
> +#include <getopt.h>
> +#include <bselftest.h>
> +#include <complete.h>
> +
> +static int run_selftest(const char *match, bool list)
> +{
> + struct selftest *test;
> + int matches = 0;
> + int err = 0;
> +
> + list_for_each_entry(test, &selftests, list) {
> + if (list) {
> + printf("%s\n", test->name);
> + matches++;
> + continue;
> + }
> +
> + if (match && strcmp(test->name, match))
> + continue;
> +
> + err |= test->func();
> + matches++;
> + }
> +
> + if (!matches) {
> + if (match)
> + printf("No tests matching '%s' found.\n", match);
> + else
> + printf("No matching tests found.\n");
> +
> + return -EINVAL;
What if there is no tests at all: is that an error if no tests were ran?
despit not using a match condition ?
> + }
> +
> + return err;
> +}
> +
snip
> diff --git a/test/self/core.c b/test/self/core.c
> new file mode 100644
> index 000000000000..d8c6e5d271ba
> --- /dev/null
> +++ b/test/self/core.c
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#define pr_fmt(fmt) "bselftest: " fmt
> +
> +#include <common.h>
> +#include <bselftest.h>
> +
> +LIST_HEAD(selftests);
> +
> +static int (*old_main)(void);
> +
> +static int run_selftests(void)
> +{
> + struct selftest *test;
> + int err = 0;
> +
> + pr_notice("Configured tests will run now\n");
> +
> + list_for_each_entry(test, &selftests, list)
> + err |= test->func();
> +
> + if (err)
> + pr_err("Some selftests failed\n");
> +
> + barebox_main = old_main;
> + return barebox_main();
> +}
Why not call run_selftests in start_barebox, right before barebox_main ?
Or maybe add a selftest initcall to be run at the very end of initcalls.
So you don't have to save and restore the barebox_main function.
> +
> +static int init_selftests(void)
> +{
> + if (!IS_ENABLED(CONFIG_SELFTEST_AUTORUN))
> + return 0;
> +
> + old_main = barebox_main;
> + barebox_main = run_selftests;
> +
> + return 0;
> +}
> +postenvironment_initcall(init_selftests);
> --
> 2.29.2
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 10/17] test: self: port Linux printf kselftest
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (8 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 09/17] test: add basic barebox self-test infrastructure Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 11/17] test: add labgrid configs for some emulated targets Ahmad Fatoum
` (6 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
Port over the Linux v5.11 selftest for printf sans the parts we don't
support. This can be used to catch regressions if changes affecting the
printf code are made.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/stdlib.h | 5 +
test/self/Kconfig | 6 +
test/self/Makefile | 1 +
test/self/printf.c | 302 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 314 insertions(+)
create mode 100644 test/self/printf.c
diff --git a/include/stdlib.h b/include/stdlib.h
index d4056087243d..8eb419e111f0 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -25,4 +25,9 @@ static inline u32 random32(void)
return ret;
}
+static inline u32 prandom_u32_max(u32 ep_ro)
+{
+ return (u32)(((u64) random32() * ep_ro) >> 32);
+}
+
#endif /* __STDLIB_H */
diff --git a/test/self/Kconfig b/test/self/Kconfig
index 720abeffc51b..73dc6c7b4f03 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -27,7 +27,13 @@ config SELFTEST_AUTORUN
config SELFTEST_ENABLE_ALL
bool "Enable all self-tests"
+ select SELFTEST_PRINTF
help
Selects all self-tests compatible with current configuration
+config SELFTEST_PRINTF
+ bool "printf selftest"
+ help
+ Tests barebox vsnprintf() functionality
+
endif
diff --git a/test/self/Makefile b/test/self/Makefile
index 78f738c8e210..b4aa49d6f817 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_SELFTEST) += core.o
+obj-$(CONFIG_SELFTEST_PRINTF) += printf.o
diff --git a/test/self/printf.c b/test/self/printf.c
new file mode 100644
index 000000000000..52fe6ac0faf9
--- /dev/null
+++ b/test/self/printf.c
@@ -0,0 +1,302 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Test cases for printf facility.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <common.h>
+#include <bselftest.h>
+#include <linux/kernel.h>
+#include <module.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/string.h>
+#include <errno.h>
+
+#include <linux/bitmap.h>
+
+#define BUF_SIZE 256
+#define PAD_SIZE 16
+#define FILL_CHAR '$'
+
+BSELFTEST_GLOBALS();
+
+static char *test_buffer __initdata;
+static char *alloced_buffer __initdata;
+
+static int __printf(4, 0) __init
+do_test(int bufsize, const char *expect, int elen,
+ const char *fmt, va_list ap)
+{
+ va_list aq;
+ int ret, written;
+
+ total_tests++;
+
+ memset(alloced_buffer, FILL_CHAR, BUF_SIZE + 2*PAD_SIZE);
+ va_copy(aq, ap);
+ ret = vsnprintf(test_buffer, bufsize, fmt, aq);
+ va_end(aq);
+
+ if (ret != elen) {
+ pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n",
+ bufsize, fmt, ret, elen);
+ pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n",
+ bufsize, fmt, test_buffer, ret, expect);
+ return 1;
+ }
+
+ if (memchr_inv(alloced_buffer, FILL_CHAR, PAD_SIZE)) {
+ pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote before buffer\n", bufsize, fmt);
+ return 1;
+ }
+
+ if (!bufsize) {
+ if (memchr_inv(test_buffer, FILL_CHAR, BUF_SIZE + PAD_SIZE)) {
+ pr_warn("vsnprintf(buf, 0, \"%s\", ...) wrote to buffer\n",
+ fmt);
+ return 1;
+ }
+ return 0;
+ }
+
+ written = min(bufsize-1, elen);
+ if (test_buffer[written]) {
+ pr_warn("vsnprintf(buf, %d, \"%s\", ...) did not nul-terminate buffer\n",
+ bufsize, fmt);
+ return 1;
+ }
+
+ if (memchr_inv(test_buffer + written + 1, FILL_CHAR, BUF_SIZE + PAD_SIZE - (written + 1))) {
+ pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n",
+ bufsize, fmt);
+ return 1;
+ }
+
+ if (memcmp(test_buffer, expect, written)) {
+ pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n",
+ bufsize, fmt, test_buffer, written, expect);
+ return 1;
+ }
+ return 0;
+}
+
+static void __printf(3, 4) __init
+__test(const char *expect, int elen, const char *fmt, ...)
+{
+ va_list ap;
+ int rand;
+ char *p;
+
+ if (elen >= BUF_SIZE) {
+ pr_err("error in test suite: expected output length %d too long. Format was '%s'.\n",
+ elen, fmt);
+ failed_tests++;
+ return;
+ }
+
+ va_start(ap, fmt);
+
+ /*
+ * Every fmt+args is subjected to four tests: Three where we
+ * tell vsnprintf varying buffer sizes (plenty, not quite
+ * enough and 0), and then we also test that bvasprintf would
+ * be able to print it as expected.
+ */
+ failed_tests += do_test(BUF_SIZE, expect, elen, fmt, ap);
+ rand = 1 + prandom_u32_max(elen+1);
+ /* Since elen < BUF_SIZE, we have 1 <= rand <= BUF_SIZE. */
+ failed_tests += do_test(rand, expect, elen, fmt, ap);
+ failed_tests += do_test(0, expect, elen, fmt, ap);
+
+ p = bvasprintf(fmt, ap);
+ if (p) {
+ total_tests++;
+ if (memcmp(p, expect, elen+1)) {
+ pr_warn("bvasprintf(..., \"%s\", ...) returned '%s', expected '%s'\n",
+ fmt, p, expect);
+ failed_tests++;
+ }
+ kfree(p);
+ }
+ va_end(ap);
+}
+
+#define test(expect, fmt, ...) \
+ __test(expect, strlen(expect), fmt, ##__VA_ARGS__)
+
+static void __init
+test_basic(void)
+{
+ /* Work around annoying "warning: zero-length gnu_printf format string". */
+ char nul = '\0';
+
+ test("", &nul);
+ test("100%", "100%%");
+ test("xxx%yyy", "xxx%cyyy", '%');
+ __test("xxx\0yyy", 7, "xxx%cyyy", '\0');
+}
+
+static void __init
+test_number(void)
+{
+ signed char val;
+
+ test("0x1234abcd ", "%#-12x", 0x1234abcd);
+ test(" 0x1234abcd", "%#12x", 0x1234abcd);
+ test("0|001| 12|+123| 1234|-123|-1234", "%d|%03d|%3d|%+d|% d|%+d|% d", 0, 1, 12, 123, 1234, -123, -1234);
+ test("0|1|1|32768|65535", "%hu|%hu|%hu|%hu|%hu", 0, 1, 65537, 32768, -1);
+ test("0|1|1|-32768|-1", "%hd|%hd|%hd|%hd|%hd", 0, 1, 65537, 32768, -1);
+ test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627);
+
+ test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627);
+
+ /*
+ * POSIX/C99: »The result of converting zero with an explicit
+ * precision of zero shall be no characters.« Hence the output
+ * from the below test should really be "00|0||| ". However,
+ * the kernel's printf also produces a single 0 in that
+ * case. This test case simply documents the current
+ * behaviour.
+ */
+ test("00|0|0|0|0", "%.2d|%.1d|%.0d|%.*d|%1.0d", 0, 0, 0, 0, 0, 0);
+
+ val = -16;
+ test("0xfffffff0|0xf0|0xf0", "%#02x|%#02x|%#02x", val, val & 0xff, (u8)val);
+
+ /* On some platforms, test failure here indicates a misaligned stack */
+ test("0x0807060504030201", "0x%016llx", 0x0807060504030201ULL);
+}
+
+static void __init
+test_string(void)
+{
+ test("", "%s%.0s", "", "123");
+ test("ABCD|abc|123", "%s|%.3s|%.*s", "ABCD", "abcdef", 3, "123456");
+ test("1 | 2|3 | 4|5 ", "%-3s|%3s|%-*s|%*s|%*s", "1", "2", 3, "3", 3, "4", -3, "5");
+ test("1234 ", "%-10.4s", "123456");
+ test(" 1234", "%10.4s", "123456");
+}
+
+#if BITS_PER_LONG == 64
+
+#define PTR_WIDTH 16
+#define PTR ((void *)0xffff0123456789abUL)
+#define PTR_STR "ffff0123456789ab"
+#define PTR_VAL_NO_CRNG "(____ptrval____)"
+#define ZEROS "00000000" /* hex 32 zero bits */
+#define ONES "ffffffff" /* hex 32 one bits */
+
+#else
+
+#define PTR_WIDTH 8
+#define PTR ((void *)0x456789ab)
+#define PTR_STR "456789ab"
+#define PTR_VAL_NO_CRNG "(ptrval)"
+#define ZEROS ""
+#define ONES ""
+
+#endif /* BITS_PER_LONG == 64 */
+
+/*
+ * NULL pointers aren't hashed.
+ */
+static void __init
+null_pointer(void)
+{
+ test(ZEROS "00000000", "%p", NULL);
+ test(ZEROS "00000000", "%px", NULL);
+}
+
+/*
+ * Error pointers aren't hashed.
+ */
+static void __init
+error_pointer(void)
+{
+ test(ONES "fffffff5", "%p", ERR_PTR(-11));
+ test(ONES "fffffff5", "%px", ERR_PTR(-11));
+}
+
+#define PTR_INVALID ((void *)0x000000ab)
+
+static void __init
+invalid_pointer(void)
+{
+ test(ZEROS "000000ab", "%px", PTR_INVALID);
+}
+
+static void __init
+ip4(void)
+{
+ IPaddr_t ip = cpu_to_be32(0x7f000001);
+
+ test("127.0.0.1", "%pI4", &ip);
+}
+
+static void __init
+ip(void)
+{
+ ip4();
+}
+
+static void __init
+uuid(void)
+{
+ const char uuid[16] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
+ 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+
+ if (!IS_ENABLED(CONFIG_PRINTF_UUID))
+ return;
+
+ test("00010203-0405-0607-0809-0a0b0c0d0e0f", "%pUb", uuid);
+ test("00010203-0405-0607-0809-0A0B0C0D0E0F", "%pUB", uuid);
+ test("03020100-0504-0706-0809-0a0b0c0d0e0f", "%pUl", uuid);
+ test("03020100-0504-0706-0809-0A0B0C0D0E0F", "%pUL", uuid);
+}
+
+static void __init
+errptr(void)
+{
+ test("error 1234", "%pe", ERR_PTR(-1234));
+ test(sizeof(void *) == 8 ? "00000000000004d2" : "000004d2", "%pe", ERR_PTR(1234));
+
+ /* Check that %pe with a non-ERR_PTR gets treated as ordinary %p. */
+ BUILD_BUG_ON(IS_ERR(PTR));
+
+ if (!IS_ENABLED(CONFIG_ERRNO_MESSAGES))
+ return;
+ test("(Operation not permitted)", "(%pe)", ERR_PTR(-EPERM));
+ test("Requested probe deferral", "%pe", ERR_PTR(-EPROBE_DEFER));
+}
+
+static void __init
+test_pointer(void)
+{
+ null_pointer();
+ error_pointer();
+ invalid_pointer();
+ ip();
+ uuid();
+ errptr();
+}
+
+static void __init test_printf(void)
+{
+ alloced_buffer = malloc(BUF_SIZE + 2*PAD_SIZE);
+ if (!alloced_buffer)
+ return;
+ test_buffer = alloced_buffer + PAD_SIZE;
+
+ test_basic();
+ test_number();
+ test_string();
+ test_pointer();
+
+ free(alloced_buffer);
+}
+
+bselftest(core, test_printf);
+MODULE_AUTHOR("Rasmus Villemoes <linux@rasmusvillemoes.dk>");
+MODULE_LICENSE("GPL");
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 11/17] test: add labgrid configs for some emulated targets
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (9 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 10/17] test: self: port Linux printf kselftest Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 12/17] test: add first sample tests Ahmad Fatoum
` (5 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
There are various ways barebox can run under emulation, some of them are
described in the documentation and some more in the git history.
Make running the emulators more convenient to use by collecting some
known-good emulator invocations in a machine readable format.
These YAML files can be parsed by labgrid for running tests or executed
by a new test/emulate.pl runner script that will be added in a follow-up
commit.
Using labgrid for this will allow reusing the same test suite for physical
targets as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/arm/a15@vexpress_defconfig.yaml | 25 +++++++++++++++++
test/arm/a9@vexpress_defconfig.yaml | 25 +++++++++++++++++
test/arm/qemu_virt64_defconfig.yaml | 28 +++++++++++++++++++
test/arm/vexpress_defconfig.yaml | 1 +
test/arm/virt@vexpress_defconfig.yaml | 26 ++++++++++++++++++
test/kconfig/virtio-pci.cfg | 6 +++++
test/mips/be@qemu-malta_defconfig.yaml | 26 ++++++++++++++++++
test/mips/le@qemu-malta_defconfig.yaml | 29 ++++++++++++++++++++
test/mips/qemu-malta_defconfig.yaml | 1 +
test/openrisc/generic_defconfig.yaml | 25 +++++++++++++++++
test/riscv/qemu@virt32_defconfig.yaml | 29 ++++++++++++++++++++
test/riscv/qemu@virt64_defconfig.yaml | 29 ++++++++++++++++++++
test/riscv/tinyemu@virt32_defconfig.yaml | 26 ++++++++++++++++++
test/riscv/tinyemu@virt64_defconfig.yaml | 26 ++++++++++++++++++
test/riscv/virt32_defconfig.yaml | 1 +
test/riscv/virt64_defconfig.yaml | 1 +
test/sandbox/sandbox_defconfig.yaml | 14 ++++++++++
test/x86/efi_defconfig.yaml | 1 +
test/x86/pc@efi_defconfig.yaml | 33 +++++++++++++++++++++++
test/x86/q35@efi_defconfig.yaml | 34 ++++++++++++++++++++++++
test/x86/virtio@efi_defconfig.yaml | 34 ++++++++++++++++++++++++
21 files changed, 420 insertions(+)
create mode 100644 test/arm/a15@vexpress_defconfig.yaml
create mode 100644 test/arm/a9@vexpress_defconfig.yaml
create mode 100644 test/arm/qemu_virt64_defconfig.yaml
create mode 120000 test/arm/vexpress_defconfig.yaml
create mode 100644 test/arm/virt@vexpress_defconfig.yaml
create mode 100644 test/kconfig/virtio-pci.cfg
create mode 100644 test/mips/be@qemu-malta_defconfig.yaml
create mode 100644 test/mips/le@qemu-malta_defconfig.yaml
create mode 120000 test/mips/qemu-malta_defconfig.yaml
create mode 100644 test/openrisc/generic_defconfig.yaml
create mode 100644 test/riscv/qemu@virt32_defconfig.yaml
create mode 100644 test/riscv/qemu@virt64_defconfig.yaml
create mode 100644 test/riscv/tinyemu@virt32_defconfig.yaml
create mode 100644 test/riscv/tinyemu@virt64_defconfig.yaml
create mode 120000 test/riscv/virt32_defconfig.yaml
create mode 120000 test/riscv/virt64_defconfig.yaml
create mode 100644 test/sandbox/sandbox_defconfig.yaml
create mode 120000 test/x86/efi_defconfig.yaml
create mode 100644 test/x86/pc@efi_defconfig.yaml
create mode 100644 test/x86/q35@efi_defconfig.yaml
create mode 100644 test/x86/virtio@efi_defconfig.yaml
diff --git a/test/arm/a15@vexpress_defconfig.yaml b/test/arm/a15@vexpress_defconfig.yaml
new file mode 100644
index 000000000000..775a98fc6b99
--- /dev/null
+++ b/test/arm/a15@vexpress_defconfig.yaml
@@ -0,0 +1,25 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: vexpress-a15
+ cpu: cortex-a15
+ memory: 1024M
+ bios: barebox-vexpress-ca15.img
+ extra_args: ''
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+images:
+ barebox-vexpress-ca15.img: ../../images/barebox-vexpress-ca15.img
+tools:
+ qemu: /usr/bin/qemu-system-arm
diff --git a/test/arm/a9@vexpress_defconfig.yaml b/test/arm/a9@vexpress_defconfig.yaml
new file mode 100644
index 000000000000..b47f401f0fb6
--- /dev/null
+++ b/test/arm/a9@vexpress_defconfig.yaml
@@ -0,0 +1,25 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: vexpress-a9
+ cpu: cortex-a9
+ memory: 1024M
+ bios: barebox-vexpress-ca9.img
+ extra_args: ''
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+images:
+ barebox-vexpress-ca9.img: ../../images/barebox-vexpress-ca9.img
+tools:
+ qemu: /usr/bin/qemu-system-arm
diff --git a/test/arm/qemu_virt64_defconfig.yaml b/test/arm/qemu_virt64_defconfig.yaml
new file mode 100644
index 000000000000..c13d94c4a1f4
--- /dev/null
+++ b/test/arm/qemu_virt64_defconfig.yaml
@@ -0,0 +1,28 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: virt
+ cpu: cortex-a57
+ memory: 1024M
+ kernel: barebox-dt-2nd.img
+ extra_args: ''
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-mmio
+ runner:
+ tuxmake_arch: arm64
+images:
+ barebox-dt-2nd.img: ../../images/barebox-dt-2nd.img
+tools:
+ qemu: /usr/bin/qemu-system-aarch64
diff --git a/test/arm/vexpress_defconfig.yaml b/test/arm/vexpress_defconfig.yaml
new file mode 120000
index 000000000000..732f51b19dc9
--- /dev/null
+++ b/test/arm/vexpress_defconfig.yaml
@@ -0,0 +1 @@
+a9@vexpress_defconfig.yaml
\ No newline at end of file
diff --git a/test/arm/virt@vexpress_defconfig.yaml b/test/arm/virt@vexpress_defconfig.yaml
new file mode 100644
index 000000000000..c2c2c486ec3b
--- /dev/null
+++ b/test/arm/virt@vexpress_defconfig.yaml
@@ -0,0 +1,26 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: virt
+ cpu: cortex-a7
+ memory: 1024M
+ kernel: barebox-dt-2nd.img
+ extra_args: ''
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-mmio
+images:
+ barebox-dt-2nd.img: ../../images/barebox-dt-2nd.img
+tools:
+ qemu: /usr/bin/qemu-system-arm
diff --git a/test/kconfig/virtio-pci.cfg b/test/kconfig/virtio-pci.cfg
new file mode 100644
index 000000000000..78237b8fca26
--- /dev/null
+++ b/test/kconfig/virtio-pci.cfg
@@ -0,0 +1,6 @@
+CONFIG_VIRTIO_MENU=y
+CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_CONSOLE=y
+CONFIG_VIRTIO_BLK=y
+CONFIG_HWRNG=y
+CONFIG_HW_RANDOM_VIRTIO=y
diff --git a/test/mips/be@qemu-malta_defconfig.yaml b/test/mips/be@qemu-malta_defconfig.yaml
new file mode 100644
index 000000000000..b81de0685813
--- /dev/null
+++ b/test/mips/be@qemu-malta_defconfig.yaml
@@ -0,0 +1,26 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: malta
+ cpu: M14Kc
+ memory: 256M
+ bios: barebox-qemu-malta.img
+ extra_args: ''
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-pci
+images:
+ barebox-qemu-malta.img: ../../images/barebox-qemu-malta.img
+tools:
+ qemu: /usr/bin/qemu-system-mips
diff --git a/test/mips/le@qemu-malta_defconfig.yaml b/test/mips/le@qemu-malta_defconfig.yaml
new file mode 100644
index 000000000000..9c49a5bf5c8b
--- /dev/null
+++ b/test/mips/le@qemu-malta_defconfig.yaml
@@ -0,0 +1,29 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: malta
+ cpu: M14Kc
+ memory: 256M
+ bios: barebox-qemu-malta.img.swapped
+ extra_args: ''
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-pci
+ runner:
+ kconfig_add:
+ - CONFIG_CPU_LITTLE_ENDIAN=y
+images:
+ barebox-qemu-malta.img.swapped: ../../images/barebox-qemu-malta.img.swapped
+tools:
+ qemu: /usr/bin/qemu-system-mipsel
diff --git a/test/mips/qemu-malta_defconfig.yaml b/test/mips/qemu-malta_defconfig.yaml
new file mode 120000
index 000000000000..481b6e547782
--- /dev/null
+++ b/test/mips/qemu-malta_defconfig.yaml
@@ -0,0 +1 @@
+be@qemu-malta_defconfig.yaml
\ No newline at end of file
diff --git a/test/openrisc/generic_defconfig.yaml b/test/openrisc/generic_defconfig.yaml
new file mode 100644
index 000000000000..94ae160206d5
--- /dev/null
+++ b/test/openrisc/generic_defconfig.yaml
@@ -0,0 +1,25 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: or1k-sim
+ cpu: or1200
+ memory: 256M
+ kernel: barebox
+ extra_args: ''
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+images:
+ barebox: ../../barebox
+tools:
+ qemu: /usr/bin/qemu-system-or1k
diff --git a/test/riscv/qemu@virt32_defconfig.yaml b/test/riscv/qemu@virt32_defconfig.yaml
new file mode 100644
index 000000000000..36943add5801
--- /dev/null
+++ b/test/riscv/qemu@virt32_defconfig.yaml
@@ -0,0 +1,29 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: virt
+ cpu: rv32
+ memory: 256M
+ kernel: barebox-dt-2nd.img
+ extra_args: -bios opensbi-riscv32-generic-fw_dynamic.bin
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-mmio
+ runner:
+ download:
+ opensbi-riscv32-generic-fw_dynamic.bin: https://github.com/qemu/qemu/blob/v5.2.0/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin?raw=true
+images:
+ barebox-dt-2nd.img: ../../images/barebox-dt-2nd.img
+tools:
+ qemu: /usr/bin/qemu-system-riscv32
diff --git a/test/riscv/qemu@virt64_defconfig.yaml b/test/riscv/qemu@virt64_defconfig.yaml
new file mode 100644
index 000000000000..da296f2aa6f2
--- /dev/null
+++ b/test/riscv/qemu@virt64_defconfig.yaml
@@ -0,0 +1,29 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: virt
+ cpu: rv64
+ memory: 256M
+ kernel: barebox-dt-2nd.img
+ extra_args: -bios opensbi-riscv64-generic-fw_dynamic.bin
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-mmio
+ runner:
+ download:
+ opensbi-riscv64-generic-fw_dynamic.bin: https://github.com/qemu/qemu/blob/v5.2.0/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin?raw=true
+images:
+ barebox-dt-2nd.img: ../../images/barebox-dt-2nd.img
+tools:
+ qemu: /usr/bin/qemu-system-riscv64
diff --git a/test/riscv/tinyemu@virt32_defconfig.yaml b/test/riscv/tinyemu@virt32_defconfig.yaml
new file mode 100644
index 000000000000..444642d6c1ce
--- /dev/null
+++ b/test/riscv/tinyemu@virt32_defconfig.yaml
@@ -0,0 +1,26 @@
+targets:
+ main:
+ drivers:
+ TinyEMUDriver:
+ temu_bin: temu
+ config: ./Documentation/boards/riscv/barebox-virt32.cfg
+ image: barebox-dt-2nd.img
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-mmio
+ runner:
+ download:
+ bbl32.bin: https://barebox.org/jsbarebox/bbl32.bin
+images:
+ barebox-dt-2nd.img: ../../images/barebox-dt-2nd.img
+tools:
+ temu: /usr/local/bin/temu
diff --git a/test/riscv/tinyemu@virt64_defconfig.yaml b/test/riscv/tinyemu@virt64_defconfig.yaml
new file mode 100644
index 000000000000..e89521b14fdf
--- /dev/null
+++ b/test/riscv/tinyemu@virt64_defconfig.yaml
@@ -0,0 +1,26 @@
+targets:
+ main:
+ drivers:
+ TinyEMUDriver:
+ temu_bin: temu
+ config: ./Documentation/boards/riscv/barebox-virt64.cfg
+ image: barebox-dt-2nd.img
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-mmio
+ runner:
+ download:
+ bbl64.bin: https://barebox.org/jsbarebox/bbl64.bin
+images:
+ barebox-dt-2nd.img: ../../images/barebox-dt-2nd.img
+tools:
+ temu: /usr/local/bin/temu
diff --git a/test/riscv/virt32_defconfig.yaml b/test/riscv/virt32_defconfig.yaml
new file mode 120000
index 000000000000..e9d7237f5339
--- /dev/null
+++ b/test/riscv/virt32_defconfig.yaml
@@ -0,0 +1 @@
+qemu@virt32_defconfig.yaml
\ No newline at end of file
diff --git a/test/riscv/virt64_defconfig.yaml b/test/riscv/virt64_defconfig.yaml
new file mode 120000
index 000000000000..ab419d5e7fb4
--- /dev/null
+++ b/test/riscv/virt64_defconfig.yaml
@@ -0,0 +1 @@
+qemu@virt64_defconfig.yaml
\ No newline at end of file
diff --git a/test/sandbox/sandbox_defconfig.yaml b/test/sandbox/sandbox_defconfig.yaml
new file mode 100644
index 000000000000..b9596f1012c8
--- /dev/null
+++ b/test/sandbox/sandbox_defconfig.yaml
@@ -0,0 +1,14 @@
+targets:
+ main:
+ drivers:
+ NativeExecutableDriver:
+ command: ./barebox
+ image: barebox
+ features:
+ - barebox
+ runner:
+ tuxmake_arch: um
+images:
+ barebox: ../../barebox
+tools:
+ qemu: /usr/local/bin/temu
diff --git a/test/x86/efi_defconfig.yaml b/test/x86/efi_defconfig.yaml
new file mode 120000
index 000000000000..942dc259d56b
--- /dev/null
+++ b/test/x86/efi_defconfig.yaml
@@ -0,0 +1 @@
+pc@efi_defconfig.yaml
\ No newline at end of file
diff --git a/test/x86/pc@efi_defconfig.yaml b/test/x86/pc@efi_defconfig.yaml
new file mode 100644
index 000000000000..1f06ddccb177
--- /dev/null
+++ b/test/x86/pc@efi_defconfig.yaml
@@ -0,0 +1,33 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: pc
+ cpu: Nehalem
+ memory: 1024M
+ kernel: barebox.efi
+ extra_args: -bios OVMF.fd
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - pci
+ runner:
+ tuxmake_arch: x86_64
+ kconfig_add:
+ - CONFIG_DRIVER_SERIAL_NS16550=y
+ - CONFIG_CONSOLE_ACTIVATE_FIRST=y # avoid duplicate output
+ download:
+ OVMF.fd: /usr/share/qemu/OVMF.fd
+images:
+ barebox.efi: ../../barebox.efi
+tools:
+ qemu: /usr/bin/qemu-system-x86_64
diff --git a/test/x86/q35@efi_defconfig.yaml b/test/x86/q35@efi_defconfig.yaml
new file mode 100644
index 000000000000..6b0f0cc1a870
--- /dev/null
+++ b/test/x86/q35@efi_defconfig.yaml
@@ -0,0 +1,34 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: q35
+ cpu: Nehalem
+ memory: 1024M
+ kernel: barebox.efi
+ extra_args: >
+ -bios OVMF.fd -global ICH9-LPC.noreboot=false
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - pci
+ runner:
+ tuxmake_arch: x86_64
+ kconfig_add:
+ - CONFIG_DRIVER_SERIAL_NS16550=y
+ - CONFIG_CONSOLE_ACTIVATE_FIRST=y # avoid duplicate output
+ download:
+ OVMF.fd: /usr/share/qemu/OVMF.fd
+images:
+ barebox.efi: ../../barebox.efi
+tools:
+ qemu: /usr/bin/qemu-system-x86_64
diff --git a/test/x86/virtio@efi_defconfig.yaml b/test/x86/virtio@efi_defconfig.yaml
new file mode 100644
index 000000000000..ab99e812eb93
--- /dev/null
+++ b/test/x86/virtio@efi_defconfig.yaml
@@ -0,0 +1,34 @@
+targets:
+ main:
+ drivers:
+ QEMUDriver:
+ qemu_bin: qemu
+ machine: pc
+ cpu: Nehalem
+ memory: 1024M
+ kernel: barebox.efi
+ extra_args: -bios OVMF.fd
+ BareboxDriver:
+ prompt: 'barebox@[^:]+:[^ ]+ '
+ bootstring: 'commandline:'
+ ShellDriver:
+ prompt: 'root@\w+:[^ ]+ '
+ login_prompt: ' login: '
+ login_timeout: 90
+ username: 'root'
+ BareboxStrategy: {}
+ features:
+ - barebox
+ - virtio-pci
+ runner:
+ tuxmake_arch: x86_64
+ kconfig_add:
+ - test/kconfig/virtio-pci.cfg
+ - CONFIG_DRIVER_SERIAL_NS16550=y
+ - CONFIG_CONSOLE_ACTIVATE_FIRST=y # avoid duplicate output
+ download:
+ OVMF.fd: /usr/share/qemu/OVMF.fd
+images:
+ barebox.efi: ../../barebox.efi
+tools:
+ qemu: /usr/bin/qemu-system-x86_64
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 12/17] test: add first sample tests
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (10 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 11/17] test: add labgrid configs for some emulated targets Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 13/17] test: support running labgrid-pytest from out-of-tree build directory Ahmad Fatoum
` (4 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
The test can be run manually with e.g.
labgrid-pytest --lg-env test/arm/qemu_virt64_defconfig.yaml test/py
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/.gitignore | 1 +
test/__init__.py | 0
test/conftest.py | 21 +++++++++++++++++++++
test/py/__init__.py | 0
test/py/helper.py | 33 +++++++++++++++++++++++++++++++++
test/py/test_shell.py | 16 ++++++++++++++++
6 files changed, 71 insertions(+)
create mode 100644 test/.gitignore
create mode 100644 test/__init__.py
create mode 100644 test/conftest.py
create mode 100644 test/py/__init__.py
create mode 100644 test/py/helper.py
create mode 100644 test/py/test_shell.py
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 000000000000..bee8a64b79a9
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+__pycache__
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/test/conftest.py b/test/conftest.py
new file mode 100644
index 000000000000..019840d0909d
--- /dev/null
+++ b/test/conftest.py
@@ -0,0 +1,21 @@
+import pytest
+from .py import helper
+
+
+@pytest.fixture(scope='function')
+def barebox(strategy, target):
+ strategy.transition('barebox')
+ return target.get_driver('BareboxDriver')
+
+
+@pytest.fixture(scope='function')
+def shell(strategy, target):
+ strategy.transition('shell')
+ return target.get_driver('ShellDriver')
+
+
+@pytest.fixture(scope="session")
+def barebox_config(strategy, target):
+ strategy.transition('barebox')
+ command = target.get_driver("BareboxDriver")
+ return helper.get_config(command)
diff --git a/test/py/__init__.py b/test/py/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/test/py/helper.py b/test/py/helper.py
new file mode 100644
index 000000000000..f4a110d89a09
--- /dev/null
+++ b/test/py/helper.py
@@ -0,0 +1,33 @@
+from labgrid.driver import BareboxDriver
+import pytest
+
+
+def get_config(command):
+ """Returns the enabled config options of barebox, either from
+ a running instance if supported or by looking into .config
+ in the build directory.
+ Args:
+ command (BareboxDriver): An instance of the BareboxDriver
+ Returns:
+ list: list of the enabled config options
+ """
+ assert isinstance(command, BareboxDriver)
+
+ out, err, returncode = command.run("cat /env/data/config")
+ if returncode != 0:
+ try:
+ with open('.config') as f:
+ out = f.read().splitlines()
+ except OSError:
+ return []
+
+ options = []
+ for line in out:
+ if line and line.startswith("CONFIG_"):
+ options.append(line.split('=')[0])
+ return options
+
+
+def skip_disabled(config, option):
+ if bool(config) and not option in config:
+ pytest.skip("skipping test due to disabled " + option + "=y dependency")
diff --git a/test/py/test_shell.py b/test/py/test_shell.py
new file mode 100644
index 000000000000..13a57061f6db
--- /dev/null
+++ b/test/py/test_shell.py
@@ -0,0 +1,16 @@
+import pytest
+from .helper import *
+
+
+def test_barebox_true(barebox, barebox_config):
+ skip_disabled(barebox_config, "CONFIG_CMD_TRUE")
+
+ _, _, returncode = barebox.run('true')
+ assert returncode == 0
+
+
+def test_barebox_false(barebox, barebox_config):
+ skip_disabled(barebox_config, "CONFIG_CMD_FALSE")
+
+ _, _, returncode = barebox.run('false')
+ assert returncode == 1
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 13/17] test: support running labgrid-pytest from out-of-tree build directory
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (11 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 12/17] test: add first sample tests Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 14/17] test: add emulate.pl, a runner for barebox on emulated targets Ahmad Fatoum
` (3 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
The labgrid YAML configs use relative paths to reference the images to
use. This won't work for out-of-tree builds. Do like Linux does for the
scripts/gdb/vmlinux-gdb.py and symlink the labgrid test stuff into the
build directory. With this done, we can now call labgrid-pytest for both
in-tree and out-of-tree builds.
Symlinks are not created for the test directory as a whole:
- ../../ from within a symlinked directory refers to the original
destination, not where it's symlinked to
- Build and test (__pycache__) artifacts are generated into test/.
we don't want those ending up in the source directory
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/Makefile b/Makefile
index 0a93915cf347..7db7cb7b4a3a 100644
--- a/Makefile
+++ b/Makefile
@@ -1136,6 +1136,10 @@ MRPROPER_FILES += .config .config.old .version .old_version \
include/config.h \
Module.symvers tags TAGS cscope*
+ifdef building_out_of_srctree
+MRPROPER_DIRS += test
+endif
+
# clean - Delete most, but leave enough to build external modules
#
clean: rm-dirs := $(CLEAN_DIRS)
@@ -1264,6 +1268,25 @@ docs: FORCE
@$(SPHINXBUILD) -b html -d $(objtree)/doctrees $(srctree)/Documentation \
$(objtree)/Documentation/html
+# Misc
+# ---------------------------------------------------------------------------
+
+# support running tests from the build directory
+
+PHONY += symlink_tests
+symlink_tests: prepare0
+ifdef building_out_of_srctree
+ @mkdir -p test/$(SRCARCH)
+ @for y in $(abspath $(srctree)/test/$(SRCARCH)/*.yaml); do \
+ ln -fsn $$y $(objtree)/test/$(SRCARCH)/ ; \
+ done
+ @ln -fsn $(abspath $(srctree)/test/py) $(objtree)/test/
+ @ln -fsn $(abspath $(srctree)/test/conftest.py) $(objtree)/test/
+ @ln -fsn $(abspath $(srctree)/test/__init__.py) $(objtree)/test/
+endif
+
+all: symlink_tests
+
# Single targets
# ---------------------------------------------------------------------------
# Single targets are compatible with:
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 14/17] test: add emulate.pl, a runner for barebox on emulated targets
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (12 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 13/17] test: support running labgrid-pytest from out-of-tree build directory Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 15/17] test: self: run selftests as part of the pytest suite Ahmad Fatoum
` (2 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
This script is a wrapper around tuxmake, qemu-system-* and labgrid-pytest.
It parses the same YAML files, labgrid-pytest uses and instructs
tuxmake to build and collect the needed images.
By default, it will start an interactive emulator session, but with
--test, it can also run labgrid-pytest instead.
The script has some knowledge of QEMU options to make common tasks like
passing images straight-forward.
Script is written with both manual use and CI in mind.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Documentation/boards/emulated.rst | 70 +++++
Makefile | 1 +
test/emulate.pl | 483 ++++++++++++++++++++++++++++++
test/kconfig/base.cfg | 0
test/kconfig/full.cfg | 0
5 files changed, 554 insertions(+)
create mode 100644 Documentation/boards/emulated.rst
create mode 100755 test/emulate.pl
create mode 100644 test/kconfig/base.cfg
create mode 100644 test/kconfig/full.cfg
diff --git a/Documentation/boards/emulated.rst b/Documentation/boards/emulated.rst
new file mode 100644
index 000000000000..0f6c7dcbbc7b
--- /dev/null
+++ b/Documentation/boards/emulated.rst
@@ -0,0 +1,70 @@
+Emulated targets
+================
+
+Some targets barebox runs on are virtualized by emulators like QEMU, which
+allows basic testing of barebox functionality without the actual hardware.
+
+Generic DT image
+----------------
+
+Supported for ARM and RISC-V. It generates a barebox image that can
+be booted with the Linux kernel booting convention, which makes
+it suitable to be passed as argument to the QEMU ``-kernel`` option.
+The device tree is either the QEMU internal device tree or a device
+tree supplied by QEMU's ``-dtb`` option. The former can be very useful
+with :ref:`virtio_sect`, because QEMU will fix up the virtio mmio
+regions into the device tree and barebox will discover the devices
+automatically, analogously to what it does with VirtIO over PCI.
+
+test/emulate.pl
+---------------
+
+The ``emulate.pl`` script shipped with barebox can be used to easily
+start VMs. It reads a number of YAML files in ``test/``, which describe
+some virtualized targets that barebox is known to run on.
+Controlled by command line options, these targets are built with
+tuxmake if available and loaded into the emulator for either interactive
+use or for automated testing with Labgrid ``QEMUDriver``.
+
+.. _tuxmake: https://pypi.org/project/tuxmake/
+.. _Labgrid: https://labgrid.org
+
+Install dependencies for interactive use::
+
+ cpan YAML::Tiny # or use e.g. libyaml-tiny-perl on debian
+ pip3 install tuxmake # optional
+
+Example usage::
+
+ # Switch to barebox source directory
+ cd barebox
+
+ # emulate ARM virt with an image built by vexpress_defconfig
+ ARCH=arm ./test/emulate.pl virt@vexpress_defconfig
+
+ # build all MIPS targets known to emulate.pl and exit
+ ARCH=mips ./test/emulate.pl --no-emulate
+
+The script can also be used from a finished barebox build directory::
+
+ # Switch to build directory
+ cd build
+
+ # run a barebox image built outside tuxmake with an emulated vexpress-ca15
+ ARCH=x86 ./test/emulate.pl efi_defconfig --no-tuxmake
+
+ # run tests instead of starting emulator interactively
+ ARCH=x86 ./test/emulate.pl efi_defconfig --no-tuxmake --test
+
+``emulate.pl`` also has some knowledge on paravirtualized devices::
+
+ # Run target and pass a block device (here /dev/virtioblk0)
+ ARCH=riscv ./test/emulate.pl --blk=rootfs.ext4 virt64_defconfig
+
+``emulate.pl`` if needed command line options can be passed directly
+to the emulator/``labgrid-pytest`` as well by placing them behind ``--``::
+
+ # appends -device ? to the command line. Add -n to see the final result
+ ARCH=riscv ./test/emulate.pl virt64_defconfig -- -device ?
+
+For a complete listing of options run ``./test/emulate.pl -h``.
diff --git a/Makefile b/Makefile
index 7db7cb7b4a3a..d65986f8693f 100644
--- a/Makefile
+++ b/Makefile
@@ -1283,6 +1283,7 @@ ifdef building_out_of_srctree
@ln -fsn $(abspath $(srctree)/test/py) $(objtree)/test/
@ln -fsn $(abspath $(srctree)/test/conftest.py) $(objtree)/test/
@ln -fsn $(abspath $(srctree)/test/__init__.py) $(objtree)/test/
+ @ln -fsn $(abspath $(srctree)/test/emulate.pl) $(objtree)/test/
endif
all: symlink_tests
diff --git a/test/emulate.pl b/test/emulate.pl
new file mode 100755
index 000000000000..cf1d2c57c590
--- /dev/null
+++ b/test/emulate.pl
@@ -0,0 +1,483 @@
+#!/usr/bin/env perl
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Ahmad Fatoum
+
+use strict;
+use warnings;
+
+use Cwd;
+use File::Basename;
+use File::Spec;
+use File::Temp 'tempdir';
+use Getopt::Long;
+use List::Util 'first';
+use Pod::Usage;
+use YAML::Tiny;
+
+my @QEMU_INTERACTIVE_OPTS = qw(-serial mon:stdio -trace file=/dev/null);
+
+my %targets;
+
+for my $arch (glob dirname(__FILE__) . "/*/") {
+ for my $cfg (glob "$arch/*.yaml") {
+ my $linkdest = readlink $cfg // '';
+
+ my $yaml = YAML::Tiny->read($cfg);
+
+ defined $yaml && exists $yaml->[0]{targets} && exists $yaml->[0]{targets}{main}
+ or die "Invalid structure for $cfg\n";
+
+ my $path = File::Spec->abs2rel($cfg, getcwd);
+ $cfg = basename($cfg);
+ $cfg =~ s/\.yaml$//;
+ $linkdest =~ s{^.*?([^/]+)\.yaml$}{$1};
+
+ $targets{basename $arch}{$cfg} = $yaml->[0]{targets}{main};
+ $targets{basename $arch}{$cfg}{path} = $path;
+ $targets{basename $arch}{$cfg}{tools} = $yaml->[0]{tools};
+ $targets{basename $arch}{$cfg}{images} = $yaml->[0]{images};
+ $targets{basename $arch}{$cfg}{alias} = $linkdest if $linkdest && $linkdest ne $cfg;
+ }
+}
+
+my %arch_aliases = (arm64 => 'arm', x86_64 => 'x86', i386 => 'x86', um => 'sandbox');
+
+my ($dryrun, $help, @blks, $rng, $list, $shell, $runtime, @kconfig_add, $artifacts);
+my ($tuxmake, $emulate, $clean, $extraconsoles, $test) = (1, 1, 1, 0, 0);
+my ($kconfig_base, $kconfig_full) = (1, 0);
+
+my @OPTS;
+
+if (defined (my $idx = first { $ARGV[$_] eq '--' } 0 .. @ARGV - 1)) {
+ @OPTS = splice @ARGV, 1 + $idx;
+}
+
+GetOptions(
+ 'help|?|h' => \$help,
+ 'dryrun|n' => \$dryrun,
+ 'list|l' => \$list,
+ 'tuxmake!' => \$tuxmake,
+ 'artifacts=s' => \$artifacts,
+ 'runtime=s' => \$runtime,
+ 'blk=s@' => \@blks,
+ 'console+' => \$extraconsoles,
+ 'rng' => \$rng,
+ 'emulate!' => \$emulate,
+ 'clean!' => \$clean,
+ 'shell' => \$shell,
+ 'kconfig-base!' => \$kconfig_base,
+ 'kconfig-full!' => \$kconfig_full,
+ 'kconfig-add|K=s@' => \@kconfig_add,
+ 'test' => \$test,
+) or pod2usage(2);
+pod2usage(1) if $help;
+
+my @ARCH = split /\s/, $ENV{ARCH} // '';
+@ARCH = @ARCH ? @ARCH : keys %targets;
+
+my $success = 0;
+
+for my $arch (@ARCH) {
+ my @targets = @ARGV ? @ARGV : keys %{$targets{$arch}};
+ @targets != 1 && !$tuxmake
+ and die "can't use --no-tuxmake with more than one config\n";
+
+ unless (defined $targets{$arch}) {
+ die "Unknown ARCH=$arch. Supported values:\n",
+ join(', ', keys %targets), "\n";
+ }
+
+ for my $config (@targets) {
+ $arch = $arch_aliases{$arch} // $arch;
+
+ unless (defined $targets{$arch}{$config}) {
+ next;
+ }
+
+ if ($list) {
+ print "ARCH=$arch $config\n";
+ $success += 1;
+ next;
+ }
+
+ if (defined $targets{$arch}{$config}{alias}) {
+ next if grep { /^$targets{$arch}{$config}{alias}$/ } @targets;
+ $config = $targets{$arch}{$config}{alias};
+ redo;
+ }
+
+ print "# $config\n" if $dryrun;
+ $success += process($arch, $config);
+ }
+}
+
+$success > 0
+ or die "No suitable config found. $0 -l to list all built-in.\n";
+
+sub process {
+ my ($ARCH, $defconfig, %keys) = @_;
+ my $target = $targets{$ARCH}{$defconfig};
+
+ if (!exists ($target->{runner}{tuxmake_arch})) {
+ $target->{runner}{tuxmake_arch} = $ARCH;
+ }
+
+ my $dir;
+
+ $dir = tempdir("bareboxbuild-XXXXXXXXXX", TMPDIR => 1, CLEANUP => $clean);
+ report('mkdir', $dir);
+
+ my %opts = (
+ target => $target, builddir => $tuxmake ? $dir : getcwd,
+ defconfig => $defconfig,
+ extra_opts => [map { s/\{config\}/$defconfig/gr } @OPTS],
+ );
+
+ build(%opts) if $tuxmake;
+
+ while (my ($k, $v) = each %{$target->{runner}{download}}) {
+ if ($v =~ m{^[/.]}) {
+ symlink_force($v, "$dir/$k");
+ } else {
+ vsystem('curl', '-L', '--create-dirs', '-o', "$dir/$k", $v) == 0
+ or die "Failed to download resource `$v': $?\n";
+ }
+
+ symlink_force("$dir/$k", "$k") unless $tuxmake;
+ }
+
+ if ($shell) {
+ pushd($dir);
+ system($ENV{SHELL} // "/bin/sh");
+ popd();
+ }
+
+ return 1 unless $emulate;
+
+ pushd($dir) if $tuxmake;
+
+ my $success = $test ? test(%opts) : emulate(%opts);
+
+ if ($tuxmake) {
+ popd();
+
+ report("rm", "-rd", $dir) if $clean;
+ }
+ print "\n\n" if $dryrun;
+ return $success;
+}
+
+sub build {
+ my %args = @_;
+ my ($runner, $dir) = ($args{target}{runner}, $args{builddir});
+
+ $args{defconfig} =~ s/[^@]+@//g;
+
+ my @TUXMAKE_ARGS = ('-a', $runner->{tuxmake_arch}, '-k', $args{defconfig});
+
+ if (defined $runner->{kconfig_add}) {
+ for my $cfg (@{$runner->{kconfig_add}}) {
+ push @TUXMAKE_ARGS, "--kconfig-add=$cfg"
+ }
+ }
+
+ push @TUXMAKE_ARGS, "--kconfig-add=test/kconfig/base.cfg" if $kconfig_base || $kconfig_full;
+ push @TUXMAKE_ARGS, "--kconfig-add=test/kconfig/full.cfg" if $kconfig_full;
+
+ for (@kconfig_add) {
+ push @TUXMAKE_ARGS, "--kconfig-add=$_";
+ }
+
+ push @TUXMAKE_ARGS, "--runtime=$runtime" if $runtime;
+
+ vsystem('tuxmake', @TUXMAKE_ARGS, '-b', $dir, '-o',
+ $artifacts // "$dir/artifacts", 'default') == 0
+ or die "Error building: $?\n";
+}
+
+sub emulate {
+ my %args = @_;
+ my %target = %{$args{target}};
+ my @OPTS = @{$args{extra_opts}};
+
+ if (defined $target{drivers}{QEMUDriver}) {
+ my %qemu = %{$target{drivers}{QEMUDriver}};
+ my ($kernel, $bios, $dtb);
+ my $qemu_virtio;
+ my $i;
+
+ $kernel = abs_configpath($qemu{kernel}, $args{target});
+ $bios = abs_configpath($qemu{bios}, $args{target});
+ $dtb = abs_configpath($qemu{dtb}, $args{target});
+
+ my @cmdline = ($target{tools}{$qemu{qemu_bin}},
+ '-M', $qemu{machine}, '-cpu', $qemu{cpu}, '-m', $qemu{memory});
+
+ push @cmdline, '-kernel', $kernel if defined $kernel;
+ push @cmdline, '-bios', $bios if defined $bios;
+ push @cmdline, '-dtb', $dtb if defined $dtb;
+
+ push @cmdline, @QEMU_INTERACTIVE_OPTS;
+ for (split /\s/, $qemu{extra_args}) {
+ push @cmdline, $_;
+ }
+
+ if (has_feature(\%target, 'virtio-pci')) {
+ $qemu_virtio = 'pci,disable-legacy=on,disable-modern=off';
+ push @{$target{features}}, 'pci';
+ push @{$target{features}}, 'virtio';
+ } elsif (has_feature(\%target, 'virtio-mmio')) {
+ $qemu_virtio = 'device';
+ push @{$target{features}}, 'virtio';
+ }
+
+ $i = 0;
+ for my $blk (@blks) {
+ if (has_feature(\%target, 'virtio')) {
+ $blk = rel2abs($blk, getcwd);
+ push @cmdline,
+ '-drive', "if=none,file=$blk,format=raw,id=hd$i",
+ '-device', "virtio-blk-$qemu_virtio,drive=hd$i";
+ } else {
+ die "--blk unsupported for target\n";
+ }
+ }
+
+ # note that barebox doesn't yet support multiple virtio consoles
+ if ($extraconsoles) {
+ $i = 0;
+
+ if (defined $qemu_virtio) {
+ push @cmdline,
+ '-device', "virtio-serial-$qemu_virtio",
+ '-chardev', "pty,id=virtcon$i",
+ '-device', "virtconsole,chardev=virtcon$i,name=console.virtcon$i";
+
+ $i++;
+ }
+
+ if ($i < $extraconsoles) {
+ # ns16550 serial driver only works with x86 so far
+ if (has_feature(\%target, 'pci')) {
+ for (; $i < $extraconsoles; $i++) {
+ push @cmdline,
+ '-chardev', "pty,id=pcicon$i",
+ '-device', "pci-serial,chardev=pcicon$i";
+ }
+ } else {
+ warn "barebox currently supports only a single extra virtio console\n";
+ }
+ }
+ }
+
+ if (defined $rng) {
+ if (has_feature(\%target, 'virtio')) {
+ push @cmdline, '-device', "virtio-rng-$qemu_virtio";
+ } else {
+ die "--rng unsupported for target\n";
+ }
+ }
+
+ vsystem(@cmdline, @OPTS) == 0 or die "Error running emulator: $?\n";
+
+ } elsif (defined $target{drivers}{TinyEMUDriver}) {
+ my %temu = %{$target{drivers}{TinyEMUDriver}};
+ my $TEMU_CFG;
+ my $i = 0;
+
+ if (exists $temu{config}) {
+ $temu{config} = rel2abs($temu{config}, getcwd . "/source/");
+ open(my $fh, '<', "$temu{config}")
+ or die "Could not open file '$temu{config}': $!";
+ $TEMU_CFG = do { local $/; <$fh> };
+ }
+
+ print ("$temu{config}\n");
+
+ defined $TEMU_CFG or die "Unknown tinyemu-config\n";
+
+ open(my $fh, '>', "tinyemu.cfg")
+ or die "Could not create file 'tinyemu.cfg': $!";
+ print $fh $TEMU_CFG;
+ print "cat >'tinyemu.cfg' <<EOF\n$TEMU_CFG\nEOF\n" if $dryrun;
+
+ for my $blk (@blks) {
+ $blk = rel2abs($blk, getcwd);
+ $TEMU_CFG =~ s[\}(?!.*\})][drive$i: { file: "$blk" },\n}]ms
+ }
+
+ die "--console unsupported for target\n" if $extraconsoles;
+ die "--rng unsupported for target\n" if defined $rng;
+
+ vsystem($temu{temu_bin}, "tinyemu.cfg", @OPTS) == 0
+ or die "Error running emulator: $?\n";
+ } elsif (defined $target{drivers}{NativeExecutableDriver}) {
+ my %exec = %{$target{drivers}{NativeExecutableDriver}};
+ vsystem($exec{command}, @OPTS) == 0 or die "Error running emulator: $?\n";
+ }
+
+ return 1;
+}
+
+sub test {
+ my %args = @_;
+ my @OPTS = @{$args{extra_opts}};
+
+ unless (defined $args{target}{drivers}{QEMUDriver}) {
+ warn "$args{target}{path}: Skippig test, no QEMUDriver\n";
+ return 0;
+ }
+
+ vsystem('labgrid-pytest', '--lg-env', "$args{target}{path}", "test/py",
+ '--lg-log', @OPTS) == 0 or die "Error running 'labgrid-pytest': $?\n";
+
+ return 1;
+}
+
+sub has_feature {
+ defined first { lc($_) eq $_[1] } @{$_[0]->{features}}
+}
+
+sub report {
+ print join(' ', map { /\s/ ? "'$_'" : $_ } @_), "\n" if $dryrun;
+ 0;
+}
+
+sub vsystem {
+ if ($dryrun) {
+ return report(@_);
+ } else {
+ my $ret = system @_;
+ warn "vsystem: $!\n" if $ret == -1;
+ return $ret >> 8;
+ }
+}
+
+sub rel2abs {
+ File::Spec->rel2abs(@_)
+}
+
+sub abs_configpath {
+ my ($path, $target) = @_;
+
+ return unless defined $path;
+ $path = $target->{images}{$path};
+ return unless defined $path;
+
+ return File::Spec->rel2abs($path, dirname $target->{path});
+}
+
+sub symlink_force {
+ unlink($_[1]);
+ symlink($_[0], $_[1]);
+}
+
+my @oldcwd;
+
+sub pushd {
+ my ($old, $new) = (getcwd, shift);
+ report ("pushd", $new);
+ push @oldcwd, $old;
+ chdir $new;
+ return $old;
+};
+
+sub popd {
+ report("popd");
+ chdir pop(@oldcwd)
+};
+
+__END__
+
+=head1 NAME
+
+emulate.pl - Build and run barebox under an emulator
+
+=head1 SYNOPSIS
+
+[ARCH=arch] emulate.pl [options] [defconfigs...] [--] [qemu/pytest-opts]
+
+=head1 OPTIONS
+
+Must be run from either barebox source or build directory.
+
+=over 8
+
+=item B<-?>, B<-h>, B<--help>
+
+Print a help message and exits
+
+=item B<-n>, B<--dryrun>
+
+Print commands and exit
+
+=item B<-l>, B<--list>
+
+Filter input with list of known targets
+
+=item B<--no-tuxmake>
+
+Don't rerun tuxkmake. Assumes current working directory is finished build directory
+
+=item B<--artifacts>=%s
+
+Destination directory for the tuxmake artifacts. By default, this is
+the artifacts/ subdirectory in the temporary build directory and is
+not persisted (unless --no-clean is specified).
+
+=item B<--blk>=%s
+
+Pass block device to emulated barebox. Can be specified more than once
+
+=item B<--console>
+
+Pass one Virt I/O console to emulated barebox.
+
+=item B<--rng>
+
+instantiate Virt I/O random number generator
+
+=item B<--no-emulate>
+
+Don't emulate anything and exit directly after build
+
+=item B<--no-clean>
+
+Don't delete temporary working directory after
+
+=item B<--shell>
+
+Open shell in temporary working directory, after build, but before emulation
+
+=item B<--test>
+
+Instead of starting emulator interactively, run it under labgrid-pytest with
+the in-tree python tests.
+
+=item B<--runtime>=%s
+
+Runtime to use for the tuxmake builds. By default, builds are
+run natively on the build host.
+Supported: null, podman-local, podman, docker, docker-local.
+
+=item B<--no-kconfig-base>
+
+Don't apply test/kconfig/base.cfg. This may lead to more tests being
+skipped.
+
+=item B<--kconfig-full>
+
+Applies test/kconfig/full.cfg on top of base.cfg. This enables as much as
+possible to avoid skipping tests for disabled functionality.
+
+=item B<--kconfig_add>=%s, B<-K>=%s
+
+Extra kconfig fragments, merged on top of the defconfig and Kconfig
+fragments described by the YAML. In tree configuration fragment
+(e.g. `test/kconfig/virtio-pci.config`), path to local file, URL,
+`CONFIG_*=[y|m|n]`, or `# CONFIG_* is not set` are supported.
+Can be specified multiple times, and will be merged in the order given.
+
+=back
+
+=cut
diff --git a/test/kconfig/base.cfg b/test/kconfig/base.cfg
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/test/kconfig/full.cfg b/test/kconfig/full.cfg
new file mode 100644
index 000000000000..e69de29bb2d1
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 15/17] test: self: run selftests as part of the pytest suite
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (13 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 14/17] test: add emulate.pl, a runner for barebox on emulated targets Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 16/17] test: add bthread test Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 17/17] [RFC] test: run ./test/emulate.pl in Github action Ahmad Fatoum
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
We don't want to enable self tests in the normal configs as they may in
future bloat size needlessly. Enable it instead in the base.cfg
fragment and add a test that verifies the selftest command
runs without errors.
Selftests can be run on startup for CONFIG_SHELL_NONE systems. This is
not implemented here. For such systems the test will be skipped
as CONFIG_CMD_SELFTEST won't be defined. To manually skip with
emulate.pl, add --no-kconfig-base.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/kconfig/base.cfg | 4 ++++
test/py/test_bselftests.py | 8 ++++++++
2 files changed, 12 insertions(+)
create mode 100644 test/py/test_bselftests.py
diff --git a/test/kconfig/base.cfg b/test/kconfig/base.cfg
index e69de29bb2d1..6a9f68349816 100644
--- a/test/kconfig/base.cfg
+++ b/test/kconfig/base.cfg
@@ -0,0 +1,4 @@
+CONFIG_TEST=y
+CONFIG_SELFTEST=y
+CONFIG_CMD_SELFTEST=y
+CONFIG_SELFTEST_ENABLE_ALL=y
diff --git a/test/py/test_bselftests.py b/test/py/test_bselftests.py
new file mode 100644
index 000000000000..48e9d38c12fc
--- /dev/null
+++ b/test/py/test_bselftests.py
@@ -0,0 +1,8 @@
+import pytest
+from .helper import *
+
+def test_bselftest(barebox, barebox_config):
+ skip_disabled(barebox_config, "CONFIG_CMD_SELFTEST")
+
+ _, _, returncode = barebox.run('selftest')
+ assert returncode == 0
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 16/17] test: add bthread test
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (14 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 15/17] test: self: run selftests as part of the pytest suite Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
2021-04-12 7:16 ` [PATCH 17/17] [RFC] test: run ./test/emulate.pl in Github action Ahmad Fatoum
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
The bthread -v command already returns an appropriate exit code if
threads can't be scheduled. Have it spawn 16 threads and switch between
them for a second and verify that all of these threads were indeed
terminated.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/kconfig/full.cfg | 2 ++
test/py/test_bthread.py | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+)
create mode 100644 test/py/test_bthread.py
diff --git a/test/kconfig/full.cfg b/test/kconfig/full.cfg
index e69de29bb2d1..39275768ea1f 100644
--- a/test/kconfig/full.cfg
+++ b/test/kconfig/full.cfg
@@ -0,0 +1,2 @@
+CONFIG_BTHREAD=y
+CONFIG_CMD_BTHREAD=y
diff --git a/test/py/test_bthread.py b/test/py/test_bthread.py
new file mode 100644
index 000000000000..6e7b4ba5007e
--- /dev/null
+++ b/test/py/test_bthread.py
@@ -0,0 +1,23 @@
+import pytest
+from .helper import *
+
+def stale_spawners(barebox):
+ threads = barebox.run_check("bthread -i")
+ if len(threads) == 0:
+ return False
+ return len([t for t in threads if t.startswith('spawner')]) > 0
+
+def test_bthread(barebox, barebox_config):
+ skip_disabled(barebox_config, "CONFIG_CMD_BTHREAD")
+
+ assert not stale_spawners(barebox)
+
+ _, _, returncode = barebox.run('bthread -vvvv')
+ assert returncode == 0
+
+ assert not stale_spawners(barebox)
+
+ switches = int(barebox.run_check("bthread -c")[0].split()[0])
+ yields = int(barebox.run_check("bthread -t")[0].split()[0])
+
+ assert yields < switches
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 17/17] [RFC] test: run ./test/emulate.pl in Github action
2021-04-12 7:16 [PATCH 00/17] add barebox in-tree testing infrastructure Ahmad Fatoum
` (15 preceding siblings ...)
2021-04-12 7:16 ` [PATCH 16/17] test: add bthread test Ahmad Fatoum
@ 2021-04-12 7:16 ` Ahmad Fatoum
16 siblings, 0 replies; 21+ messages in thread
From: Ahmad Fatoum @ 2021-04-12 7:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, rcz
See https://github.com/a3f/barebox/actions for an example how this could
look like.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
.github/workflows/build-configs.yaml | 41 ++++++++++++++++
.github/workflows/vm-tests.yaml | 71 ++++++++++++++++++++++++++++
.gitignore | 2 +
test/kconfig/no-deps.cfg | 3 ++
4 files changed, 117 insertions(+)
create mode 100644 .github/workflows/build-configs.yaml
create mode 100644 .github/workflows/vm-tests.yaml
create mode 100644 test/kconfig/no-deps.cfg
diff --git a/.github/workflows/build-configs.yaml b/.github/workflows/build-configs.yaml
new file mode 100644
index 000000000000..5025c2e04017
--- /dev/null
+++ b/.github/workflows/build-configs.yaml
@@ -0,0 +1,41 @@
+name: Build Configs
+on:
+ push:
+
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: ['ubuntu-latest' ]
+ ARCH: [ 'arm', 'mips', 'riscv' ]
+ name: ARCH=${{ matrix.ARCH }} Build
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ - name: Setup Environment
+ run: |
+ sudo apt-get update -qq
+ sudo apt-get install -y --no-install-recommends libyaml-tiny-perl \
+ lzop libusb-1.0-0-dev
+ pip3 install tuxmake
+
+ - name: Build Configs
+ run: |
+ for cfg in arch/${{ matrix.ARCH }}/configs/*_defconfig; do
+ cfg=$(basename $cfg)
+ DESTDIR="./artifacts/${{ matrix.ARCH }}-$cfg"
+ mkdir -p $DESTDIR
+ tuxmake -a "${{ matrix.ARCH }}" -k $cfg --runtime=podman -o $DESTDIR default \
+ --kconfig-add test/kconfig/no-deps.cfg
+ done
+
+ - name: Publish Build Artifacts
+ uses: actions/upload-artifact@v2
+ if: always()
+ with:
+ name: Build Logs
+ path: artifacts/
+ if-no-files-found: error
diff --git a/.github/workflows/vm-tests.yaml b/.github/workflows/vm-tests.yaml
new file mode 100644
index 000000000000..ac74dec5789b
--- /dev/null
+++ b/.github/workflows/vm-tests.yaml
@@ -0,0 +1,71 @@
+name: VM Tests
+on:
+ push:
+
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: ['ubuntu-latest' ]
+ ARCH: [ 'arm', 'mips', 'x86', 'riscv', 'openrisc' ]
+ name: ARCH=${{ matrix.ARCH }} Test
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ - name: Setup Environment
+ run: |
+ sudo apt-get update -qq
+ sudo apt-get install -y --no-install-recommends libyaml-tiny-perl \
+ qemu-system-arm qemu-system-mips qemu-system-x86 qemu-system-common qemu-system-misc
+ curl --remote-name --location \
+ http://ftp.us.debian.org/debian/pool/main/e/edk2/ovmf_2020.11-4_all.deb
+ sudo dpkg -i ovmf_2020.11-4_all.deb
+ pushd /tmp
+ git clone --depth 1 https://github.com/labgrid-project/labgrid
+ pushd labgrid
+ pip3 install -r requirements.txt
+ sudo python3 setup.py install
+ sudo ln -s $(which pytest) /usr/local/bin/labgrid-pytest
+ #pip3 install tuxmake
+ popd
+ git clone --depth 1 https://gitlab.com/a3f/tuxmake
+ cd tuxmake
+ python3 -m pip install flit
+ flit install
+ popd
+ sudo apt install lzop
+ if [ "${{ matrix.ARCH }}" = "openrisc" ]; then
+ curl --remote-name --location \
+ https://github.com/stffrdhrn/gcc/releases/download/or1k-10.0.0-20190723/or1k-linux-10.0.0-20190723.tar.xz
+ pushd /usr/local
+ sudo tar -xf $OLDPWD/or1k-linux-10.0.0-20190723.tar.xz --strip 1
+ popd
+ sudo ln -s /usr/lib/x86_64-linux-gnu/libmpfr.so.6 /usr/lib/x86_64-linux-gnu/libmpfr.so.4
+ fi
+
+ - name: Build and Run Tests
+ run: |
+ NAME=${{ matrix.ARCH }}-{config}
+ OPTS="--kconfig-full --test -- --junitxml=$PWD/$NAME.tests.xml --lg-log=$PWD/log/$NAME"
+ if [ "${{ matrix.ARCH }}" != "openrisc" ]; then
+ OPTS="--runtime=podman $OPTS"
+ fi
+
+ ARCH=${{ matrix.ARCH }} ./test/emulate.pl $OPTS
+
+ - name: Publish Test Results
+ uses: EnricoMi/publish-unit-test-result-action@v1.11
+ if: always()
+ with:
+ files: ./*.tests.xml
+
+ - name: Publish Labgrid Log Results
+ uses: actions/upload-artifact@v2
+ if: always()
+ with:
+ name: Console Logs
+ path: log/
+ if-no-files-found: error
diff --git a/.gitignore b/.gitignore
index d7a37b3c9b39..ee67c725ba34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -88,3 +88,5 @@ GTAGS
/allrandom.config
/allyes.config
/compile_commands.json
+
+!.github/
diff --git a/test/kconfig/no-deps.cfg b/test/kconfig/no-deps.cfg
new file mode 100644
index 000000000000..98ffd398decc
--- /dev/null
+++ b/test/kconfig/no-deps.cfg
@@ -0,0 +1,3 @@
+# CONFIG_ARCH_IMX_USBLOADER is not set
+# CONFIG_OMAP3_USB_LOADER is not set
+# CONFIG_OMAP4_HOSTTOOL_USBBOOT is not set
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread