buildoptions.py 10 KB

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