]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/testing/tests/package/test_python.py
79773fff63c92db085e5b36f764a0f858fb72d2c
[coffee/buildroot.git] / support / testing / tests / package / test_python.py
1 import os
2
3 import infra.basetest
4
5 class TestPythonBase(infra.basetest.BRTest):
6     config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
7         """
8         BR2_TARGET_ROOTFS_CPIO=y
9         # BR2_TARGET_ROOTFS_TAR is not set
10         """
11     interpreter = "python"
12
13     def login(self):
14         cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
15         self.emulator.boot(arch="armv5",
16                            kernel="builtin",
17                            options=["-initrd", cpio_file])
18         self.emulator.login()
19
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)
24
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)
29
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)
37
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)
42
43 class TestPython2(TestPythonBase):
44     config = TestPythonBase.config + \
45         """
46         BR2_PACKAGE_PYTHON=y
47         """
48     def test_run(self):
49         self.login()
50         self.version_test("Python 2")
51         self.math_floor_test()
52         self.libc_time_test()
53         self.zlib_test()
54
55 class TestPython3(TestPythonBase):
56     config = TestPythonBase.config + \
57         """
58         BR2_PACKAGE_PYTHON3=y
59         """
60     def test_run(self):
61         self.login()
62         self.version_test("Python 3")
63         self.math_floor_test()
64         self.libc_time_test()
65         self.zlib_test()