test_octave.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import os
  2. import infra.basetest
  3. class TestOctave(infra.basetest.BRTest):
  4. # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it does
  5. # not include gfortran.
  6. config = \
  7. """
  8. BR2_aarch64=y
  9. BR2_TOOLCHAIN_EXTERNAL=y
  10. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  11. BR2_LINUX_KERNEL=y
  12. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  13. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.26"
  14. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  15. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  16. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  17. BR2_TARGET_ROOTFS_CPIO=y
  18. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  19. # BR2_TARGET_ROOTFS_TAR is not set
  20. BR2_PACKAGE_OCTAVE=y
  21. """
  22. timeout = 60
  23. def octave_cmd(self, octave_expr):
  24. return "octave --quiet --eval '{}'".format(octave_expr)
  25. def test_run(self):
  26. img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
  27. kern = os.path.join(self.builddir, "images", "Image")
  28. self.emulator.boot(arch="aarch64",
  29. kernel=kern,
  30. kernel_cmdline=["console=ttyAMA0"],
  31. options=["-M", "virt", "-cpu", "cortex-a57", "-m", "512M", "-initrd", img])
  32. self.emulator.login()
  33. # Check Euler identity
  34. cmd = self.octave_cmd("assert (exp(i*pi)+1, 0, 1e-10)")
  35. self.assertRunOk(cmd)
  36. # Solve equation system example from Octave homepage
  37. octave_expr = "b = [4; 9; 2]; "
  38. octave_expr += "A = [ 3 4 5; 1 3 1; 3 5 9 ]; "
  39. octave_expr += "x = A \\ b; "
  40. octave_expr += "assert(x, [-1.5; 4; -1.5], 1e-10)"
  41. cmd = self.octave_cmd(octave_expr)
  42. self.assertRunOk(cmd)
  43. # Check octave can fail
  44. cmd = self.octave_cmd("assert(false)")
  45. _, exit_code = self.emulator.run(cmd)
  46. self.assertNotEqual(exit_code, 0)
  47. # Check string output
  48. string = "Hello World"
  49. cmd = self.octave_cmd("printf(\"{}\\n\")".format(string))
  50. output, exit_code = self.emulator.run(cmd)
  51. self.assertEqual(exit_code, 0)
  52. self.assertEqual(output, [string])
  53. # Run some octave self tests
  54. octave_modules = [
  55. "elfun/atan2d",
  56. "elfun/sind",
  57. "general/gradient",
  58. "general/num2str",
  59. "polynomial/poly",
  60. "signal/fftconv",
  61. "special-matrix/magic",
  62. "specfun/isprime",
  63. "statistics/corr",
  64. "strings/str2num"
  65. ]
  66. for mod in octave_modules:
  67. cmd = self.octave_cmd('assert(test(\"{}\"),true)'.format(mod))
  68. self.assertRunOk(cmd)