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