From: "Yann E. MORIN" <yann.morin.1998@free.fr>
To: Julien Olivain <ju.o@free.fr>
Cc: buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH 1/1] support/testing: add micropython runtime test
Date: Sun, 21 Jan 2024 14:59:18 +0100 [thread overview]
Message-ID: <Za0jNoEFYccULASy@landeda> (raw)
In-Reply-To: <20240116210556.589407-1-ju.o@free.fr>
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
prev parent reply other threads:[~2024-01-21 13:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Za0jNoEFYccULASy@landeda \
--to=yann.morin.1998@free.fr \
--cc=buildroot@buildroot.org \
--cc=ju.o@free.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox