* [Buildroot] [PATCH 1/1] support/testing: add micropython runtime test
@ 2024-01-16 21:05 Julien Olivain
2024-01-21 13:59 ` Yann E. MORIN
0 siblings, 1 reply; 2+ messages in thread
From: Julien Olivain @ 2024-01-16 21:05 UTC (permalink / raw)
To: buildroot; +Cc: Julien Olivain
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Test is working on tag 2023.11, but fails on tag 2023.11.1 and branch
master at commit e07402a (micropython fail to compile, maybe due to
the bump to version 1.22.0?).
This is unrelated to this test, since the failure can be reproduced
with:
cat > .config <<EOF
BR2_aarch64=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_PACKAGE_MICROPYTHON=y
EOF
make olddefconfig
make
Build fail with:
/buildroot/output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-none-linux-gnu/13.2.1/../../../../aarch64-none-linux-gnu/bin/ld: build-standard/modffi.o: in function 'char2ffi_type':
/buildroot/output/build/micropython-1.22.0/ports/unix/modffi.c:119:(.text.char2ffi_type+0x28): undefined reference to 'ffi_type_sint8'
[...and many others...]
The test is also working when patch [1] is applied, because libffi is
no longer compiled.
[1] https://patchwork.ozlabs.org/project/buildroot/patch/20240116183629.365115-1-fontaine.fabrice@gmail.com/
---
DEVELOPERS | 2 +
.../testing/tests/package/test_micropython.py | 66 +++++++++++++++++++
.../rootfs-overlay/root/mandel.py | 25 +++++++
3 files changed, 93 insertions(+)
create mode 100644 support/testing/tests/package/test_micropython.py
create mode 100755 support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py
diff --git a/DEVELOPERS b/DEVELOPERS
index f5b04937b6..0f961ea486 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1789,6 +1789,8 @@ F: support/testing/tests/package/test_lzip.py
F: support/testing/tests/package/test_lsof.py
F: support/testing/tests/package/test_lz4.py
F: support/testing/tests/package/test_lzop.py
+F: support/testing/tests/package/test_micropython.py
+F: support/testing/tests/package/test_micropython/
F: support/testing/tests/package/test_mtools.py
F: support/testing/tests/package/test_ncdu.py
F: support/testing/tests/package/test_nftables.py
diff --git a/support/testing/tests/package/test_micropython.py b/support/testing/tests/package/test_micropython.py
new file mode 100644
index 0000000000..6d213c7ea5
--- /dev/null
+++ b/support/testing/tests/package/test_micropython.py
@@ -0,0 +1,66 @@
+import os
+
+import infra.basetest
+
+
+class TestMicroPython(infra.basetest.BRTest):
+ config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+ f"""
+ BR2_PACKAGE_MICROPYTHON=y
+ BR2_ROOTFS_OVERLAY="{infra.filepath("tests/package/test_micropython/rootfs-overlay")}"
+ BR2_TARGET_ROOTFS_CPIO=y
+ # BR2_TARGET_ROOTFS_TAR is not set
+ """
+
+ def run_upy_code(self, python_code):
+ cmd = f'micropython -c "{python_code}"'
+ self.assertRunOk(cmd)
+
+ def test_run(self):
+ cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+ self.emulator.boot(arch="armv5",
+ kernel="builtin",
+ options=["-initrd", cpio_file])
+ self.emulator.login()
+
+ # The micropython binary can execute.
+ self.assertRunOk("micropython -h")
+
+ # Check implementation is 'micropython'.
+ py_code = "import sys ; assert sys.implementation.name == 'micropython'"
+ self.run_upy_code(py_code)
+
+ # Query interpreter version and implementation.
+ py_code = "import sys ; "
+ py_code += "print('Version:', sys.version) ; "
+ py_code += "print('Implementation:', sys.implementation)"
+ self.run_upy_code(py_code)
+
+ # Check micropython optimization are correctly reported.
+ for opt_level in range(4):
+ py_code = "import micropython ; "
+ py_code += "opt = micropython.opt_level() ; "
+ py_code += "print(opt) ; "
+ py_code += f"assert opt == {opt_level}"
+ cmd = f"micropython -O{opt_level} -c '{py_code}'"
+ self.assertRunOk(cmd)
+
+ # Check micropython can return a non-zero exit code.
+ expected_code = 123
+ py_code = "import sys ; "
+ py_code += f"sys.exit({expected_code})"
+ cmd = f'micropython -c "{py_code}"'
+ _, exit_code = self.emulator.run(cmd)
+ self.assertEqual(exit_code, expected_code)
+
+ # We check micropython computes correctly.
+ input_value = 1234
+ expected_output = str(sum(range(input_value)))
+ py_code = f"print(sum(range(({input_value}))))"
+ cmd = f'micropython -c "{py_code}"'
+ output, exit_code = self.emulator.run(cmd)
+ self.assertEqual(exit_code, 0)
+ self.assertEqual(output[0], expected_output)
+
+ # Finally, we check check a small script can execute.
+ self.assertRunOk("/root/mandel.py", timeout=10)
diff --git a/support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py b/support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py
new file mode 100755
index 0000000000..0552f6894c
--- /dev/null
+++ b/support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py
@@ -0,0 +1,25 @@
+#! /usr/bin/env micropython
+
+from micropython import mem_info
+
+POINTS = list(",.:-;!/>)|&IH%*Z")
+
+
+def mandel():
+ for y in range(-15, 16):
+ for x in range(1, 85):
+ i = 0
+ r = 0
+ for k in range(112):
+ j = (r*r) - (i*i) - 2 + (x/25)
+ i = 2 * r * i + (y/10)
+ if j*j + i*i >= 11:
+ break
+ r = j
+ print(POINTS[k & 0xF], end='')
+ print()
+
+
+if __name__ == '__main__':
+ mandel()
+ mem_info()
--
2.43.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [Buildroot] [PATCH 1/1] support/testing: add micropython runtime test
2024-01-16 21:05 [Buildroot] [PATCH 1/1] support/testing: add micropython runtime test Julien Olivain
@ 2024-01-21 13:59 ` Yann E. MORIN
0 siblings, 0 replies; 2+ messages in thread
From: Yann E. MORIN @ 2024-01-21 13:59 UTC (permalink / raw)
To: Julien Olivain; +Cc: buildroot
Julien, All,
On 2024-01-16 22:05 +0100, Julien Olivain spake thusly:
> Signed-off-by: Julien Olivain <ju.o@free.fr>
I did a few cosmetic changes, mostly: run commands on the target, but
run the verification in the infra. For example, I changed constructs
like:
run("micropython -c 'foo = something(); assert foo == 0'")
into:
out = run("micropython -c 'print(something())'")
self.assertEqual(int(out[0]), 0, "error message")
Indeed, we don't want to be using the tested program to validate that
the tested program works as expected...
Applied to master with those few changes, thanks!
> ---
> Test is working on tag 2023.11, but fails on tag 2023.11.1 and branch
> master at commit e07402a (micropython fail to compile, maybe due to
> the bump to version 1.22.0?).
[--SNIP--]
> /buildroot/output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-none-linux-gnu/13.2.1/../../../../aarch64-none-linux-gnu/bin/ld: build-standard/modffi.o: in function 'char2ffi_type':
> /buildroot/output/build/micropython-1.22.0/ports/unix/modffi.c:119:(.text.char2ffi_type+0x28): undefined reference to 'ffi_type_sint8'
> [...and many others...]
The culprit was commit 9024e1866523 (package/micropython: drop GIT_DIR=.
workaround), for which I pushed a fixup, as 6c9be611a8b7.
Regards,
Yann E. MORIN.
> The test is also working when patch [1] is applied, because libffi is
> no longer compiled.
>
> [1] https://patchwork.ozlabs.org/project/buildroot/patch/20240116183629.365115-1-fontaine.fabrice@gmail.com/
> ---
> DEVELOPERS | 2 +
> .../testing/tests/package/test_micropython.py | 66 +++++++++++++++++++
> .../rootfs-overlay/root/mandel.py | 25 +++++++
> 3 files changed, 93 insertions(+)
> create mode 100644 support/testing/tests/package/test_micropython.py
> create mode 100755 support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py
>
> diff --git a/DEVELOPERS b/DEVELOPERS
> index f5b04937b6..0f961ea486 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -1789,6 +1789,8 @@ F: support/testing/tests/package/test_lzip.py
> F: support/testing/tests/package/test_lsof.py
> F: support/testing/tests/package/test_lz4.py
> F: support/testing/tests/package/test_lzop.py
> +F: support/testing/tests/package/test_micropython.py
> +F: support/testing/tests/package/test_micropython/
> F: support/testing/tests/package/test_mtools.py
> F: support/testing/tests/package/test_ncdu.py
> F: support/testing/tests/package/test_nftables.py
> diff --git a/support/testing/tests/package/test_micropython.py b/support/testing/tests/package/test_micropython.py
> new file mode 100644
> index 0000000000..6d213c7ea5
> --- /dev/null
> +++ b/support/testing/tests/package/test_micropython.py
> @@ -0,0 +1,66 @@
> +import os
> +
> +import infra.basetest
> +
> +
> +class TestMicroPython(infra.basetest.BRTest):
> + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
> + f"""
> + BR2_PACKAGE_MICROPYTHON=y
> + BR2_ROOTFS_OVERLAY="{infra.filepath("tests/package/test_micropython/rootfs-overlay")}"
> + BR2_TARGET_ROOTFS_CPIO=y
> + # BR2_TARGET_ROOTFS_TAR is not set
> + """
> +
> + def run_upy_code(self, python_code):
> + cmd = f'micropython -c "{python_code}"'
> + self.assertRunOk(cmd)
> +
> + def test_run(self):
> + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
> + self.emulator.boot(arch="armv5",
> + kernel="builtin",
> + options=["-initrd", cpio_file])
> + self.emulator.login()
> +
> + # The micropython binary can execute.
> + self.assertRunOk("micropython -h")
> +
> + # Check implementation is 'micropython'.
> + py_code = "import sys ; assert sys.implementation.name == 'micropython'"
> + self.run_upy_code(py_code)
> +
> + # Query interpreter version and implementation.
> + py_code = "import sys ; "
> + py_code += "print('Version:', sys.version) ; "
> + py_code += "print('Implementation:', sys.implementation)"
> + self.run_upy_code(py_code)
> +
> + # Check micropython optimization are correctly reported.
> + for opt_level in range(4):
> + py_code = "import micropython ; "
> + py_code += "opt = micropython.opt_level() ; "
> + py_code += "print(opt) ; "
> + py_code += f"assert opt == {opt_level}"
> + cmd = f"micropython -O{opt_level} -c '{py_code}'"
> + self.assertRunOk(cmd)
> +
> + # Check micropython can return a non-zero exit code.
> + expected_code = 123
> + py_code = "import sys ; "
> + py_code += f"sys.exit({expected_code})"
> + cmd = f'micropython -c "{py_code}"'
> + _, exit_code = self.emulator.run(cmd)
> + self.assertEqual(exit_code, expected_code)
> +
> + # We check micropython computes correctly.
> + input_value = 1234
> + expected_output = str(sum(range(input_value)))
> + py_code = f"print(sum(range(({input_value}))))"
> + cmd = f'micropython -c "{py_code}"'
> + output, exit_code = self.emulator.run(cmd)
> + self.assertEqual(exit_code, 0)
> + self.assertEqual(output[0], expected_output)
> +
> + # Finally, we check check a small script can execute.
> + self.assertRunOk("/root/mandel.py", timeout=10)
> diff --git a/support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py b/support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py
> new file mode 100755
> index 0000000000..0552f6894c
> --- /dev/null
> +++ b/support/testing/tests/package/test_micropython/rootfs-overlay/root/mandel.py
> @@ -0,0 +1,25 @@
> +#! /usr/bin/env micropython
> +
> +from micropython import mem_info
> +
> +POINTS = list(",.:-;!/>)|&IH%*Z")
> +
> +
> +def mandel():
> + for y in range(-15, 16):
> + for x in range(1, 85):
> + i = 0
> + r = 0
> + for k in range(112):
> + j = (r*r) - (i*i) - 2 + (x/25)
> + i = 2 * r * i + (y/10)
> + if j*j + i*i >= 11:
> + break
> + r = j
> + print(POINTS[k & 0xF], end='')
> + print()
> +
> +
> +if __name__ == '__main__':
> + mandel()
> + mem_info()
> --
> 2.43.0
>
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-21 13:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-16 21:05 [Buildroot] [PATCH 1/1] support/testing: add micropython runtime test Julien Olivain
2024-01-21 13:59 ` Yann E. MORIN
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox