test_4th.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import os
  2. from math import sqrt
  3. import infra.basetest
  4. class Test4th(infra.basetest.BRTest):
  5. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  6. """
  7. BR2_PACKAGE_4TH=y
  8. BR2_TARGET_ROOTFS_CPIO=y
  9. # BR2_TARGET_ROOTFS_TAR is not set
  10. """
  11. def test_run(self):
  12. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  13. self.emulator.boot(arch="armv5",
  14. kernel="builtin",
  15. options=["-initrd", cpio_file])
  16. self.emulator.login()
  17. # We set the DIR4TH variable where 4th demos and libraries are
  18. # installed.
  19. self.assertRunOk("export DIR4TH=/usr/share/4th/")
  20. # We run a simple "hello world" demo.
  21. out, ret = self.emulator.run("4th cxq demo/hello.4th")
  22. self.assertEqual(ret, 0)
  23. self.assertEqual(out[0], "Hello world!")
  24. # We run a demo doing some square root maths.
  25. out, ret = self.emulator.run("4th cxq demo/squares.4th")
  26. self.assertEqual(ret, 0)
  27. self.assertTrue(len(out) > 1)
  28. for line in out[1:]:
  29. columns = line.split()
  30. value = float(columns[0])
  31. value_sqrt = float(columns[1])
  32. result_check = sqrt(value)
  33. self.assertAlmostEqual(value_sqrt, result_check, delta=0.1)
  34. # We run a word count demo and the 4th source file. We save
  35. # the word count for a later check.
  36. out, ret = self.emulator.run("4th cxq wc.4th /usr/share/4th/wc.4th")
  37. self.assertEqual(ret, 0)
  38. wc_out = out[0].split()
  39. # We run the same command using system "wc" command. We expect
  40. # the same numbers.
  41. out, ret = self.emulator.run("wc /usr/share/4th/wc.4th")
  42. self.assertEqual(ret, 0)
  43. self.assertEqual(out[0].split(), wc_out)
  44. # We run a slightly more complex computation example.
  45. self.assertRunOk("4th cxq fractals.4th")