mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-10-01 06:21:56 -09:00
support/testing/tests/package/test_tcl.py: new runtime test
Signed-off-by: Julien Olivain <ju.o@free.fr> [Arnout: use f-string instead of string.format] Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
This commit is contained in:
committed by
Arnout Vandecappelle
parent
47cbcb70d0
commit
2031fc8809
@@ -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_rdma_core/
|
||||||
F: support/testing/tests/package/test_screen.py
|
F: support/testing/tests/package/test_screen.py
|
||||||
F: support/testing/tests/package/test_stress_ng.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.py
|
||||||
F: support/testing/tests/package/test_weston/
|
F: support/testing/tests/package/test_weston/
|
||||||
F: support/testing/tests/package/test_xz.py
|
F: support/testing/tests/package/test_xz.py
|
||||||
|
|||||||
50
support/testing/tests/package/test_tcl.py
Normal file
50
support/testing/tests/package/test_tcl.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
|
import infra.basetest
|
||||||
|
|
||||||
|
|
||||||
|
class TestTcl(infra.basetest.BRTest):
|
||||||
|
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
|
||||||
|
f"""
|
||||||
|
BR2_PACKAGE_TCL=y
|
||||||
|
# BR2_PACKAGE_TCL_SHLIB_ONLY is not set
|
||||||
|
BR2_ROOTFS_OVERLAY="{infra.filepath("tests/package/test_tcl/rootfs-overlay")}"
|
||||||
|
BR2_TARGET_ROOTFS_CPIO=y
|
||||||
|
# BR2_TARGET_ROOTFS_TAR is not set
|
||||||
|
"""
|
||||||
|
|
||||||
|
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)
|
||||||
11
support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl
Executable file
11
support/testing/tests/package/test_tcl/rootfs-overlay/root/factorial.tcl
Executable file
@@ -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]]
|
||||||
Reference in New Issue
Block a user