mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-09-09 16:01:54 -09:00
support/testing: quickjs: new runtime test
Signed-off-by: Julien Olivain <ju.o@free.fr>
This commit is contained in:
@@ -2030,6 +2030,8 @@ F: support/testing/tests/package/test_python_pyqt5.py
|
||||
F: support/testing/tests/package/test_python_pyqt5/
|
||||
F: support/testing/tests/package/test_python_spake2.py
|
||||
F: support/testing/tests/package/test_python_sympy.py
|
||||
F: support/testing/tests/package/test_quickjs.py
|
||||
F: support/testing/tests/package/test_quickjs/
|
||||
F: support/testing/tests/package/test_rdma_core.py
|
||||
F: support/testing/tests/package/test_rdma_core/
|
||||
F: support/testing/tests/package/test_rrdtool.py
|
||||
|
||||
52
support/testing/tests/package/test_quickjs.py
Normal file
52
support/testing/tests/package/test_quickjs.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
|
||||
import infra.basetest
|
||||
|
||||
|
||||
class TestQuickJS(infra.basetest.BRTest):
|
||||
rootfs_overlay = \
|
||||
infra.filepath("tests/package/test_quickjs/rootfs-overlay")
|
||||
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
|
||||
f"""
|
||||
BR2_PACKAGE_QUICKJS=y
|
||||
BR2_ROOTFS_OVERLAY="{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="armv7",
|
||||
kernel="builtin",
|
||||
options=["-initrd", cpio_file])
|
||||
self.emulator.login()
|
||||
|
||||
# We check can print a message from the command line.
|
||||
msg = "Hello Buildroot!"
|
||||
js_expr = f"console.log(\"{msg}\");"
|
||||
cmd = f"qjs -e '{js_expr}'"
|
||||
out, ret = self.emulator.run(cmd)
|
||||
self.assertEqual(ret, 0)
|
||||
self.assertEqual(out[0], msg)
|
||||
|
||||
# We check we can exit with a specific code.
|
||||
exit_code = 123
|
||||
js_expr = f"std.exit({exit_code});"
|
||||
cmd = f"qjs --std -e '{js_expr}'"
|
||||
out, ret = self.emulator.run(cmd)
|
||||
self.assertEqual(ret, exit_code)
|
||||
self.assertEqual(len(out), 0)
|
||||
|
||||
# We check we can do basic arithmetic.
|
||||
val1 = 1234
|
||||
val2 = 5678
|
||||
js_expr = f"console.log({val1} * {val2});"
|
||||
cmd = f"qjs -e '{js_expr}'"
|
||||
out, ret = self.emulator.run(cmd)
|
||||
self.assertEqual(ret, 0)
|
||||
expected_result = val1 * val2
|
||||
self.assertEqual(int(out[0]), expected_result)
|
||||
|
||||
# We check we can run a slightly more complex program and dump
|
||||
# the memory usage.
|
||||
self.assertRunOk("qjs -d --std mandel.js")
|
||||
@@ -0,0 +1,21 @@
|
||||
function mandel(file) {
|
||||
points = ",.:-;!/>)|&IH%*Z";
|
||||
for (y = -15; y <= 15; y++) {
|
||||
for (x = 1; x <= 84; x++) {
|
||||
i = 0;
|
||||
r = 0;
|
||||
for (k = 0; k <= 111; k++) {
|
||||
j = (r*r) - (i*i) - 2 + (x/25);
|
||||
i = 2 * r * i + (y/10);
|
||||
if ((j*j + i*i) >= 11) {
|
||||
break;
|
||||
}
|
||||
r = j;
|
||||
}
|
||||
file.puts(points[k & 0xF]);
|
||||
}
|
||||
file.puts("\n");
|
||||
}
|
||||
}
|
||||
|
||||
mandel(std.out);
|
||||
Reference in New Issue
Block a user