support/testing/tests/package/test_swipl.py: new test

This commit adds a test case for the recently added swipl package. It
should have been part of commit
69710addd1 ("package/swipl: new
package") but was forgotten.

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Julien Olivain
2024-08-06 22:06:11 +02:00
committed by Thomas Petazzoni
parent 69710addd1
commit 4dc5c45bd2
2 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import os
import infra.basetest
class TestSWIPL(infra.basetest.BRTest):
rootfs_overlay = \
infra.filepath("tests/package/test_swipl/rootfs-overlay")
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
f"""
BR2_PACKAGE_SWIPL=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="armv5",
kernel="builtin",
options=["-initrd", cpio_file])
self.emulator.login()
# Check program executes.
cmd = "swipl --version"
self.assertRunOk(cmd)
# Check swipl fails when goal is false.
cmd = "swipl -g false"
_, exit_code = self.emulator.run(cmd)
self.assertNotEqual(exit_code, 0)
# Test output.
string = "Hello Buildroot !"
cmd = f"swipl -g 'writeln(\"{string}\")' -t halt"
output, exit_code = self.emulator.run(cmd)
self.assertEqual(exit_code, 0)
self.assertEqual(output[0], string)
# Check the swipl demo file works (ex: "sam" likes "pizza").
cmd = "swipl -g '[swi(demo/likes)]' -g 'likes(sam,pizza)' -t halt"
self.assertRunOk(cmd)
# Run a more complex logic program (solve a sudoku).
cmd = "swipl -g top -t halt /root/sudoku.pl"
self.assertRunOk(cmd, timeout=10)