5 class TestPythonBase(infra.basetest.BRTest):
6 config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
8 BR2_TARGET_ROOTFS_CPIO=y
9 # BR2_TARGET_ROOTFS_TAR is not set
11 interpreter = "python"
14 cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
15 self.emulator.boot(arch="armv5",
17 options=["-initrd", cpio_file])
20 def version_test(self, version, timeout=-1):
21 cmd = self.interpreter + " --version 2>&1 | grep '^{}'".format(version)
22 _, exit_code = self.emulator.run(cmd, timeout)
23 self.assertEqual(exit_code, 0)
25 def math_floor_test(self, timeout=-1):
26 cmd = self.interpreter + " -c 'import math; math.floor(12.3)'"
27 _, exit_code = self.emulator.run(cmd, timeout)
28 self.assertEqual(exit_code, 0)
30 def libc_time_test(self, timeout=-1):
31 cmd = self.interpreter + " -c 'from __future__ import print_function;"
32 cmd += "import ctypes;"
33 cmd += "libc = ctypes.cdll.LoadLibrary(\"libc.so.1\");"
34 cmd += "print(libc.time(None))'"
35 _, exit_code = self.emulator.run(cmd, timeout)
36 self.assertEqual(exit_code, 0)
38 def zlib_test(self, timeout=-1):
39 cmd = self.interpreter + " -c 'import zlib'"
40 _, exit_code = self.emulator.run(cmd, timeout)
41 self.assertEqual(exit_code, 1)
43 class TestPython2(TestPythonBase):
44 config = TestPythonBase.config + \
50 self.version_test("Python 2")
51 self.math_floor_test()
55 class TestPython3(TestPythonBase):
56 config = TestPythonBase.config + \
62 self.version_test("Python 3")
63 self.math_floor_test()