test_external.py 8.8 KB

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