Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | import os |
| 2 | import re |
| 3 | |
| 4 | import oeqa.utils.ftools as ftools |
| 5 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars |
| 6 | |
| 7 | from oeqa.selftest.case import OESelftestTestCase |
| 8 | from oeqa.core.decorator.oeid import OETestID |
| 9 | |
| 10 | class BitbakeTests(OESelftestTestCase): |
| 11 | |
| 12 | def getline(self, res, line): |
| 13 | for l in res.output.split('\n'): |
| 14 | if line in l: |
| 15 | return l |
| 16 | |
| 17 | @OETestID(789) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | # Test bitbake can run from the <builddir>/conf directory |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | def test_run_bitbake_from_dir_1(self): |
| 20 | os.chdir(os.path.join(self.builddir, 'conf')) |
| 21 | self.assertEqual(bitbake('-e').status, 0, msg = "bitbake couldn't run from \"conf\" dir") |
| 22 | |
| 23 | @OETestID(790) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 24 | # Test bitbake can run from the <builddir>'s parent directory |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 25 | def test_run_bitbake_from_dir_2(self): |
| 26 | my_env = os.environ.copy() |
| 27 | my_env['BBPATH'] = my_env['BUILDDIR'] |
| 28 | os.chdir(os.path.dirname(os.environ['BUILDDIR'])) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from builddir's parent directory") |
| 30 | |
| 31 | # Test bitbake can run from some other random system location (we use /tmp/) |
| 32 | def test_run_bitbake_from_dir_3(self): |
| 33 | my_env = os.environ.copy() |
| 34 | my_env['BBPATH'] = my_env['BUILDDIR'] |
| 35 | os.chdir("/tmp/") |
| 36 | self.assertEqual(bitbake('-e', env=my_env).status, 0, msg = "bitbake couldn't run from /tmp/") |
| 37 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 38 | |
| 39 | @OETestID(806) |
| 40 | def test_event_handler(self): |
| 41 | self.write_config("INHERIT += \"test_events\"") |
| 42 | result = bitbake('m4-native') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 43 | find_build_started = re.search(r"NOTE: Test for bb\.event\.BuildStarted(\n.*)*NOTE: Executing RunQueue Tasks", result.output) |
| 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) |
| 47 | self.assertFalse('Test for bb.event.InvalidEvent' in result.output, msg = "\"Test for bb.event.InvalidEvent\" message found during bitbake process. bitbake output: %s" % result.output) |
| 48 | |
| 49 | @OETestID(103) |
| 50 | def test_local_sstate(self): |
| 51 | bitbake('m4-native') |
| 52 | bitbake('m4-native -cclean') |
| 53 | result = bitbake('m4-native') |
| 54 | find_setscene = re.search("m4-native.*do_.*_setscene", result.output) |
| 55 | self.assertTrue(find_setscene, msg = "No \"m4-native.*do_.*_setscene\" message found during bitbake m4-native. bitbake output: %s" % result.output ) |
| 56 | |
| 57 | @OETestID(105) |
| 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 | |
| 62 | @OETestID(107) |
| 63 | def test_bitbake_invalid_target(self): |
| 64 | result = bitbake('asdf', ignore_status=True) |
| 65 | self.assertTrue("ERROR: Nothing PROVIDES 'asdf'" in result.output, msg = "Though no 'asdf' target exists, bitbake didn't output any err. message. bitbake output: %s" % result.output) |
| 66 | |
| 67 | @OETestID(106) |
| 68 | def test_warnings_errors(self): |
| 69 | result = bitbake('-b asdf', ignore_status=True) |
| 70 | find_warnings = re.search("Summary: There w.{2,3}? [1-9][0-9]* WARNING messages* shown", result.output) |
| 71 | find_errors = re.search("Summary: There w.{2,3}? [1-9][0-9]* ERROR messages* shown", result.output) |
| 72 | self.assertTrue(find_warnings, msg="Did not find the mumber of warnings at the end of the build:\n" + result.output) |
| 73 | self.assertTrue(find_errors, msg="Did not find the mumber of errors at the end of the build:\n" + result.output) |
| 74 | |
| 75 | @OETestID(108) |
| 76 | def test_invalid_patch(self): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 77 | # This patch should fail to apply. |
| 78 | self.write_recipeinc('man-db', 'FILESEXTRAPATHS_prepend := "${THISDIR}/files:"\nSRC_URI += "file://0001-Test-patch-here.patch"') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 79 | self.write_config("INHERIT_remove = \"report-error\"") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 80 | result = bitbake('man-db -c patch', ignore_status=True) |
| 81 | self.delete_recipeinc('man-db') |
| 82 | bitbake('-cclean man-db') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 83 | line = self.getline(result, "Function failed: patch_do_patch") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 84 | self.assertTrue(line and line.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 | |
| 86 | @OETestID(1354) |
| 87 | def test_force_task_1(self): |
| 88 | # test 1 from bug 5875 |
| 89 | test_recipe = 'zlib' |
| 90 | test_data = "Microsoft Made No Profit From Anyone's Zunes Yo" |
| 91 | bb_vars = get_bb_vars(['D', 'PKGDEST', 'mandir'], test_recipe) |
| 92 | image_dir = bb_vars['D'] |
| 93 | pkgsplit_dir = bb_vars['PKGDEST'] |
| 94 | man_dir = bb_vars['mandir'] |
| 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 | |
| 111 | @OETestID(163) |
| 112 | def test_force_task_2(self): |
| 113 | # test 2 from bug 5875 |
| 114 | test_recipe = 'zlib' |
| 115 | |
| 116 | bitbake(test_recipe) |
| 117 | self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe) |
| 118 | |
| 119 | result = bitbake('-C compile %s' % test_recipe) |
| 120 | look_for_tasks = ['do_compile:', 'do_install:', 'do_populate_sysroot:', 'do_package:'] |
| 121 | for task in look_for_tasks: |
| 122 | self.assertIn(task, result.output, msg="Couldn't find %s task.") |
| 123 | |
| 124 | @OETestID(167) |
| 125 | def test_bitbake_g(self): |
| 126 | result = bitbake('-g core-image-minimal') |
| 127 | for f in ['pn-buildlist', 'recipe-depends.dot', 'task-depends.dot']: |
| 128 | self.addCleanup(os.remove, f) |
| 129 | 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) |
| 130 | self.assertTrue('busybox' in ftools.read_file(os.path.join(self.builddir, 'task-depends.dot')), msg = "No \"busybox\" dependency found in task-depends.dot file.") |
| 131 | |
| 132 | @OETestID(899) |
| 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 | |
| 141 | @OETestID(168) |
| 142 | def test_invalid_recipe_src_uri(self): |
| 143 | data = 'SRC_URI = "file://invalid"' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 144 | self.write_recipeinc('man-db', data) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 145 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" |
| 146 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" |
| 147 | INHERIT_remove = \"report-error\" |
| 148 | """) |
| 149 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) |
| 150 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 151 | bitbake('-ccleanall man-db') |
| 152 | result = bitbake('-c fetch man-db', ignore_status=True) |
| 153 | bitbake('-ccleanall man-db') |
| 154 | self.delete_recipeinc('man-db') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 155 | self.assertEqual(result.status, 1, msg="Command succeded when it should have failed. bitbake output: %s" % result.output) |
| 156 | self.assertTrue('Fetcher failure: Unable to find file file://invalid anywhere. The paths that were searched were:' in result.output, msg = "\"invalid\" file \ |
| 157 | doesn't exist, yet no error message encountered. bitbake output: %s" % result.output) |
| 158 | line = self.getline(result, 'Fetcher failure for URL: \'file://invalid\'. Unable to fetch URL from any source.') |
| 159 | self.assertTrue(line and line.startswith("ERROR:"), msg = "\"invalid\" file \ |
| 160 | doesn't exist, yet fetcher didn't report any error. bitbake output: %s" % result.output) |
| 161 | |
| 162 | @OETestID(171) |
| 163 | def test_rename_downloaded_file(self): |
| 164 | # TODO unique dldir instead of using cleanall |
| 165 | # TODO: need to set sstatedir? |
| 166 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" |
| 167 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" |
| 168 | """) |
| 169 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) |
| 170 | |
| 171 | data = 'SRC_URI = "${GNU_MIRROR}/aspell/aspell-${PV}.tar.gz;downloadfilename=test-aspell.tar.gz"' |
| 172 | self.write_recipeinc('aspell', data) |
| 173 | result = bitbake('-f -c fetch aspell', ignore_status=True) |
| 174 | self.delete_recipeinc('aspell') |
| 175 | self.assertEqual(result.status, 0, msg = "Couldn't fetch aspell. %s" % result.output) |
| 176 | dl_dir = get_bb_var("DL_DIR") |
| 177 | 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) |
| 178 | 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) |
| 179 | |
| 180 | @OETestID(1028) |
| 181 | def test_environment(self): |
| 182 | self.write_config("TEST_ENV=\"localconf\"") |
| 183 | result = runCmd('bitbake -e | grep TEST_ENV=') |
| 184 | self.assertTrue('localconf' in result.output, msg = "bitbake didn't report any value for TEST_ENV variable. To test, run 'bitbake -e | grep TEST_ENV='") |
| 185 | |
| 186 | @OETestID(1029) |
| 187 | def test_dry_run(self): |
| 188 | result = runCmd('bitbake -n m4-native') |
| 189 | self.assertEqual(0, result.status, "bitbake dry run didn't run as expected. %s" % result.output) |
| 190 | |
| 191 | @OETestID(1030) |
| 192 | def test_just_parse(self): |
| 193 | result = runCmd('bitbake -p') |
| 194 | self.assertEqual(0, result.status, "errors encountered when parsing recipes. %s" % result.output) |
| 195 | |
| 196 | @OETestID(1031) |
| 197 | def test_version(self): |
| 198 | result = runCmd('bitbake -s | grep wget') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 199 | find = re.search(r"wget *:([0-9a-zA-Z\.\-]+)", result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 200 | self.assertTrue(find, "No version returned for searched recipe. bitbake output: %s" % result.output) |
| 201 | |
| 202 | @OETestID(1032) |
| 203 | def test_prefile(self): |
| 204 | preconf = os.path.join(self.builddir, 'conf/prefile.conf') |
| 205 | self.track_for_cleanup(preconf) |
| 206 | ftools.write_file(preconf ,"TEST_PREFILE=\"prefile\"") |
| 207 | result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=') |
| 208 | self.assertTrue('prefile' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration. ") |
| 209 | self.write_config("TEST_PREFILE=\"localconf\"") |
| 210 | result = runCmd('bitbake -r conf/prefile.conf -e | grep TEST_PREFILE=') |
| 211 | self.assertTrue('localconf' in result.output, "Preconfigure file \"prefile.conf\"was not taken into consideration.") |
| 212 | |
| 213 | @OETestID(1033) |
| 214 | def test_postfile(self): |
| 215 | postconf = os.path.join(self.builddir, 'conf/postfile.conf') |
| 216 | self.track_for_cleanup(postconf) |
| 217 | ftools.write_file(postconf , "TEST_POSTFILE=\"postfile\"") |
| 218 | self.write_config("TEST_POSTFILE=\"localconf\"") |
| 219 | result = runCmd('bitbake -R conf/postfile.conf -e | grep TEST_POSTFILE=') |
| 220 | self.assertTrue('postfile' in result.output, "Postconfigure file \"postfile.conf\"was not taken into consideration.") |
| 221 | |
| 222 | @OETestID(1034) |
| 223 | def test_checkuri(self): |
| 224 | result = runCmd('bitbake -c checkuri m4') |
| 225 | self.assertEqual(0, result.status, msg = "\"checkuri\" task was not executed. bitbake output: %s" % result.output) |
| 226 | |
| 227 | @OETestID(1035) |
| 228 | def test_continue(self): |
| 229 | self.write_config("""DL_DIR = \"${TOPDIR}/download-selftest\" |
| 230 | SSTATE_DIR = \"${TOPDIR}/download-selftest\" |
| 231 | INHERIT_remove = \"report-error\" |
| 232 | """) |
| 233 | self.track_for_cleanup(os.path.join(self.builddir, "download-selftest")) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 234 | self.write_recipeinc('man-db',"\ndo_fail_task () {\nexit 1 \n}\n\naddtask do_fail_task before do_fetch\n" ) |
| 235 | runCmd('bitbake -c cleanall man-db xcursor-transparent-theme') |
| 236 | 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] | 237 | errorpos = result.output.find('ERROR: Function failed: do_fail_task') |
| 238 | manver = re.search("NOTE: recipe xcursor-transparent-theme-(.*?): task do_unpack: Started", result.output) |
| 239 | continuepos = result.output.find('NOTE: recipe xcursor-transparent-theme-%s: task do_unpack: Started' % manver.group(1)) |
| 240 | self.assertLess(errorpos,continuepos, msg = "bitbake didn't pass do_fail_task. bitbake output: %s" % result.output) |
| 241 | |
| 242 | @OETestID(1119) |
| 243 | def test_non_gplv3(self): |
| 244 | self.write_config('INCOMPATIBLE_LICENSE = "GPLv3"') |
| 245 | result = bitbake('selftest-ed', ignore_status=True) |
| 246 | self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output)) |
| 247 | lic_dir = get_bb_var('LICENSE_DIRECTORY') |
| 248 | self.assertFalse(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv3'))) |
| 249 | self.assertTrue(os.path.isfile(os.path.join(lic_dir, 'selftest-ed/generic_GPLv2'))) |
| 250 | |
| 251 | @OETestID(1422) |
| 252 | def test_setscene_only(self): |
| 253 | """ Bitbake option to restore from sstate only within a build (i.e. execute no real tasks, only setscene)""" |
| 254 | test_recipe = 'ed' |
| 255 | |
| 256 | bitbake(test_recipe) |
| 257 | bitbake('-c clean %s' % test_recipe) |
| 258 | ret = bitbake('--setscene-only %s' % test_recipe) |
| 259 | |
| 260 | tasks = re.findall(r'task\s+(do_\S+):', ret.output) |
| 261 | |
| 262 | for task in tasks: |
| 263 | self.assertIn('_setscene', task, 'A task different from _setscene ran: %s.\n' |
| 264 | 'Executed tasks were: %s' % (task, str(tasks))) |
| 265 | |
| 266 | @OETestID(1425) |
| 267 | def test_bbappend_order(self): |
| 268 | """ Bitbake should bbappend to recipe in a predictable order """ |
| 269 | test_recipe = 'ed' |
| 270 | bb_vars = get_bb_vars(['SUMMARY', 'PV'], test_recipe) |
| 271 | test_recipe_summary_before = bb_vars['SUMMARY'] |
| 272 | test_recipe_pv = bb_vars['PV'] |
| 273 | recipe_append_file = test_recipe + '_' + test_recipe_pv + '.bbappend' |
| 274 | expected_recipe_summary = test_recipe_summary_before |
| 275 | |
| 276 | for i in range(5): |
| 277 | recipe_append_dir = test_recipe + '_test_' + str(i) |
| 278 | recipe_append_path = os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir, recipe_append_file) |
| 279 | os.mkdir(os.path.join(self.testlayer_path, 'recipes-test', recipe_append_dir)) |
| 280 | feature = 'SUMMARY += "%s"\n' % i |
| 281 | ftools.write_file(recipe_append_path, feature) |
| 282 | expected_recipe_summary += ' %s' % i |
| 283 | |
| 284 | self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, 'recipes-test', |
| 285 | test_recipe + '_test_*')) |
| 286 | |
| 287 | test_recipe_summary_after = get_bb_var('SUMMARY', test_recipe) |
| 288 | self.assertEqual(expected_recipe_summary, test_recipe_summary_after) |