buildoptions.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import os
  7. import re
  8. import glob as g
  9. import shutil
  10. import tempfile
  11. from oeqa.selftest.case import OESelftestTestCase
  12. from oeqa.selftest.cases.buildhistory import BuildhistoryBase
  13. from oeqa.core.decorator.data import skipIfMachine
  14. from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars
  15. import oeqa.utils.ftools as ftools
  16. from oeqa.core.decorator import OETestTag
  17. class ImageOptionsTests(OESelftestTestCase):
  18. def test_incremental_image_generation(self):
  19. image_pkgtype = get_bb_var("IMAGE_PKGTYPE")
  20. if image_pkgtype != 'rpm':
  21. self.skipTest('Not using RPM as main package format')
  22. bitbake("-c clean core-image-minimal")
  23. self.write_config('INC_RPM_IMAGE_GEN = "1"')
  24. self.append_config('IMAGE_FEATURES += "ssh-server-openssh"')
  25. bitbake("core-image-minimal")
  26. log_data_file = os.path.join(get_bb_var("WORKDIR", "core-image-minimal"), "temp/log.do_rootfs")
  27. log_data_created = ftools.read_file(log_data_file)
  28. incremental_created = re.search(r"Installing\s*:\s*packagegroup-core-ssh-openssh", log_data_created)
  29. self.remove_config('IMAGE_FEATURES += "ssh-server-openssh"')
  30. self.assertTrue(incremental_created, msg = "Match failed in:\n%s" % log_data_created)
  31. bitbake("core-image-minimal")
  32. log_data_removed = ftools.read_file(log_data_file)
  33. incremental_removed = re.search(r"Erasing\s*:\s*packagegroup-core-ssh-openssh", log_data_removed)
  34. self.assertTrue(incremental_removed, msg = "Match failed in:\n%s" % log_data_removed)
  35. def test_ccache_tool(self):
  36. bitbake("ccache-native")
  37. bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'ccache-native')
  38. p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "ccache"
  39. self.assertTrue(os.path.isfile(p), msg = "No ccache found (%s)" % p)
  40. self.write_config('INHERIT += "ccache"')
  41. recipe = "libgcc-initial"
  42. self.add_command_to_tearDown('bitbake -c clean %s' % recipe)
  43. bitbake("%s -c clean" % recipe)
  44. bitbake("%s -f -c compile" % recipe)
  45. log_compile = os.path.join(get_bb_var("WORKDIR", recipe), "temp/log.do_compile")
  46. with open(log_compile, "r") as f:
  47. loglines = "".join(f.readlines())
  48. self.assertIn("ccache", loglines, msg="No match for ccache in %s log.do_compile. For further details: %s" % (recipe , log_compile))
  49. def test_read_only_image(self):
  50. distro_features = get_bb_var('DISTRO_FEATURES')
  51. if not ('x11' in distro_features and 'opengl' in distro_features):
  52. self.skipTest('core-image-sato/weston requires x11 and opengl in distro features')
  53. self.write_config('IMAGE_FEATURES += "read-only-rootfs"')
  54. bitbake("core-image-sato core-image-weston")
  55. # do_image will fail if there are any pending postinsts
  56. class DiskMonTest(OESelftestTestCase):
  57. def test_stoptask_behavior(self):
  58. self.write_config('BB_DISKMON_DIRS = "STOPTASKS,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
  59. res = bitbake("delay -c delay", ignore_status = True)
  60. self.assertTrue('ERROR: No new tasks can be executed since the disk space monitor action is "STOPTASKS"!' in res.output, msg = "Tasks should have stopped. Disk monitor is set to STOPTASK: %s" % res.output)
  61. self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
  62. self.write_config('BB_DISKMON_DIRS = "HALT,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
  63. res = bitbake("delay -c delay", ignore_status = True)
  64. self.assertTrue('ERROR: Immediately halt since the disk space monitor action is "HALT"!' in res.output, "Tasks should have been halted immediately. Disk monitor is set to HALT: %s" % res.output)
  65. self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
  66. self.write_config('BB_DISKMON_DIRS = "WARN,${TMPDIR},100000G,100K"\nBB_HEARTBEAT_EVENT = "1"')
  67. res = bitbake("delay -c delay")
  68. self.assertTrue('WARNING: The free space' in res.output, msg = "A warning should have been displayed for disk monitor is set to WARN: %s" %res.output)
  69. class SanityOptionsTest(OESelftestTestCase):
  70. def getline(self, res, line):
  71. for l in res.output.split('\n'):
  72. if line in l:
  73. return l
  74. def test_options_warnqa_errorqa_switch(self):
  75. self.write_config("INHERIT:remove = \"report-error\"")
  76. if "packages-list" not in get_bb_var("ERROR_QA"):
  77. self.append_config("ERROR_QA:append:pn-xcursor-transparent-theme = \" packages-list\"")
  78. self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
  79. self.add_command_to_tearDown('bitbake -c clean xcursor-transparent-theme')
  80. res = bitbake("xcursor-transparent-theme -f -c package", ignore_status=True)
  81. self.delete_recipeinc('xcursor-transparent-theme')
  82. line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
  83. self.assertTrue(line and line.startswith("ERROR:"), msg=res.output)
  84. self.assertEqual(res.status, 1, msg = "bitbake reported exit code %s. It should have been 1. Bitbake output: %s" % (str(res.status), res.output))
  85. self.write_recipeinc('xcursor-transparent-theme', 'PACKAGES += \"${PN}-dbg\"')
  86. self.append_config('ERROR_QA:remove:pn-xcursor-transparent-theme = "packages-list"')
  87. self.append_config('WARN_QA:append:pn-xcursor-transparent-theme = " packages-list"')
  88. res = bitbake("xcursor-transparent-theme -f -c package")
  89. self.delete_recipeinc('xcursor-transparent-theme')
  90. line = self.getline(res, "QA Issue: xcursor-transparent-theme-dbg is listed in PACKAGES multiple times, this leads to packaging errors.")
  91. self.assertTrue(line and line.startswith("WARNING:"), msg=res.output)
  92. def test_layer_without_git_dir(self):
  93. """
  94. Summary: Test that layer git revisions are displayed and do not fail without git repository
  95. Expected: The build to be successful and without "fatal" errors
  96. Product: oe-core
  97. Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
  98. AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
  99. """
  100. dirpath = tempfile.mkdtemp()
  101. dummy_layer_name = 'meta-dummy'
  102. dummy_layer_path = os.path.join(dirpath, dummy_layer_name)
  103. dummy_layer_conf_dir = os.path.join(dummy_layer_path, 'conf')
  104. os.makedirs(dummy_layer_conf_dir)
  105. dummy_layer_conf_path = os.path.join(dummy_layer_conf_dir, 'layer.conf')
  106. dummy_layer_content = 'BBPATH .= ":${LAYERDIR}"\n' \
  107. 'BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"\n' \
  108. 'BBFILE_COLLECTIONS += "%s"\n' \
  109. 'BBFILE_PATTERN_%s = "^${LAYERDIR}/"\n' \
  110. 'BBFILE_PRIORITY_%s = "6"\n' % (dummy_layer_name, dummy_layer_name, dummy_layer_name)
  111. ftools.write_file(dummy_layer_conf_path, dummy_layer_content)
  112. bblayers_conf = 'BBLAYERS += "%s"\n' % dummy_layer_path
  113. self.write_bblayers_config(bblayers_conf)
  114. test_recipe = 'ed'
  115. ret = bitbake('-n %s' % test_recipe)
  116. err = 'fatal: Not a git repository'
  117. shutil.rmtree(dirpath)
  118. self.assertNotIn(err, ret.output)
  119. class BuildhistoryTests(BuildhistoryBase):
  120. def test_buildhistory_basic(self):
  121. self.run_buildhistory_operation('xcursor-transparent-theme')
  122. self.assertTrue(os.path.isdir(get_bb_var('BUILDHISTORY_DIR')), "buildhistory dir was not created.")
  123. def test_buildhistory_buildtime_pr_backwards(self):
  124. target = 'xcursor-transparent-theme'
  125. error = "ERROR:.*QA Issue: Package version for package %s went backwards which would break package feeds \(from .*-r1.* to .*-r0.*\)" % target
  126. self.run_buildhistory_operation(target, target_config="PR = \"r1\"", change_bh_location=True)
  127. self.run_buildhistory_operation(target, target_config="PR = \"r0\"", change_bh_location=False, expect_error=True, error_regex=error)
  128. def test_fileinfo(self):
  129. self.config_buildhistory()
  130. bitbake('hicolor-icon-theme')
  131. history_dir = get_bb_var('BUILDHISTORY_DIR_PACKAGE', 'hicolor-icon-theme')
  132. self.assertTrue(os.path.isdir(history_dir), 'buildhistory dir was not created.')
  133. def load_bh(f):
  134. d = {}
  135. for line in open(f):
  136. split = [s.strip() for s in line.split('=', 1)]
  137. if len(split) > 1:
  138. d[split[0]] = split[1]
  139. return d
  140. data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme', 'latest'))
  141. self.assertIn('FILELIST', data)
  142. self.assertEqual(data['FILELIST'], '/usr/share/icons/hicolor/index.theme')
  143. self.assertGreater(int(data['PKGSIZE']), 0)
  144. data = load_bh(os.path.join(history_dir, 'hicolor-icon-theme-dev', 'latest'))
  145. if 'FILELIST' in data:
  146. self.assertEqual(data['FILELIST'], '/usr/share/pkgconfig/default-icon-theme.pc')
  147. self.assertGreater(int(data['PKGSIZE']), 0)
  148. class ArchiverTest(OESelftestTestCase):
  149. def test_arch_work_dir_and_export_source(self):
  150. """
  151. Test for archiving the work directory and exporting the source files.
  152. """
  153. self.write_config("""
  154. INHERIT += "archiver"
  155. PACKAGE_CLASSES = "package_rpm"
  156. ARCHIVER_MODE[src] = "original"
  157. ARCHIVER_MODE[srpm] = "1"
  158. """)
  159. res = bitbake("xcursor-transparent-theme", ignore_status=True)
  160. self.assertEqual(res.status, 0, "\nCouldn't build xcursortransparenttheme.\nbitbake output %s" % res.output)
  161. deploy_dir_src = get_bb_var('DEPLOY_DIR_SRC')
  162. pkgs_path = g.glob(str(deploy_dir_src) + "/allarch*/xcurs*")
  163. src_file_glob = str(pkgs_path[0]) + "/xcursor*.src.rpm"
  164. tar_file_glob = str(pkgs_path[0]) + "/xcursor*.tar.xz"
  165. self.assertTrue((g.glob(src_file_glob) and g.glob(tar_file_glob)), "Couldn't find .src.rpm and .tar.xz files under %s/allarch*/xcursor*" % deploy_dir_src)
  166. class ToolchainOptions(OESelftestTestCase):
  167. def test_toolchain_fortran(self):
  168. """
  169. Test that Fortran works by building a Hello, World binary.
  170. """
  171. features = 'FORTRAN:forcevariable = ",fortran"\n'
  172. self.write_config(features)
  173. bitbake('fortran-helloworld')
  174. @OETestTag("yocto-mirrors")
  175. class SourceMirroring(OESelftestTestCase):
  176. # Can we download everything from the Yocto Sources Mirror over http only
  177. def test_yocto_source_mirror(self):
  178. self.write_config("""
  179. BB_ALLOWED_NETWORKS = "downloads.yoctoproject.org"
  180. MIRRORS = ""
  181. DL_DIR = "${TMPDIR}/test_downloads"
  182. STAMPS_DIR = "${TMPDIR}/test_stamps"
  183. SSTATE_DIR = "${TMPDIR}/test_sstate-cache"
  184. PREMIRRORS = "\\
  185. bzr://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  186. cvs://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  187. git://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  188. gitsm://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  189. hg://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  190. osc://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  191. p4://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  192. svn://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  193. ftp://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  194. http://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n \\
  195. https://.*/.* http://downloads.yoctoproject.org/mirror/sources/ \\n"
  196. """)
  197. bitbake("world --runall fetch --continue")
  198. class Poisoning(OESelftestTestCase):
  199. def test_poisoning(self):
  200. # The poison recipe fails if the poisoning didn't work
  201. bitbake("poison")