Message ID | 20230917171244.139679-1-ju.o@free.fr |
---|---|
State | Accepted |
Headers | show |
Series | [1/1] support/testing/tests/package/test_tcl.py: new runtime test | expand |
On 17/09/2023 19:12, Julien Olivain wrote: > Signed-off-by: Julien Olivain <ju.o@free.fr> Applied to master, thanks, with one little change... > --- > Patch tested on branch master at commit 7af8dee with commands: > > make check-package > ... > 0 warnings generated > > support/testing/run-tests \ > -d dl -o output_folder \ > tests.package.test_tcl > ... > OK > > Note: for the record, writing this test caught the issue fixed in > commit 7af8dee "package/tcl: add mandatory dependency to zlib". It also > identifed a toolchain issue with the proposed fix: > https://patchwork.ozlabs.org/project/buildroot/patch/20230917152303.1300577-1-yann.morin.1998@free.fr/ > --- > DEVELOPERS | 2 + > support/testing/tests/package/test_tcl.py | 52 +++++++++++++++++++ > .../rootfs-overlay/root/factorial.tcl | 11 ++++ > 3 files changed, 65 insertions(+) > create mode 100644 support/testing/tests/package/test_tcl.py > create mode 100755 support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl > > diff --git a/DEVELOPERS b/DEVELOPERS > index 7fae4841e4..e8b78a8d46 100644 > --- a/DEVELOPERS > +++ b/DEVELOPERS > @@ -1772,6 +1772,8 @@ F: support/testing/tests/package/test_rdma_core.py > F: support/testing/tests/package/test_rdma_core/ > F: support/testing/tests/package/test_screen.py > F: support/testing/tests/package/test_stress_ng.py > +F: support/testing/tests/package/test_tcl.py > +F: support/testing/tests/package/test_tcl/ > F: support/testing/tests/package/test_weston.py > F: support/testing/tests/package/test_weston/ > F: support/testing/tests/package/test_xz.py > diff --git a/support/testing/tests/package/test_tcl.py b/support/testing/tests/package/test_tcl.py > new file mode 100644 > index 0000000000..5986ebff01 > --- /dev/null > +++ b/support/testing/tests/package/test_tcl.py > @@ -0,0 +1,52 @@ > +import math > +import os > + > +import infra.basetest > + > + > +class TestTcl(infra.basetest.BRTest): > + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ > + """ > + BR2_PACKAGE_TCL=y > + # BR2_PACKAGE_TCL_SHLIB_ONLY is not set > + BR2_ROOTFS_OVERLAY="{}" > + BR2_TARGET_ROOTFS_CPIO=y > + # BR2_TARGET_ROOTFS_TAR is not set > + """.format( > + infra.filepath("tests/package/test_tcl/rootfs-overlay") > + ) I admit that this is the pattern we have pretty much everywhere right now in the tests, but we started using f-strings a while ago, and it looks much cleaner like that. So I changed this into an f-string. Regards, Arnout > + > + 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() > + > + # Print tcl the interpreter version and patchlevel. > + tcl_cmds = "puts \"tcl_version: $tcl_version\";" > + tcl_cmds += "puts \"patchlevel: [info patchlevel]\";" > + tcl_cmds += "exit 0" > + cmd = f"echo '{tcl_cmds}' | tclsh" > + self.assertRunOk(cmd) > + > + # We check tclsh correctly print a string. > + txt = "Hello Buildroot" > + cmd = f"echo 'puts \"{txt}\"; exit 0' | tclsh" > + output, exit_code = self.emulator.run(cmd) > + self.assertEqual(exit_code, 0) > + self.assertEqual(output[0], txt) > + > + # We check tclsh can return a non-zero exit code. > + expected_code = 123 > + cmd = f"echo 'exit {expected_code}' | tclsh" > + _, exit_code = self.emulator.run(cmd) > + self.assertEqual(exit_code, expected_code) > + > + # We check a tcl program computing factorial run correctly. > + input_value = 12 > + expected_output = str(math.factorial(input_value)) > + cmd = f"/root/factorial.tcl {input_value}" > + output, exit_code = self.emulator.run(cmd) > + self.assertEqual(exit_code, 0) > + self.assertEqual(output[0], expected_output) > diff --git a/support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl b/support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl > new file mode 100755 > index 0000000000..0398f24ceb > --- /dev/null > +++ b/support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl > @@ -0,0 +1,11 @@ > +#! /usr/bin/env tclsh > + > +proc factorial {n} { > + set f 1 > + for {set i 1} {$i <= $n} {incr i} { > + set f [expr {$f * $i}] > + } > + return $f > +} > + > +puts [factorial [lindex $argv 0]]
diff --git a/DEVELOPERS b/DEVELOPERS index 7fae4841e4..e8b78a8d46 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1772,6 +1772,8 @@ F: support/testing/tests/package/test_rdma_core.py F: support/testing/tests/package/test_rdma_core/ F: support/testing/tests/package/test_screen.py F: support/testing/tests/package/test_stress_ng.py +F: support/testing/tests/package/test_tcl.py +F: support/testing/tests/package/test_tcl/ F: support/testing/tests/package/test_weston.py F: support/testing/tests/package/test_weston/ F: support/testing/tests/package/test_xz.py diff --git a/support/testing/tests/package/test_tcl.py b/support/testing/tests/package/test_tcl.py new file mode 100644 index 0000000000..5986ebff01 --- /dev/null +++ b/support/testing/tests/package/test_tcl.py @@ -0,0 +1,52 @@ +import math +import os + +import infra.basetest + + +class TestTcl(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_PACKAGE_TCL=y + # BR2_PACKAGE_TCL_SHLIB_ONLY is not set + BR2_ROOTFS_OVERLAY="{}" + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """.format( + infra.filepath("tests/package/test_tcl/rootfs-overlay") + ) + + 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() + + # Print tcl the interpreter version and patchlevel. + tcl_cmds = "puts \"tcl_version: $tcl_version\";" + tcl_cmds += "puts \"patchlevel: [info patchlevel]\";" + tcl_cmds += "exit 0" + cmd = f"echo '{tcl_cmds}' | tclsh" + self.assertRunOk(cmd) + + # We check tclsh correctly print a string. + txt = "Hello Buildroot" + cmd = f"echo 'puts \"{txt}\"; exit 0' | tclsh" + output, exit_code = self.emulator.run(cmd) + self.assertEqual(exit_code, 0) + self.assertEqual(output[0], txt) + + # We check tclsh can return a non-zero exit code. + expected_code = 123 + cmd = f"echo 'exit {expected_code}' | tclsh" + _, exit_code = self.emulator.run(cmd) + self.assertEqual(exit_code, expected_code) + + # We check a tcl program computing factorial run correctly. + input_value = 12 + expected_output = str(math.factorial(input_value)) + cmd = f"/root/factorial.tcl {input_value}" + output, exit_code = self.emulator.run(cmd) + self.assertEqual(exit_code, 0) + self.assertEqual(output[0], expected_output) diff --git a/support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl b/support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl new file mode 100755 index 0000000000..0398f24ceb --- /dev/null +++ b/support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl @@ -0,0 +1,11 @@ +#! /usr/bin/env tclsh + +proc factorial {n} { + set f 1 + for {set i 1} {$i <= $n} {incr i} { + set f [expr {$f * $i}] + } + return $f +} + +puts [factorial [lindex $argv 0]]
Signed-off-by: Julien Olivain <ju.o@free.fr> --- Patch tested on branch master at commit 7af8dee with commands: make check-package ... 0 warnings generated support/testing/run-tests \ -d dl -o output_folder \ tests.package.test_tcl ... OK Note: for the record, writing this test caught the issue fixed in commit 7af8dee "package/tcl: add mandatory dependency to zlib". It also identifed a toolchain issue with the proposed fix: https://patchwork.ozlabs.org/project/buildroot/patch/20230917152303.1300577-1-yann.morin.1998@free.fr/ --- DEVELOPERS | 2 + support/testing/tests/package/test_tcl.py | 52 +++++++++++++++++++ .../rootfs-overlay/root/factorial.tcl | 11 ++++ 3 files changed, 65 insertions(+) create mode 100644 support/testing/tests/package/test_tcl.py create mode 100755 support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl