]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/testing/tests/toolchain/test_external.py
support/testing: fix code style
[coffee/buildroot.git] / support / testing / tests / toolchain / test_external.py
1 import os
2 import infra
3
4 BASIC_CONFIG = \
5     """
6     BR2_TARGET_ROOTFS_CPIO=y
7     # BR2_TARGET_ROOTFS_TAR is not set
8     """
9
10
11 def has_broken_links(path):
12     for root, dirs, files in os.walk(path):
13         for f in files:
14             fpath = os.path.join(root, f)
15             if not os.path.exists(fpath):
16                 return True
17     return False
18
19
20 class TestExternalToolchain(infra.basetest.BRTest):
21     def common_check(self):
22         # Check for broken symlinks
23         for d in ["lib", "usr/lib"]:
24             path = os.path.join(self.builddir, "staging", d)
25             self.assertFalse(has_broken_links(path))
26             path = os.path.join(self.builddir, "target", d)
27             self.assertFalse(has_broken_links(path))
28
29         interp = infra.get_elf_prog_interpreter(self.builddir,
30                                                 self.toolchain_prefix,
31                                                 "bin/busybox")
32         interp_path = os.path.join(self.builddir, "target", interp[1:])
33         self.assertTrue(os.path.exists(interp_path))
34
35
36 class TestExternalToolchainSourceryArmv4(TestExternalToolchain):
37     config = BASIC_CONFIG + \
38         """
39         BR2_arm=y
40         BR2_arm920t=y
41         BR2_TOOLCHAIN_EXTERNAL=y
42         BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM=y
43         """
44     toolchain_prefix = "arm-none-linux-gnueabi"
45
46     def test_run(self):
47         TestExternalToolchain.common_check(self)
48
49         # Check the architecture variant
50         arch = infra.get_file_arch(self.builddir,
51                                    self.toolchain_prefix,
52                                    "lib/libc.so.6")
53         self.assertEqual(arch, "v4T")
54
55         # Check the sysroot symlink
56         symlink = os.path.join(self.builddir, "staging", "armv4t")
57         self.assertTrue(os.path.exists(symlink))
58         self.assertEqual(os.readlink(symlink), "./")
59
60         # Boot the system
61         img = os.path.join(self.builddir, "images", "rootfs.cpio")
62         self.emulator.boot(arch="armv5",
63                            kernel="builtin",
64                            options=["-initrd", img])
65         self.emulator.login()
66
67
68 class TestExternalToolchainSourceryArmv5(TestExternalToolchain):
69     config = BASIC_CONFIG + \
70         """
71         BR2_arm=y
72         BR2_TOOLCHAIN_EXTERNAL=y
73         BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM=y
74         """
75     toolchain_prefix = "arm-none-linux-gnueabi"
76
77     def test_run(self):
78         TestExternalToolchain.common_check(self)
79
80         # Check the architecture variant
81         arch = infra.get_file_arch(self.builddir,
82                                    self.toolchain_prefix,
83                                    "lib/libc.so.6")
84         self.assertEqual(arch, "v5TE")
85
86         # Boot the system
87         img = os.path.join(self.builddir, "images", "rootfs.cpio")
88         self.emulator.boot(arch="armv5",
89                            kernel="builtin",
90                            options=["-initrd", img])
91         self.emulator.login()
92
93
94 class TestExternalToolchainSourceryArmv7(TestExternalToolchain):
95     config = BASIC_CONFIG + \
96         """
97         BR2_arm=y
98         BR2_cortex_a8=y
99         BR2_ARM_EABI=y
100         BR2_ARM_INSTRUCTIONS_THUMB2=y
101         BR2_TOOLCHAIN_EXTERNAL=y
102         BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_ARM=y
103         """
104     toolchain_prefix = "arm-none-linux-gnueabi"
105
106     def test_run(self):
107         TestExternalToolchain.common_check(self)
108
109         # Check the architecture variant
110         arch = infra.get_file_arch(self.builddir,
111                                    self.toolchain_prefix,
112                                    "lib/libc.so.6")
113         self.assertEqual(arch, "v7")
114         isa = infra.get_elf_arch_tag(self.builddir,
115                                      self.toolchain_prefix,
116                                      "lib/libc.so.6",
117                                      "Tag_THUMB_ISA_use")
118         self.assertEqual(isa, "Thumb-2")
119
120         # Check we have the sysroot symlink
121         symlink = os.path.join(self.builddir, "staging", "thumb2")
122         self.assertTrue(os.path.exists(symlink))
123         self.assertEqual(os.readlink(symlink), "./")
124
125         # Boot the system
126         img = os.path.join(self.builddir, "images", "rootfs.cpio")
127         self.emulator.boot(arch="armv7",
128                            kernel="builtin",
129                            options=["-initrd", img])
130         self.emulator.login()
131
132
133 class TestExternalToolchainLinaroArm(TestExternalToolchain):
134     config = BASIC_CONFIG + \
135         """
136         BR2_arm=y
137         BR2_cortex_a8=y
138         BR2_TOOLCHAIN_EXTERNAL=y
139         BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM=y
140         """
141     toolchain_prefix = "arm-linux-gnueabihf"
142
143     def test_run(self):
144         TestExternalToolchain.common_check(self)
145
146         # Check the architecture variant
147         arch = infra.get_file_arch(self.builddir,
148                                    self.toolchain_prefix,
149                                    "lib/libc.so.6")
150         self.assertEqual(arch, "v7")
151         isa = infra.get_elf_arch_tag(self.builddir,
152                                      self.toolchain_prefix,
153                                      "lib/libc.so.6",
154                                      "Tag_THUMB_ISA_use")
155         self.assertEqual(isa, "Thumb-2")
156
157         # Boot the system
158         img = os.path.join(self.builddir, "images", "rootfs.cpio")
159         self.emulator.boot(arch="armv7",
160                            kernel="builtin",
161                            options=["-initrd", img])
162         self.emulator.login()
163
164
165 class TestExternalToolchainBuildrootMusl(TestExternalToolchain):
166     config = BASIC_CONFIG + \
167         """
168         BR2_arm=y
169         BR2_cortex_a9=y
170         BR2_ARM_ENABLE_VFP=y
171         BR2_TOOLCHAIN_EXTERNAL=y
172         BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
173         BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
174         BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-cortex-a9-musl-2017.05-444-g6c704ba.tar.bz2"
175         BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
176         BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_11=y
177         BR2_TOOLCHAIN_EXTERNAL_CUSTOM_MUSL=y
178         BR2_TOOLCHAIN_EXTERNAL_CXX=y
179         """
180     toolchain_prefix = "arm-linux"
181
182     def test_run(self):
183         TestExternalToolchain.common_check(self)
184         img = os.path.join(self.builddir, "images", "rootfs.cpio")
185         self.emulator.boot(arch="armv7",
186                            kernel="builtin",
187                            options=["-initrd", img])
188         self.emulator.login()
189
190
191 class TestExternalToolchainCtngMusl(TestExternalToolchain):
192     config = BASIC_CONFIG + \
193         """
194         BR2_arm=y
195         BR2_cortex_a9=y
196         BR2_ARM_ENABLE_VFP=y
197         BR2_TOOLCHAIN_EXTERNAL=y
198         BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
199         BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
200         BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.net/toolchains/tarballs/arm-ctng-linux-musleabihf.tar.xz"
201         BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-ctng-linux-musleabihf"
202         BR2_TOOLCHAIN_EXTERNAL_GCC_7=y
203         BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y
204         BR2_TOOLCHAIN_EXTERNAL_CUSTOM_MUSL=y
205         BR2_TOOLCHAIN_EXTERNAL_CXX=y
206         """
207     toolchain_prefix = "arm-ctng-linux-musleabihf"
208
209     def test_run(self):
210         TestExternalToolchain.common_check(self)
211         img = os.path.join(self.builddir, "images", "rootfs.cpio")
212         self.emulator.boot(arch="armv7",
213                            kernel="builtin",
214                            options=["-initrd", img])
215         self.emulator.login()
216
217
218 class TestExternalToolchainBuildrootuClibc(TestExternalToolchain):
219     config = BASIC_CONFIG + \
220         """
221         BR2_arm=y
222         BR2_TOOLCHAIN_EXTERNAL=y
223         BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
224         BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
225         BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-2017.05-444-g6c704ba.tar.bz2"
226         BR2_TOOLCHAIN_EXTERNAL_GCC_4_9=y
227         BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y
228         BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
229         # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
230         BR2_TOOLCHAIN_EXTERNAL_CXX=y
231         """
232     toolchain_prefix = "arm-linux"
233
234     def test_run(self):
235         TestExternalToolchain.common_check(self)
236         img = os.path.join(self.builddir, "images", "rootfs.cpio")
237         self.emulator.boot(arch="armv7",
238                            kernel="builtin",
239                            options=["-initrd", img])
240         self.emulator.login()
241
242
243 class TestExternalToolchainCCache(TestExternalToolchainBuildrootuClibc):
244     extraconfig = \
245         """
246         BR2_CCACHE=y
247         BR2_CCACHE_DIR="{builddir}/ccache-dir"
248         """
249
250     def __init__(self, names):
251         super(TestExternalToolchainBuildrootuClibc, self).__init__(names)
252         self.config += self.extraconfig.format(builddir=self.builddir)