Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | import os |
| 6 | import re |
| 7 | |
| 8 | import oeqa.utils.ftools as ftools |
| 9 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars |
| 10 | |
| 11 | from oeqa.selftest.case import OESelftestTestCase |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 13 | class BitbakeTests(OESelftestTestCase): |
| 14 | |
| 15 | def getline(self, res, line): |
| 16 | for l in res.output.split('\n'): |
| 17 | if line in l: |
| 18 | return l |
| 19 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 20 | # Test bitbake can run from the <builddir>/conf directory |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | def test_run_bitbake_from_dir_1(self): |
| 22 | os.chdir(os.path.join(self.builddir, 'conf')) |
| 23 | self.assertEqual(bitbake('-e').status, 0, msg = "bitbake couldn't run from \"conf\" dir") |
| 24 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 25 | # Test bitbake can run from the <builddir>'s parent directory |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 26 | def test_run_bitbake_from_dir_2(self): |
| 27 | my_env = os.environ.copy() |
| 28 | my_env['BBPATH'] = my_env['BUILDDIR'] |
| 29 | os.chdir(os.path.dirname(os.environ['BUILDDIR'])) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from builddir's parent directory") |
| 31 | |
| 32 | # Test bitbake can run from some other random system location (we use /tmp/) |
| 33 | def test_run_bitbake_from_dir_3(self): |
| 34 | my_env = os.environ.copy() |
| 35 | my_env['BBPATH'] = my_env['BUILDDIR'] |
| 36 | os.chdir("/tmp/") |
| 37 | self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from /tmp/") |
| 38 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 39 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 40 | def test_event_handler(self): |
| 41 | self.write_config("INHERIT += \"test_events\"") |
| 42 | result = bitbake('m4-native') |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 43 | find_build_started = re.search(r"NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing.*Tasks", result.output) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 44 | find_build_completed = re.search(r"Tasks Summary:.*(\n.*)*NOTE: Test for bb\.event\.BuildCompleted", result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 45 | self.assertTrue(find_build_started, msg = "Match failed in:\n%s" % result.output) |
| 46 | self.assertTrue(find_build_completed, msg = "Match failed in:\n%s" % result.output) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 47 | self.assertNotIn('Test for bb.event.InvalidEvent', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 48 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 49 | def test_local_sstate(self): |
| 50 | bitbake('m4-native') |
| 51 | bitbake('m4-native -cclean') |
| 52 | result = bitbake('m4-native') |
| 53 | find_setscene = re.search("m4-native.*do_.*_setscene", result.output) |
| 54 | self.assertTrue(find_setscene, msg = "No \"m4-native.*do_.*_setscene\" message found during bitbake m4-native. bitbake output: %s" % result.output ) |
| 55 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 56 | def test_bitbake_invalid_recipe(self): |
| 57 | result = bitbake('-b asdf', ignore_status=True) |
| 58 | self.assertTrue("ERROR: Unable to find any recipe file matching 'asdf'" in result.output, msg = "Though asdf recipe doesn't exist, bitbake didn't output any err. message. bitbake output: %s" % result.output) |
| 59 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 60 | def test_bitbake_invalid_target(self): |
| 61 | result = bitbake('asdf', ignore_status=True) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 62 | self.assertIn("ERROR: Nothing PROVIDES 'asdf'", result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 63 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | def test_warnings_errors(self): |
| 65 | result = bitbake('-b asdf', ignore_status=True) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 66 | find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages*", result.output) |
| 67 | find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages*", result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 68 | self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output) |
| 69 | self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output) |
| 70 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | def test_invalid_patch(self): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 72 | # This patch should fail to apply. |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 73 | self.write_recipeinc('man-db', 'FILESEXTRAPATHS:prepend := "${THISDIR}/files:"\nSRC_URI += "file://0001-Test-patch-here.patch"') |
| 74 | self.write_config("INHERIT:remove = \"report-error\"") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 75 | result = bitbake('man-db -c patch', ignore_status=True) |
| 76 | self.delete_recipeinc('man-db') |
| 77 | bitbake('-cclean man-db') |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 78 | found = False |
| 79 | for l in result.output.split('\n'): |
| 80 | if l.startswith("ERROR:") and "failed" in l and "do_patch" in l: |
| 81 | found = l |
| 82 | self.assertTrue(found and found.startswith("ERROR:"), msg = "Incorrectly formed patch application didn't fail. bitbake output: %s" % result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 83 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 84 | def test_force_task_1(self): |
| 85 | # test 1 from bug 5875 |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 86 | import uuid |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 87 | test_recipe = 'zlib' |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 88 | # Need to use uuid otherwise hash equivlance would change the workflow |
| 89 | test_data = "Microsoft Made No Profit From Anyone's Zunes Yo %s" % uuid.uuid1() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 90 | bb_vars = get_bb_vars(['D', 'PKGDEST', 'mandir'], test_recipe) |
| 91 | image_dir = bb_vars['D'] |
| 92 | pkgsplit_dir = bb_vars['PKGDEST'] |
| 93 | man_dir = bb_vars['mandir'] |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 94 | self.write_config("PACKAGE_CLASSES = \"package_rpm\"") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 95 | |
| 96 | bitbake('-c clean %s' % test_recipe) |
| 97 | bitbake('-c package -f %s' % test_recipe) |
| 98 | self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe) |
| 99 | |
| 100 | man_file = os.path.join(image_dir + man_dir, 'man3/zlib.3') |
| 101 | ftools.append_file(man_file, test_data) |
| 102 | bitbake('-c package -f %s' % test_recipe) |
| 103 | |
| 104 | man_split_file = os.path.join(pkgsplit_dir, 'zlib-doc' + man_dir, 'man3/zlib.3') |
| 105 | man_split_content = ftools.read_file(man_split_file) |
| 106 | self.assertIn(test_data, man_split_content, 'The man file has not changed in packages-split.') |
| 107 | |
| 108 | ret = bitbake(test_recipe) |
| 109 | self.assertIn('task do_package_write_rpm:', ret.output, 'Task do_package_write_rpm did not re-executed.') |
| 110 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 111 | def test_force_task_2(self): |
| 112 | # test 2 from bug 5875 |
| 113 | test_recipe = 'zlib' |
| 114 | |
| 115 | bitbake(test_recipe) |
| 116 | self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe) |
| 117 | |
| 118 | result = bitbake('-C compile %s' % test_recipe) |
| 119 | look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:'] |
| 120 | for task in look_for_tasks: |
| 121 | self.assertIn(task, result.output, msg="Couldn't find %s task.") |
| 122 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 123 | def test_bitbake_g(self): |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 124 | recipe = 'base-files' |
| 125 | result = bitbake('-g %s' % recipe) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 126 | for f in ['pn-buildlist', 'task-depends.dot']: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 127 | self.addCleanup(os.remove, f) |
| 128 | self.assertTrue('Task dependencies saved to \'task-depends.dot\'' in result.output, msg = "No task dependency \"task-depends.dot\" file was generated for the given task target. bitbake output: %s" % result.output) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 129 | self.assertIn(recipe, ftools.read_file(os.path.join(self.builddir, 'task-depends.dot'))) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 130 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 131 | def test_image_manifest(self): |
| 132 | bitbake('core-image-minimal') |
| 133 | bb_vars = get_bb_vars(["DEPLOY_DIR_IMAGE", "IMAGE_LINK_NAME"], "core-image-minimal") |
| 134 | deploydir = bb_vars["DEPLOY_DIR_IMAGE"] |
| 135 | imagename = bb_vars["IMAGE_LINK_NAME"] |
| 136 | manifest = os.path.join(deploydir, imagename + ".manifest") |
| 137 | self.assertTrue(os.path.islink(manifest), msg="No manifest file created for image. It should have been created in %s" % manifest) |
| 138 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 139 | def test_invalid_recipe_src_uri(self): |
| 140 | data = 'SRC_URI = "file://invalid"' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 141 | self.write_recipeinc('man-db', data) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 142 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" |
| 143 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 144 | INHERIT:remove = \"report-error\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 145 | """) |
| 146 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) |
| 147 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 148 | result = bitbake('-c fetch man-db', ignore_status=True) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 149 | self.delete_recipeinc('man-db') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 150 | self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output) |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 151 | self.assertIn('Unable to get checksum for man-db SRC_URI entry invalid: file could not be found', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 152 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 153 | def test_rename_downloaded_file(self): |
| 154 | # TODO unique dldir instead of using cleanall |
| 155 | # TODO: need to set sstatedir? |
| 156 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" |
| 157 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" |
| 158 | """) |
| 159 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) |
| 160 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 161 | data = 'SRC_URI = "https://downloads.yoctoproject.org/mirror/sources/aspell-${PV}.tar.gz;downloadfilename=test-aspell.tar.gz"' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 162 | self.write_recipeinc('aspell', data) |
| 163 | result = bitbake('-f -c fetch aspell', ignore_status=True) |
| 164 | self.delete_recipeinc('aspell') |
| 165 | self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output) |
| 166 | dl_dir = get_bb_var("DL_DIR") |
| 167 | self.assertTrue(os.path.isfile(os.path.join(dl_dir, 'test-aspell.tar.gz')), msg = "File rename failed. No corresponding test-aspell.tar.gz file found under %s" % dl_dir) |
| 168 | self.assertTrue(os.path.isfile(os.path.join(dl_dir, 'test-aspell.tar.gz.done')), "File rename failed. No corresponding test-aspell.tar.gz.done file found under %s" % dl_dir) |
| 169 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 170 | def test_environment(self): |
| 171 | self.write_config("TEST_ENV=\"localconf\"") |
| 172 | result = runCmd('bitbake -e | grep TEST_ENV=') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 173 | self.assertIn('localconf', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 174 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 175 | def test_dry_run(self): |
| 176 | result = runCmd('bitbake -n m4-native') |
| 177 | self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output) |
| 178 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 179 | def test_just_parse(self): |
| 180 | result = runCmd('bitbake -p') |
| 181 | self.assertEqual(0, result.status, "errors encountered when parsing recipes. %s" % result.output) |
| 182 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 183 | def test_version(self): |
| 184 | result = runCmd('bitbake -s | grep wget') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 185 | find = re.search(r"wget *:([0-9a-zA-Z\.\-]+)", result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 186 | self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output) |
| 187 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 188 | def test_prefile(self): |
| 189 | preconf = os.path.join(self.builddir, 'conf/prefile.conf') |
| 190 | self.track_for_cleanup(preconf) |
| 191 | ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"") |
| 192 | result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 193 | self.assertIn('prefile', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 194 | self.write_config("TEST_PREFILE=\"localconf\"") |
| 195 | result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 196 | self.assertIn('localconf', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 197 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 198 | def test_postfile(self): |
| 199 | postconf = os.path.join(self.builddir, 'conf/postfile.conf') |
| 200 | self.track_for_cleanup(postconf) |
| 201 | ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"") |
| 202 | self.write_config("TEST_POSTFILE=\"localconf\"") |
| 203 | result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 204 | self.assertIn('postfile', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 205 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 206 | def test_checkuri(self): |
| 207 | result = runCmd('bitbake -c checkuri m4') |
| 208 | self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output) |
| 209 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 210 | def test_continue(self): |
| 211 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" |
| 212 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 213 | INHERIT:remove = \"report-error\" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 214 | """) |
| 215 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 216 | self.write_recipeinc('man-db',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" ) |
| 217 | runCmd('bitbake -c cleanall man-db xcursor-transparent-theme') |
| 218 | result = runCmd('bitbake -c unpack -k man-db xcursor-transparent-theme', ignore_status=True) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 219 | errorpos = result.output.find('ERROR: Function failed: do_fail_task') |
| 220 | manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output) |
| 221 | continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1)) |
| 222 | self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output) |
| 223 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 224 | def test_non_gplv3(self): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 225 | self.write_config('INCOMPATIBLE_LICENSE = "GPL-3.0-or-later"') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 226 | result = bitbake('selftest-ed', ignore_status=True) |
| 227 | self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output)) |
| 228 | lic_dir = get_bb_var('LICENSE_DIRECTORY') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 229 | self.assertFalse(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPL-3.0-or-later'))) |
| 230 | self.assertTrue(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPL-2.0-or-later'))) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 231 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 232 | def test_setscene_only(self): |
| 233 | """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)""" |
| 234 | test_recipe = 'ed' |
| 235 | |
| 236 | bitbake(test_recipe) |
| 237 | bitbake('-c clean %s' % test_recipe) |
| 238 | ret = bitbake('--setscene-only %s' % test_recipe) |
| 239 | |
| 240 | tasks = re.findall(r'task\s+(do_\S+):', ret.output) |
| 241 | |
| 242 | for task in tasks: |
| 243 | self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n' |
| 244 | 'Executed tasks were: %s' % (task, str(tasks))) |
| 245 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 246 | def test_skip_setscene(self): |
| 247 | test_recipe = 'ed' |
| 248 | |
| 249 | bitbake(test_recipe) |
| 250 | bitbake('-c clean %s' % test_recipe) |
| 251 | |
| 252 | ret = bitbake('--setscene-only %s' % test_recipe) |
| 253 | tasks = re.findall(r'task\s+(do_\S+):', ret.output) |
| 254 | |
| 255 | for task in tasks: |
| 256 | self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n' |
| 257 | 'Executed tasks were: %s' % (task, str(tasks))) |
| 258 | |
| 259 | # Run without setscene. Should do nothing |
| 260 | ret = bitbake('--skip-setscene %s' % test_recipe) |
| 261 | tasks = re.findall(r'task\s+(do_\S+):', ret.output) |
| 262 | |
| 263 | self.assertFalse(tasks, 'Tasks %s ran when they should not have' % (str(tasks))) |
| 264 | |
| 265 | # Clean (leave sstate cache) and run with --skip-setscene. No setscene |
| 266 | # tasks should run |
| 267 | bitbake('-c clean %s' % test_recipe) |
| 268 | |
| 269 | ret = bitbake('--skip-setscene %s' % test_recipe) |
| 270 | tasks = re.findall(r'task\s+(do_\S+):', ret.output) |
| 271 | |
| 272 | for task in tasks: |
| 273 | self.assertNotIn('_setscene', task, 'A _setscene task ran: %s.\n' |
| 274 | 'Executed tasks were: %s' % (task, str(tasks))) |
| 275 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 276 | def test_bbappend_order(self): |
| 277 | """ Bitbake should bbappend to recipe in a predictable order """ |
| 278 | test_recipe = 'ed' |
| 279 | bb_vars = get_bb_vars(['SUMMARY', 'PV'], test_recipe) |
| 280 | test_recipe_summary_before = bb_vars['SUMMARY'] |
| 281 | test_recipe_pv = bb_vars['PV'] |
| 282 | recipe_append_file = test_recipe + '_' + test_recipe_pv + '.bbappend' |
| 283 | expected_recipe_summary = test_recipe_summary_before |
| 284 | |
| 285 | for i in range(5): |
| 286 | recipe_append_dir = test_recipe + '_test_' + str(i) |
| 287 | recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir, recipe_append_file) |
| 288 | os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir)) |
| 289 | feature = 'SUMMARY += "%s"\n' % i |
| 290 | ftools.write_file(recipe_append_path, feature) |
| 291 | expected_recipe_summary += ' %s' % i |
| 292 | |
| 293 | self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, 'recipes-test', |
| 294 | test_recipe + '_test_*')) |
| 295 | |
| 296 | test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe) |
| 297 | self.assertEqual(expected_recipe_summary, test_recipe_summary_after) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 298 | |
| 299 | def test_git_patchtool(self): |
| 300 | """ PATCHTOOL=git should work with non-git sources like tarballs |
| 301 | test recipe for the test must NOT containt git:// repository in SRC_URI |
| 302 | """ |
| 303 | test_recipe = "man-db" |
| 304 | self.write_recipeinc(test_recipe, 'PATCHTOOL=\"git\"') |
| 305 | src = get_bb_var("SRC_URI",test_recipe) |
| 306 | gitscm = re.search("git://", src) |
| 307 | self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe)) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 308 | result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 309 | fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output) |
| 310 | self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"") |
| 311 | self.delete_recipeinc(test_recipe) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 312 | bitbake('-cclean {}'.format(test_recipe)) |
| 313 | |
| 314 | def test_git_patchtool2(self): |
| 315 | """ Test if PATCHTOOL=git works with git repo and doesn't reinitialize it |
| 316 | """ |
| 317 | test_recipe = "gitrepotest" |
| 318 | src = get_bb_var("SRC_URI",test_recipe) |
| 319 | gitscm = re.search("git://", src) |
| 320 | self.assertTrue(gitscm, "test_git_patchtool pre-condition failed: {} test recipe doesn't contains git repo!".format(test_recipe)) |
| 321 | result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False) |
| 322 | srcdir = get_bb_var('S', test_recipe) |
| 323 | result = runCmd("git log", cwd = srcdir) |
| 324 | self.assertFalse("bitbake_patching_started" in result.output, msg = "Repository has been reinitialized. {}".format(srcdir)) |
| 325 | self.delete_recipeinc(test_recipe) |
| 326 | bitbake('-cclean {}'.format(test_recipe)) |
| 327 | |
| 328 | |
| 329 | def test_git_unpack_nonetwork(self): |
| 330 | """ |
| 331 | Test that a recipe with a floating tag that needs to be resolved upstream doesn't |
| 332 | access the network in a patch task run in a separate builld invocation |
| 333 | """ |
| 334 | |
| 335 | # Enable the recipe to float using a distro override |
| 336 | self.write_config("DISTROOVERRIDES .= \":gitunpack-enable-recipe\"") |
| 337 | |
| 338 | bitbake('gitunpackoffline -c fetch') |
| 339 | bitbake('gitunpackoffline -c patch') |
| 340 | |
| 341 | def test_git_unpack_nonetwork_fail(self): |
| 342 | """ |
| 343 | Test that a recipe with a floating tag which doesn't call get_srcrev() in the fetcher |
| 344 | raises an error when the fetcher is called. |
| 345 | """ |
| 346 | |
| 347 | # Enable the recipe to float using a distro override |
| 348 | self.write_config("DISTROOVERRIDES .= \":gitunpack-enable-recipe\"") |
| 349 | |
| 350 | result = bitbake('gitunpackoffline-fail -c fetch', ignore_status=True) |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 351 | self.assertTrue(re.search("Recipe uses a floating tag/branch .* for repo .* without a fixed SRCREV yet doesn't call bb.fetch2.get_srcrev()", result.output), msg = "Recipe without PV set to SRCPV should have failed: %s" % result.output) |