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