test_python.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 'import ctypes;"
  25. cmd += "libc = ctypes.cdll.LoadLibrary(\"libc.so.1\");"
  26. cmd += "print libc.time(None)'"
  27. _, exit_code = self.emulator.run(cmd)
  28. self.assertEqual(exit_code, 0)
  29. def zlib_test(self):
  30. cmd = "python -c 'import zlib'"
  31. _, exit_code = self.emulator.run(cmd)
  32. self.assertEqual(exit_code, 1)
  33. class TestPython2(TestPythonBase):
  34. config = TestPythonBase.config + \
  35. """
  36. BR2_PACKAGE_PYTHON=y
  37. """
  38. def test_run(self):
  39. self.login()
  40. self.version_test("Python 2")
  41. self.math_floor_test()
  42. self.libc_time_test()
  43. self.zlib_test()