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