test_swipl.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. import infra.basetest
  3. class TestSWIPL(infra.basetest.BRTest):
  4. rootfs_overlay = \
  5. infra.filepath("tests/package/test_swipl/rootfs-overlay")
  6. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  7. f"""
  8. BR2_PACKAGE_SWIPL=y
  9. BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
  10. BR2_TARGET_ROOTFS_CPIO=y
  11. # BR2_TARGET_ROOTFS_TAR is not set
  12. """
  13. def test_run(self):
  14. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  15. self.emulator.boot(arch="armv5",
  16. kernel="builtin",
  17. options=["-initrd", cpio_file])
  18. self.emulator.login()
  19. # Check program executes.
  20. cmd = "swipl --version"
  21. self.assertRunOk(cmd)
  22. # Check swipl fails when goal is false.
  23. cmd = "swipl -g false"
  24. _, exit_code = self.emulator.run(cmd)
  25. self.assertNotEqual(exit_code, 0)
  26. # Test output.
  27. string = "Hello Buildroot !"
  28. cmd = f"swipl -g 'writeln(\"{string}\")' -t halt"
  29. output, exit_code = self.emulator.run(cmd)
  30. self.assertEqual(exit_code, 0)
  31. self.assertEqual(output[0], string)
  32. # Check the swipl demo file works (ex: "sam" likes "pizza").
  33. cmd = "swipl -g '[swi(demo/likes)]' -g 'likes(sam,pizza)' -t halt"
  34. self.assertRunOk(cmd)
  35. # Run a more complex logic program (solve a sudoku).
  36. cmd = "swipl -g top -t halt /root/sudoku.pl"
  37. self.assertRunOk(cmd, timeout=10)