test_python.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import os
  2. import infra.basetest
  3. class TestPythonBase(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_TARGET_ROOTFS_CPIO=y
  7. # BR2_TARGET_ROOTFS_TAR is not set
  8. """
  9. def login(self):
  10. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  11. self.emulator.boot(arch="armv5",
  12. kernel="builtin",
  13. options=["-initrd", cpio_file])
  14. self.emulator.login()
  15. def version_test(self, version):
  16. cmd = "python --version 2>&1 | grep '^{}'".format(version)
  17. _, exit_code = self.emulator.run(cmd)
  18. self.assertEqual(exit_code, 0)
  19. def math_floor_test(self):
  20. cmd = "python -c 'import math; math.floor(12.3)'"
  21. _, exit_code = self.emulator.run(cmd)
  22. self.assertEqual(exit_code, 0)
  23. def libc_time_test(self):
  24. cmd = "python -c 'from __future__ import print_function;"
  25. cmd += "import ctypes;"
  26. cmd += "libc = ctypes.cdll.LoadLibrary(\"libc.so.1\");"
  27. cmd += "print(libc.time(None))'"
  28. _, exit_code = self.emulator.run(cmd)
  29. self.assertEqual(exit_code, 0)
  30. def zlib_test(self):
  31. cmd = "python -c 'import zlib'"
  32. _, exit_code = self.emulator.run(cmd)
  33. self.assertEqual(exit_code, 1)
  34. class TestPython2(TestPythonBase):
  35. config = TestPythonBase.config + \
  36. """
  37. BR2_PACKAGE_PYTHON=y
  38. """
  39. def test_run(self):
  40. self.login()
  41. self.version_test("Python 2")
  42. self.math_floor_test()
  43. self.libc_time_test()
  44. self.zlib_test()
  45. class TestPython3(TestPythonBase):
  46. config = TestPythonBase.config + \
  47. """
  48. BR2_PACKAGE_PYTHON3=y
  49. """
  50. def test_run(self):
  51. self.login()
  52. self.version_test("Python 3")
  53. self.math_floor_test()
  54. self.libc_time_test()
  55. self.zlib_test()