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 TestExternalToolchainLinaroArm(TestExternalToolchain): 41 config = BASIC_CONFIG + \ 42 """ 43 BR2_arm=y 44 BR2_cortex_a8=y 45 BR2_TOOLCHAIN_EXTERNAL=y 46 BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM=y 47 """ 48 toolchain_prefix = "arm-linux-gnueabihf" 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, "v7") 58 isa = infra.get_elf_arch_tag(self.builddir, 59 self.toolchain_prefix, 60 "lib/libc.so.6", 61 "Tag_THUMB_ISA_use") 62 self.assertEqual(isa, "Thumb-2") 63 64 # Boot the system 65 img = os.path.join(self.builddir, "images", "rootfs.cpio") 66 self.emulator.boot(arch="armv7", 67 kernel="builtin", 68 options=["-initrd", img]) 69 self.emulator.login() 70 71 72class TestExternalToolchainBuildrootMusl(TestExternalToolchain): 73 config = BASIC_CONFIG + \ 74 """ 75 BR2_arm=y 76 BR2_cortex_a9=y 77 BR2_ARM_ENABLE_VFP=y 78 BR2_TOOLCHAIN_EXTERNAL=y 79 BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y 80 BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y 81 BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-cortex-a9-musl-2017.05-1078-g95b1dae.tar.bz2" 82 BR2_TOOLCHAIN_EXTERNAL_GCC_6=y 83 BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_12=y 84 BR2_TOOLCHAIN_EXTERNAL_CUSTOM_MUSL=y 85 BR2_TOOLCHAIN_EXTERNAL_CXX=y 86 """ 87 toolchain_prefix = "arm-linux" 88 89 def test_run(self): 90 TestExternalToolchain.common_check(self) 91 img = os.path.join(self.builddir, "images", "rootfs.cpio") 92 self.emulator.boot(arch="armv7", 93 kernel="builtin", 94 options=["-initrd", img]) 95 self.emulator.login() 96 97 98class TestExternalToolchainCtngMusl(TestExternalToolchain): 99 config = BASIC_CONFIG + \ 100 """ 101 BR2_arm=y 102 BR2_cortex_a9=y 103 BR2_ARM_ENABLE_VFP=y 104 BR2_TOOLCHAIN_EXTERNAL=y 105 BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y 106 BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y 107 BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.net/toolchains/tarballs/arm-ctng-linux-musleabihf.tar.xz" 108 BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-ctng-linux-musleabihf" 109 BR2_TOOLCHAIN_EXTERNAL_GCC_7=y 110 BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y 111 BR2_TOOLCHAIN_EXTERNAL_CUSTOM_MUSL=y 112 BR2_TOOLCHAIN_EXTERNAL_CXX=y 113 """ 114 toolchain_prefix = "arm-ctng-linux-musleabihf" 115 116 def test_run(self): 117 TestExternalToolchain.common_check(self) 118 img = os.path.join(self.builddir, "images", "rootfs.cpio") 119 self.emulator.boot(arch="armv7", 120 kernel="builtin", 121 options=["-initrd", img]) 122 self.emulator.login() 123 124 125class TestExternalToolchainBuildrootuClibc(TestExternalToolchain): 126 config = BASIC_CONFIG + \ 127 """ 128 BR2_arm=y 129 BR2_TOOLCHAIN_EXTERNAL=y 130 BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y 131 BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y 132 BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-2017.05-1078-g95b1dae.tar.bz2" 133 BR2_TOOLCHAIN_EXTERNAL_GCC_4_9=y 134 BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y 135 BR2_TOOLCHAIN_EXTERNAL_LOCALE=y 136 # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set 137 BR2_TOOLCHAIN_EXTERNAL_CXX=y 138 """ 139 toolchain_prefix = "arm-linux" 140 141 def test_run(self): 142 TestExternalToolchain.common_check(self) 143 img = os.path.join(self.builddir, "images", "rootfs.cpio") 144 self.emulator.boot(arch="armv7", 145 kernel="builtin", 146 options=["-initrd", img]) 147 self.emulator.login() 148 149 150class TestExternalToolchainCCache(TestExternalToolchainBuildrootuClibc): 151 extraconfig = \ 152 """ 153 BR2_CCACHE=y 154 BR2_CCACHE_DIR="{builddir}/ccache-dir" 155 """ 156 157 def __init__(self, names): 158 super(TestExternalToolchainBuildrootuClibc, self).__init__(names) 159 self.config += self.extraconfig.format(builddir=self.builddir) 160