devtool.py 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  1. import os
  2. import re
  3. import shutil
  4. import tempfile
  5. import glob
  6. import fnmatch
  7. import oeqa.utils.ftools as ftools
  8. from oeqa.selftest.case import OESelftestTestCase
  9. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer
  10. from oeqa.utils.commands import get_bb_vars, runqemu, get_test_layer
  11. from oeqa.core.decorator.oeid import OETestID
  12. class DevtoolBase(OESelftestTestCase):
  13. buffer = True
  14. def _test_recipe_contents(self, recipefile, checkvars, checkinherits):
  15. with open(recipefile, 'r') as f:
  16. invar = None
  17. invalue = None
  18. for line in f:
  19. var = None
  20. if invar:
  21. value = line.strip().strip('"')
  22. if value.endswith('\\'):
  23. invalue += ' ' + value[:-1].strip()
  24. continue
  25. else:
  26. invalue += ' ' + value.strip()
  27. var = invar
  28. value = invalue
  29. invar = None
  30. elif '=' in line:
  31. splitline = line.split('=', 1)
  32. var = splitline[0].rstrip()
  33. value = splitline[1].strip().strip('"')
  34. if value.endswith('\\'):
  35. invalue = value[:-1].strip()
  36. invar = var
  37. continue
  38. elif line.startswith('inherit '):
  39. inherits = line.split()[1:]
  40. if var and var in checkvars:
  41. needvalue = checkvars.pop(var)
  42. if needvalue is None:
  43. self.fail('Variable %s should not appear in recipe, but value is being set to "%s"' % (var, value))
  44. if isinstance(needvalue, set):
  45. if var == 'LICENSE':
  46. value = set(value.split(' & '))
  47. else:
  48. value = set(value.split())
  49. self.assertEqual(value, needvalue, 'values for %s do not match' % var)
  50. missingvars = {}
  51. for var, value in checkvars.items():
  52. if value is not None:
  53. missingvars[var] = value
  54. self.assertEqual(missingvars, {}, 'Some expected variables not found in recipe: %s' % checkvars)
  55. for inherit in checkinherits:
  56. self.assertIn(inherit, inherits, 'Missing inherit of %s' % inherit)
  57. def _check_bbappend(self, testrecipe, recipefile, appenddir):
  58. result = runCmd('bitbake-layers show-appends', cwd=self.builddir)
  59. resultlines = result.output.splitlines()
  60. inrecipe = False
  61. bbappends = []
  62. bbappendfile = None
  63. for line in resultlines:
  64. if inrecipe:
  65. if line.startswith(' '):
  66. bbappends.append(line.strip())
  67. else:
  68. break
  69. elif line == '%s:' % os.path.basename(recipefile):
  70. inrecipe = True
  71. self.assertLessEqual(len(bbappends), 2, '%s recipe is being bbappended by another layer - bbappends found:\n %s' % (testrecipe, '\n '.join(bbappends)))
  72. for bbappend in bbappends:
  73. if bbappend.startswith(appenddir):
  74. bbappendfile = bbappend
  75. break
  76. else:
  77. self.fail('bbappend for recipe %s does not seem to be created in test layer' % testrecipe)
  78. return bbappendfile
  79. def _create_temp_layer(self, templayerdir, addlayer, templayername, priority=999, recipepathspec='recipes-*/*'):
  80. create_temp_layer(templayerdir, templayername, priority, recipepathspec)
  81. if addlayer:
  82. self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
  83. result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
  84. def _process_ls_output(self, output):
  85. """
  86. Convert ls -l output to a format we can reasonably compare from one context
  87. to another (e.g. from host to target)
  88. """
  89. filelist = []
  90. for line in output.splitlines():
  91. splitline = line.split()
  92. if len(splitline) < 8:
  93. self.fail('_process_ls_output: invalid output line: %s' % line)
  94. # Remove trailing . on perms
  95. splitline[0] = splitline[0].rstrip('.')
  96. # Remove leading . on paths
  97. splitline[-1] = splitline[-1].lstrip('.')
  98. # Drop fields we don't want to compare
  99. del splitline[7]
  100. del splitline[6]
  101. del splitline[5]
  102. del splitline[4]
  103. del splitline[1]
  104. filelist.append(' '.join(splitline))
  105. return filelist
  106. class DevtoolTests(DevtoolBase):
  107. @classmethod
  108. def setUpClass(cls):
  109. super(DevtoolTests, cls).setUpClass()
  110. bb_vars = get_bb_vars(['TOPDIR', 'SSTATE_DIR'])
  111. cls.original_sstate = bb_vars['SSTATE_DIR']
  112. cls.devtool_sstate = os.path.join(bb_vars['TOPDIR'], 'sstate_devtool')
  113. cls.sstate_conf = 'SSTATE_DIR = "%s"\n' % cls.devtool_sstate
  114. cls.sstate_conf += ('SSTATE_MIRRORS += "file://.* file:///%s/PATH"\n'
  115. % cls.original_sstate)
  116. @classmethod
  117. def tearDownClass(cls):
  118. cls.logger.debug('Deleting devtool sstate cache on %s' % cls.devtool_sstate)
  119. runCmd('rm -rf %s' % cls.devtool_sstate)
  120. super(DevtoolTests, cls).tearDownClass()
  121. def setUp(self):
  122. """Test case setup function"""
  123. super(DevtoolTests, self).setUp()
  124. self.workspacedir = os.path.join(self.builddir, 'workspace')
  125. self.assertTrue(not os.path.exists(self.workspacedir),
  126. 'This test cannot be run with a workspace directory '
  127. 'under the build directory')
  128. self.append_config(self.sstate_conf)
  129. def _check_src_repo(self, repo_dir):
  130. """Check srctree git repository"""
  131. self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')),
  132. 'git repository for external source tree not found')
  133. result = runCmd('git status --porcelain', cwd=repo_dir)
  134. self.assertEqual(result.output.strip(), "",
  135. 'Created git repo is not clean')
  136. result = runCmd('git symbolic-ref HEAD', cwd=repo_dir)
  137. self.assertEqual(result.output.strip(), "refs/heads/devtool",
  138. 'Wrong branch in git repo')
  139. def _check_repo_status(self, repo_dir, expected_status):
  140. """Check the worktree status of a repository"""
  141. result = runCmd('git status . --porcelain',
  142. cwd=repo_dir)
  143. for line in result.output.splitlines():
  144. for ind, (f_status, fn_re) in enumerate(expected_status):
  145. if re.match(fn_re, line[3:]):
  146. if f_status != line[:2]:
  147. self.fail('Unexpected status in line: %s' % line)
  148. expected_status.pop(ind)
  149. break
  150. else:
  151. self.fail('Unexpected modified file in line: %s' % line)
  152. if expected_status:
  153. self.fail('Missing file changes: %s' % expected_status)
  154. @OETestID(1158)
  155. def test_create_workspace(self):
  156. # Check preconditions
  157. result = runCmd('bitbake-layers show-layers')
  158. self.assertTrue('\nworkspace' not in result.output, 'This test cannot be run with a workspace layer in bblayers.conf')
  159. # Try creating a workspace layer with a specific path
  160. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  161. self.track_for_cleanup(tempdir)
  162. result = runCmd('devtool create-workspace %s' % tempdir)
  163. self.assertTrue(os.path.isfile(os.path.join(tempdir, 'conf', 'layer.conf')), msg = "No workspace created. devtool output: %s " % result.output)
  164. result = runCmd('bitbake-layers show-layers')
  165. self.assertIn(tempdir, result.output)
  166. # Try creating a workspace layer with the default path
  167. self.track_for_cleanup(self.workspacedir)
  168. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  169. result = runCmd('devtool create-workspace')
  170. self.assertTrue(os.path.isfile(os.path.join(self.workspacedir, 'conf', 'layer.conf')), msg = "No workspace created. devtool output: %s " % result.output)
  171. result = runCmd('bitbake-layers show-layers')
  172. self.assertNotIn(tempdir, result.output)
  173. self.assertIn(self.workspacedir, result.output)
  174. @OETestID(1159)
  175. def test_devtool_add(self):
  176. # Fetch source
  177. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  178. self.track_for_cleanup(tempdir)
  179. pn = 'pv'
  180. pv = '1.5.3'
  181. url = 'http://www.ivarch.com/programs/sources/pv-1.5.3.tar.bz2'
  182. result = runCmd('wget %s' % url, cwd=tempdir)
  183. result = runCmd('tar xfv %s' % os.path.basename(url), cwd=tempdir)
  184. srcdir = os.path.join(tempdir, '%s-%s' % (pn, pv))
  185. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure')), 'Unable to find configure script in source directory')
  186. # Test devtool add
  187. self.track_for_cleanup(self.workspacedir)
  188. self.add_command_to_tearDown('bitbake -c cleansstate %s' % pn)
  189. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  190. result = runCmd('devtool add %s %s' % (pn, srcdir))
  191. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  192. # Test devtool status
  193. result = runCmd('devtool status')
  194. recipepath = '%s/recipes/%s/%s_%s.bb' % (self.workspacedir, pn, pn, pv)
  195. self.assertIn(recipepath, result.output)
  196. self.assertIn(srcdir, result.output)
  197. # Test devtool find-recipe
  198. result = runCmd('devtool -q find-recipe %s' % pn)
  199. self.assertEqual(recipepath, result.output.strip())
  200. # Test devtool edit-recipe
  201. result = runCmd('VISUAL="echo 123" devtool -q edit-recipe %s' % pn)
  202. self.assertEqual('123 %s' % recipepath, result.output.strip())
  203. # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then)
  204. bitbake('%s -c cleansstate' % pn)
  205. # Test devtool build
  206. result = runCmd('devtool build %s' % pn)
  207. bb_vars = get_bb_vars(['D', 'bindir'], pn)
  208. installdir = bb_vars['D']
  209. self.assertTrue(installdir, 'Could not query installdir variable')
  210. bindir = bb_vars['bindir']
  211. self.assertTrue(bindir, 'Could not query bindir variable')
  212. if bindir[0] == '/':
  213. bindir = bindir[1:]
  214. self.assertTrue(os.path.isfile(os.path.join(installdir, bindir, 'pv')), 'pv binary not found in D')
  215. @OETestID(1423)
  216. def test_devtool_add_git_local(self):
  217. # Fetch source from a remote URL, but do it outside of devtool
  218. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  219. self.track_for_cleanup(tempdir)
  220. pn = 'dbus-wait'
  221. srcrev = '6cc6077a36fe2648a5f993fe7c16c9632f946517'
  222. # We choose an https:// git URL here to check rewriting the URL works
  223. url = 'https://git.yoctoproject.org/git/dbus-wait'
  224. # Force fetching to "noname" subdir so we verify we're picking up the name from autoconf
  225. # instead of the directory name
  226. result = runCmd('git clone %s noname' % url, cwd=tempdir)
  227. srcdir = os.path.join(tempdir, 'noname')
  228. result = runCmd('git reset --hard %s' % srcrev, cwd=srcdir)
  229. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure script in source directory')
  230. # Test devtool add
  231. self.track_for_cleanup(self.workspacedir)
  232. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  233. # Don't specify a name since we should be able to auto-detect it
  234. result = runCmd('devtool add %s' % srcdir)
  235. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  236. # Check the recipe name is correct
  237. recipefile = get_bb_var('FILE', pn)
  238. self.assertIn('%s_git.bb' % pn, recipefile, 'Recipe file incorrectly named')
  239. self.assertIn(recipefile, result.output)
  240. # Test devtool status
  241. result = runCmd('devtool status')
  242. self.assertIn(pn, result.output)
  243. self.assertIn(srcdir, result.output)
  244. self.assertIn(recipefile, result.output)
  245. checkvars = {}
  246. checkvars['LICENSE'] = 'GPLv2'
  247. checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
  248. checkvars['S'] = '${WORKDIR}/git'
  249. checkvars['PV'] = '0.1+git${SRCPV}'
  250. checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/dbus-wait;protocol=https'
  251. checkvars['SRCREV'] = srcrev
  252. checkvars['DEPENDS'] = set(['dbus'])
  253. self._test_recipe_contents(recipefile, checkvars, [])
  254. @OETestID(1162)
  255. def test_devtool_add_library(self):
  256. # Fetch source
  257. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  258. self.track_for_cleanup(tempdir)
  259. version = '1.1'
  260. url = 'https://www.intra2net.com/en/developer/libftdi/download/libftdi1-%s.tar.bz2' % version
  261. result = runCmd('wget %s' % url, cwd=tempdir)
  262. result = runCmd('tar xfv libftdi1-%s.tar.bz2' % version, cwd=tempdir)
  263. srcdir = os.path.join(tempdir, 'libftdi1-%s' % version)
  264. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'CMakeLists.txt')), 'Unable to find CMakeLists.txt in source directory')
  265. # Test devtool add (and use -V so we test that too)
  266. self.track_for_cleanup(self.workspacedir)
  267. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  268. result = runCmd('devtool add libftdi %s -V %s' % (srcdir, version))
  269. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  270. # Test devtool status
  271. result = runCmd('devtool status')
  272. self.assertIn('libftdi', result.output)
  273. self.assertIn(srcdir, result.output)
  274. # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then)
  275. bitbake('libftdi -c cleansstate')
  276. # libftdi's python/CMakeLists.txt is a bit broken, so let's just disable it
  277. # There's also the matter of it installing cmake files to a path we don't
  278. # normally cover, which triggers the installed-vs-shipped QA test we have
  279. # within do_package
  280. recipefile = '%s/recipes/libftdi/libftdi_%s.bb' % (self.workspacedir, version)
  281. result = runCmd('recipetool setvar %s EXTRA_OECMAKE -- \'-DPYTHON_BINDINGS=OFF -DLIBFTDI_CMAKE_CONFIG_DIR=${datadir}/cmake/Modules\'' % recipefile)
  282. with open(recipefile, 'a') as f:
  283. f.write('\nFILES_${PN}-dev += "${datadir}/cmake/Modules"\n')
  284. # We don't have the ability to pick up this dependency automatically yet...
  285. f.write('\nDEPENDS += "libusb1"\n')
  286. f.write('\nTESTLIBOUTPUT = "${COMPONENTS_DIR}/${TUNE_PKGARCH}/${PN}/${libdir}"\n')
  287. # Test devtool build
  288. result = runCmd('devtool build libftdi')
  289. bb_vars = get_bb_vars(['TESTLIBOUTPUT', 'STAMP'], 'libftdi')
  290. staging_libdir = bb_vars['TESTLIBOUTPUT']
  291. self.assertTrue(staging_libdir, 'Could not query TESTLIBOUTPUT variable')
  292. self.assertTrue(os.path.isfile(os.path.join(staging_libdir, 'libftdi1.so.2.1.0')), "libftdi binary not found in STAGING_LIBDIR. Output of devtool build libftdi %s" % result.output)
  293. # Test devtool reset
  294. stampprefix = bb_vars['STAMP']
  295. result = runCmd('devtool reset libftdi')
  296. result = runCmd('devtool status')
  297. self.assertNotIn('libftdi', result.output)
  298. self.assertTrue(stampprefix, 'Unable to get STAMP value for recipe libftdi')
  299. matches = glob.glob(stampprefix + '*')
  300. self.assertFalse(matches, 'Stamp files exist for recipe libftdi that should have been cleaned')
  301. self.assertFalse(os.path.isfile(os.path.join(staging_libdir, 'libftdi1.so.2.1.0')), 'libftdi binary still found in STAGING_LIBDIR after cleaning')
  302. @OETestID(1160)
  303. def test_devtool_add_fetch(self):
  304. # Fetch source
  305. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  306. self.track_for_cleanup(tempdir)
  307. testver = '0.23'
  308. url = 'https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-%s.tar.gz' % testver
  309. testrecipe = 'python-markupsafe'
  310. srcdir = os.path.join(tempdir, testrecipe)
  311. # Test devtool add
  312. self.track_for_cleanup(self.workspacedir)
  313. self.add_command_to_tearDown('bitbake -c cleansstate %s' % testrecipe)
  314. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  315. result = runCmd('devtool add %s %s -f %s' % (testrecipe, srcdir, url))
  316. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. %s' % result.output)
  317. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory')
  318. self.assertTrue(os.path.isdir(os.path.join(srcdir, '.git')), 'git repository for external source tree was not created')
  319. # Test devtool status
  320. result = runCmd('devtool status')
  321. self.assertIn(testrecipe, result.output)
  322. self.assertIn(srcdir, result.output)
  323. # Check recipe
  324. recipefile = get_bb_var('FILE', testrecipe)
  325. self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named')
  326. checkvars = {}
  327. checkvars['S'] = '${WORKDIR}/MarkupSafe-${PV}'
  328. checkvars['SRC_URI'] = url.replace(testver, '${PV}')
  329. self._test_recipe_contents(recipefile, checkvars, [])
  330. # Try with version specified
  331. result = runCmd('devtool reset -n %s' % testrecipe)
  332. shutil.rmtree(srcdir)
  333. fakever = '1.9'
  334. result = runCmd('devtool add %s %s -f %s -V %s' % (testrecipe, srcdir, url, fakever))
  335. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory')
  336. # Test devtool status
  337. result = runCmd('devtool status')
  338. self.assertIn(testrecipe, result.output)
  339. self.assertIn(srcdir, result.output)
  340. # Check recipe
  341. recipefile = get_bb_var('FILE', testrecipe)
  342. self.assertIn('%s_%s.bb' % (testrecipe, fakever), recipefile, 'Recipe file incorrectly named')
  343. checkvars = {}
  344. checkvars['S'] = '${WORKDIR}/MarkupSafe-%s' % testver
  345. checkvars['SRC_URI'] = url
  346. self._test_recipe_contents(recipefile, checkvars, [])
  347. @OETestID(1161)
  348. def test_devtool_add_fetch_git(self):
  349. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  350. self.track_for_cleanup(tempdir)
  351. url = 'gitsm://git.yoctoproject.org/mraa'
  352. checkrev = 'ae127b19a50aa54255e4330ccfdd9a5d058e581d'
  353. testrecipe = 'mraa'
  354. srcdir = os.path.join(tempdir, testrecipe)
  355. # Test devtool add
  356. self.track_for_cleanup(self.workspacedir)
  357. self.add_command_to_tearDown('bitbake -c cleansstate %s' % testrecipe)
  358. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  359. result = runCmd('devtool add %s %s -a -f %s' % (testrecipe, srcdir, url))
  360. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created: %s' % result.output)
  361. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'imraa', 'imraa.c')), 'Unable to find imraa/imraa.c in source directory')
  362. # Test devtool status
  363. result = runCmd('devtool status')
  364. self.assertIn(testrecipe, result.output)
  365. self.assertIn(srcdir, result.output)
  366. # Check recipe
  367. recipefile = get_bb_var('FILE', testrecipe)
  368. self.assertIn('_git.bb', recipefile, 'Recipe file incorrectly named')
  369. checkvars = {}
  370. checkvars['S'] = '${WORKDIR}/git'
  371. checkvars['PV'] = '1.0+git${SRCPV}'
  372. checkvars['SRC_URI'] = url
  373. checkvars['SRCREV'] = '${AUTOREV}'
  374. self._test_recipe_contents(recipefile, checkvars, [])
  375. # Try with revision and version specified
  376. result = runCmd('devtool reset -n %s' % testrecipe)
  377. shutil.rmtree(srcdir)
  378. url_rev = '%s;rev=%s' % (url, checkrev)
  379. result = runCmd('devtool add %s %s -f "%s" -V 1.5' % (testrecipe, srcdir, url_rev))
  380. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'imraa', 'imraa.c')), 'Unable to find imraa/imraa.c in source directory')
  381. # Test devtool status
  382. result = runCmd('devtool status')
  383. self.assertIn(testrecipe, result.output)
  384. self.assertIn(srcdir, result.output)
  385. # Check recipe
  386. recipefile = get_bb_var('FILE', testrecipe)
  387. self.assertIn('_git.bb', recipefile, 'Recipe file incorrectly named')
  388. checkvars = {}
  389. checkvars['S'] = '${WORKDIR}/git'
  390. checkvars['PV'] = '1.5+git${SRCPV}'
  391. checkvars['SRC_URI'] = url
  392. checkvars['SRCREV'] = checkrev
  393. self._test_recipe_contents(recipefile, checkvars, [])
  394. @OETestID(1391)
  395. def test_devtool_add_fetch_simple(self):
  396. # Fetch source from a remote URL, auto-detecting name
  397. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  398. self.track_for_cleanup(tempdir)
  399. testver = '1.6.0'
  400. url = 'http://www.ivarch.com/programs/sources/pv-%s.tar.bz2' % testver
  401. testrecipe = 'pv'
  402. srcdir = os.path.join(self.workspacedir, 'sources', testrecipe)
  403. # Test devtool add
  404. self.track_for_cleanup(self.workspacedir)
  405. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  406. result = runCmd('devtool add %s' % url)
  407. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. %s' % result.output)
  408. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure')), 'Unable to find configure script in source directory')
  409. self.assertTrue(os.path.isdir(os.path.join(srcdir, '.git')), 'git repository for external source tree was not created')
  410. # Test devtool status
  411. result = runCmd('devtool status')
  412. self.assertIn(testrecipe, result.output)
  413. self.assertIn(srcdir, result.output)
  414. # Check recipe
  415. recipefile = get_bb_var('FILE', testrecipe)
  416. self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named')
  417. checkvars = {}
  418. checkvars['S'] = None
  419. checkvars['SRC_URI'] = url.replace(testver, '${PV}')
  420. self._test_recipe_contents(recipefile, checkvars, [])
  421. @OETestID(1164)
  422. def test_devtool_modify(self):
  423. import oe.path
  424. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  425. self.track_for_cleanup(tempdir)
  426. self.track_for_cleanup(self.workspacedir)
  427. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  428. self.add_command_to_tearDown('bitbake -c clean mdadm')
  429. result = runCmd('devtool modify mdadm -x %s' % tempdir)
  430. self.assertExists(os.path.join(tempdir, 'Makefile'), 'Extracted source could not be found')
  431. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  432. matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'mdadm_*.bbappend'))
  433. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  434. # Test devtool status
  435. result = runCmd('devtool status')
  436. self.assertIn('mdadm', result.output)
  437. self.assertIn(tempdir, result.output)
  438. self._check_src_repo(tempdir)
  439. bitbake('mdadm -C unpack')
  440. def check_line(checkfile, expected, message, present=True):
  441. # Check for $expected, on a line on its own, in checkfile.
  442. with open(checkfile, 'r') as f:
  443. if present:
  444. self.assertIn(expected + '\n', f, message)
  445. else:
  446. self.assertNotIn(expected + '\n', f, message)
  447. modfile = os.path.join(tempdir, 'mdadm.8.in')
  448. bb_vars = get_bb_vars(['PKGD', 'mandir'], 'mdadm')
  449. pkgd = bb_vars['PKGD']
  450. self.assertTrue(pkgd, 'Could not query PKGD variable')
  451. mandir = bb_vars['mandir']
  452. self.assertTrue(mandir, 'Could not query mandir variable')
  453. manfile = oe.path.join(pkgd, mandir, 'man8', 'mdadm.8')
  454. check_line(modfile, 'Linux Software RAID', 'Could not find initial string')
  455. check_line(modfile, 'antique pin sardine', 'Unexpectedly found replacement string', present=False)
  456. result = runCmd("sed -i 's!^Linux Software RAID$!antique pin sardine!' %s" % modfile)
  457. check_line(modfile, 'antique pin sardine', 'mdadm.8.in file not modified (sed failed)')
  458. bitbake('mdadm -c package')
  459. check_line(manfile, 'antique pin sardine', 'man file not modified. man searched file path: %s' % manfile)
  460. result = runCmd('git checkout -- %s' % modfile, cwd=tempdir)
  461. check_line(modfile, 'Linux Software RAID', 'man .in file not restored (git failed)')
  462. bitbake('mdadm -c package')
  463. check_line(manfile, 'Linux Software RAID', 'man file not updated. man searched file path: %s' % manfile)
  464. result = runCmd('devtool reset mdadm')
  465. result = runCmd('devtool status')
  466. self.assertNotIn('mdadm', result.output)
  467. @OETestID(1620)
  468. def test_devtool_buildclean(self):
  469. def assertFile(path, *paths):
  470. f = os.path.join(path, *paths)
  471. self.assertExists(f)
  472. def assertNoFile(path, *paths):
  473. f = os.path.join(path, *paths)
  474. self.assertNotExists(f)
  475. # Clean up anything in the workdir/sysroot/sstate cache
  476. bitbake('mdadm m4 -c cleansstate')
  477. # Try modifying a recipe
  478. tempdir_mdadm = tempfile.mkdtemp(prefix='devtoolqa')
  479. tempdir_m4 = tempfile.mkdtemp(prefix='devtoolqa')
  480. builddir_m4 = tempfile.mkdtemp(prefix='devtoolqa')
  481. self.track_for_cleanup(tempdir_mdadm)
  482. self.track_for_cleanup(tempdir_m4)
  483. self.track_for_cleanup(builddir_m4)
  484. self.track_for_cleanup(self.workspacedir)
  485. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  486. self.add_command_to_tearDown('bitbake -c clean mdadm m4')
  487. self.write_recipeinc('m4', 'EXTERNALSRC_BUILD = "%s"\ndo_clean() {\n\t:\n}\n' % builddir_m4)
  488. try:
  489. runCmd('devtool modify mdadm -x %s' % tempdir_mdadm)
  490. runCmd('devtool modify m4 -x %s' % tempdir_m4)
  491. assertNoFile(tempdir_mdadm, 'mdadm')
  492. assertNoFile(builddir_m4, 'src/m4')
  493. result = bitbake('m4 -e')
  494. result = bitbake('mdadm m4 -c compile')
  495. self.assertEqual(result.status, 0)
  496. assertFile(tempdir_mdadm, 'mdadm')
  497. assertFile(builddir_m4, 'src/m4')
  498. # Check that buildclean task exists and does call make clean
  499. bitbake('mdadm m4 -c buildclean')
  500. assertNoFile(tempdir_mdadm, 'mdadm')
  501. assertNoFile(builddir_m4, 'src/m4')
  502. bitbake('mdadm m4 -c compile')
  503. assertFile(tempdir_mdadm, 'mdadm')
  504. assertFile(builddir_m4, 'src/m4')
  505. bitbake('mdadm m4 -c clean')
  506. # Check that buildclean task is run before clean for B == S
  507. assertNoFile(tempdir_mdadm, 'mdadm')
  508. # Check that buildclean task is not run before clean for B != S
  509. assertFile(builddir_m4, 'src/m4')
  510. finally:
  511. self.delete_recipeinc('m4')
  512. @OETestID(1166)
  513. def test_devtool_modify_invalid(self):
  514. # Try modifying some recipes
  515. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  516. self.track_for_cleanup(tempdir)
  517. self.track_for_cleanup(self.workspacedir)
  518. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  519. testrecipes = 'perf kernel-devsrc package-index core-image-minimal meta-toolchain packagegroup-core-sdk meta-ide-support'.split()
  520. # Find actual name of gcc-source since it now includes the version - crude, but good enough for this purpose
  521. result = runCmd('bitbake-layers show-recipes gcc-source*')
  522. for line in result.output.splitlines():
  523. # just match those lines that contain a real target
  524. m = re.match('(?P<recipe>^[a-zA-Z0-9.-]+)(?P<colon>:$)', line)
  525. if m:
  526. testrecipes.append(m.group('recipe'))
  527. for testrecipe in testrecipes:
  528. # Check it's a valid recipe
  529. bitbake('%s -e' % testrecipe)
  530. # devtool extract should fail
  531. result = runCmd('devtool extract %s %s' % (testrecipe, os.path.join(tempdir, testrecipe)), ignore_status=True)
  532. self.assertNotEqual(result.status, 0, 'devtool extract on %s should have failed. devtool output: %s' % (testrecipe, result.output))
  533. self.assertNotIn('Fetching ', result.output, 'devtool extract on %s should have errored out before trying to fetch' % testrecipe)
  534. self.assertIn('ERROR: ', result.output, 'devtool extract on %s should have given an ERROR' % testrecipe)
  535. # devtool modify should fail
  536. result = runCmd('devtool modify %s -x %s' % (testrecipe, os.path.join(tempdir, testrecipe)), ignore_status=True)
  537. self.assertNotEqual(result.status, 0, 'devtool modify on %s should have failed. devtool output: %s' % (testrecipe, result.output))
  538. self.assertIn('ERROR: ', result.output, 'devtool modify on %s should have given an ERROR' % testrecipe)
  539. @OETestID(1365)
  540. def test_devtool_modify_native(self):
  541. # Check preconditions
  542. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  543. # Try modifying some recipes
  544. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  545. self.track_for_cleanup(tempdir)
  546. self.track_for_cleanup(self.workspacedir)
  547. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  548. bbclassextended = False
  549. inheritnative = False
  550. testrecipes = 'mtools-native apt-native desktop-file-utils-native'.split()
  551. for testrecipe in testrecipes:
  552. checkextend = 'native' in (get_bb_var('BBCLASSEXTEND', testrecipe) or '').split()
  553. if not bbclassextended:
  554. bbclassextended = checkextend
  555. if not inheritnative:
  556. inheritnative = not checkextend
  557. result = runCmd('devtool modify %s -x %s' % (testrecipe, os.path.join(tempdir, testrecipe)))
  558. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool modify output: %s' % result.output)
  559. result = runCmd('devtool build %s' % testrecipe)
  560. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool build output: %s' % result.output)
  561. result = runCmd('devtool reset %s' % testrecipe)
  562. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool reset output: %s' % result.output)
  563. self.assertTrue(bbclassextended, 'None of these recipes are BBCLASSEXTENDed to native - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
  564. self.assertTrue(inheritnative, 'None of these recipes do "inherit native" - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
  565. @OETestID(1165)
  566. def test_devtool_modify_git(self):
  567. # Check preconditions
  568. testrecipe = 'psplash'
  569. src_uri = get_bb_var('SRC_URI', testrecipe)
  570. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  571. # Clean up anything in the workdir/sysroot/sstate cache
  572. bitbake('%s -c cleansstate' % testrecipe)
  573. # Try modifying a recipe
  574. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  575. self.track_for_cleanup(tempdir)
  576. self.track_for_cleanup(self.workspacedir)
  577. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  578. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  579. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  580. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  581. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output)
  582. matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'psplash_*.bbappend'))
  583. self.assertTrue(matches, 'bbappend not created')
  584. # Test devtool status
  585. result = runCmd('devtool status')
  586. self.assertIn(testrecipe, result.output)
  587. self.assertIn(tempdir, result.output)
  588. # Check git repo
  589. self._check_src_repo(tempdir)
  590. # Try building
  591. bitbake(testrecipe)
  592. @OETestID(1167)
  593. def test_devtool_modify_localfiles(self):
  594. # Check preconditions
  595. testrecipe = 'lighttpd'
  596. src_uri = (get_bb_var('SRC_URI', testrecipe) or '').split()
  597. foundlocal = False
  598. for item in src_uri:
  599. if item.startswith('file://') and '.patch' not in item:
  600. foundlocal = True
  601. break
  602. self.assertTrue(foundlocal, 'This test expects the %s recipe to fetch local files and it seems that it no longer does' % testrecipe)
  603. # Clean up anything in the workdir/sysroot/sstate cache
  604. bitbake('%s -c cleansstate' % testrecipe)
  605. # Try modifying a recipe
  606. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  607. self.track_for_cleanup(tempdir)
  608. self.track_for_cleanup(self.workspacedir)
  609. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  610. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  611. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  612. self.assertExists(os.path.join(tempdir, 'configure.ac'), 'Extracted source could not be found')
  613. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  614. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % testrecipe))
  615. self.assertTrue(matches, 'bbappend not created')
  616. # Test devtool status
  617. result = runCmd('devtool status')
  618. self.assertIn(testrecipe, result.output)
  619. self.assertIn(tempdir, result.output)
  620. # Try building
  621. bitbake(testrecipe)
  622. @OETestID(1378)
  623. def test_devtool_modify_virtual(self):
  624. # Try modifying a virtual recipe
  625. virtrecipe = 'virtual/make'
  626. realrecipe = 'make'
  627. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  628. self.track_for_cleanup(tempdir)
  629. self.track_for_cleanup(self.workspacedir)
  630. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  631. result = runCmd('devtool modify %s -x %s' % (virtrecipe, tempdir))
  632. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  633. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  634. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % realrecipe))
  635. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  636. # Test devtool status
  637. result = runCmd('devtool status')
  638. self.assertNotIn(virtrecipe, result.output)
  639. self.assertIn(realrecipe, result.output)
  640. # Check git repo
  641. self._check_src_repo(tempdir)
  642. # This is probably sufficient
  643. @OETestID(1169)
  644. def test_devtool_update_recipe(self):
  645. # Check preconditions
  646. testrecipe = 'minicom'
  647. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  648. recipefile = bb_vars['FILE']
  649. src_uri = bb_vars['SRC_URI']
  650. self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
  651. self._check_repo_status(os.path.dirname(recipefile), [])
  652. # First, modify a recipe
  653. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  654. self.track_for_cleanup(tempdir)
  655. self.track_for_cleanup(self.workspacedir)
  656. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  657. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  658. # We don't use -x here so that we test the behaviour of devtool modify without it
  659. result = runCmd('devtool modify %s %s' % (testrecipe, tempdir))
  660. # Check git repo
  661. self._check_src_repo(tempdir)
  662. # Add a couple of commits
  663. # FIXME: this only tests adding, need to also test update and remove
  664. result = runCmd('echo "Additional line" >> README', cwd=tempdir)
  665. result = runCmd('git commit -a -m "Change the README"', cwd=tempdir)
  666. result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir)
  667. result = runCmd('git add devtool-new-file', cwd=tempdir)
  668. result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
  669. self.add_command_to_tearDown('cd %s; rm %s/*.patch; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  670. result = runCmd('devtool update-recipe %s' % testrecipe)
  671. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  672. ('??', '.*/0001-Change-the-README.patch$'),
  673. ('??', '.*/0002-Add-a-new-file.patch$')]
  674. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  675. @OETestID(1172)
  676. def test_devtool_update_recipe_git(self):
  677. # Check preconditions
  678. testrecipe = 'mtd-utils'
  679. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  680. recipefile = bb_vars['FILE']
  681. src_uri = bb_vars['SRC_URI']
  682. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  683. patches = []
  684. for entry in src_uri.split():
  685. if entry.startswith('file://') and entry.endswith('.patch'):
  686. patches.append(entry[7:].split(';')[0])
  687. self.assertGreater(len(patches), 0, 'The %s recipe does not appear to contain any patches, so this test will not be effective' % testrecipe)
  688. self._check_repo_status(os.path.dirname(recipefile), [])
  689. # First, modify a recipe
  690. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  691. self.track_for_cleanup(tempdir)
  692. self.track_for_cleanup(self.workspacedir)
  693. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  694. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  695. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  696. # Check git repo
  697. self._check_src_repo(tempdir)
  698. # Add a couple of commits
  699. # FIXME: this only tests adding, need to also test update and remove
  700. result = runCmd('echo "# Additional line" >> Makefile.am', cwd=tempdir)
  701. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempdir)
  702. result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir)
  703. result = runCmd('git add devtool-new-file', cwd=tempdir)
  704. result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
  705. self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  706. result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe)
  707. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile))] + \
  708. [(' D', '.*/%s$' % patch) for patch in patches]
  709. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  710. result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
  711. addlines = ['SRCREV = ".*"', 'SRC_URI = "git://git.infradead.org/mtd-utils.git"']
  712. srcurilines = src_uri.split()
  713. srcurilines[0] = 'SRC_URI = "' + srcurilines[0]
  714. srcurilines.append('"')
  715. removelines = ['SRCREV = ".*"'] + srcurilines
  716. for line in result.output.splitlines():
  717. if line.startswith('+++') or line.startswith('---'):
  718. continue
  719. elif line.startswith('+'):
  720. matched = False
  721. for item in addlines:
  722. if re.match(item, line[1:].strip()):
  723. matched = True
  724. break
  725. self.assertTrue(matched, 'Unexpected diff add line: %s' % line)
  726. elif line.startswith('-'):
  727. matched = False
  728. for item in removelines:
  729. if re.match(item, line[1:].strip()):
  730. matched = True
  731. break
  732. self.assertTrue(matched, 'Unexpected diff remove line: %s' % line)
  733. # Now try with auto mode
  734. runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile)))
  735. result = runCmd('devtool update-recipe %s' % testrecipe)
  736. result = runCmd('git rev-parse --show-toplevel', cwd=os.path.dirname(recipefile))
  737. topleveldir = result.output.strip()
  738. relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe)
  739. expected_status = [(' M', os.path.relpath(recipefile, topleveldir)),
  740. ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath),
  741. ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)]
  742. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  743. @OETestID(1170)
  744. def test_devtool_update_recipe_append(self):
  745. # Check preconditions
  746. testrecipe = 'mdadm'
  747. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  748. recipefile = bb_vars['FILE']
  749. src_uri = bb_vars['SRC_URI']
  750. self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
  751. self._check_repo_status(os.path.dirname(recipefile), [])
  752. # First, modify a recipe
  753. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  754. tempsrcdir = os.path.join(tempdir, 'source')
  755. templayerdir = os.path.join(tempdir, 'layer')
  756. self.track_for_cleanup(tempdir)
  757. self.track_for_cleanup(self.workspacedir)
  758. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  759. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  760. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir))
  761. # Check git repo
  762. self._check_src_repo(tempsrcdir)
  763. # Add a commit
  764. result = runCmd("sed 's!\\(#define VERSION\\W*\"[^\"]*\\)\"!\\1-custom\"!' -i ReadMe.c", cwd=tempsrcdir)
  765. result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir)
  766. self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe))
  767. # Create a temporary layer and add it to bblayers.conf
  768. self._create_temp_layer(templayerdir, True, 'selftestupdaterecipe')
  769. # Create the bbappend
  770. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  771. self.assertNotIn('WARNING:', result.output)
  772. # Check recipe is still clean
  773. self._check_repo_status(os.path.dirname(recipefile), [])
  774. # Check bbappend was created
  775. splitpath = os.path.dirname(recipefile).split(os.sep)
  776. appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
  777. bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir)
  778. patchfile = os.path.join(appenddir, testrecipe, '0001-Add-our-custom-version.patch')
  779. self.assertExists(patchfile, 'Patch file not created')
  780. # Check bbappend contents
  781. expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
  782. '\n',
  783. 'SRC_URI += "file://0001-Add-our-custom-version.patch"\n',
  784. '\n']
  785. with open(bbappendfile, 'r') as f:
  786. self.assertEqual(expectedlines, f.readlines())
  787. # Check we can run it again and bbappend isn't modified
  788. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  789. with open(bbappendfile, 'r') as f:
  790. self.assertEqual(expectedlines, f.readlines())
  791. # Drop new commit and check patch gets deleted
  792. result = runCmd('git reset HEAD^', cwd=tempsrcdir)
  793. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  794. self.assertNotExists(patchfile, 'Patch file not deleted')
  795. expectedlines2 = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n',
  796. '\n']
  797. with open(bbappendfile, 'r') as f:
  798. self.assertEqual(expectedlines2, f.readlines())
  799. # Put commit back and check we can run it if layer isn't in bblayers.conf
  800. os.remove(bbappendfile)
  801. result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir)
  802. result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir)
  803. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  804. self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output)
  805. self.assertExists(patchfile, 'Patch file not created (with disabled layer)')
  806. with open(bbappendfile, 'r') as f:
  807. self.assertEqual(expectedlines, f.readlines())
  808. # Deleting isn't expected to work under these circumstances
  809. @OETestID(1171)
  810. def test_devtool_update_recipe_append_git(self):
  811. # Check preconditions
  812. testrecipe = 'mtd-utils'
  813. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  814. recipefile = bb_vars['FILE']
  815. src_uri = bb_vars['SRC_URI']
  816. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  817. for entry in src_uri.split():
  818. if entry.startswith('git://'):
  819. git_uri = entry
  820. break
  821. self._check_repo_status(os.path.dirname(recipefile), [])
  822. # First, modify a recipe
  823. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  824. tempsrcdir = os.path.join(tempdir, 'source')
  825. templayerdir = os.path.join(tempdir, 'layer')
  826. self.track_for_cleanup(tempdir)
  827. self.track_for_cleanup(self.workspacedir)
  828. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  829. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  830. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir))
  831. # Check git repo
  832. self._check_src_repo(tempsrcdir)
  833. # Add a commit
  834. result = runCmd('echo "# Additional line" >> Makefile.am', cwd=tempsrcdir)
  835. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir)
  836. self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe))
  837. # Create a temporary layer
  838. os.makedirs(os.path.join(templayerdir, 'conf'))
  839. with open(os.path.join(templayerdir, 'conf', 'layer.conf'), 'w') as f:
  840. f.write('BBPATH .= ":${LAYERDIR}"\n')
  841. f.write('BBFILES += "${LAYERDIR}/recipes-*/*/*.bbappend"\n')
  842. f.write('BBFILE_COLLECTIONS += "oeselftesttemplayer"\n')
  843. f.write('BBFILE_PATTERN_oeselftesttemplayer = "^${LAYERDIR}/"\n')
  844. f.write('BBFILE_PRIORITY_oeselftesttemplayer = "999"\n')
  845. f.write('BBFILE_PATTERN_IGNORE_EMPTY_oeselftesttemplayer = "1"\n')
  846. f.write('LAYERSERIES_COMPAT_oeselftesttemplayer = "${LAYERSERIES_COMPAT_core}"\n')
  847. self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
  848. result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
  849. # Create the bbappend
  850. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  851. self.assertNotIn('WARNING:', result.output)
  852. # Check recipe is still clean
  853. self._check_repo_status(os.path.dirname(recipefile), [])
  854. # Check bbappend was created
  855. splitpath = os.path.dirname(recipefile).split(os.sep)
  856. appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
  857. bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir)
  858. self.assertNotExists(os.path.join(appenddir, testrecipe), 'Patch directory should not be created')
  859. # Check bbappend contents
  860. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  861. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  862. '\n',
  863. 'SRC_URI = "%s"\n' % git_uri,
  864. '\n'])
  865. with open(bbappendfile, 'r') as f:
  866. self.assertEqual(expectedlines, set(f.readlines()))
  867. # Check we can run it again and bbappend isn't modified
  868. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  869. with open(bbappendfile, 'r') as f:
  870. self.assertEqual(expectedlines, set(f.readlines()))
  871. # Drop new commit and check SRCREV changes
  872. result = runCmd('git reset HEAD^', cwd=tempsrcdir)
  873. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  874. self.assertNotExists(os.path.join(appenddir, testrecipe), 'Patch directory should not be created')
  875. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  876. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  877. '\n',
  878. 'SRC_URI = "%s"\n' % git_uri,
  879. '\n'])
  880. with open(bbappendfile, 'r') as f:
  881. self.assertEqual(expectedlines, set(f.readlines()))
  882. # Put commit back and check we can run it if layer isn't in bblayers.conf
  883. os.remove(bbappendfile)
  884. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir)
  885. result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir)
  886. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  887. self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output)
  888. self.assertNotExists(os.path.join(appenddir, testrecipe), 'Patch directory should not be created')
  889. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  890. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  891. '\n',
  892. 'SRC_URI = "%s"\n' % git_uri,
  893. '\n'])
  894. with open(bbappendfile, 'r') as f:
  895. self.assertEqual(expectedlines, set(f.readlines()))
  896. # Deleting isn't expected to work under these circumstances
  897. @OETestID(1370)
  898. def test_devtool_update_recipe_local_files(self):
  899. """Check that local source files are copied over instead of patched"""
  900. testrecipe = 'makedevs'
  901. recipefile = get_bb_var('FILE', testrecipe)
  902. # Setup srctree for modifying the recipe
  903. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  904. self.track_for_cleanup(tempdir)
  905. self.track_for_cleanup(self.workspacedir)
  906. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  907. # (don't bother with cleaning the recipe on teardown, we won't be
  908. # building it)
  909. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  910. # Check git repo
  911. self._check_src_repo(tempdir)
  912. # Try building just to ensure we haven't broken that
  913. bitbake("%s" % testrecipe)
  914. # Edit / commit local source
  915. runCmd('echo "/* Foobar */" >> oe-local-files/makedevs.c', cwd=tempdir)
  916. runCmd('echo "Foo" > oe-local-files/new-local', cwd=tempdir)
  917. runCmd('echo "Bar" > new-file', cwd=tempdir)
  918. runCmd('git add new-file', cwd=tempdir)
  919. runCmd('git commit -m "Add new file"', cwd=tempdir)
  920. self.add_command_to_tearDown('cd %s; git clean -fd .; git checkout .' %
  921. os.path.dirname(recipefile))
  922. runCmd('devtool update-recipe %s' % testrecipe)
  923. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  924. (' M', '.*/makedevs/makedevs.c$'),
  925. ('??', '.*/makedevs/new-local$'),
  926. ('??', '.*/makedevs/0001-Add-new-file.patch$')]
  927. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  928. @OETestID(1371)
  929. def test_devtool_update_recipe_local_files_2(self):
  930. """Check local source files support when oe-local-files is in Git"""
  931. testrecipe = 'devtool-test-local'
  932. recipefile = get_bb_var('FILE', testrecipe)
  933. recipedir = os.path.dirname(recipefile)
  934. result = runCmd('git status --porcelain .', cwd=recipedir)
  935. if result.output.strip():
  936. self.fail('Recipe directory for %s contains uncommitted changes' % testrecipe)
  937. # Setup srctree for modifying the recipe
  938. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  939. self.track_for_cleanup(tempdir)
  940. self.track_for_cleanup(self.workspacedir)
  941. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  942. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  943. # Check git repo
  944. self._check_src_repo(tempdir)
  945. # Add oe-local-files to Git
  946. runCmd('rm oe-local-files/.gitignore', cwd=tempdir)
  947. runCmd('git add oe-local-files', cwd=tempdir)
  948. runCmd('git commit -m "Add local sources"', cwd=tempdir)
  949. # Edit / commit local sources
  950. runCmd('echo "# Foobar" >> oe-local-files/file1', cwd=tempdir)
  951. runCmd('git commit -am "Edit existing file"', cwd=tempdir)
  952. runCmd('git rm oe-local-files/file2', cwd=tempdir)
  953. runCmd('git commit -m"Remove file"', cwd=tempdir)
  954. runCmd('echo "Foo" > oe-local-files/new-local', cwd=tempdir)
  955. runCmd('git add oe-local-files/new-local', cwd=tempdir)
  956. runCmd('git commit -m "Add new local file"', cwd=tempdir)
  957. runCmd('echo "Gar" > new-file', cwd=tempdir)
  958. runCmd('git add new-file', cwd=tempdir)
  959. runCmd('git commit -m "Add new file"', cwd=tempdir)
  960. self.add_command_to_tearDown('cd %s; git clean -fd .; git checkout .' %
  961. os.path.dirname(recipefile))
  962. # Checkout unmodified file to working copy -> devtool should still pick
  963. # the modified version from HEAD
  964. runCmd('git checkout HEAD^ -- oe-local-files/file1', cwd=tempdir)
  965. runCmd('devtool update-recipe %s' % testrecipe)
  966. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  967. (' M', '.*/file1$'),
  968. (' D', '.*/file2$'),
  969. ('??', '.*/new-local$'),
  970. ('??', '.*/0001-Add-new-file.patch$')]
  971. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  972. @OETestID(1627)
  973. def test_devtool_update_recipe_local_files_3(self):
  974. # First, modify the recipe
  975. testrecipe = 'devtool-test-localonly'
  976. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  977. recipefile = bb_vars['FILE']
  978. src_uri = bb_vars['SRC_URI']
  979. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  980. self.track_for_cleanup(tempdir)
  981. self.track_for_cleanup(self.workspacedir)
  982. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  983. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  984. result = runCmd('devtool modify %s' % testrecipe)
  985. # Modify one file
  986. runCmd('echo "Another line" >> file2', cwd=os.path.join(self.workspacedir, 'sources', testrecipe, 'oe-local-files'))
  987. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  988. result = runCmd('devtool update-recipe %s' % testrecipe)
  989. expected_status = [(' M', '.*/%s/file2$' % testrecipe)]
  990. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  991. @OETestID(1629)
  992. def test_devtool_update_recipe_local_patch_gz(self):
  993. # First, modify the recipe
  994. testrecipe = 'devtool-test-patch-gz'
  995. if get_bb_var('DISTRO') == 'poky-tiny':
  996. self.skipTest("The DISTRO 'poky-tiny' does not provide the dependencies needed by %s" % testrecipe)
  997. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  998. recipefile = bb_vars['FILE']
  999. src_uri = bb_vars['SRC_URI']
  1000. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1001. self.track_for_cleanup(tempdir)
  1002. self.track_for_cleanup(self.workspacedir)
  1003. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1004. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1005. result = runCmd('devtool modify %s' % testrecipe)
  1006. # Modify one file
  1007. srctree = os.path.join(self.workspacedir, 'sources', testrecipe)
  1008. runCmd('echo "Another line" >> README', cwd=srctree)
  1009. runCmd('git commit -a --amend --no-edit', cwd=srctree)
  1010. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1011. result = runCmd('devtool update-recipe %s' % testrecipe)
  1012. expected_status = [(' M', '.*/%s/readme.patch.gz$' % testrecipe)]
  1013. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1014. patch_gz = os.path.join(os.path.dirname(recipefile), testrecipe, 'readme.patch.gz')
  1015. result = runCmd('file %s' % patch_gz)
  1016. if 'gzip compressed data' not in result.output:
  1017. self.fail('New patch file is not gzipped - file reports:\n%s' % result.output)
  1018. @OETestID(1628)
  1019. def test_devtool_update_recipe_local_files_subdir(self):
  1020. # Try devtool update-recipe on a recipe that has a file with subdir= set in
  1021. # SRC_URI such that it overwrites a file that was in an archive that
  1022. # was also in SRC_URI
  1023. # First, modify the recipe
  1024. testrecipe = 'devtool-test-subdir'
  1025. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  1026. recipefile = bb_vars['FILE']
  1027. src_uri = bb_vars['SRC_URI']
  1028. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1029. self.track_for_cleanup(tempdir)
  1030. self.track_for_cleanup(self.workspacedir)
  1031. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1032. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1033. result = runCmd('devtool modify %s' % testrecipe)
  1034. testfile = os.path.join(self.workspacedir, 'sources', testrecipe, 'testfile')
  1035. self.assertExists(testfile, 'Extracted source could not be found')
  1036. with open(testfile, 'r') as f:
  1037. contents = f.read().rstrip()
  1038. self.assertEqual(contents, 'Modified version', 'File has apparently not been overwritten as it should have been')
  1039. # Test devtool update-recipe without modifying any files
  1040. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1041. result = runCmd('devtool update-recipe %s' % testrecipe)
  1042. expected_status = []
  1043. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1044. @OETestID(1163)
  1045. def test_devtool_extract(self):
  1046. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1047. # Try devtool extract
  1048. self.track_for_cleanup(tempdir)
  1049. self.track_for_cleanup(self.workspacedir)
  1050. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1051. result = runCmd('devtool extract matchbox-terminal %s' % tempdir)
  1052. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  1053. self._check_src_repo(tempdir)
  1054. @OETestID(1379)
  1055. def test_devtool_extract_virtual(self):
  1056. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1057. # Try devtool extract
  1058. self.track_for_cleanup(tempdir)
  1059. self.track_for_cleanup(self.workspacedir)
  1060. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1061. result = runCmd('devtool extract virtual/make %s' % tempdir)
  1062. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  1063. self._check_src_repo(tempdir)
  1064. @OETestID(1168)
  1065. def test_devtool_reset_all(self):
  1066. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1067. self.track_for_cleanup(tempdir)
  1068. self.track_for_cleanup(self.workspacedir)
  1069. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1070. testrecipe1 = 'mdadm'
  1071. testrecipe2 = 'cronie'
  1072. result = runCmd('devtool modify -x %s %s' % (testrecipe1, os.path.join(tempdir, testrecipe1)))
  1073. result = runCmd('devtool modify -x %s %s' % (testrecipe2, os.path.join(tempdir, testrecipe2)))
  1074. result = runCmd('devtool build %s' % testrecipe1)
  1075. result = runCmd('devtool build %s' % testrecipe2)
  1076. stampprefix1 = get_bb_var('STAMP', testrecipe1)
  1077. self.assertTrue(stampprefix1, 'Unable to get STAMP value for recipe %s' % testrecipe1)
  1078. stampprefix2 = get_bb_var('STAMP', testrecipe2)
  1079. self.assertTrue(stampprefix2, 'Unable to get STAMP value for recipe %s' % testrecipe2)
  1080. result = runCmd('devtool reset -a')
  1081. self.assertIn(testrecipe1, result.output)
  1082. self.assertIn(testrecipe2, result.output)
  1083. result = runCmd('devtool status')
  1084. self.assertNotIn(testrecipe1, result.output)
  1085. self.assertNotIn(testrecipe2, result.output)
  1086. matches1 = glob.glob(stampprefix1 + '*')
  1087. self.assertFalse(matches1, 'Stamp files exist for recipe %s that should have been cleaned' % testrecipe1)
  1088. matches2 = glob.glob(stampprefix2 + '*')
  1089. self.assertFalse(matches2, 'Stamp files exist for recipe %s that should have been cleaned' % testrecipe2)
  1090. @OETestID(1272)
  1091. def test_devtool_deploy_target(self):
  1092. # NOTE: Whilst this test would seemingly be better placed as a runtime test,
  1093. # unfortunately the runtime tests run under bitbake and you can't run
  1094. # devtool within bitbake (since devtool needs to run bitbake itself).
  1095. # Additionally we are testing build-time functionality as well, so
  1096. # really this has to be done as an oe-selftest test.
  1097. #
  1098. # Check preconditions
  1099. machine = get_bb_var('MACHINE')
  1100. if not machine.startswith('qemu'):
  1101. self.skipTest('This test only works with qemu machines')
  1102. if not os.path.exists('/etc/runqemu-nosudo'):
  1103. self.skipTest('You must set up tap devices with scripts/runqemu-gen-tapdevs before running this test')
  1104. result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ip tuntap show', ignore_status=True)
  1105. if result.status != 0:
  1106. result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ifconfig -a', ignore_status=True)
  1107. if result.status != 0:
  1108. self.skipTest('Failed to determine if tap devices exist with ifconfig or ip: %s' % result.output)
  1109. for line in result.output.splitlines():
  1110. if line.startswith('tap'):
  1111. break
  1112. else:
  1113. self.skipTest('No tap devices found - you must set up tap devices with scripts/runqemu-gen-tapdevs before running this test')
  1114. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1115. # Definitions
  1116. testrecipe = 'mdadm'
  1117. testfile = '/sbin/mdadm'
  1118. testimage = 'oe-selftest-image'
  1119. testcommand = '/sbin/mdadm --help'
  1120. # Build an image to run
  1121. bitbake("%s qemu-native qemu-helper-native" % testimage)
  1122. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  1123. self.add_command_to_tearDown('bitbake -c clean %s' % testimage)
  1124. self.add_command_to_tearDown('rm -f %s/%s*' % (deploy_dir_image, testimage))
  1125. # Clean recipe so the first deploy will fail
  1126. bitbake("%s -c clean" % testrecipe)
  1127. # Try devtool modify
  1128. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1129. self.track_for_cleanup(tempdir)
  1130. self.track_for_cleanup(self.workspacedir)
  1131. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1132. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  1133. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1134. # Test that deploy-target at this point fails (properly)
  1135. result = runCmd('devtool deploy-target -n %s root@localhost' % testrecipe, ignore_status=True)
  1136. self.assertNotEqual(result.output, 0, 'devtool deploy-target should have failed, output: %s' % result.output)
  1137. self.assertNotIn(result.output, 'Traceback', 'devtool deploy-target should have failed with a proper error not a traceback, output: %s' % result.output)
  1138. result = runCmd('devtool build %s' % testrecipe)
  1139. # First try a dry-run of deploy-target
  1140. result = runCmd('devtool deploy-target -n %s root@localhost' % testrecipe)
  1141. self.assertIn(' %s' % testfile, result.output)
  1142. # Boot the image
  1143. with runqemu(testimage) as qemu:
  1144. # Now really test deploy-target
  1145. result = runCmd('devtool deploy-target -c %s root@%s' % (testrecipe, qemu.ip))
  1146. # Run a test command to see if it was installed properly
  1147. sshargs = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
  1148. result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand))
  1149. # Check if it deployed all of the files with the right ownership/perms
  1150. # First look on the host - need to do this under pseudo to get the correct ownership/perms
  1151. bb_vars = get_bb_vars(['D', 'FAKEROOTENV', 'FAKEROOTCMD'], testrecipe)
  1152. installdir = bb_vars['D']
  1153. fakerootenv = bb_vars['FAKEROOTENV']
  1154. fakerootcmd = bb_vars['FAKEROOTCMD']
  1155. result = runCmd('%s %s find . -type f -exec ls -l {} \;' % (fakerootenv, fakerootcmd), cwd=installdir)
  1156. filelist1 = self._process_ls_output(result.output)
  1157. # Now look on the target
  1158. tempdir2 = tempfile.mkdtemp(prefix='devtoolqa')
  1159. self.track_for_cleanup(tempdir2)
  1160. tmpfilelist = os.path.join(tempdir2, 'files.txt')
  1161. with open(tmpfilelist, 'w') as f:
  1162. for line in filelist1:
  1163. splitline = line.split()
  1164. f.write(splitline[-1] + '\n')
  1165. result = runCmd('cat %s | ssh -q %s root@%s \'xargs ls -l\'' % (tmpfilelist, sshargs, qemu.ip))
  1166. filelist2 = self._process_ls_output(result.output)
  1167. filelist1.sort(key=lambda item: item.split()[-1])
  1168. filelist2.sort(key=lambda item: item.split()[-1])
  1169. self.assertEqual(filelist1, filelist2)
  1170. # Test undeploy-target
  1171. result = runCmd('devtool undeploy-target -c %s root@%s' % (testrecipe, qemu.ip))
  1172. result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand), ignore_status=True)
  1173. self.assertNotEqual(result, 0, 'undeploy-target did not remove command as it should have')
  1174. @OETestID(1366)
  1175. def test_devtool_build_image(self):
  1176. """Test devtool build-image plugin"""
  1177. # Check preconditions
  1178. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1179. image = 'core-image-minimal'
  1180. self.track_for_cleanup(self.workspacedir)
  1181. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1182. self.add_command_to_tearDown('bitbake -c clean %s' % image)
  1183. bitbake('%s -c clean' % image)
  1184. # Add target and native recipes to workspace
  1185. recipes = ['mdadm', 'parted-native']
  1186. for recipe in recipes:
  1187. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1188. self.track_for_cleanup(tempdir)
  1189. self.add_command_to_tearDown('bitbake -c clean %s' % recipe)
  1190. runCmd('devtool modify %s -x %s' % (recipe, tempdir))
  1191. # Try to build image
  1192. result = runCmd('devtool build-image %s' % image)
  1193. self.assertNotEqual(result, 0, 'devtool build-image failed')
  1194. # Check if image contains expected packages
  1195. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  1196. image_link_name = get_bb_var('IMAGE_LINK_NAME', image)
  1197. reqpkgs = [item for item in recipes if not item.endswith('-native')]
  1198. with open(os.path.join(deploy_dir_image, image_link_name + '.manifest'), 'r') as f:
  1199. for line in f:
  1200. splitval = line.split()
  1201. if splitval:
  1202. pkg = splitval[0]
  1203. if pkg in reqpkgs:
  1204. reqpkgs.remove(pkg)
  1205. if reqpkgs:
  1206. self.fail('The following packages were not present in the image as expected: %s' % ', '.join(reqpkgs))
  1207. @OETestID(1367)
  1208. def test_devtool_upgrade(self):
  1209. # Check preconditions
  1210. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1211. self.track_for_cleanup(self.workspacedir)
  1212. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1213. # Check parameters
  1214. result = runCmd('devtool upgrade -h')
  1215. for param in 'recipename srctree --version -V --branch -b --keep-temp --no-patch'.split():
  1216. self.assertIn(param, result.output)
  1217. # For the moment, we are using a real recipe.
  1218. recipe = 'devtool-upgrade-test1'
  1219. version = '1.6.0'
  1220. oldrecipefile = get_bb_var('FILE', recipe)
  1221. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1222. self.track_for_cleanup(tempdir)
  1223. # Check that recipe is not already under devtool control
  1224. result = runCmd('devtool status')
  1225. self.assertNotIn(recipe, result.output)
  1226. # Check upgrade. Code does not check if new PV is older or newer that current PV, so, it may be that
  1227. # we are downgrading instead of upgrading.
  1228. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, version))
  1229. # Check if srctree at least is populated
  1230. self.assertTrue(len(os.listdir(tempdir)) > 0, 'srctree (%s) should be populated with new (%s) source code' % (tempdir, version))
  1231. # Check new recipe subdirectory is present
  1232. self.assertExists(os.path.join(self.workspacedir, 'recipes', recipe, '%s-%s' % (recipe, version)), 'Recipe folder should exist')
  1233. # Check new recipe file is present
  1234. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, '%s_%s.bb' % (recipe, version))
  1235. self.assertExists(newrecipefile, 'Recipe file should exist after upgrade')
  1236. # Check devtool status and make sure recipe is present
  1237. result = runCmd('devtool status')
  1238. self.assertIn(recipe, result.output)
  1239. self.assertIn(tempdir, result.output)
  1240. # Check recipe got changed as expected
  1241. with open(oldrecipefile + '.upgraded', 'r') as f:
  1242. desiredlines = f.readlines()
  1243. with open(newrecipefile, 'r') as f:
  1244. newlines = f.readlines()
  1245. self.assertEqual(desiredlines, newlines)
  1246. # Check devtool reset recipe
  1247. result = runCmd('devtool reset %s -n' % recipe)
  1248. result = runCmd('devtool status')
  1249. self.assertNotIn(recipe, result.output)
  1250. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after resetting')
  1251. @OETestID(1433)
  1252. def test_devtool_upgrade_git(self):
  1253. # Check preconditions
  1254. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1255. self.track_for_cleanup(self.workspacedir)
  1256. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1257. recipe = 'devtool-upgrade-test2'
  1258. commit = '6cc6077a36fe2648a5f993fe7c16c9632f946517'
  1259. oldrecipefile = get_bb_var('FILE', recipe)
  1260. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1261. self.track_for_cleanup(tempdir)
  1262. # Check that recipe is not already under devtool control
  1263. result = runCmd('devtool status')
  1264. self.assertNotIn(recipe, result.output)
  1265. # Check upgrade
  1266. result = runCmd('devtool upgrade %s %s -S %s' % (recipe, tempdir, commit))
  1267. # Check if srctree at least is populated
  1268. self.assertTrue(len(os.listdir(tempdir)) > 0, 'srctree (%s) should be populated with new (%s) source code' % (tempdir, commit))
  1269. # Check new recipe file is present
  1270. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, os.path.basename(oldrecipefile))
  1271. self.assertExists(newrecipefile, 'Recipe file should exist after upgrade')
  1272. # Check devtool status and make sure recipe is present
  1273. result = runCmd('devtool status')
  1274. self.assertIn(recipe, result.output)
  1275. self.assertIn(tempdir, result.output)
  1276. # Check recipe got changed as expected
  1277. with open(oldrecipefile + '.upgraded', 'r') as f:
  1278. desiredlines = f.readlines()
  1279. with open(newrecipefile, 'r') as f:
  1280. newlines = f.readlines()
  1281. self.assertEqual(desiredlines, newlines)
  1282. # Check devtool reset recipe
  1283. result = runCmd('devtool reset %s -n' % recipe)
  1284. result = runCmd('devtool status')
  1285. self.assertNotIn(recipe, result.output)
  1286. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after resetting')
  1287. @OETestID(1352)
  1288. def test_devtool_layer_plugins(self):
  1289. """Test that devtool can use plugins from other layers.
  1290. This test executes the selftest-reverse command from meta-selftest."""
  1291. self.track_for_cleanup(self.workspacedir)
  1292. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1293. s = "Microsoft Made No Profit From Anyone's Zunes Yo"
  1294. result = runCmd("devtool --quiet selftest-reverse \"%s\"" % s)
  1295. self.assertEqual(result.output, s[::-1])
  1296. def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
  1297. dstdir = basedstdir
  1298. self.assertExists(dstdir)
  1299. for p in paths:
  1300. dstdir = os.path.join(dstdir, p)
  1301. if not os.path.exists(dstdir):
  1302. os.makedirs(dstdir)
  1303. self.track_for_cleanup(dstdir)
  1304. dstfile = os.path.join(dstdir, os.path.basename(srcfile))
  1305. if srcfile != dstfile:
  1306. shutil.copy(srcfile, dstfile)
  1307. self.track_for_cleanup(dstfile)
  1308. @OETestID(1625)
  1309. def test_devtool_load_plugin(self):
  1310. """Test that devtool loads only the first found plugin in BBPATH."""
  1311. self.track_for_cleanup(self.workspacedir)
  1312. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1313. devtool = runCmd("which devtool")
  1314. fromname = runCmd("devtool --quiet pluginfile")
  1315. srcfile = fromname.output
  1316. bbpath = get_bb_var('BBPATH')
  1317. searchpath = bbpath.split(':') + [os.path.dirname(devtool.output)]
  1318. plugincontent = []
  1319. with open(srcfile) as fh:
  1320. plugincontent = fh.readlines()
  1321. try:
  1322. self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
  1323. for path in searchpath:
  1324. self._copy_file_with_cleanup(srcfile, path, 'lib', 'devtool')
  1325. result = runCmd("devtool --quiet count")
  1326. self.assertEqual(result.output, '1')
  1327. result = runCmd("devtool --quiet multiloaded")
  1328. self.assertEqual(result.output, "no")
  1329. for path in searchpath:
  1330. result = runCmd("devtool --quiet bbdir")
  1331. self.assertEqual(result.output, path)
  1332. os.unlink(os.path.join(result.output, 'lib', 'devtool', 'bbpath.py'))
  1333. finally:
  1334. with open(srcfile, 'w') as fh:
  1335. fh.writelines(plugincontent)
  1336. def _setup_test_devtool_finish_upgrade(self):
  1337. # Check preconditions
  1338. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1339. self.track_for_cleanup(self.workspacedir)
  1340. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1341. # Use a "real" recipe from meta-selftest
  1342. recipe = 'devtool-upgrade-test1'
  1343. oldversion = '1.5.3'
  1344. newversion = '1.6.0'
  1345. oldrecipefile = get_bb_var('FILE', recipe)
  1346. recipedir = os.path.dirname(oldrecipefile)
  1347. result = runCmd('git status --porcelain .', cwd=recipedir)
  1348. if result.output.strip():
  1349. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  1350. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1351. self.track_for_cleanup(tempdir)
  1352. # Check that recipe is not already under devtool control
  1353. result = runCmd('devtool status')
  1354. self.assertNotIn(recipe, result.output)
  1355. # Do the upgrade
  1356. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, newversion))
  1357. # Check devtool status and make sure recipe is present
  1358. result = runCmd('devtool status')
  1359. self.assertIn(recipe, result.output)
  1360. self.assertIn(tempdir, result.output)
  1361. # Make a change to the source
  1362. result = runCmd('sed -i \'/^#include "pv.h"/a \\/* Here is a new comment *\\/\' src/pv/number.c', cwd=tempdir)
  1363. result = runCmd('git status --porcelain', cwd=tempdir)
  1364. self.assertIn('M src/pv/number.c', result.output)
  1365. result = runCmd('git commit src/pv/number.c -m "Add a comment to the code"', cwd=tempdir)
  1366. # Check if patch is there
  1367. recipedir = os.path.dirname(oldrecipefile)
  1368. olddir = os.path.join(recipedir, recipe + '-' + oldversion)
  1369. patchfn = '0001-Add-a-note-line-to-the-quick-reference.patch'
  1370. self.assertExists(os.path.join(olddir, patchfn), 'Original patch file does not exist')
  1371. return recipe, oldrecipefile, recipedir, olddir, newversion, patchfn
  1372. @OETestID(1623)
  1373. def test_devtool_finish_upgrade_origlayer(self):
  1374. recipe, oldrecipefile, recipedir, olddir, newversion, patchfn = self._setup_test_devtool_finish_upgrade()
  1375. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1376. self.assertIn('/meta-selftest/', recipedir)
  1377. # Try finish to the original layer
  1378. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1379. result = runCmd('devtool finish %s meta-selftest' % recipe)
  1380. result = runCmd('devtool status')
  1381. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1382. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  1383. self.assertNotExists(oldrecipefile, 'Old recipe file should have been deleted but wasn\'t')
  1384. self.assertNotExists(os.path.join(olddir, patchfn), 'Old patch file should have been deleted but wasn\'t')
  1385. newrecipefile = os.path.join(recipedir, '%s_%s.bb' % (recipe, newversion))
  1386. newdir = os.path.join(recipedir, recipe + '-' + newversion)
  1387. self.assertExists(newrecipefile, 'New recipe file should have been copied into existing layer but wasn\'t')
  1388. self.assertExists(os.path.join(newdir, patchfn), 'Patch file should have been copied into new directory but wasn\'t')
  1389. self.assertExists(os.path.join(newdir, '0002-Add-a-comment-to-the-code.patch'), 'New patch file should have been created but wasn\'t')
  1390. @OETestID(1624)
  1391. def test_devtool_finish_upgrade_otherlayer(self):
  1392. recipe, oldrecipefile, recipedir, olddir, newversion, patchfn = self._setup_test_devtool_finish_upgrade()
  1393. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1394. self.assertIn('/meta-selftest/', recipedir)
  1395. # Try finish to a different layer - should create a bbappend
  1396. # This cleanup isn't strictly necessary but do it anyway just in case it goes wrong and writes to here
  1397. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1398. oe_core_dir = os.path.join(get_bb_var('COREBASE'), 'meta')
  1399. newrecipedir = os.path.join(oe_core_dir, 'recipes-test', 'devtool')
  1400. newrecipefile = os.path.join(newrecipedir, '%s_%s.bb' % (recipe, newversion))
  1401. self.track_for_cleanup(newrecipedir)
  1402. result = runCmd('devtool finish %s oe-core' % recipe)
  1403. result = runCmd('devtool status')
  1404. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1405. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  1406. self.assertExists(oldrecipefile, 'Old recipe file should not have been deleted')
  1407. self.assertExists(os.path.join(olddir, patchfn), 'Old patch file should not have been deleted')
  1408. newdir = os.path.join(newrecipedir, recipe + '-' + newversion)
  1409. self.assertExists(newrecipefile, 'New recipe file should have been copied into existing layer but wasn\'t')
  1410. self.assertExists(os.path.join(newdir, patchfn), 'Patch file should have been copied into new directory but wasn\'t')
  1411. self.assertExists(os.path.join(newdir, '0002-Add-a-comment-to-the-code.patch'), 'New patch file should have been created but wasn\'t')
  1412. def _setup_test_devtool_finish_modify(self):
  1413. # Check preconditions
  1414. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1415. # Try modifying a recipe
  1416. self.track_for_cleanup(self.workspacedir)
  1417. recipe = 'mdadm'
  1418. oldrecipefile = get_bb_var('FILE', recipe)
  1419. recipedir = os.path.dirname(oldrecipefile)
  1420. result = runCmd('git status --porcelain .', cwd=recipedir)
  1421. if result.output.strip():
  1422. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  1423. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1424. self.track_for_cleanup(tempdir)
  1425. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1426. result = runCmd('devtool modify %s %s' % (recipe, tempdir))
  1427. self.assertExists(os.path.join(tempdir, 'Makefile'), 'Extracted source could not be found')
  1428. # Test devtool status
  1429. result = runCmd('devtool status')
  1430. self.assertIn(recipe, result.output)
  1431. self.assertIn(tempdir, result.output)
  1432. # Make a change to the source
  1433. result = runCmd('sed -i \'/^#include "mdadm.h"/a \\/* Here is a new comment *\\/\' maps.c', cwd=tempdir)
  1434. result = runCmd('git status --porcelain', cwd=tempdir)
  1435. self.assertIn('M maps.c', result.output)
  1436. result = runCmd('git commit maps.c -m "Add a comment to the code"', cwd=tempdir)
  1437. for entry in os.listdir(recipedir):
  1438. filesdir = os.path.join(recipedir, entry)
  1439. if os.path.isdir(filesdir):
  1440. break
  1441. else:
  1442. self.fail('Unable to find recipe files directory for %s' % recipe)
  1443. return recipe, oldrecipefile, recipedir, filesdir
  1444. @OETestID(1621)
  1445. def test_devtool_finish_modify_origlayer(self):
  1446. recipe, oldrecipefile, recipedir, filesdir = self._setup_test_devtool_finish_modify()
  1447. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1448. self.assertIn('/meta/', recipedir)
  1449. # Try finish to the original layer
  1450. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1451. result = runCmd('devtool finish %s meta' % recipe)
  1452. result = runCmd('devtool status')
  1453. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1454. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  1455. expected_status = [(' M', '.*/%s$' % os.path.basename(oldrecipefile)),
  1456. ('??', '.*/.*-Add-a-comment-to-the-code.patch$')]
  1457. self._check_repo_status(recipedir, expected_status)
  1458. @OETestID(1622)
  1459. def test_devtool_finish_modify_otherlayer(self):
  1460. recipe, oldrecipefile, recipedir, filesdir = self._setup_test_devtool_finish_modify()
  1461. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  1462. self.assertIn('/meta/', recipedir)
  1463. relpth = os.path.relpath(recipedir, os.path.join(get_bb_var('COREBASE'), 'meta'))
  1464. appenddir = os.path.join(get_test_layer(), relpth)
  1465. self.track_for_cleanup(appenddir)
  1466. # Try finish to the original layer
  1467. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1468. result = runCmd('devtool finish %s meta-selftest' % recipe)
  1469. result = runCmd('devtool status')
  1470. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1471. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  1472. result = runCmd('git status --porcelain .', cwd=recipedir)
  1473. if result.output.strip():
  1474. self.fail('Recipe directory for %s contains the following unexpected changes after finish:\n%s' % (recipe, result.output.strip()))
  1475. recipefn = os.path.splitext(os.path.basename(oldrecipefile))[0]
  1476. recipefn = recipefn.split('_')[0] + '_%'
  1477. appendfile = os.path.join(appenddir, recipefn + '.bbappend')
  1478. self.assertExists(appendfile, 'bbappend %s should have been created but wasn\'t' % appendfile)
  1479. newdir = os.path.join(appenddir, recipe)
  1480. files = os.listdir(newdir)
  1481. foundpatch = None
  1482. for fn in files:
  1483. if fnmatch.fnmatch(fn, '*-Add-a-comment-to-the-code.patch'):
  1484. foundpatch = fn
  1485. if not foundpatch:
  1486. self.fail('No patch file created next to bbappend')
  1487. files.remove(foundpatch)
  1488. if files:
  1489. self.fail('Unexpected file(s) copied next to bbappend: %s' % ', '.join(files))
  1490. @OETestID(1626)
  1491. def test_devtool_rename(self):
  1492. # Check preconditions
  1493. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1494. self.track_for_cleanup(self.workspacedir)
  1495. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1496. # First run devtool add
  1497. # We already have this recipe in OE-Core, but that doesn't matter
  1498. recipename = 'i2c-tools'
  1499. recipever = '3.1.2'
  1500. recipefile = os.path.join(self.workspacedir, 'recipes', recipename, '%s_%s.bb' % (recipename, recipever))
  1501. url = 'http://downloads.yoctoproject.org/mirror/sources/i2c-tools-%s.tar.bz2' % recipever
  1502. def add_recipe():
  1503. result = runCmd('devtool add %s' % url)
  1504. self.assertExists(recipefile, 'Expected recipe file not created')
  1505. self.assertExists(os.path.join(self.workspacedir, 'sources', recipename), 'Source directory not created')
  1506. checkvars = {}
  1507. checkvars['S'] = None
  1508. checkvars['SRC_URI'] = url.replace(recipever, '${PV}')
  1509. self._test_recipe_contents(recipefile, checkvars, [])
  1510. add_recipe()
  1511. # Now rename it - change both name and version
  1512. newrecipename = 'mynewrecipe'
  1513. newrecipever = '456'
  1514. newrecipefile = os.path.join(self.workspacedir, 'recipes', newrecipename, '%s_%s.bb' % (newrecipename, newrecipever))
  1515. result = runCmd('devtool rename %s %s -V %s' % (recipename, newrecipename, newrecipever))
  1516. self.assertExists(newrecipefile, 'Recipe file not renamed')
  1517. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipename), 'Old recipe directory still exists')
  1518. newsrctree = os.path.join(self.workspacedir, 'sources', newrecipename)
  1519. self.assertExists(newsrctree, 'Source directory not renamed')
  1520. checkvars = {}
  1521. checkvars['S'] = '${WORKDIR}/%s-%s' % (recipename, recipever)
  1522. checkvars['SRC_URI'] = url
  1523. self._test_recipe_contents(newrecipefile, checkvars, [])
  1524. # Try again - change just name this time
  1525. result = runCmd('devtool reset -n %s' % newrecipename)
  1526. shutil.rmtree(newsrctree)
  1527. add_recipe()
  1528. newrecipefile = os.path.join(self.workspacedir, 'recipes', newrecipename, '%s_%s.bb' % (newrecipename, recipever))
  1529. result = runCmd('devtool rename %s %s' % (recipename, newrecipename))
  1530. self.assertExists(newrecipefile, 'Recipe file not renamed')
  1531. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipename), 'Old recipe directory still exists')
  1532. self.assertExists(os.path.join(self.workspacedir, 'sources', newrecipename), 'Source directory not renamed')
  1533. checkvars = {}
  1534. checkvars['S'] = '${WORKDIR}/%s-${PV}' % recipename
  1535. checkvars['SRC_URI'] = url.replace(recipever, '${PV}')
  1536. self._test_recipe_contents(newrecipefile, checkvars, [])
  1537. # Try again - change just version this time
  1538. result = runCmd('devtool reset -n %s' % newrecipename)
  1539. shutil.rmtree(newsrctree)
  1540. add_recipe()
  1541. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipename, '%s_%s.bb' % (recipename, newrecipever))
  1542. result = runCmd('devtool rename %s -V %s' % (recipename, newrecipever))
  1543. self.assertExists(newrecipefile, 'Recipe file not renamed')
  1544. self.assertExists(os.path.join(self.workspacedir, 'sources', recipename), 'Source directory no longer exists')
  1545. checkvars = {}
  1546. checkvars['S'] = '${WORKDIR}/${BPN}-%s' % recipever
  1547. checkvars['SRC_URI'] = url
  1548. self._test_recipe_contents(newrecipefile, checkvars, [])
  1549. @OETestID(1577)
  1550. def test_devtool_virtual_kernel_modify(self):
  1551. """
  1552. Summary: The purpose of this test case is to verify that
  1553. devtool modify works correctly when building
  1554. the kernel.
  1555. Dependencies: NA
  1556. Steps: 1. Build kernel with bitbake.
  1557. 2. Save the config file generated.
  1558. 3. Clean the environment.
  1559. 4. Use `devtool modify virtual/kernel` to validate following:
  1560. 4.1 The source is checked out correctly.
  1561. 4.2 The resulting configuration is the same as
  1562. what was get on step 2.
  1563. 4.3 The Kernel can be build correctly.
  1564. 4.4 Changes made on the source are reflected on the
  1565. subsequent builds.
  1566. 4.5 Changes on the configuration are reflected on the
  1567. subsequent builds
  1568. Expected: devtool modify is able to checkout the source of the kernel
  1569. and modification to the source and configurations are reflected
  1570. when building the kernel.
  1571. """
  1572. kernel_provider = get_bb_var('PREFERRED_PROVIDER_virtual/kernel')
  1573. # Clean up the enviroment
  1574. bitbake('%s -c clean' % kernel_provider)
  1575. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1576. tempdir_cfg = tempfile.mkdtemp(prefix='config_qa')
  1577. self.track_for_cleanup(tempdir)
  1578. self.track_for_cleanup(tempdir_cfg)
  1579. self.track_for_cleanup(self.workspacedir)
  1580. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1581. self.add_command_to_tearDown('bitbake -c clean %s' % kernel_provider)
  1582. #Step 1
  1583. #Here is just generated the config file instead of all the kernel to optimize the
  1584. #time of executing this test case.
  1585. bitbake('%s -c configure' % kernel_provider)
  1586. bbconfig = os.path.join(get_bb_var('B', kernel_provider),'.config')
  1587. #Step 2
  1588. runCmd('cp %s %s' % (bbconfig, tempdir_cfg))
  1589. self.assertExists(os.path.join(tempdir_cfg, '.config'), 'Could not copy .config file from kernel')
  1590. tmpconfig = os.path.join(tempdir_cfg, '.config')
  1591. #Step 3
  1592. bitbake('%s -c clean' % kernel_provider)
  1593. #Step 4.1
  1594. runCmd('devtool modify virtual/kernel -x %s' % tempdir)
  1595. self.assertExists(os.path.join(tempdir, 'Makefile'), 'Extracted source could not be found')
  1596. #Step 4.2
  1597. configfile = os.path.join(tempdir,'.config')
  1598. diff = runCmd('diff %s %s' % (tmpconfig, configfile))
  1599. self.assertEqual(0,diff.status,'Kernel .config file is not the same using bitbake and devtool')
  1600. #Step 4.3
  1601. #NOTE: virtual/kernel is mapped to kernel_provider
  1602. result = runCmd('devtool build %s' % kernel_provider)
  1603. self.assertEqual(0,result.status,'Cannot build kernel using `devtool build`')
  1604. kernelfile = os.path.join(get_bb_var('KBUILD_OUTPUT', kernel_provider), 'vmlinux')
  1605. self.assertExists(kernelfile, 'Kernel was not build correctly')
  1606. #Modify the kernel source
  1607. modfile = os.path.join(tempdir,'arch/x86/boot/header.S')
  1608. modstring = "Use a boot loader. Devtool testing."
  1609. modapplied = runCmd("sed -i 's/Use a boot loader./%s/' %s" % (modstring, modfile))
  1610. self.assertEqual(0,modapplied.status,'Modification to %s on kernel source failed' % modfile)
  1611. #Modify the configuration
  1612. codeconfigfile = os.path.join(tempdir,'.config.new')
  1613. modconfopt = "CONFIG_SG_POOL=n"
  1614. modconf = runCmd("sed -i 's/CONFIG_SG_POOL=y/%s/' %s" % (modconfopt, codeconfigfile))
  1615. self.assertEqual(0,modconf.status,'Modification to %s failed' % codeconfigfile)
  1616. #Build again kernel with devtool
  1617. rebuild = runCmd('devtool build %s' % kernel_provider)
  1618. self.assertEqual(0,rebuild.status,'Fail to build kernel after modification of source and config')
  1619. #Step 4.4
  1620. bzimagename = 'bzImage-' + get_bb_var('KERNEL_VERSION_NAME', kernel_provider)
  1621. bzimagefile = os.path.join(get_bb_var('D', kernel_provider),'boot', bzimagename)
  1622. checkmodcode = runCmd("grep '%s' %s" % (modstring, bzimagefile))
  1623. self.assertEqual(0,checkmodcode.status,'Modification on kernel source failed')
  1624. #Step 4.5
  1625. checkmodconfg = runCmd("grep %s %s" % (modconfopt, codeconfigfile))
  1626. self.assertEqual(0,checkmodconfg.status,'Modification to configuration file failed')