2017-03-20 21:36:53 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
import infra.basetest
|
|
|
|
|
|
|
|
class TestPythonBase(infra.basetest.BRTest):
|
|
|
|
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
|
|
|
|
"""
|
|
|
|
BR2_TARGET_ROOTFS_CPIO=y
|
|
|
|
# BR2_TARGET_ROOTFS_TAR is not set
|
|
|
|
"""
|
2017-07-12 04:40:05 +02:00
|
|
|
def login(self):
|
2017-03-20 21:36:53 +01:00
|
|
|
cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
|
|
|
|
self.emulator.boot(arch="armv5",
|
|
|
|
kernel="builtin",
|
|
|
|
options=["-initrd", cpio_file])
|
|
|
|
self.emulator.login()
|
2017-07-12 04:40:05 +02:00
|
|
|
|
|
|
|
def version_test(self, version):
|
|
|
|
cmd = "python --version 2>&1 | grep '^{}'".format(version)
|
2017-03-20 21:36:53 +01:00
|
|
|
_, exit_code = self.emulator.run(cmd)
|
|
|
|
self.assertEqual(exit_code, 0)
|
|
|
|
|
2017-07-12 04:40:05 +02:00
|
|
|
def math_floor_test(self):
|
2017-03-20 21:36:53 +01:00
|
|
|
cmd = "python -c 'import math; math.floor(12.3)'"
|
|
|
|
_, exit_code = self.emulator.run(cmd)
|
|
|
|
self.assertEqual(exit_code, 0)
|
|
|
|
|
2017-07-12 04:40:05 +02:00
|
|
|
def libc_time_test(self):
|
2017-07-12 04:40:06 +02:00
|
|
|
cmd = "python -c 'from __future__ import print_function;"
|
|
|
|
cmd += "import ctypes;"
|
2017-03-20 21:36:53 +01:00
|
|
|
cmd += "libc = ctypes.cdll.LoadLibrary(\"libc.so.1\");"
|
2017-07-12 04:40:06 +02:00
|
|
|
cmd += "print(libc.time(None))'"
|
2017-03-20 21:36:53 +01:00
|
|
|
_, exit_code = self.emulator.run(cmd)
|
|
|
|
self.assertEqual(exit_code, 0)
|
|
|
|
|
2017-07-12 04:40:05 +02:00
|
|
|
def zlib_test(self):
|
2017-03-20 21:36:53 +01:00
|
|
|
cmd = "python -c 'import zlib'"
|
|
|
|
_, exit_code = self.emulator.run(cmd)
|
|
|
|
self.assertEqual(exit_code, 1)
|
2017-07-12 04:40:05 +02:00
|
|
|
|
|
|
|
class TestPython2(TestPythonBase):
|
|
|
|
config = TestPythonBase.config + \
|
|
|
|
"""
|
|
|
|
BR2_PACKAGE_PYTHON=y
|
|
|
|
"""
|
|
|
|
def test_run(self):
|
|
|
|
self.login()
|
|
|
|
self.version_test("Python 2")
|
|
|
|
self.math_floor_test()
|
|
|
|
self.libc_time_test()
|
|
|
|
self.zlib_test()
|
2017-07-12 04:40:06 +02:00
|
|
|
|
|
|
|
class TestPython3(TestPythonBase):
|
|
|
|
config = TestPythonBase.config + \
|
|
|
|
"""
|
|
|
|
BR2_PACKAGE_PYTHON3=y
|
|
|
|
"""
|
|
|
|
def test_run(self):
|
|
|
|
self.login()
|
|
|
|
self.version_test("Python 3")
|
|
|
|
self.math_floor_test()
|
|
|
|
self.libc_time_test()
|
|
|
|
self.zlib_test()
|