buildoptions.py 11 KB

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