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