devtool.py 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import errno
  7. import os
  8. import re
  9. import shutil
  10. import tempfile
  11. import glob
  12. import fnmatch
  13. import unittest
  14. import json
  15. from oeqa.selftest.case import OESelftestTestCase
  16. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer
  17. from oeqa.utils.commands import get_bb_vars, runqemu, get_test_layer
  18. from oeqa.core.decorator import OETestTag
  19. oldmetapath = None
  20. def setUpModule():
  21. import bb.utils
  22. global templayerdir
  23. templayerdir = tempfile.mkdtemp(prefix='devtoolqa')
  24. corecopydir = os.path.join(templayerdir, 'core-copy')
  25. bblayers_conf = os.path.join(os.environ['BUILDDIR'], 'conf', 'bblayers.conf')
  26. edited_layers = []
  27. # make sure user doesn't have a local workspace
  28. result = runCmd('bitbake-layers show-layers')
  29. assert "workspacelayer" not in result.output, "Devtool test suite cannot be run with a local workspace directory"
  30. # We need to take a copy of the meta layer so we can modify it and not
  31. # have any races against other tests that might be running in parallel
  32. # however things like COREBASE mean that you can't just copy meta, you
  33. # need the whole repository.
  34. def bblayers_edit_cb(layerpath, canonical_layerpath):
  35. global oldmetapath
  36. if not canonical_layerpath.endswith('/'):
  37. # This helps us match exactly when we're using this path later
  38. canonical_layerpath += '/'
  39. if not edited_layers and canonical_layerpath.endswith('/meta/'):
  40. canonical_layerpath = os.path.realpath(canonical_layerpath) + '/'
  41. edited_layers.append(layerpath)
  42. oldmetapath = os.path.realpath(layerpath)
  43. # when downloading poky from tar.gz some tests will be skipped (BUG 12389)
  44. try:
  45. runCmd('git rev-parse --is-inside-work-tree', cwd=canonical_layerpath)
  46. except:
  47. raise unittest.SkipTest("devtool tests require folder to be a git repo")
  48. result = runCmd('git rev-parse --show-toplevel', cwd=canonical_layerpath)
  49. oldreporoot = result.output.rstrip()
  50. newmetapath = os.path.join(corecopydir, os.path.relpath(oldmetapath, oldreporoot))
  51. runCmd('git clone file://%s %s' % (oldreporoot, corecopydir), cwd=templayerdir)
  52. # Now we need to copy any modified files
  53. # You might ask "why not just copy the entire tree instead of
  54. # cloning and doing this?" - well, the problem with that is
  55. # TMPDIR or an equally large subdirectory might exist
  56. # under COREBASE and we don't want to copy that, so we have
  57. # to be selective.
  58. result = runCmd('git status --porcelain', cwd=oldreporoot)
  59. for line in result.output.splitlines():
  60. if line.startswith(' M ') or line.startswith('?? '):
  61. relpth = line.split()[1]
  62. pth = os.path.join(oldreporoot, relpth)
  63. if pth.startswith(canonical_layerpath):
  64. if relpth.endswith('/'):
  65. destdir = os.path.join(corecopydir, relpth)
  66. # avoid race condition by not copying .pyc files YPBZ#13421,13803
  67. shutil.copytree(pth, destdir, ignore=shutil.ignore_patterns('*.pyc', '__pycache__'))
  68. else:
  69. destdir = os.path.join(corecopydir, os.path.dirname(relpth))
  70. bb.utils.mkdirhier(destdir)
  71. shutil.copy2(pth, destdir)
  72. return newmetapath
  73. else:
  74. return layerpath
  75. bb.utils.edit_bblayers_conf(bblayers_conf, None, None, bblayers_edit_cb)
  76. def tearDownModule():
  77. if oldmetapath:
  78. edited_layers = []
  79. def bblayers_edit_cb(layerpath, canonical_layerpath):
  80. if not edited_layers and canonical_layerpath.endswith('/meta'):
  81. edited_layers.append(layerpath)
  82. return oldmetapath
  83. else:
  84. return layerpath
  85. bblayers_conf = os.path.join(os.environ['BUILDDIR'], 'conf', 'bblayers.conf')
  86. bb.utils.edit_bblayers_conf(bblayers_conf, None, None, bblayers_edit_cb)
  87. shutil.rmtree(templayerdir)
  88. class DevtoolTestCase(OESelftestTestCase):
  89. def setUp(self):
  90. """Test case setup function"""
  91. super(DevtoolTestCase, self).setUp()
  92. self.workspacedir = os.path.join(self.builddir, 'workspace')
  93. self.assertTrue(not os.path.exists(self.workspacedir),
  94. 'This test cannot be run with a workspace directory '
  95. 'under the build directory')
  96. def _check_src_repo(self, repo_dir):
  97. """Check srctree git repository"""
  98. self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')),
  99. 'git repository for external source tree not found')
  100. result = runCmd('git status --porcelain', cwd=repo_dir)
  101. self.assertEqual(result.output.strip(), "",
  102. 'Created git repo is not clean')
  103. result = runCmd('git symbolic-ref HEAD', cwd=repo_dir)
  104. self.assertEqual(result.output.strip(), "refs/heads/devtool",
  105. 'Wrong branch in git repo')
  106. def _check_repo_status(self, repo_dir, expected_status):
  107. """Check the worktree status of a repository"""
  108. result = runCmd('git status . --porcelain',
  109. cwd=repo_dir)
  110. for line in result.output.splitlines():
  111. for ind, (f_status, fn_re) in enumerate(expected_status):
  112. if re.match(fn_re, line[3:]):
  113. if f_status != line[:2]:
  114. self.fail('Unexpected status in line: %s' % line)
  115. expected_status.pop(ind)
  116. break
  117. else:
  118. self.fail('Unexpected modified file in line: %s' % line)
  119. if expected_status:
  120. self.fail('Missing file changes: %s' % expected_status)
  121. def _test_recipe_contents(self, recipefile, checkvars, checkinherits):
  122. with open(recipefile, 'r') as f:
  123. invar = None
  124. invalue = None
  125. inherits = set()
  126. for line in f:
  127. var = None
  128. if invar:
  129. value = line.strip().strip('"')
  130. if value.endswith('\\'):
  131. invalue += ' ' + value[:-1].strip()
  132. continue
  133. else:
  134. invalue += ' ' + value.strip()
  135. var = invar
  136. value = invalue
  137. invar = None
  138. elif '=' in line:
  139. splitline = line.split('=', 1)
  140. var = splitline[0].rstrip()
  141. value = splitline[1].strip().strip('"')
  142. if value.endswith('\\'):
  143. invalue = value[:-1].strip()
  144. invar = var
  145. continue
  146. elif line.startswith('inherit '):
  147. inherits.update(line.split()[1:])
  148. if var and var in checkvars:
  149. needvalue = checkvars.pop(var)
  150. if needvalue is None:
  151. self.fail('Variable %s should not appear in recipe, but value is being set to "%s"' % (var, value))
  152. if isinstance(needvalue, set):
  153. if var == 'LICENSE':
  154. value = set(value.split(' & '))
  155. else:
  156. value = set(value.split())
  157. self.assertEqual(value, needvalue, 'values for %s do not match' % var)
  158. missingvars = {}
  159. for var, value in checkvars.items():
  160. if value is not None:
  161. missingvars[var] = value
  162. self.assertEqual(missingvars, {}, 'Some expected variables not found in recipe: %s' % checkvars)
  163. for inherit in checkinherits:
  164. self.assertIn(inherit, inherits, 'Missing inherit of %s' % inherit)
  165. def _check_bbappend(self, testrecipe, recipefile, appenddir):
  166. result = runCmd('bitbake-layers show-appends', cwd=self.builddir)
  167. resultlines = result.output.splitlines()
  168. inrecipe = False
  169. bbappends = []
  170. bbappendfile = None
  171. for line in resultlines:
  172. if inrecipe:
  173. if line.startswith(' '):
  174. bbappends.append(line.strip())
  175. else:
  176. break
  177. elif line == '%s:' % os.path.basename(recipefile):
  178. inrecipe = True
  179. self.assertLessEqual(len(bbappends), 2, '%s recipe is being bbappended by another layer - bbappends found:\n %s' % (testrecipe, '\n '.join(bbappends)))
  180. for bbappend in bbappends:
  181. if bbappend.startswith(appenddir):
  182. bbappendfile = bbappend
  183. break
  184. else:
  185. self.fail('bbappend for recipe %s does not seem to be created in test layer' % testrecipe)
  186. return bbappendfile
  187. def _create_temp_layer(self, templayerdir, addlayer, templayername, priority=999, recipepathspec='recipes-*/*'):
  188. create_temp_layer(templayerdir, templayername, priority, recipepathspec)
  189. if addlayer:
  190. self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
  191. result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
  192. def _process_ls_output(self, output):
  193. """
  194. Convert ls -l output to a format we can reasonably compare from one context
  195. to another (e.g. from host to target)
  196. """
  197. filelist = []
  198. for line in output.splitlines():
  199. splitline = line.split()
  200. if len(splitline) < 8:
  201. self.fail('_process_ls_output: invalid output line: %s' % line)
  202. # Remove trailing . on perms
  203. splitline[0] = splitline[0].rstrip('.')
  204. # Remove leading . on paths
  205. splitline[-1] = splitline[-1].lstrip('.')
  206. # Drop fields we don't want to compare
  207. del splitline[7]
  208. del splitline[6]
  209. del splitline[5]
  210. del splitline[4]
  211. del splitline[1]
  212. filelist.append(' '.join(splitline))
  213. return filelist
  214. def _check_diff(self, diffoutput, addlines, removelines):
  215. """Check output from 'git diff' matches expectation"""
  216. remaining_addlines = addlines[:]
  217. remaining_removelines = removelines[:]
  218. for line in diffoutput.splitlines():
  219. if line.startswith('+++') or line.startswith('---'):
  220. continue
  221. elif line.startswith('+'):
  222. matched = False
  223. for item in addlines:
  224. if re.match(item, line[1:].strip()):
  225. matched = True
  226. remaining_addlines.remove(item)
  227. break
  228. self.assertTrue(matched, 'Unexpected diff add line: %s' % line)
  229. elif line.startswith('-'):
  230. matched = False
  231. for item in removelines:
  232. if re.match(item, line[1:].strip()):
  233. matched = True
  234. remaining_removelines.remove(item)
  235. break
  236. self.assertTrue(matched, 'Unexpected diff remove line: %s' % line)
  237. if remaining_addlines:
  238. self.fail('Expected added lines not found: %s' % remaining_addlines)
  239. if remaining_removelines:
  240. self.fail('Expected removed lines not found: %s' % remaining_removelines)
  241. def _check_runqemu_prerequisites(self):
  242. """Check runqemu is available
  243. Whilst some tests would seemingly be better placed as a runtime test,
  244. unfortunately the runtime tests run under bitbake and you can't run
  245. devtool within bitbake (since devtool needs to run bitbake itself).
  246. Additionally we are testing build-time functionality as well, so
  247. really this has to be done as an oe-selftest test.
  248. """
  249. machine = get_bb_var('MACHINE')
  250. if not machine.startswith('qemu'):
  251. self.skipTest('This test only works with qemu machines')
  252. if not os.path.exists('/etc/runqemu-nosudo'):
  253. self.skipTest('You must set up tap devices with scripts/runqemu-gen-tapdevs before running this test')
  254. result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ip tuntap show', ignore_status=True)
  255. if result.status != 0:
  256. result = runCmd('PATH="$PATH:/sbin:/usr/sbin" ifconfig -a', ignore_status=True)
  257. if result.status != 0:
  258. self.skipTest('Failed to determine if tap devices exist with ifconfig or ip: %s' % result.output)
  259. for line in result.output.splitlines():
  260. if line.startswith('tap'):
  261. break
  262. else:
  263. self.skipTest('No tap devices found - you must set up tap devices with scripts/runqemu-gen-tapdevs before running this test')
  264. def _test_devtool_add_git_url(self, git_url, version, pn, resulting_src_uri, srcrev=None):
  265. self.track_for_cleanup(self.workspacedir)
  266. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  267. command = 'devtool add --version %s %s %s' % (version, pn, git_url)
  268. if srcrev :
  269. command += ' --srcrev %s' %srcrev
  270. result = runCmd(command)
  271. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  272. # Check the recipe name is correct
  273. recipefile = get_bb_var('FILE', pn)
  274. self.assertIn('%s_git.bb' % pn, recipefile, 'Recipe file incorrectly named')
  275. self.assertIn(recipefile, result.output)
  276. # Test devtool status
  277. result = runCmd('devtool status')
  278. self.assertIn(pn, result.output)
  279. self.assertIn(recipefile, result.output)
  280. checkvars = {}
  281. checkvars['SRC_URI'] = resulting_src_uri
  282. self._test_recipe_contents(recipefile, checkvars, [])
  283. class DevtoolBase(DevtoolTestCase):
  284. @classmethod
  285. def setUpClass(cls):
  286. super(DevtoolBase, cls).setUpClass()
  287. bb_vars = get_bb_vars(['TOPDIR', 'SSTATE_DIR'])
  288. cls.original_sstate = bb_vars['SSTATE_DIR']
  289. cls.devtool_sstate = os.path.join(bb_vars['TOPDIR'], 'sstate_devtool')
  290. cls.sstate_conf = 'SSTATE_DIR = "%s"\n' % cls.devtool_sstate
  291. cls.sstate_conf += ('SSTATE_MIRRORS += "file://.* file:///%s/PATH"\n'
  292. % cls.original_sstate)
  293. cls.sstate_conf += ('BB_HASHSERVE_UPSTREAM = "hashserv.yocto.io:8687"\n')
  294. @classmethod
  295. def tearDownClass(cls):
  296. cls.logger.debug('Deleting devtool sstate cache on %s' % cls.devtool_sstate)
  297. runCmd('rm -rf %s' % cls.devtool_sstate)
  298. super(DevtoolBase, cls).tearDownClass()
  299. def setUp(self):
  300. """Test case setup function"""
  301. super(DevtoolBase, self).setUp()
  302. self.append_config(self.sstate_conf)
  303. class DevtoolTests(DevtoolBase):
  304. def test_create_workspace(self):
  305. # Check preconditions
  306. result = runCmd('bitbake-layers show-layers')
  307. self.assertTrue('\nworkspace' not in result.output, 'This test cannot be run with a workspace layer in bblayers.conf')
  308. # remove conf/devtool.conf to avoid it corrupting tests
  309. devtoolconf = os.path.join(self.builddir, 'conf', 'devtool.conf')
  310. self.track_for_cleanup(devtoolconf)
  311. # Try creating a workspace layer with a specific path
  312. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  313. self.track_for_cleanup(tempdir)
  314. result = runCmd('devtool create-workspace %s' % tempdir)
  315. self.assertTrue(os.path.isfile(os.path.join(tempdir, 'conf', 'layer.conf')), msg = "No workspace created. devtool output: %s " % result.output)
  316. result = runCmd('bitbake-layers show-layers')
  317. self.assertIn(tempdir, result.output)
  318. # Try creating a workspace layer with the default path
  319. self.track_for_cleanup(self.workspacedir)
  320. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  321. result = runCmd('devtool create-workspace')
  322. self.assertTrue(os.path.isfile(os.path.join(self.workspacedir, 'conf', 'layer.conf')), msg = "No workspace created. devtool output: %s " % result.output)
  323. result = runCmd('bitbake-layers show-layers')
  324. self.assertNotIn(tempdir, result.output)
  325. self.assertIn(self.workspacedir, result.output)
  326. class DevtoolAddTests(DevtoolBase):
  327. def test_devtool_add(self):
  328. # Fetch source
  329. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  330. self.track_for_cleanup(tempdir)
  331. pn = 'pv'
  332. pv = '1.5.3'
  333. url = 'http://downloads.yoctoproject.org/mirror/sources/pv-1.5.3.tar.bz2'
  334. result = runCmd('wget %s' % url, cwd=tempdir)
  335. result = runCmd('tar xfv %s' % os.path.basename(url), cwd=tempdir)
  336. srcdir = os.path.join(tempdir, '%s-%s' % (pn, pv))
  337. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure')), 'Unable to find configure script in source directory')
  338. # Test devtool add
  339. self.track_for_cleanup(self.workspacedir)
  340. self.add_command_to_tearDown('bitbake -c cleansstate %s' % pn)
  341. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  342. result = runCmd('devtool add %s %s' % (pn, srcdir))
  343. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  344. # Test devtool status
  345. result = runCmd('devtool status')
  346. recipepath = '%s/recipes/%s/%s_%s.bb' % (self.workspacedir, pn, pn, pv)
  347. self.assertIn(recipepath, result.output)
  348. self.assertIn(srcdir, result.output)
  349. # Test devtool find-recipe
  350. result = runCmd('devtool -q find-recipe %s' % pn)
  351. self.assertEqual(recipepath, result.output.strip())
  352. # Test devtool edit-recipe
  353. result = runCmd('VISUAL="echo 123" devtool -q edit-recipe %s' % pn)
  354. self.assertEqual('123 %s' % recipepath, result.output.strip())
  355. # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then)
  356. bitbake('%s -c cleansstate' % pn)
  357. # Test devtool build
  358. result = runCmd('devtool build %s' % pn)
  359. bb_vars = get_bb_vars(['D', 'bindir'], pn)
  360. installdir = bb_vars['D']
  361. self.assertTrue(installdir, 'Could not query installdir variable')
  362. bindir = bb_vars['bindir']
  363. self.assertTrue(bindir, 'Could not query bindir variable')
  364. if bindir[0] == '/':
  365. bindir = bindir[1:]
  366. self.assertTrue(os.path.isfile(os.path.join(installdir, bindir, 'pv')), 'pv binary not found in D')
  367. def test_devtool_add_binary(self):
  368. # Create a binary package containing a known test file
  369. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  370. self.track_for_cleanup(tempdir)
  371. pn = 'tst-bin'
  372. pv = '1.0'
  373. test_file_dir = "var/lib/%s/" % pn
  374. test_file_name = "test_file"
  375. test_file_content = "TEST CONTENT"
  376. test_file_package_root = os.path.join(tempdir, pn)
  377. test_file_dir_full = os.path.join(test_file_package_root, test_file_dir)
  378. bb.utils.mkdirhier(test_file_dir_full)
  379. with open(os.path.join(test_file_dir_full, test_file_name), "w") as f:
  380. f.write(test_file_content)
  381. bin_package_path = os.path.join(tempdir, "%s.tar.gz" % pn)
  382. runCmd("tar czf %s -C %s ." % (bin_package_path, test_file_package_root))
  383. # Test devtool add -b on the binary package
  384. self.track_for_cleanup(self.workspacedir)
  385. self.add_command_to_tearDown('bitbake -c cleansstate %s' % pn)
  386. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  387. result = runCmd('devtool add -b %s %s' % (pn, bin_package_path))
  388. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  389. # Build the resulting recipe
  390. result = runCmd('devtool build %s' % pn)
  391. installdir = get_bb_var('D', pn)
  392. self.assertTrue(installdir, 'Could not query installdir variable')
  393. # Check that a known file from the binary package has indeed been installed
  394. self.assertTrue(os.path.isfile(os.path.join(installdir, test_file_dir, test_file_name)), '%s not found in D' % test_file_name)
  395. def test_devtool_add_git_local(self):
  396. # We need dbus built so that DEPENDS recognition works
  397. bitbake('dbus')
  398. # Fetch source from a remote URL, but do it outside of devtool
  399. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  400. self.track_for_cleanup(tempdir)
  401. pn = 'dbus-wait'
  402. srcrev = '6cc6077a36fe2648a5f993fe7c16c9632f946517'
  403. # We choose an https:// git URL here to check rewriting the URL works
  404. url = 'https://git.yoctoproject.org/git/dbus-wait'
  405. # Force fetching to "noname" subdir so we verify we're picking up the name from autoconf
  406. # instead of the directory name
  407. result = runCmd('git clone %s noname' % url, cwd=tempdir)
  408. srcdir = os.path.join(tempdir, 'noname')
  409. result = runCmd('git reset --hard %s' % srcrev, cwd=srcdir)
  410. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure script in source directory')
  411. # Test devtool add
  412. self.track_for_cleanup(self.workspacedir)
  413. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  414. # Don't specify a name since we should be able to auto-detect it
  415. result = runCmd('devtool add %s' % srcdir)
  416. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  417. # Check the recipe name is correct
  418. recipefile = get_bb_var('FILE', pn)
  419. self.assertIn('%s_git.bb' % pn, recipefile, 'Recipe file incorrectly named')
  420. self.assertIn(recipefile, result.output)
  421. # Test devtool status
  422. result = runCmd('devtool status')
  423. self.assertIn(pn, result.output)
  424. self.assertIn(srcdir, result.output)
  425. self.assertIn(recipefile, result.output)
  426. checkvars = {}
  427. checkvars['LICENSE'] = 'GPL-2.0-only'
  428. checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
  429. checkvars['S'] = '${WORKDIR}/git'
  430. checkvars['PV'] = '0.1+git'
  431. checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/dbus-wait;protocol=https;branch=master'
  432. checkvars['SRCREV'] = srcrev
  433. checkvars['DEPENDS'] = set(['dbus'])
  434. self._test_recipe_contents(recipefile, checkvars, [])
  435. def test_devtool_add_git_style1(self):
  436. version = 'v3.1.0'
  437. pn = 'mbedtls'
  438. # this will trigger reformat_git_uri with branch parameter in url
  439. git_url = "'git://git@github.com/ARMmbed/mbedtls.git;branch=mbedtls-2.28;protocol=https'"
  440. resulting_src_uri = "git://git@github.com/ARMmbed/mbedtls.git;branch=mbedtls-2.28;protocol=https"
  441. self._test_devtool_add_git_url(git_url, version, pn, resulting_src_uri)
  442. def test_devtool_add_git_style2(self):
  443. version = 'v3.1.0'
  444. srcrev = 'v3.1.0'
  445. pn = 'mbedtls'
  446. # this will trigger reformat_git_uri with branch parameter in url
  447. git_url = "'git://git@github.com/ARMmbed/mbedtls.git;protocol=https'"
  448. resulting_src_uri = "git://git@github.com/ARMmbed/mbedtls.git;protocol=https;branch=master"
  449. self._test_devtool_add_git_url(git_url, version, pn, resulting_src_uri, srcrev)
  450. def test_devtool_add_library(self):
  451. # Fetch source
  452. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  453. self.track_for_cleanup(tempdir)
  454. version = '1.1'
  455. url = 'https://www.intra2net.com/en/developer/libftdi/download/libftdi1-%s.tar.bz2' % version
  456. result = runCmd('wget %s' % url, cwd=tempdir)
  457. result = runCmd('tar xfv libftdi1-%s.tar.bz2' % version, cwd=tempdir)
  458. srcdir = os.path.join(tempdir, 'libftdi1-%s' % version)
  459. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'CMakeLists.txt')), 'Unable to find CMakeLists.txt in source directory')
  460. # Test devtool add (and use -V so we test that too)
  461. self.track_for_cleanup(self.workspacedir)
  462. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  463. result = runCmd('devtool add libftdi %s -V %s' % (srcdir, version))
  464. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  465. # Test devtool status
  466. result = runCmd('devtool status')
  467. self.assertIn('libftdi', result.output)
  468. self.assertIn(srcdir, result.output)
  469. # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then)
  470. bitbake('libftdi -c cleansstate')
  471. # libftdi's python/CMakeLists.txt is a bit broken, so let's just disable it
  472. # There's also the matter of it installing cmake files to a path we don't
  473. # normally cover, which triggers the installed-vs-shipped QA test we have
  474. # within do_package
  475. recipefile = '%s/recipes/libftdi/libftdi_%s.bb' % (self.workspacedir, version)
  476. result = runCmd('recipetool setvar %s EXTRA_OECMAKE -- \'-DPYTHON_BINDINGS=OFF -DLIBFTDI_CMAKE_CONFIG_DIR=${datadir}/cmake/Modules\'' % recipefile)
  477. with open(recipefile, 'a') as f:
  478. f.write('\nFILES:${PN}-dev += "${datadir}/cmake/Modules"\n')
  479. # We don't have the ability to pick up this dependency automatically yet...
  480. f.write('\nDEPENDS += "libusb1"\n')
  481. f.write('\nTESTLIBOUTPUT = "${COMPONENTS_DIR}/${TUNE_PKGARCH}/${PN}/${libdir}"\n')
  482. # Test devtool build
  483. result = runCmd('devtool build libftdi')
  484. bb_vars = get_bb_vars(['TESTLIBOUTPUT', 'STAMP'], 'libftdi')
  485. staging_libdir = bb_vars['TESTLIBOUTPUT']
  486. self.assertTrue(staging_libdir, 'Could not query TESTLIBOUTPUT variable')
  487. 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)
  488. # Test devtool reset
  489. stampprefix = bb_vars['STAMP']
  490. result = runCmd('devtool reset libftdi')
  491. result = runCmd('devtool status')
  492. self.assertNotIn('libftdi', result.output)
  493. self.assertTrue(stampprefix, 'Unable to get STAMP value for recipe libftdi')
  494. matches = glob.glob(stampprefix + '*')
  495. self.assertFalse(matches, 'Stamp files exist for recipe libftdi that should have been cleaned')
  496. self.assertFalse(os.path.isfile(os.path.join(staging_libdir, 'libftdi1.so.2.1.0')), 'libftdi binary still found in STAGING_LIBDIR after cleaning')
  497. def test_devtool_add_fetch(self):
  498. # Fetch source
  499. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  500. self.track_for_cleanup(tempdir)
  501. testver = '0.23'
  502. url = 'https://files.pythonhosted.org/packages/c0/41/bae1254e0396c0cc8cf1751cb7d9afc90a602353695af5952530482c963f/MarkupSafe-%s.tar.gz' % testver
  503. testrecipe = 'python-markupsafe'
  504. srcdir = os.path.join(tempdir, testrecipe)
  505. # Test devtool add
  506. self.track_for_cleanup(self.workspacedir)
  507. self.add_command_to_tearDown('bitbake -c cleansstate %s' % testrecipe)
  508. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  509. result = runCmd('devtool add --no-pypi %s %s -f %s' % (testrecipe, srcdir, url))
  510. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. %s' % result.output)
  511. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory')
  512. self.assertTrue(os.path.isdir(os.path.join(srcdir, '.git')), 'git repository for external source tree was not created')
  513. # Test devtool status
  514. result = runCmd('devtool status')
  515. self.assertIn(testrecipe, result.output)
  516. self.assertIn(srcdir, result.output)
  517. # Check recipe
  518. recipefile = get_bb_var('FILE', testrecipe)
  519. self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named')
  520. checkvars = {}
  521. checkvars['S'] = '${WORKDIR}/MarkupSafe-${PV}'
  522. checkvars['SRC_URI'] = url.replace(testver, '${PV}')
  523. self._test_recipe_contents(recipefile, checkvars, [])
  524. # Try with version specified
  525. result = runCmd('devtool reset -n %s' % testrecipe)
  526. shutil.rmtree(srcdir)
  527. fakever = '1.9'
  528. result = runCmd('devtool add --no-pypi %s %s -f %s -V %s' % (testrecipe, srcdir, url, fakever))
  529. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory')
  530. # Test devtool status
  531. result = runCmd('devtool status')
  532. self.assertIn(testrecipe, result.output)
  533. self.assertIn(srcdir, result.output)
  534. # Check recipe
  535. recipefile = get_bb_var('FILE', testrecipe)
  536. self.assertIn('%s_%s.bb' % (testrecipe, fakever), recipefile, 'Recipe file incorrectly named')
  537. checkvars = {}
  538. checkvars['S'] = '${WORKDIR}/MarkupSafe-%s' % testver
  539. checkvars['SRC_URI'] = url
  540. self._test_recipe_contents(recipefile, checkvars, [])
  541. def test_devtool_add_fetch_git(self):
  542. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  543. self.track_for_cleanup(tempdir)
  544. url = 'gitsm://git.yoctoproject.org/mraa'
  545. url_branch = '%s;branch=master' % url
  546. checkrev = 'ae127b19a50aa54255e4330ccfdd9a5d058e581d'
  547. testrecipe = 'mraa'
  548. srcdir = os.path.join(tempdir, testrecipe)
  549. # Test devtool add
  550. self.track_for_cleanup(self.workspacedir)
  551. self.add_command_to_tearDown('bitbake -c cleansstate %s' % testrecipe)
  552. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  553. result = runCmd('devtool add %s %s -a -f %s' % (testrecipe, srcdir, url))
  554. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created: %s' % result.output)
  555. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'imraa', 'imraa.c')), 'Unable to find imraa/imraa.c in source directory')
  556. # Test devtool status
  557. result = runCmd('devtool status')
  558. self.assertIn(testrecipe, result.output)
  559. self.assertIn(srcdir, result.output)
  560. # Check recipe
  561. recipefile = get_bb_var('FILE', testrecipe)
  562. self.assertIn('_git.bb', recipefile, 'Recipe file incorrectly named')
  563. checkvars = {}
  564. checkvars['S'] = '${WORKDIR}/git'
  565. checkvars['PV'] = '1.0+git'
  566. checkvars['SRC_URI'] = url_branch
  567. checkvars['SRCREV'] = '${AUTOREV}'
  568. self._test_recipe_contents(recipefile, checkvars, [])
  569. # Try with revision and version specified
  570. result = runCmd('devtool reset -n %s' % testrecipe)
  571. shutil.rmtree(srcdir)
  572. url_rev = '%s;rev=%s' % (url, checkrev)
  573. result = runCmd('devtool add %s %s -f "%s" -V 1.5' % (testrecipe, srcdir, url_rev))
  574. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'imraa', 'imraa.c')), 'Unable to find imraa/imraa.c in source directory')
  575. # Test devtool status
  576. result = runCmd('devtool status')
  577. self.assertIn(testrecipe, result.output)
  578. self.assertIn(srcdir, result.output)
  579. # Check recipe
  580. recipefile = get_bb_var('FILE', testrecipe)
  581. self.assertIn('_git.bb', recipefile, 'Recipe file incorrectly named')
  582. checkvars = {}
  583. checkvars['S'] = '${WORKDIR}/git'
  584. checkvars['PV'] = '1.5+git'
  585. checkvars['SRC_URI'] = url_branch
  586. checkvars['SRCREV'] = checkrev
  587. self._test_recipe_contents(recipefile, checkvars, [])
  588. def test_devtool_add_fetch_simple(self):
  589. # Fetch source from a remote URL, auto-detecting name
  590. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  591. self.track_for_cleanup(tempdir)
  592. testver = '1.6.0'
  593. url = 'http://www.ivarch.com/programs/sources/pv-%s.tar.bz2' % testver
  594. testrecipe = 'pv'
  595. srcdir = os.path.join(self.workspacedir, 'sources', testrecipe)
  596. # Test devtool add
  597. self.track_for_cleanup(self.workspacedir)
  598. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  599. result = runCmd('devtool add %s' % url)
  600. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. %s' % result.output)
  601. self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure')), 'Unable to find configure script in source directory')
  602. self.assertTrue(os.path.isdir(os.path.join(srcdir, '.git')), 'git repository for external source tree was not created')
  603. # Test devtool status
  604. result = runCmd('devtool status')
  605. self.assertIn(testrecipe, result.output)
  606. self.assertIn(srcdir, result.output)
  607. # Check recipedevtool add
  608. recipefile = get_bb_var('FILE', testrecipe)
  609. self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named')
  610. checkvars = {}
  611. checkvars['S'] = None
  612. checkvars['SRC_URI'] = url.replace(testver, '${PV}')
  613. self._test_recipe_contents(recipefile, checkvars, [])
  614. def test_devtool_add_npm(self):
  615. collections = get_bb_var('BBFILE_COLLECTIONS').split()
  616. if "openembedded-layer" not in collections:
  617. self.skipTest("Test needs meta-oe for nodejs")
  618. pn = 'savoirfairelinux-node-server-example'
  619. pv = '1.0.0'
  620. url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=' + pv
  621. # Test devtool add
  622. self.track_for_cleanup(self.workspacedir)
  623. self.add_command_to_tearDown('bitbake -c cleansstate %s' % pn)
  624. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  625. result = runCmd('devtool add \'%s\'' % url)
  626. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  627. self.assertExists(os.path.join(self.workspacedir, 'recipes', pn, '%s_%s.bb' % (pn, pv)), 'Recipe not created')
  628. self.assertExists(os.path.join(self.workspacedir, 'recipes', pn, pn, 'npm-shrinkwrap.json'), 'Shrinkwrap not created')
  629. # Test devtool status
  630. result = runCmd('devtool status')
  631. self.assertIn(pn, result.output)
  632. # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then)
  633. bitbake('%s -c cleansstate' % pn)
  634. # Test devtool build
  635. result = runCmd('devtool build %s' % pn)
  636. def test_devtool_add_python_egg_requires(self):
  637. # Fetch source
  638. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  639. self.track_for_cleanup(tempdir)
  640. testver = '0.14.0'
  641. url = 'https://files.pythonhosted.org/packages/e9/9e/25d59f5043cf763833b2581c8027fa92342c4cf8ee523b498ecdf460c16d/uvicorn-%s.tar.gz' % testver
  642. testrecipe = 'python3-uvicorn'
  643. srcdir = os.path.join(tempdir, testrecipe)
  644. # Test devtool add
  645. self.track_for_cleanup(self.workspacedir)
  646. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  647. result = runCmd('devtool add %s %s -f %s' % (testrecipe, srcdir, url))
  648. class DevtoolModifyTests(DevtoolBase):
  649. def test_devtool_modify(self):
  650. import oe.path
  651. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  652. self.track_for_cleanup(tempdir)
  653. self.track_for_cleanup(self.workspacedir)
  654. self.add_command_to_tearDown('bitbake -c clean mdadm')
  655. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  656. result = runCmd('devtool modify mdadm -x %s' % tempdir)
  657. self.assertExists(os.path.join(tempdir, 'Makefile'), 'Extracted source could not be found')
  658. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  659. matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'mdadm_*.bbappend'))
  660. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  661. # Test devtool status
  662. result = runCmd('devtool status')
  663. self.assertIn('mdadm', result.output)
  664. self.assertIn(tempdir, result.output)
  665. self._check_src_repo(tempdir)
  666. bitbake('mdadm -C unpack')
  667. def check_line(checkfile, expected, message, present=True):
  668. # Check for $expected, on a line on its own, in checkfile.
  669. with open(checkfile, 'r') as f:
  670. if present:
  671. self.assertIn(expected + '\n', f, message)
  672. else:
  673. self.assertNotIn(expected + '\n', f, message)
  674. modfile = os.path.join(tempdir, 'mdadm.8.in')
  675. bb_vars = get_bb_vars(['PKGD', 'mandir'], 'mdadm')
  676. pkgd = bb_vars['PKGD']
  677. self.assertTrue(pkgd, 'Could not query PKGD variable')
  678. mandir = bb_vars['mandir']
  679. self.assertTrue(mandir, 'Could not query mandir variable')
  680. manfile = oe.path.join(pkgd, mandir, 'man8', 'mdadm.8')
  681. check_line(modfile, 'Linux Software RAID', 'Could not find initial string')
  682. check_line(modfile, 'antique pin sardine', 'Unexpectedly found replacement string', present=False)
  683. result = runCmd("sed -i 's!^Linux Software RAID$!antique pin sardine!' %s" % modfile)
  684. check_line(modfile, 'antique pin sardine', 'mdadm.8.in file not modified (sed failed)')
  685. bitbake('mdadm -c package')
  686. check_line(manfile, 'antique pin sardine', 'man file not modified. man searched file path: %s' % manfile)
  687. result = runCmd('git checkout -- %s' % modfile, cwd=tempdir)
  688. check_line(modfile, 'Linux Software RAID', 'man .in file not restored (git failed)')
  689. bitbake('mdadm -c package')
  690. check_line(manfile, 'Linux Software RAID', 'man file not updated. man searched file path: %s' % manfile)
  691. result = runCmd('devtool reset mdadm')
  692. result = runCmd('devtool status')
  693. self.assertNotIn('mdadm', result.output)
  694. def test_devtool_modify_go(self):
  695. import oe.path
  696. from tempfile import TemporaryDirectory
  697. with TemporaryDirectory(prefix='devtoolqa') as tempdir:
  698. self.track_for_cleanup(self.workspacedir)
  699. self.add_command_to_tearDown('bitbake -c clean go-helloworld')
  700. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  701. result = runCmd('devtool modify go-helloworld -x %s' % tempdir)
  702. self.assertExists(
  703. oe.path.join(tempdir, 'src', 'golang.org', 'x', 'example', 'go.mod'),
  704. 'Extracted source could not be found'
  705. )
  706. self.assertExists(
  707. oe.path.join(self.workspacedir, 'conf', 'layer.conf'),
  708. 'Workspace directory not created'
  709. )
  710. matches = glob.glob(oe.path.join(self.workspacedir, 'appends', 'go-helloworld_*.bbappend'))
  711. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  712. def test_devtool_buildclean(self):
  713. def assertFile(path, *paths):
  714. f = os.path.join(path, *paths)
  715. self.assertExists(f)
  716. def assertNoFile(path, *paths):
  717. f = os.path.join(path, *paths)
  718. self.assertNotExists(f)
  719. # Clean up anything in the workdir/sysroot/sstate cache
  720. bitbake('mdadm m4 -c cleansstate')
  721. # Try modifying a recipe
  722. tempdir_mdadm = tempfile.mkdtemp(prefix='devtoolqa')
  723. tempdir_m4 = tempfile.mkdtemp(prefix='devtoolqa')
  724. builddir_m4 = tempfile.mkdtemp(prefix='devtoolqa')
  725. self.track_for_cleanup(tempdir_mdadm)
  726. self.track_for_cleanup(tempdir_m4)
  727. self.track_for_cleanup(builddir_m4)
  728. self.track_for_cleanup(self.workspacedir)
  729. self.add_command_to_tearDown('bitbake -c clean mdadm m4')
  730. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  731. self.write_recipeinc('m4', 'EXTERNALSRC_BUILD = "%s"\ndo_clean() {\n\t:\n}\n' % builddir_m4)
  732. try:
  733. runCmd('devtool modify mdadm -x %s' % tempdir_mdadm)
  734. runCmd('devtool modify m4 -x %s' % tempdir_m4)
  735. assertNoFile(tempdir_mdadm, 'mdadm')
  736. assertNoFile(builddir_m4, 'src/m4')
  737. result = bitbake('m4 -e')
  738. result = bitbake('mdadm m4 -c compile')
  739. self.assertEqual(result.status, 0)
  740. assertFile(tempdir_mdadm, 'mdadm')
  741. assertFile(builddir_m4, 'src/m4')
  742. # Check that buildclean task exists and does call make clean
  743. bitbake('mdadm m4 -c buildclean')
  744. assertNoFile(tempdir_mdadm, 'mdadm')
  745. assertNoFile(builddir_m4, 'src/m4')
  746. runCmd('echo "#Trigger rebuild" >> %s/Makefile' % tempdir_mdadm)
  747. bitbake('mdadm m4 -c compile')
  748. assertFile(tempdir_mdadm, 'mdadm')
  749. assertFile(builddir_m4, 'src/m4')
  750. bitbake('mdadm m4 -c clean')
  751. # Check that buildclean task is run before clean for B == S
  752. assertNoFile(tempdir_mdadm, 'mdadm')
  753. # Check that buildclean task is not run before clean for B != S
  754. assertFile(builddir_m4, 'src/m4')
  755. finally:
  756. self.delete_recipeinc('m4')
  757. def test_devtool_modify_invalid(self):
  758. # Try modifying some recipes
  759. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  760. self.track_for_cleanup(tempdir)
  761. self.track_for_cleanup(self.workspacedir)
  762. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  763. testrecipes = 'perf kernel-devsrc package-index core-image-minimal meta-toolchain packagegroup-core-sdk'.split()
  764. # Find actual name of gcc-source since it now includes the version - crude, but good enough for this purpose
  765. result = runCmd('bitbake-layers show-recipes gcc-source*')
  766. for line in result.output.splitlines():
  767. # just match those lines that contain a real target
  768. m = re.match('(?P<recipe>^[a-zA-Z0-9.-]+)(?P<colon>:$)', line)
  769. if m:
  770. testrecipes.append(m.group('recipe'))
  771. for testrecipe in testrecipes:
  772. # Check it's a valid recipe
  773. bitbake('%s -e' % testrecipe)
  774. # devtool extract should fail
  775. result = runCmd('devtool extract %s %s' % (testrecipe, os.path.join(tempdir, testrecipe)), ignore_status=True)
  776. self.assertNotEqual(result.status, 0, 'devtool extract on %s should have failed. devtool output: %s' % (testrecipe, result.output))
  777. self.assertNotIn('Fetching ', result.output, 'devtool extract on %s should have errored out before trying to fetch' % testrecipe)
  778. self.assertIn('ERROR: ', result.output, 'devtool extract on %s should have given an ERROR' % testrecipe)
  779. # devtool modify should fail
  780. result = runCmd('devtool modify %s -x %s' % (testrecipe, os.path.join(tempdir, testrecipe)), ignore_status=True)
  781. self.assertNotEqual(result.status, 0, 'devtool modify on %s should have failed. devtool output: %s' % (testrecipe, result.output))
  782. self.assertIn('ERROR: ', result.output, 'devtool modify on %s should have given an ERROR' % testrecipe)
  783. def test_devtool_modify_native(self):
  784. # Check preconditions
  785. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  786. # Try modifying some recipes
  787. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  788. self.track_for_cleanup(tempdir)
  789. self.track_for_cleanup(self.workspacedir)
  790. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  791. bbclassextended = False
  792. inheritnative = False
  793. testrecipes = 'cdrtools-native mtools-native apt-native desktop-file-utils-native'.split()
  794. for testrecipe in testrecipes:
  795. checkextend = 'native' in (get_bb_var('BBCLASSEXTEND', testrecipe) or '').split()
  796. if not bbclassextended:
  797. bbclassextended = checkextend
  798. if not inheritnative:
  799. inheritnative = not checkextend
  800. result = runCmd('devtool modify %s -x %s' % (testrecipe, os.path.join(tempdir, testrecipe)))
  801. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool modify output: %s' % result.output)
  802. result = runCmd('devtool build %s' % testrecipe)
  803. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool build output: %s' % result.output)
  804. result = runCmd('devtool reset %s' % testrecipe)
  805. self.assertNotIn('ERROR: ', result.output, 'ERROR in devtool reset output: %s' % result.output)
  806. self.assertTrue(bbclassextended, 'None of these recipes are BBCLASSEXTENDed to native - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
  807. self.assertTrue(inheritnative, 'None of these recipes do "inherit native" - need to adjust testrecipes list: %s' % ', '.join(testrecipes))
  808. def test_devtool_modify_localfiles_only(self):
  809. # Check preconditions
  810. testrecipe = 'base-files'
  811. src_uri = (get_bb_var('SRC_URI', testrecipe) or '').split()
  812. foundlocalonly = False
  813. correct_symlink = False
  814. for item in src_uri:
  815. if item.startswith('file://'):
  816. if '.patch' not in item:
  817. foundlocalonly = True
  818. else:
  819. foundlocalonly = False
  820. break
  821. self.assertTrue(foundlocalonly, 'This test expects the %s recipe to fetch local files only and it seems that it no longer does' % testrecipe)
  822. # Clean up anything in the workdir/sysroot/sstate cache
  823. bitbake('%s -c cleansstate' % testrecipe)
  824. # Try modifying a recipe
  825. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  826. self.track_for_cleanup(tempdir)
  827. self.track_for_cleanup(self.workspacedir)
  828. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  829. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  830. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  831. srcfile = os.path.join(tempdir, 'share/dot.bashrc')
  832. self.assertExists(srcfile, 'Extracted source could not be found')
  833. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % testrecipe))
  834. self.assertTrue(matches, 'bbappend not created')
  835. # Test devtool status
  836. result = runCmd('devtool status')
  837. self.assertIn(testrecipe, result.output)
  838. self.assertIn(tempdir, result.output)
  839. # Try building
  840. bitbake(testrecipe)
  841. def test_devtool_modify_git(self):
  842. # Check preconditions
  843. testrecipe = 'psplash'
  844. src_uri = get_bb_var('SRC_URI', testrecipe)
  845. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  846. # Clean up anything in the workdir/sysroot/sstate cache
  847. bitbake('%s -c cleansstate' % testrecipe)
  848. # Try modifying a recipe
  849. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  850. self.track_for_cleanup(tempdir)
  851. self.track_for_cleanup(self.workspacedir)
  852. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  853. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  854. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  855. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  856. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output)
  857. matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'psplash_*.bbappend'))
  858. self.assertTrue(matches, 'bbappend not created')
  859. # Test devtool status
  860. result = runCmd('devtool status')
  861. self.assertIn(testrecipe, result.output)
  862. self.assertIn(tempdir, result.output)
  863. # Check git repo
  864. self._check_src_repo(tempdir)
  865. # Try building
  866. bitbake(testrecipe)
  867. def test_devtool_modify_git_no_extract(self):
  868. # Check preconditions
  869. testrecipe = 'psplash'
  870. src_uri = get_bb_var('SRC_URI', testrecipe)
  871. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  872. # Clean up anything in the workdir/sysroot/sstate cache
  873. bitbake('%s -c cleansstate' % testrecipe)
  874. # Try modifying a recipe
  875. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  876. self.track_for_cleanup(tempdir)
  877. self.track_for_cleanup(self.workspacedir)
  878. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  879. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  880. result = runCmd('git clone https://git.yoctoproject.org/psplash %s && devtool modify -n %s %s' % (tempdir, testrecipe, tempdir))
  881. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output)
  882. matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'psplash_*.bbappend'))
  883. self.assertTrue(matches, 'bbappend not created')
  884. # Test devtool status
  885. result = runCmd('devtool status')
  886. self.assertIn(testrecipe, result.output)
  887. self.assertIn(tempdir, result.output)
  888. def test_devtool_modify_git_crates_subpath(self):
  889. # This tests two things in devtool context:
  890. # - that we support local git dependencies for cargo based recipe
  891. # - that we support patches in SRC_URI when git url contains subpath parameter
  892. # Check preconditions:
  893. # recipe inherits cargo
  894. # git:// uri with a subpath as the main package
  895. # some crate:// in SRC_URI
  896. # others git:// in SRC_URI
  897. # cointains a patch
  898. testrecipe = 'hello-rs'
  899. bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'UNPACKDIR', 'CARGO_HOME'], testrecipe)
  900. recipefile = bb_vars['FILE']
  901. unpackdir = bb_vars['UNPACKDIR']
  902. cargo_home = bb_vars['CARGO_HOME']
  903. src_uri = bb_vars['SRC_URI'].split()
  904. self.assertTrue(src_uri[0].startswith('git://'),
  905. 'This test expects the %s recipe to have a git repo has its main uri' % testrecipe)
  906. self.assertIn(';subpath=', src_uri[0],
  907. 'This test expects the %s recipe to have a git uri with subpath' % testrecipe)
  908. self.assertTrue(any([uri.startswith('crate://') for uri in src_uri]),
  909. 'This test expects the %s recipe to have some crates in its src uris' % testrecipe)
  910. self.assertGreaterEqual(sum(map(lambda x:x.startswith('git://'), src_uri)), 2,
  911. 'This test expects the %s recipe to have several git:// uris' % testrecipe)
  912. self.assertTrue(any([uri.startswith('file://') and '.patch' in uri for uri in src_uri]),
  913. 'This test expects the %s recipe to have a patch in its src uris' % testrecipe)
  914. self._test_recipe_contents(recipefile, {}, ['ptest-cargo'])
  915. # Clean up anything in the workdir/sysroot/sstate cache
  916. bitbake('%s -c cleansstate' % testrecipe)
  917. # Try modifying a recipe
  918. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  919. self.track_for_cleanup(tempdir)
  920. self.track_for_cleanup(self.workspacedir)
  921. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  922. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  923. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  924. self.assertExists(os.path.join(tempdir, 'Cargo.toml'), 'Extracted source could not be found')
  925. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output)
  926. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % testrecipe))
  927. self.assertTrue(matches, 'bbappend not created')
  928. # Test devtool status
  929. result = runCmd('devtool status')
  930. self.assertIn(testrecipe, result.output)
  931. self.assertIn(tempdir, result.output)
  932. # Check git repo
  933. self._check_src_repo(tempdir)
  934. # Check that the patch is correctly applied.
  935. # The last commit message in the tree must contain the following note:
  936. # Notes (devtool):
  937. # original patch: <patchname>
  938. # ..
  939. patchname = None
  940. for uri in src_uri:
  941. if uri.startswith('file://') and '.patch' in uri:
  942. patchname = uri.replace("file://", "").partition('.patch')[0] + '.patch'
  943. self.assertIsNotNone(patchname)
  944. result = runCmd('git -C %s log -1' % tempdir)
  945. self.assertIn("Notes (devtool):\n original patch: %s" % patchname, result.output)
  946. # Configure the recipe to check that the git dependencies are correctly patched in cargo config
  947. bitbake('-c configure %s' % testrecipe)
  948. cargo_config_path = os.path.join(cargo_home, 'config')
  949. with open(cargo_config_path, "r") as f:
  950. cargo_config_contents = [line.strip('\n') for line in f.readlines()]
  951. # Get back git dependencies of the recipe (ignoring the main one)
  952. # and check that they are all correctly patched to be fetched locally
  953. git_deps = [uri for uri in src_uri if uri.startswith("git://")][1:]
  954. for git_dep in git_deps:
  955. raw_url, _, raw_parms = git_dep.partition(";")
  956. parms = {}
  957. for parm in raw_parms.split(";"):
  958. name_parm, _, value_parm = parm.partition('=')
  959. parms[name_parm]=value_parm
  960. self.assertIn('protocol', parms, 'git dependencies uri should contain the "protocol" parameter')
  961. self.assertIn('name', parms, 'git dependencies uri should contain the "name" parameter')
  962. self.assertIn('destsuffix', parms, 'git dependencies uri should contain the "destsuffix" parameter')
  963. self.assertIn('type', parms, 'git dependencies uri should contain the "type" parameter')
  964. self.assertEqual(parms['type'], 'git-dependency', 'git dependencies uri should have "type=git-dependency"')
  965. raw_url = raw_url.replace("git://", '%s://' % parms['protocol'])
  966. patch_line = '[patch."%s"]' % raw_url
  967. path_patched = os.path.join(unpackdir, parms['destsuffix'])
  968. path_override_line = '%s = { path = "%s" }' % (parms['name'], path_patched)
  969. # Would have been better to use tomllib to read this file :/
  970. self.assertIn(patch_line, cargo_config_contents)
  971. self.assertIn(path_override_line, cargo_config_contents)
  972. # Try to package the recipe
  973. bitbake('-c package_qa %s' % testrecipe)
  974. def test_devtool_modify_localfiles(self):
  975. # Check preconditions
  976. testrecipe = 'lighttpd'
  977. src_uri = (get_bb_var('SRC_URI', testrecipe) or '').split()
  978. foundlocal = False
  979. for item in src_uri:
  980. if item.startswith('file://') and '.patch' not in item:
  981. foundlocal = True
  982. break
  983. self.assertTrue(foundlocal, 'This test expects the %s recipe to fetch local files and it seems that it no longer does' % testrecipe)
  984. # Clean up anything in the workdir/sysroot/sstate cache
  985. bitbake('%s -c cleansstate' % testrecipe)
  986. # Try modifying a recipe
  987. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  988. self.track_for_cleanup(tempdir)
  989. self.track_for_cleanup(self.workspacedir)
  990. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  991. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  992. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  993. self.assertExists(os.path.join(tempdir, 'configure.ac'), 'Extracted source could not be found')
  994. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  995. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % testrecipe))
  996. self.assertTrue(matches, 'bbappend not created')
  997. # Test devtool status
  998. result = runCmd('devtool status')
  999. self.assertIn(testrecipe, result.output)
  1000. self.assertIn(tempdir, result.output)
  1001. # Try building
  1002. bitbake(testrecipe)
  1003. def test_devtool_modify_virtual(self):
  1004. # Try modifying a virtual recipe
  1005. virtrecipe = 'virtual/make'
  1006. realrecipe = 'make'
  1007. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1008. self.track_for_cleanup(tempdir)
  1009. self.track_for_cleanup(self.workspacedir)
  1010. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1011. result = runCmd('devtool modify %s -x %s' % (virtrecipe, tempdir))
  1012. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  1013. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created')
  1014. matches = glob.glob(os.path.join(self.workspacedir, 'appends', '%s_*.bbappend' % realrecipe))
  1015. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  1016. # Test devtool status
  1017. result = runCmd('devtool status')
  1018. self.assertNotIn(virtrecipe, result.output)
  1019. self.assertIn(realrecipe, result.output)
  1020. # Check git repo
  1021. self._check_src_repo(tempdir)
  1022. # This is probably sufficient
  1023. def test_devtool_modify_overrides(self):
  1024. # Try modifying a recipe with patches in overrides
  1025. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1026. self.track_for_cleanup(tempdir)
  1027. self.track_for_cleanup(self.workspacedir)
  1028. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1029. result = runCmd('devtool modify devtool-patch-overrides -x %s' % (tempdir))
  1030. self._check_src_repo(tempdir)
  1031. source = os.path.join(tempdir, "source")
  1032. def check(branch, expected):
  1033. runCmd('git -C %s checkout %s' % (tempdir, branch))
  1034. with open(source, "rt") as f:
  1035. content = f.read()
  1036. self.assertEqual(content, expected)
  1037. if self.td["MACHINE"] == "qemux86":
  1038. check('devtool', 'This is a test for qemux86\n')
  1039. elif self.td["MACHINE"] == "qemuarm":
  1040. check('devtool', 'This is a test for qemuarm\n')
  1041. else:
  1042. check('devtool', 'This is a test for something\n')
  1043. check('devtool-no-overrides', 'This is a test for something\n')
  1044. check('devtool-override-qemuarm', 'This is a test for qemuarm\n')
  1045. check('devtool-override-qemux86', 'This is a test for qemux86\n')
  1046. def test_devtool_modify_multiple_sources(self):
  1047. # This test check that recipes fetching several sources can be used with devtool modify/build
  1048. # Check preconditions
  1049. testrecipe = 'bzip2'
  1050. src_uri = get_bb_var('SRC_URI', testrecipe)
  1051. src1 = 'https://' in src_uri
  1052. src2 = 'git://' in src_uri
  1053. self.assertTrue(src1 and src2, 'This test expects the %s recipe to fetch both a git source and a tarball and it seems that it no longer does' % testrecipe)
  1054. # Clean up anything in the workdir/sysroot/sstate cache
  1055. bitbake('%s -c cleansstate' % testrecipe)
  1056. # Try modifying a recipe
  1057. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1058. self.track_for_cleanup(tempdir)
  1059. self.track_for_cleanup(self.workspacedir)
  1060. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  1061. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1062. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1063. self.assertEqual(result.status, 0, "Could not modify recipe %s. Output: %s" % (testrecipe, result.output))
  1064. # Test devtool status
  1065. result = runCmd('devtool status')
  1066. self.assertIn(testrecipe, result.output)
  1067. self.assertIn(tempdir, result.output)
  1068. # Try building
  1069. result = bitbake(testrecipe)
  1070. self.assertEqual(result.status, 0, "Bitbake failed, exit code %s, output %s" % (result.status, result.output))
  1071. class DevtoolUpdateTests(DevtoolBase):
  1072. def test_devtool_update_recipe(self):
  1073. # Check preconditions
  1074. testrecipe = 'minicom'
  1075. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  1076. recipefile = bb_vars['FILE']
  1077. src_uri = bb_vars['SRC_URI']
  1078. self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
  1079. self._check_repo_status(os.path.dirname(recipefile), [])
  1080. # First, modify a recipe
  1081. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1082. self.track_for_cleanup(tempdir)
  1083. self.track_for_cleanup(self.workspacedir)
  1084. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1085. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1086. # We don't use -x here so that we test the behaviour of devtool modify without it
  1087. result = runCmd('devtool modify %s %s' % (testrecipe, tempdir))
  1088. # Check git repo
  1089. self._check_src_repo(tempdir)
  1090. # Add a couple of commits
  1091. # FIXME: this only tests adding, need to also test update and remove
  1092. result = runCmd('echo "Additional line" >> README', cwd=tempdir)
  1093. result = runCmd('git commit -a -m "Change the README"', cwd=tempdir)
  1094. result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir)
  1095. result = runCmd('git add devtool-new-file', cwd=tempdir)
  1096. result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
  1097. self.add_command_to_tearDown('cd %s; rm %s/*.patch; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1098. result = runCmd('devtool update-recipe %s' % testrecipe)
  1099. result = runCmd('git add minicom', cwd=os.path.dirname(recipefile))
  1100. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  1101. ('A ', '.*/0001-Change-the-README.patch$'),
  1102. ('A ', '.*/0002-Add-a-new-file.patch$')]
  1103. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1104. def test_devtool_update_recipe_git(self):
  1105. # Check preconditions
  1106. testrecipe = 'mtd-utils-selftest'
  1107. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  1108. recipefile = bb_vars['FILE']
  1109. src_uri = bb_vars['SRC_URI']
  1110. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  1111. patches = []
  1112. for entry in src_uri.split():
  1113. if entry.startswith('file://') and entry.endswith('.patch'):
  1114. patches.append(entry[7:].split(';')[0])
  1115. self.assertGreater(len(patches), 0, 'The %s recipe does not appear to contain any patches, so this test will not be effective' % testrecipe)
  1116. self._check_repo_status(os.path.dirname(recipefile), [])
  1117. # First, modify a recipe
  1118. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1119. self.track_for_cleanup(tempdir)
  1120. self.track_for_cleanup(self.workspacedir)
  1121. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1122. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1123. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1124. # Check git repo
  1125. self._check_src_repo(tempdir)
  1126. # Add a couple of commits
  1127. # FIXME: this only tests adding, need to also test update and remove
  1128. result = runCmd('echo "# Additional line" >> Makefile.am', cwd=tempdir)
  1129. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempdir)
  1130. result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir)
  1131. result = runCmd('git add devtool-new-file', cwd=tempdir)
  1132. result = runCmd('git commit -m "Add a new file"', cwd=tempdir)
  1133. self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1134. result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe)
  1135. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile))] + \
  1136. [(' D', '.*/%s$' % patch) for patch in patches]
  1137. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1138. result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
  1139. addlines = ['SRCREV = ".*"', 'SRC_URI = "git://git.infradead.org/mtd-utils.git;branch=master"']
  1140. srcurilines = src_uri.split()
  1141. srcurilines[0] = 'SRC_URI = "' + srcurilines[0]
  1142. srcurilines.append('"')
  1143. removelines = ['SRCREV = ".*"'] + srcurilines
  1144. self._check_diff(result.output, addlines, removelines)
  1145. # Now try with auto mode
  1146. runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile)))
  1147. result = runCmd('devtool update-recipe %s' % testrecipe)
  1148. result = runCmd('git rev-parse --show-toplevel', cwd=os.path.dirname(recipefile))
  1149. topleveldir = result.output.strip()
  1150. relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe)
  1151. expected_status = [(' M', os.path.relpath(recipefile, topleveldir)),
  1152. ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath),
  1153. ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)]
  1154. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1155. def test_devtool_update_recipe_append(self):
  1156. # Check preconditions
  1157. testrecipe = 'mdadm'
  1158. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  1159. recipefile = bb_vars['FILE']
  1160. src_uri = bb_vars['SRC_URI']
  1161. self.assertNotIn('git://', src_uri, 'This test expects the %s recipe to NOT be a git recipe' % testrecipe)
  1162. self._check_repo_status(os.path.dirname(recipefile), [])
  1163. # First, modify a recipe
  1164. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1165. tempsrcdir = os.path.join(tempdir, 'source')
  1166. templayerdir = os.path.join(tempdir, 'layer')
  1167. self.track_for_cleanup(tempdir)
  1168. self.track_for_cleanup(self.workspacedir)
  1169. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1170. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1171. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir))
  1172. # Check git repo
  1173. self._check_src_repo(tempsrcdir)
  1174. # Add a commit
  1175. result = runCmd("sed 's!\\(#define VERSION\\W*\"[^\"]*\\)\"!\\1-custom\"!' -i ReadMe.c", cwd=tempsrcdir)
  1176. result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir)
  1177. self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe))
  1178. # Create a temporary layer and add it to bblayers.conf
  1179. self._create_temp_layer(templayerdir, True, 'selftestupdaterecipe')
  1180. # Create the bbappend
  1181. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  1182. self.assertNotIn('WARNING:', result.output)
  1183. # Check recipe is still clean
  1184. self._check_repo_status(os.path.dirname(recipefile), [])
  1185. # Check bbappend was created
  1186. splitpath = os.path.dirname(recipefile).split(os.sep)
  1187. appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
  1188. bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir)
  1189. patchfile = os.path.join(appenddir, testrecipe, '0001-Add-our-custom-version.patch')
  1190. self.assertExists(patchfile, 'Patch file not created')
  1191. # Check bbappend contents
  1192. expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  1193. '\n',
  1194. 'SRC_URI += "file://0001-Add-our-custom-version.patch"\n',
  1195. '\n']
  1196. with open(bbappendfile, 'r') as f:
  1197. self.assertEqual(expectedlines, f.readlines())
  1198. # Check we can run it again and bbappend isn't modified
  1199. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  1200. with open(bbappendfile, 'r') as f:
  1201. self.assertEqual(expectedlines, f.readlines())
  1202. # Drop new commit and check patch gets deleted
  1203. result = runCmd('git reset HEAD^ --hard', cwd=tempsrcdir)
  1204. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  1205. self.assertNotExists(patchfile, 'Patch file not deleted')
  1206. expectedlines2 = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  1207. '\n']
  1208. with open(bbappendfile, 'r') as f:
  1209. self.assertEqual(expectedlines2, f.readlines())
  1210. # Put commit back and check we can run it if layer isn't in bblayers.conf
  1211. os.remove(bbappendfile)
  1212. result = runCmd("sed 's!\\(#define VERSION\\W*\"[^\"]*\\)\"!\\1-custom\"!' -i ReadMe.c", cwd=tempsrcdir)
  1213. result = runCmd('git commit -a -m "Add our custom version"', cwd=tempsrcdir)
  1214. result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir)
  1215. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  1216. self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output)
  1217. self.assertExists(patchfile, 'Patch file not created (with disabled layer)')
  1218. with open(bbappendfile, 'r') as f:
  1219. self.assertEqual(expectedlines, f.readlines())
  1220. # Deleting isn't expected to work under these circumstances
  1221. def test_devtool_update_recipe_append_git(self):
  1222. # Check preconditions
  1223. testrecipe = 'mtd-utils-selftest'
  1224. bb_vars = get_bb_vars(['FILE', 'SRC_URI', 'LAYERSERIES_CORENAMES'], testrecipe)
  1225. recipefile = bb_vars['FILE']
  1226. src_uri = bb_vars['SRC_URI']
  1227. corenames = bb_vars['LAYERSERIES_CORENAMES']
  1228. self.assertIn('git://', src_uri, 'This test expects the %s recipe to be a git recipe' % testrecipe)
  1229. for entry in src_uri.split():
  1230. if entry.startswith('git://'):
  1231. git_uri = entry
  1232. break
  1233. self._check_repo_status(os.path.dirname(recipefile), [])
  1234. # First, modify a recipe
  1235. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1236. tempsrcdir = os.path.join(tempdir, 'source')
  1237. templayerdir = os.path.join(tempdir, 'layer')
  1238. self.track_for_cleanup(tempdir)
  1239. self.track_for_cleanup(self.workspacedir)
  1240. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1241. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1242. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempsrcdir))
  1243. # Check git repo
  1244. self._check_src_repo(tempsrcdir)
  1245. # Add a commit
  1246. result = runCmd('echo "# Additional line" >> Makefile.am', cwd=tempsrcdir)
  1247. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir)
  1248. self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (os.path.dirname(recipefile), testrecipe))
  1249. # Create a temporary layer
  1250. os.makedirs(os.path.join(templayerdir, 'conf'))
  1251. with open(os.path.join(templayerdir, 'conf', 'layer.conf'), 'w') as f:
  1252. f.write('BBPATH .= ":${LAYERDIR}"\n')
  1253. f.write('BBFILES += "${LAYERDIR}/recipes-*/*/*.bbappend"\n')
  1254. f.write('BBFILE_COLLECTIONS += "oeselftesttemplayer"\n')
  1255. f.write('BBFILE_PATTERN_oeselftesttemplayer = "^${LAYERDIR}/"\n')
  1256. f.write('BBFILE_PRIORITY_oeselftesttemplayer = "999"\n')
  1257. f.write('BBFILE_PATTERN_IGNORE_EMPTY_oeselftesttemplayer = "1"\n')
  1258. f.write('LAYERSERIES_COMPAT_oeselftesttemplayer = "%s"\n' % corenames)
  1259. self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
  1260. result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
  1261. # Create the bbappend
  1262. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  1263. self.assertNotIn('WARNING:', result.output)
  1264. # Check recipe is still clean
  1265. self._check_repo_status(os.path.dirname(recipefile), [])
  1266. # Check bbappend was created
  1267. splitpath = os.path.dirname(recipefile).split(os.sep)
  1268. appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
  1269. bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir)
  1270. self.assertNotExists(os.path.join(appenddir, testrecipe), 'Patch directory should not be created')
  1271. # Check bbappend contents
  1272. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  1273. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  1274. '\n',
  1275. 'SRC_URI = "%s"\n' % git_uri,
  1276. '\n'])
  1277. with open(bbappendfile, 'r') as f:
  1278. self.assertEqual(expectedlines, set(f.readlines()))
  1279. # Check we can run it again and bbappend isn't modified
  1280. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  1281. with open(bbappendfile, 'r') as f:
  1282. self.assertEqual(expectedlines, set(f.readlines()))
  1283. # Drop new commit and check SRCREV changes
  1284. result = runCmd('git reset HEAD^ --hard', cwd=tempsrcdir)
  1285. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  1286. self.assertNotExists(os.path.join(appenddir, testrecipe), 'Patch directory should not be created')
  1287. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  1288. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  1289. '\n',
  1290. 'SRC_URI = "%s"\n' % git_uri,
  1291. '\n'])
  1292. with open(bbappendfile, 'r') as f:
  1293. self.assertEqual(expectedlines, set(f.readlines()))
  1294. # Put commit back and check we can run it if layer isn't in bblayers.conf
  1295. os.remove(bbappendfile)
  1296. result = runCmd('echo "# Additional line" >> Makefile.am', cwd=tempsrcdir)
  1297. result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir)
  1298. result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir)
  1299. result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir))
  1300. self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output)
  1301. self.assertNotExists(os.path.join(appenddir, testrecipe), 'Patch directory should not be created')
  1302. result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
  1303. expectedlines = set(['SRCREV = "%s"\n' % result.output,
  1304. '\n',
  1305. 'SRC_URI = "%s"\n' % git_uri,
  1306. '\n'])
  1307. with open(bbappendfile, 'r') as f:
  1308. self.assertEqual(expectedlines, set(f.readlines()))
  1309. # Deleting isn't expected to work under these circumstances
  1310. def test_devtool_update_recipe_local_files(self):
  1311. """Check that local source files are copied over instead of patched"""
  1312. testrecipe = 'makedevs'
  1313. recipefile = get_bb_var('FILE', testrecipe)
  1314. # Setup srctree for modifying the recipe
  1315. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1316. self.track_for_cleanup(tempdir)
  1317. self.track_for_cleanup(self.workspacedir)
  1318. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1319. # (don't bother with cleaning the recipe on teardown, we won't be
  1320. # building it)
  1321. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1322. # Check git repo
  1323. self._check_src_repo(tempdir)
  1324. # Try building just to ensure we haven't broken that
  1325. bitbake("%s" % testrecipe)
  1326. # Edit / commit local source
  1327. runCmd('echo "/* Foobar */" >> makedevs.c', cwd=tempdir)
  1328. runCmd('echo "Foo" > new-local', cwd=tempdir)
  1329. runCmd('echo "Bar" > new-file', cwd=tempdir)
  1330. runCmd('git add new-file', cwd=tempdir)
  1331. runCmd('git commit -m "Add new file"', cwd=tempdir)
  1332. runCmd('git add new-local', cwd=tempdir)
  1333. runCmd('devtool update-recipe %s' % testrecipe)
  1334. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  1335. (' M', '.*/makedevs/makedevs.c$'),
  1336. ('??', '.*/makedevs/new-local$'),
  1337. ('??', '.*/makedevs/0001-Add-new-file.patch$')]
  1338. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1339. # Now try to update recipe in another layer, so first, clean it
  1340. runCmd('cd %s; git clean -fd .; git checkout .' % os.path.dirname(recipefile))
  1341. # Create a temporary layer and add it to bblayers.conf
  1342. self._create_temp_layer(templayerdir, True, 'templayer')
  1343. # Update recipe in templayer
  1344. result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir))
  1345. self.assertNotIn('WARNING:', result.output)
  1346. # Check recipe is still clean
  1347. self._check_repo_status(os.path.dirname(recipefile), [])
  1348. splitpath = os.path.dirname(recipefile).split(os.sep)
  1349. appenddir = os.path.join(templayerdir, splitpath[-2], splitpath[-1])
  1350. bbappendfile = self._check_bbappend(testrecipe, recipefile, appenddir)
  1351. patchfile = os.path.join(appenddir, testrecipe, '0001-Add-new-file.patch')
  1352. new_local_file = os.path.join(appenddir, testrecipe, 'new_local')
  1353. local_file = os.path.join(appenddir, testrecipe, 'makedevs.c')
  1354. self.assertExists(patchfile, 'Patch file 0001-Add-new-file.patch not created')
  1355. self.assertExists(local_file, 'File makedevs.c not created')
  1356. self.assertExists(patchfile, 'File new_local not created')
  1357. def _test_devtool_update_recipe_local_files_2(self):
  1358. """Check local source files support when editing local files in Git"""
  1359. testrecipe = 'devtool-test-local'
  1360. recipefile = get_bb_var('FILE', testrecipe)
  1361. recipedir = os.path.dirname(recipefile)
  1362. result = runCmd('git status --porcelain .', cwd=recipedir)
  1363. if result.output.strip():
  1364. self.fail('Recipe directory for %s contains uncommitted changes' % testrecipe)
  1365. # Setup srctree for modifying the recipe
  1366. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1367. self.track_for_cleanup(tempdir)
  1368. self.track_for_cleanup(self.workspacedir)
  1369. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1370. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1371. # Check git repo
  1372. self._check_src_repo(tempdir)
  1373. # Edit / commit local sources
  1374. runCmd('echo "# Foobar" >> file1', cwd=tempdir)
  1375. runCmd('git commit -am "Edit existing file"', cwd=tempdir)
  1376. runCmd('git rm file2', cwd=tempdir)
  1377. runCmd('git commit -m"Remove file"', cwd=tempdir)
  1378. runCmd('echo "Foo" > new-local', cwd=tempdir)
  1379. runCmd('git add new-local', cwd=tempdir)
  1380. runCmd('git commit -m "Add new local file"', cwd=tempdir)
  1381. runCmd('echo "Gar" > new-file', cwd=tempdir)
  1382. runCmd('git add new-file', cwd=tempdir)
  1383. runCmd('git commit -m "Add new file"', cwd=tempdir)
  1384. self.add_command_to_tearDown('cd %s; git clean -fd .; git checkout .' %
  1385. os.path.dirname(recipefile))
  1386. # Checkout unmodified file to working copy -> devtool should still pick
  1387. # the modified version from HEAD
  1388. runCmd('git checkout HEAD^ -- file1', cwd=tempdir)
  1389. runCmd('devtool update-recipe %s' % testrecipe)
  1390. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  1391. (' M', '.*/file1$'),
  1392. (' D', '.*/file2$'),
  1393. ('??', '.*/new-local$'),
  1394. ('??', '.*/0001-Add-new-file.patch$')]
  1395. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1396. def test_devtool_update_recipe_with_gitignore(self):
  1397. # First, modify the recipe
  1398. testrecipe = 'devtool-test-ignored'
  1399. bb_vars = get_bb_vars(['FILE'], testrecipe)
  1400. recipefile = bb_vars['FILE']
  1401. patchfile = os.path.join(os.path.dirname(recipefile), testrecipe, testrecipe + '.patch')
  1402. newpatchfile = os.path.join(os.path.dirname(recipefile), testrecipe, testrecipe + '.patch.expected')
  1403. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1404. self.track_for_cleanup(tempdir)
  1405. self.track_for_cleanup(self.workspacedir)
  1406. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1407. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1408. result = runCmd('devtool modify %s' % testrecipe)
  1409. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1410. result = runCmd('devtool finish --force-patch-refresh %s meta-selftest' % testrecipe)
  1411. # Check recipe got changed as expected
  1412. with open(newpatchfile, 'r') as f:
  1413. desiredlines = f.readlines()
  1414. with open(patchfile, 'r') as f:
  1415. newlines = f.readlines()
  1416. # Ignore the initial lines, because oe-selftest creates own meta-selftest repo
  1417. # which changes the metadata subject which is added into the patch, but keep
  1418. # .patch.expected as it is in case someone runs devtool finish --force-patch-refresh
  1419. # devtool-test-ignored manually, then it should generate exactly the same .patch file
  1420. self.assertEqual(desiredlines[5:], newlines[5:])
  1421. def test_devtool_update_recipe_long_filename(self):
  1422. # First, modify the recipe
  1423. testrecipe = 'devtool-test-long-filename'
  1424. bb_vars = get_bb_vars(['FILE'], testrecipe)
  1425. recipefile = bb_vars['FILE']
  1426. patchfilename = '0001-I-ll-patch-you-only-if-devtool-lets-me-to-do-it-corr.patch'
  1427. patchfile = os.path.join(os.path.dirname(recipefile), testrecipe, patchfilename)
  1428. newpatchfile = os.path.join(os.path.dirname(recipefile), testrecipe, patchfilename + '.expected')
  1429. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1430. self.track_for_cleanup(tempdir)
  1431. self.track_for_cleanup(self.workspacedir)
  1432. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1433. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1434. result = runCmd('devtool modify %s' % testrecipe)
  1435. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1436. result = runCmd('devtool finish --force-patch-refresh %s meta-selftest' % testrecipe)
  1437. # Check recipe got changed as expected
  1438. with open(newpatchfile, 'r') as f:
  1439. desiredlines = f.readlines()
  1440. with open(patchfile, 'r') as f:
  1441. newlines = f.readlines()
  1442. # Ignore the initial lines, because oe-selftest creates own meta-selftest repo
  1443. # which changes the metadata subject which is added into the patch, but keep
  1444. # .patch.expected as it is in case someone runs devtool finish --force-patch-refresh
  1445. # devtool-test-ignored manually, then it should generate exactly the same .patch file
  1446. self.assertEqual(desiredlines[5:], newlines[5:])
  1447. def test_devtool_update_recipe_local_files_3(self):
  1448. # First, modify the recipe
  1449. testrecipe = 'devtool-test-localonly'
  1450. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  1451. recipefile = bb_vars['FILE']
  1452. src_uri = bb_vars['SRC_URI']
  1453. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1454. self.track_for_cleanup(tempdir)
  1455. self.track_for_cleanup(self.workspacedir)
  1456. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1457. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1458. result = runCmd('devtool modify %s' % testrecipe)
  1459. # Modify one file
  1460. runCmd('echo "Another line" >> file2', cwd=os.path.join(self.workspacedir, 'sources', testrecipe))
  1461. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1462. result = runCmd('devtool update-recipe %s' % testrecipe)
  1463. expected_status = [(' M', '.*/%s/file2$' % testrecipe)]
  1464. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1465. def test_devtool_update_recipe_local_patch_gz(self):
  1466. # First, modify the recipe
  1467. testrecipe = 'devtool-test-patch-gz'
  1468. if get_bb_var('DISTRO') == 'poky-tiny':
  1469. self.skipTest("The DISTRO 'poky-tiny' does not provide the dependencies needed by %s" % testrecipe)
  1470. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  1471. recipefile = bb_vars['FILE']
  1472. src_uri = bb_vars['SRC_URI']
  1473. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1474. self.track_for_cleanup(tempdir)
  1475. self.track_for_cleanup(self.workspacedir)
  1476. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1477. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1478. result = runCmd('devtool modify %s' % testrecipe)
  1479. # Modify one file
  1480. srctree = os.path.join(self.workspacedir, 'sources', testrecipe)
  1481. runCmd('echo "Another line" >> README', cwd=srctree)
  1482. runCmd('git commit -a --amend --no-edit --no-verify', cwd=srctree)
  1483. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1484. result = runCmd('devtool update-recipe %s' % testrecipe)
  1485. expected_status = [(' M', '.*/%s/readme.patch.gz$' % testrecipe)]
  1486. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1487. patch_gz = os.path.join(os.path.dirname(recipefile), testrecipe, 'readme.patch.gz')
  1488. result = runCmd('file %s' % patch_gz)
  1489. if 'gzip compressed data' not in result.output:
  1490. self.fail('New patch file is not gzipped - file reports:\n%s' % result.output)
  1491. def test_devtool_update_recipe_local_files_subdir(self):
  1492. # Try devtool update-recipe on a recipe that has a file with subdir= set in
  1493. # SRC_URI such that it overwrites a file that was in an archive that
  1494. # was also in SRC_URI
  1495. # First, modify the recipe
  1496. testrecipe = 'devtool-test-subdir'
  1497. bb_vars = get_bb_vars(['FILE', 'SRC_URI'], testrecipe)
  1498. recipefile = bb_vars['FILE']
  1499. src_uri = bb_vars['SRC_URI']
  1500. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1501. self.track_for_cleanup(tempdir)
  1502. self.track_for_cleanup(self.workspacedir)
  1503. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1504. # (don't bother with cleaning the recipe on teardown, we won't be building it)
  1505. result = runCmd('devtool modify %s' % testrecipe)
  1506. testfile = os.path.join(self.workspacedir, 'sources', testrecipe, 'testfile')
  1507. self.assertExists(testfile, 'Extracted source could not be found')
  1508. with open(testfile, 'r') as f:
  1509. contents = f.read().rstrip()
  1510. self.assertEqual(contents, 'Modified version', 'File has apparently not been overwritten as it should have been')
  1511. # Test devtool update-recipe without modifying any files
  1512. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile)))
  1513. result = runCmd('devtool update-recipe %s' % testrecipe)
  1514. expected_status = []
  1515. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1516. def test_devtool_finish_modify_git_subdir(self):
  1517. # Check preconditions
  1518. testrecipe = 'dos2unix'
  1519. self.append_config('ERROR_QA:remove:pn-dos2unix = "patch-status"\n')
  1520. bb_vars = get_bb_vars(['SRC_URI', 'S', 'WORKDIR', 'FILE'], testrecipe)
  1521. self.assertIn('git://', bb_vars['SRC_URI'], 'This test expects the %s recipe to be a git recipe' % testrecipe)
  1522. workdir_git = '%s/git/' % bb_vars['WORKDIR']
  1523. if not bb_vars['S'].startswith(workdir_git):
  1524. self.fail('This test expects the %s recipe to be building from a subdirectory of the git repo' % testrecipe)
  1525. subdir = bb_vars['S'].split(workdir_git, 1)[1]
  1526. # Clean up anything in the workdir/sysroot/sstate cache
  1527. bitbake('%s -c cleansstate' % testrecipe)
  1528. # Try modifying a recipe
  1529. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1530. self.track_for_cleanup(tempdir)
  1531. self.track_for_cleanup(self.workspacedir)
  1532. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  1533. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1534. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1535. testsrcfile = os.path.join(tempdir, subdir, 'dos2unix.c')
  1536. self.assertExists(testsrcfile, 'Extracted source could not be found')
  1537. self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output)
  1538. self.assertNotExists(os.path.join(tempdir, subdir, '.git'), 'Subdirectory has been initialised as a git repo')
  1539. # Check git repo
  1540. self._check_src_repo(tempdir)
  1541. # Modify file
  1542. runCmd("sed -i '1s:^:/* Add a comment */\\n:' %s" % testsrcfile)
  1543. result = runCmd('git commit -a -m "Add a comment"', cwd=tempdir)
  1544. # Now try updating original recipe
  1545. recipefile = bb_vars['FILE']
  1546. recipedir = os.path.dirname(recipefile)
  1547. self.add_command_to_tearDown('cd %s; rm -f %s/*.patch; git checkout .' % (recipedir, testrecipe))
  1548. result = runCmd('devtool update-recipe %s' % testrecipe)
  1549. expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
  1550. ('??', '.*/%s/%s/$' % (testrecipe, testrecipe))]
  1551. self._check_repo_status(os.path.dirname(recipefile), expected_status)
  1552. result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
  1553. removelines = ['SRC_URI = "git://.*"']
  1554. addlines = [
  1555. 'SRC_URI = "git://.* \\\\',
  1556. 'file://0001-Add-a-comment.patch;patchdir=.. \\\\',
  1557. '"'
  1558. ]
  1559. self._check_diff(result.output, addlines, removelines)
  1560. # Put things back so we can run devtool finish on a different layer
  1561. runCmd('cd %s; rm -f %s/*.patch; git checkout .' % (recipedir, testrecipe))
  1562. # Run devtool finish
  1563. res = re.search('recipes-.*', recipedir)
  1564. self.assertTrue(res, 'Unable to find recipe subdirectory')
  1565. recipesubdir = res[0]
  1566. self.add_command_to_tearDown('rm -rf %s' % os.path.join(self.testlayer_path, recipesubdir))
  1567. result = runCmd('devtool finish %s meta-selftest' % testrecipe)
  1568. # Check bbappend file contents
  1569. appendfn = os.path.join(self.testlayer_path, recipesubdir, '%s_%%.bbappend' % testrecipe)
  1570. with open(appendfn, 'r') as f:
  1571. appendlines = f.readlines()
  1572. expected_appendlines = [
  1573. 'FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
  1574. '\n',
  1575. 'SRC_URI += "file://0001-Add-a-comment.patch;patchdir=.."\n',
  1576. '\n'
  1577. ]
  1578. self.assertEqual(appendlines, expected_appendlines)
  1579. self.assertExists(os.path.join(os.path.dirname(appendfn), testrecipe, '0001-Add-a-comment.patch'))
  1580. # Try building
  1581. bitbake('%s -c patch' % testrecipe)
  1582. def test_devtool_git_submodules(self):
  1583. # This tests if we can add a patch in a git submodule and extract it properly using devtool finish
  1584. # Check preconditions
  1585. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1586. self.track_for_cleanup(self.workspacedir)
  1587. recipe = 'vulkan-samples'
  1588. src_uri = get_bb_var('SRC_URI', recipe)
  1589. self.assertIn('gitsm://', src_uri, 'This test expects the %s recipe to be a git recipe with submodules' % recipe)
  1590. oldrecipefile = get_bb_var('FILE', recipe)
  1591. recipedir = os.path.dirname(oldrecipefile)
  1592. result = runCmd('git status --porcelain .', cwd=recipedir)
  1593. if result.output.strip():
  1594. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  1595. self.assertIn('/meta/', recipedir)
  1596. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1597. self.track_for_cleanup(tempdir)
  1598. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1599. result = runCmd('devtool modify %s %s' % (recipe, tempdir))
  1600. self.assertExists(os.path.join(tempdir, 'CMakeLists.txt'), 'Extracted source could not be found')
  1601. # Test devtool status
  1602. result = runCmd('devtool status')
  1603. self.assertIn(recipe, result.output)
  1604. self.assertIn(tempdir, result.output)
  1605. # Modify a source file in a submodule, (grab the first one)
  1606. result = runCmd('git submodule --quiet foreach \'echo $sm_path\'', cwd=tempdir)
  1607. submodule = result.output.splitlines()[0]
  1608. submodule_path = os.path.join(tempdir, submodule)
  1609. runCmd('echo "#This is a first comment" >> testfile', cwd=submodule_path)
  1610. result = runCmd('git status --porcelain . ', cwd=submodule_path)
  1611. self.assertIn("testfile", result.output)
  1612. runCmd('git add testfile; git commit -m "Adding a new file"', cwd=submodule_path)
  1613. # Try finish to the original layer
  1614. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  1615. runCmd('devtool finish -f %s meta' % recipe)
  1616. result = runCmd('devtool status')
  1617. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  1618. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  1619. expected_status = [(' M', '.*/%s$' % os.path.basename(oldrecipefile)),
  1620. ('??', '.*/.*-Adding-a-new-file.patch$')]
  1621. self._check_repo_status(recipedir, expected_status)
  1622. # Make sure the patch is added to the recipe with the correct "patchdir" option
  1623. result = runCmd('git diff .', cwd=recipedir)
  1624. addlines = [
  1625. 'file://0001-Adding-a-new-file.patch;patchdir=%s \\\\' % submodule
  1626. ]
  1627. self._check_diff(result.output, addlines, [])
  1628. class DevtoolExtractTests(DevtoolBase):
  1629. def test_devtool_extract(self):
  1630. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1631. # Try devtool extract
  1632. self.track_for_cleanup(tempdir)
  1633. self.track_for_cleanup(self.workspacedir)
  1634. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1635. result = runCmd('devtool extract matchbox-terminal %s' % tempdir)
  1636. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  1637. self._check_src_repo(tempdir)
  1638. def test_devtool_extract_virtual(self):
  1639. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1640. # Try devtool extract
  1641. self.track_for_cleanup(tempdir)
  1642. self.track_for_cleanup(self.workspacedir)
  1643. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1644. result = runCmd('devtool extract virtual/make %s' % tempdir)
  1645. self.assertExists(os.path.join(tempdir, 'Makefile.am'), 'Extracted source could not be found')
  1646. self._check_src_repo(tempdir)
  1647. def test_devtool_reset_all(self):
  1648. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1649. self.track_for_cleanup(tempdir)
  1650. self.track_for_cleanup(self.workspacedir)
  1651. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1652. testrecipe1 = 'mdadm'
  1653. testrecipe2 = 'cronie'
  1654. result = runCmd('devtool modify -x %s %s' % (testrecipe1, os.path.join(tempdir, testrecipe1)))
  1655. result = runCmd('devtool modify -x %s %s' % (testrecipe2, os.path.join(tempdir, testrecipe2)))
  1656. result = runCmd('devtool build %s' % testrecipe1)
  1657. result = runCmd('devtool build %s' % testrecipe2)
  1658. stampprefix1 = get_bb_var('STAMP', testrecipe1)
  1659. self.assertTrue(stampprefix1, 'Unable to get STAMP value for recipe %s' % testrecipe1)
  1660. stampprefix2 = get_bb_var('STAMP', testrecipe2)
  1661. self.assertTrue(stampprefix2, 'Unable to get STAMP value for recipe %s' % testrecipe2)
  1662. result = runCmd('devtool reset -a')
  1663. self.assertIn(testrecipe1, result.output)
  1664. self.assertIn(testrecipe2, result.output)
  1665. result = runCmd('devtool status')
  1666. self.assertNotIn(testrecipe1, result.output)
  1667. self.assertNotIn(testrecipe2, result.output)
  1668. matches1 = glob.glob(stampprefix1 + '*')
  1669. self.assertFalse(matches1, 'Stamp files exist for recipe %s that should have been cleaned' % testrecipe1)
  1670. matches2 = glob.glob(stampprefix2 + '*')
  1671. self.assertFalse(matches2, 'Stamp files exist for recipe %s that should have been cleaned' % testrecipe2)
  1672. @OETestTag("runqemu")
  1673. def test_devtool_deploy_target(self):
  1674. self._check_runqemu_prerequisites()
  1675. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1676. # Definitions
  1677. testrecipe = 'mdadm'
  1678. testfile = '/sbin/mdadm'
  1679. if "usrmerge" in get_bb_var('DISTRO_FEATURES'):
  1680. testfile = '/usr/sbin/mdadm'
  1681. testimage = 'oe-selftest-image'
  1682. testcommand = '/sbin/mdadm --help'
  1683. # Build an image to run
  1684. bitbake("%s qemu-native qemu-helper-native" % testimage)
  1685. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  1686. self.add_command_to_tearDown('bitbake -c clean %s' % testimage)
  1687. self.add_command_to_tearDown('rm -f %s/%s*' % (deploy_dir_image, testimage))
  1688. # Clean recipe so the first deploy will fail
  1689. bitbake("%s -c clean" % testrecipe)
  1690. # Try devtool modify
  1691. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1692. self.track_for_cleanup(tempdir)
  1693. self.track_for_cleanup(self.workspacedir)
  1694. self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe)
  1695. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1696. result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir))
  1697. # Test that deploy-target at this point fails (properly)
  1698. result = runCmd('devtool deploy-target -n %s root@localhost' % testrecipe, ignore_status=True)
  1699. self.assertNotEqual(result.output, 0, 'devtool deploy-target should have failed, output: %s' % result.output)
  1700. self.assertNotIn(result.output, 'Traceback', 'devtool deploy-target should have failed with a proper error not a traceback, output: %s' % result.output)
  1701. result = runCmd('devtool build %s' % testrecipe)
  1702. # First try a dry-run of deploy-target
  1703. result = runCmd('devtool deploy-target -n %s root@localhost' % testrecipe)
  1704. self.assertIn(' %s' % testfile, result.output)
  1705. # Boot the image
  1706. with runqemu(testimage) as qemu:
  1707. # Now really test deploy-target
  1708. result = runCmd('devtool deploy-target -c %s root@%s' % (testrecipe, qemu.ip))
  1709. # Run a test command to see if it was installed properly
  1710. sshargs = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
  1711. result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand))
  1712. # Check if it deployed all of the files with the right ownership/perms
  1713. # First look on the host - need to do this under pseudo to get the correct ownership/perms
  1714. bb_vars = get_bb_vars(['D', 'FAKEROOTENV', 'FAKEROOTCMD'], testrecipe)
  1715. installdir = bb_vars['D']
  1716. fakerootenv = bb_vars['FAKEROOTENV']
  1717. fakerootcmd = bb_vars['FAKEROOTCMD']
  1718. result = runCmd('%s %s find . -type f -exec ls -l {} \\;' % (fakerootenv, fakerootcmd), cwd=installdir)
  1719. filelist1 = self._process_ls_output(result.output)
  1720. # Now look on the target
  1721. tempdir2 = tempfile.mkdtemp(prefix='devtoolqa')
  1722. self.track_for_cleanup(tempdir2)
  1723. tmpfilelist = os.path.join(tempdir2, 'files.txt')
  1724. with open(tmpfilelist, 'w') as f:
  1725. for line in filelist1:
  1726. splitline = line.split()
  1727. f.write(splitline[-1] + '\n')
  1728. result = runCmd('cat %s | ssh -q %s root@%s \'xargs ls -l\'' % (tmpfilelist, sshargs, qemu.ip))
  1729. filelist2 = self._process_ls_output(result.output)
  1730. filelist1.sort(key=lambda item: item.split()[-1])
  1731. filelist2.sort(key=lambda item: item.split()[-1])
  1732. self.assertEqual(filelist1, filelist2)
  1733. # Test undeploy-target
  1734. result = runCmd('devtool undeploy-target -c %s root@%s' % (testrecipe, qemu.ip))
  1735. result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand), ignore_status=True)
  1736. self.assertNotEqual(result, 0, 'undeploy-target did not remove command as it should have')
  1737. def test_devtool_build_image(self):
  1738. """Test devtool build-image plugin"""
  1739. # Check preconditions
  1740. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1741. image = 'core-image-minimal'
  1742. self.track_for_cleanup(self.workspacedir)
  1743. self.add_command_to_tearDown('bitbake -c clean %s' % image)
  1744. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1745. bitbake('%s -c clean' % image)
  1746. # Add target and native recipes to workspace
  1747. recipes = ['mdadm', 'parted-native']
  1748. for recipe in recipes:
  1749. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1750. self.track_for_cleanup(tempdir)
  1751. self.add_command_to_tearDown('bitbake -c clean %s' % recipe)
  1752. runCmd('devtool modify %s -x %s' % (recipe, tempdir))
  1753. # Try to build image
  1754. result = runCmd('devtool build-image %s' % image)
  1755. self.assertNotEqual(result, 0, 'devtool build-image failed')
  1756. # Check if image contains expected packages
  1757. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  1758. image_link_name = get_bb_var('IMAGE_LINK_NAME', image)
  1759. reqpkgs = [item for item in recipes if not item.endswith('-native')]
  1760. with open(os.path.join(deploy_dir_image, image_link_name + '.manifest'), 'r') as f:
  1761. for line in f:
  1762. splitval = line.split()
  1763. if splitval:
  1764. pkg = splitval[0]
  1765. if pkg in reqpkgs:
  1766. reqpkgs.remove(pkg)
  1767. if reqpkgs:
  1768. self.fail('The following packages were not present in the image as expected: %s' % ', '.join(reqpkgs))
  1769. class DevtoolUpgradeTests(DevtoolBase):
  1770. def setUp(self):
  1771. super().setUp()
  1772. try:
  1773. runCmd("git config --global user.name")
  1774. runCmd("git config --global user.email")
  1775. except:
  1776. self.skip("Git user.name and user.email must be set")
  1777. def test_devtool_upgrade(self):
  1778. # Check preconditions
  1779. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1780. self.track_for_cleanup(self.workspacedir)
  1781. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1782. # Check parameters
  1783. result = runCmd('devtool upgrade -h')
  1784. for param in 'recipename srctree --version -V --branch -b --keep-temp --no-patch'.split():
  1785. self.assertIn(param, result.output)
  1786. # For the moment, we are using a real recipe.
  1787. recipe = 'devtool-upgrade-test1'
  1788. version = '1.6.0'
  1789. oldrecipefile = get_bb_var('FILE', recipe)
  1790. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1791. self.track_for_cleanup(tempdir)
  1792. # Check that recipe is not already under devtool control
  1793. result = runCmd('devtool status')
  1794. self.assertNotIn(recipe, result.output)
  1795. # Check upgrade. Code does not check if new PV is older or newer that current PV, so, it may be that
  1796. # we are downgrading instead of upgrading.
  1797. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, version))
  1798. # Check if srctree at least is populated
  1799. self.assertTrue(len(os.listdir(tempdir)) > 0, 'srctree (%s) should be populated with new (%s) source code' % (tempdir, version))
  1800. # Check new recipe subdirectory is present
  1801. self.assertExists(os.path.join(self.workspacedir, 'recipes', recipe, '%s-%s' % (recipe, version)), 'Recipe folder should exist')
  1802. # Check new recipe file is present
  1803. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, '%s_%s.bb' % (recipe, version))
  1804. self.assertExists(newrecipefile, 'Recipe file should exist after upgrade')
  1805. # Check devtool status and make sure recipe is present
  1806. result = runCmd('devtool status')
  1807. self.assertIn(recipe, result.output)
  1808. self.assertIn(tempdir, result.output)
  1809. # Check recipe got changed as expected
  1810. with open(oldrecipefile + '.upgraded', 'r') as f:
  1811. desiredlines = f.readlines()
  1812. with open(newrecipefile, 'r') as f:
  1813. newlines = f.readlines()
  1814. self.assertEqual(desiredlines, newlines)
  1815. # Check devtool reset recipe
  1816. result = runCmd('devtool reset %s -n' % recipe)
  1817. result = runCmd('devtool status')
  1818. self.assertNotIn(recipe, result.output)
  1819. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after resetting')
  1820. def test_devtool_upgrade_git(self):
  1821. # Check preconditions
  1822. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1823. self.track_for_cleanup(self.workspacedir)
  1824. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1825. recipe = 'devtool-upgrade-test2'
  1826. commit = '6cc6077a36fe2648a5f993fe7c16c9632f946517'
  1827. oldrecipefile = get_bb_var('FILE', recipe)
  1828. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1829. self.track_for_cleanup(tempdir)
  1830. # Check that recipe is not already under devtool control
  1831. result = runCmd('devtool status')
  1832. self.assertNotIn(recipe, result.output)
  1833. # Check upgrade
  1834. result = runCmd('devtool upgrade %s %s -S %s' % (recipe, tempdir, commit))
  1835. # Check if srctree at least is populated
  1836. self.assertTrue(len(os.listdir(tempdir)) > 0, 'srctree (%s) should be populated with new (%s) source code' % (tempdir, commit))
  1837. # Check new recipe file is present
  1838. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, os.path.basename(oldrecipefile))
  1839. self.assertExists(newrecipefile, 'Recipe file should exist after upgrade')
  1840. # Check devtool status and make sure recipe is present
  1841. result = runCmd('devtool status')
  1842. self.assertIn(recipe, result.output)
  1843. self.assertIn(tempdir, result.output)
  1844. # Check recipe got changed as expected
  1845. with open(oldrecipefile + '.upgraded', 'r') as f:
  1846. desiredlines = f.readlines()
  1847. with open(newrecipefile, 'r') as f:
  1848. newlines = f.readlines()
  1849. self.assertEqual(desiredlines, newlines)
  1850. # Check devtool reset recipe
  1851. result = runCmd('devtool reset %s -n' % recipe)
  1852. result = runCmd('devtool status')
  1853. self.assertNotIn(recipe, result.output)
  1854. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after resetting')
  1855. def test_devtool_upgrade_drop_md5sum(self):
  1856. # Check preconditions
  1857. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1858. self.track_for_cleanup(self.workspacedir)
  1859. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1860. # For the moment, we are using a real recipe.
  1861. recipe = 'devtool-upgrade-test3'
  1862. version = '1.6.0'
  1863. oldrecipefile = get_bb_var('FILE', recipe)
  1864. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1865. self.track_for_cleanup(tempdir)
  1866. # Check upgrade. Code does not check if new PV is older or newer that current PV, so, it may be that
  1867. # we are downgrading instead of upgrading.
  1868. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, version))
  1869. # Check new recipe file is present
  1870. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, '%s_%s.bb' % (recipe, version))
  1871. self.assertExists(newrecipefile, 'Recipe file should exist after upgrade')
  1872. # Check recipe got changed as expected
  1873. with open(oldrecipefile + '.upgraded', 'r') as f:
  1874. desiredlines = f.readlines()
  1875. with open(newrecipefile, 'r') as f:
  1876. newlines = f.readlines()
  1877. self.assertEqual(desiredlines, newlines)
  1878. def test_devtool_upgrade_all_checksums(self):
  1879. # Check preconditions
  1880. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1881. self.track_for_cleanup(self.workspacedir)
  1882. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1883. # For the moment, we are using a real recipe.
  1884. recipe = 'devtool-upgrade-test4'
  1885. version = '1.6.0'
  1886. oldrecipefile = get_bb_var('FILE', recipe)
  1887. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1888. self.track_for_cleanup(tempdir)
  1889. # Check upgrade. Code does not check if new PV is older or newer that current PV, so, it may be that
  1890. # we are downgrading instead of upgrading.
  1891. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, version))
  1892. # Check new recipe file is present
  1893. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, '%s_%s.bb' % (recipe, version))
  1894. self.assertExists(newrecipefile, 'Recipe file should exist after upgrade')
  1895. # Check recipe got changed as expected
  1896. with open(oldrecipefile + '.upgraded', 'r') as f:
  1897. desiredlines = f.readlines()
  1898. with open(newrecipefile, 'r') as f:
  1899. newlines = f.readlines()
  1900. self.assertEqual(desiredlines, newlines)
  1901. def test_devtool_upgrade_recipe_update_extra_tasks(self):
  1902. # Check preconditions
  1903. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  1904. self.track_for_cleanup(self.workspacedir)
  1905. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1906. recipe = 'python3-guessing-game'
  1907. version = '0.2.0'
  1908. commit = '40cf004c2772ffa20ea803fa3be1528a75be3e98'
  1909. oldrecipefile = get_bb_var('FILE', recipe)
  1910. oldcratesincfile = os.path.join(os.path.dirname(oldrecipefile), os.path.basename(oldrecipefile).strip('_git.bb') + '-crates.inc')
  1911. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  1912. self.track_for_cleanup(tempdir)
  1913. # Check that recipe is not already under devtool control
  1914. result = runCmd('devtool status')
  1915. self.assertNotIn(recipe, result.output)
  1916. # Check upgrade
  1917. result = runCmd('devtool upgrade %s %s --version %s --srcrev %s' % (recipe, tempdir, version, commit))
  1918. # Check if srctree at least is populated
  1919. self.assertTrue(len(os.listdir(tempdir)) > 0, 'srctree (%s) should be populated with new (%s) source code' % (tempdir, commit))
  1920. # Check new recipe file and new -crates.inc files are present
  1921. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipe, os.path.basename(oldrecipefile))
  1922. newcratesincfile = os.path.join(self.workspacedir, 'recipes', recipe, os.path.basename(oldcratesincfile))
  1923. self.assertExists(newrecipefile, 'Recipe file should exist after upgrade')
  1924. self.assertExists(newcratesincfile, 'Recipe crates.inc file should exist after upgrade')
  1925. # Check devtool status and make sure recipe is present
  1926. result = runCmd('devtool status')
  1927. self.assertIn(recipe, result.output)
  1928. self.assertIn(tempdir, result.output)
  1929. # Check recipe got changed as expected
  1930. with open(oldrecipefile + '.upgraded', 'r') as f:
  1931. desiredlines = f.readlines()
  1932. with open(newrecipefile, 'r') as f:
  1933. newlines = f.readlines()
  1934. self.assertEqual(desiredlines, newlines)
  1935. # Check crates.inc got changed as expected
  1936. with open(oldcratesincfile + '.upgraded', 'r') as f:
  1937. desiredlines = f.readlines()
  1938. with open(newcratesincfile, 'r') as f:
  1939. newlines = f.readlines()
  1940. self.assertEqual(desiredlines, newlines)
  1941. # Check devtool reset recipe
  1942. result = runCmd('devtool reset %s -n' % recipe)
  1943. result = runCmd('devtool status')
  1944. self.assertNotIn(recipe, result.output)
  1945. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after resetting')
  1946. def test_devtool_layer_plugins(self):
  1947. """Test that devtool can use plugins from other layers.
  1948. This test executes the selftest-reverse command from meta-selftest."""
  1949. self.track_for_cleanup(self.workspacedir)
  1950. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1951. s = "Microsoft Made No Profit From Anyone's Zunes Yo"
  1952. result = runCmd("devtool --quiet selftest-reverse \"%s\"" % s)
  1953. self.assertEqual(result.output, s[::-1])
  1954. def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
  1955. dstdir = basedstdir
  1956. self.assertExists(dstdir)
  1957. for p in paths:
  1958. dstdir = os.path.join(dstdir, p)
  1959. if not os.path.exists(dstdir):
  1960. try:
  1961. os.makedirs(dstdir)
  1962. except PermissionError:
  1963. return False
  1964. except OSError as e:
  1965. if e.errno == errno.EROFS:
  1966. return False
  1967. else:
  1968. raise e
  1969. if p == "lib":
  1970. # Can race with other tests
  1971. self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
  1972. else:
  1973. self.track_for_cleanup(dstdir)
  1974. dstfile = os.path.join(dstdir, os.path.basename(srcfile))
  1975. if srcfile != dstfile:
  1976. try:
  1977. shutil.copy(srcfile, dstfile)
  1978. except PermissionError:
  1979. return False
  1980. self.track_for_cleanup(dstfile)
  1981. return True
  1982. def test_devtool_load_plugin(self):
  1983. """Test that devtool loads only the first found plugin in BBPATH."""
  1984. self.track_for_cleanup(self.workspacedir)
  1985. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  1986. devtool = runCmd("which devtool")
  1987. fromname = runCmd("devtool --quiet pluginfile")
  1988. srcfile = fromname.output
  1989. bbpath = get_bb_var('BBPATH')
  1990. searchpath = bbpath.split(':') + [os.path.dirname(devtool.output)]
  1991. plugincontent = []
  1992. with open(srcfile) as fh:
  1993. plugincontent = fh.readlines()
  1994. try:
  1995. self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
  1996. searchpath = [
  1997. path for path in searchpath
  1998. if self._copy_file_with_cleanup(srcfile, path, 'lib', 'devtool')
  1999. ]
  2000. result = runCmd("devtool --quiet count")
  2001. self.assertEqual(result.output, '1')
  2002. result = runCmd("devtool --quiet multiloaded")
  2003. self.assertEqual(result.output, "no")
  2004. for path in searchpath:
  2005. result = runCmd("devtool --quiet bbdir")
  2006. self.assertEqual(os.path.realpath(result.output), os.path.realpath(path))
  2007. os.unlink(os.path.join(result.output, 'lib', 'devtool', 'bbpath.py'))
  2008. finally:
  2009. with open(srcfile, 'w') as fh:
  2010. fh.writelines(plugincontent)
  2011. def _setup_test_devtool_finish_upgrade(self):
  2012. # Check preconditions
  2013. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  2014. self.track_for_cleanup(self.workspacedir)
  2015. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  2016. # Use a "real" recipe from meta-selftest
  2017. recipe = 'devtool-upgrade-test1'
  2018. oldversion = '1.5.3'
  2019. newversion = '1.6.0'
  2020. oldrecipefile = get_bb_var('FILE', recipe)
  2021. recipedir = os.path.dirname(oldrecipefile)
  2022. result = runCmd('git status --porcelain .', cwd=recipedir)
  2023. if result.output.strip():
  2024. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  2025. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  2026. self.track_for_cleanup(tempdir)
  2027. # Check that recipe is not already under devtool control
  2028. result = runCmd('devtool status')
  2029. self.assertNotIn(recipe, result.output)
  2030. # Do the upgrade
  2031. result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, newversion))
  2032. # Check devtool status and make sure recipe is present
  2033. result = runCmd('devtool status')
  2034. self.assertIn(recipe, result.output)
  2035. self.assertIn(tempdir, result.output)
  2036. # Make a change to the source
  2037. result = runCmd('sed -i \'/^#include "pv.h"/a \\/* Here is a new comment *\\/\' src/pv/number.c', cwd=tempdir)
  2038. result = runCmd('git status --porcelain', cwd=tempdir)
  2039. self.assertIn('M src/pv/number.c', result.output)
  2040. result = runCmd('git commit src/pv/number.c -m "Add a comment to the code"', cwd=tempdir)
  2041. # Check if patch is there
  2042. recipedir = os.path.dirname(oldrecipefile)
  2043. olddir = os.path.join(recipedir, recipe + '-' + oldversion)
  2044. patchfn = '0001-Add-a-note-line-to-the-quick-reference.patch'
  2045. backportedpatchfn = 'backported.patch'
  2046. self.assertExists(os.path.join(olddir, patchfn), 'Original patch file does not exist')
  2047. self.assertExists(os.path.join(olddir, backportedpatchfn), 'Backported patch file does not exist')
  2048. return recipe, oldrecipefile, recipedir, olddir, newversion, patchfn, backportedpatchfn
  2049. def test_devtool_finish_upgrade_origlayer(self):
  2050. recipe, oldrecipefile, recipedir, olddir, newversion, patchfn, backportedpatchfn = self._setup_test_devtool_finish_upgrade()
  2051. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  2052. self.assertIn('/meta-selftest/', recipedir)
  2053. # Try finish to the original layer
  2054. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  2055. result = runCmd('devtool finish %s meta-selftest' % recipe)
  2056. result = runCmd('devtool status')
  2057. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  2058. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  2059. self.assertNotExists(oldrecipefile, 'Old recipe file should have been deleted but wasn\'t')
  2060. self.assertNotExists(os.path.join(olddir, patchfn), 'Old patch file should have been deleted but wasn\'t')
  2061. self.assertNotExists(os.path.join(olddir, backportedpatchfn), 'Old backported patch file should have been deleted but wasn\'t')
  2062. newrecipefile = os.path.join(recipedir, '%s_%s.bb' % (recipe, newversion))
  2063. newdir = os.path.join(recipedir, recipe + '-' + newversion)
  2064. self.assertExists(newrecipefile, 'New recipe file should have been copied into existing layer but wasn\'t')
  2065. self.assertExists(os.path.join(newdir, patchfn), 'Patch file should have been copied into new directory but wasn\'t')
  2066. self.assertNotExists(os.path.join(newdir, backportedpatchfn), 'Backported patch file should not have been copied into new directory but was')
  2067. self.assertExists(os.path.join(newdir, '0002-Add-a-comment-to-the-code.patch'), 'New patch file should have been created but wasn\'t')
  2068. with open(newrecipefile, 'r') as f:
  2069. newcontent = f.read()
  2070. self.assertNotIn(backportedpatchfn, newcontent, "Backported patch should have been removed from the recipe but wasn't")
  2071. self.assertIn(patchfn, newcontent, "Old patch should have not been removed from the recipe but was")
  2072. self.assertIn("0002-Add-a-comment-to-the-code.patch", newcontent, "New patch should have been added to the recipe but wasn't")
  2073. self.assertIn("http://www.ivarch.com/programs/sources/pv-${PV}.tar.gz", newcontent, "New recipe no longer has upstream source in SRC_URI")
  2074. def test_devtool_finish_upgrade_otherlayer(self):
  2075. recipe, oldrecipefile, recipedir, olddir, newversion, patchfn, backportedpatchfn = self._setup_test_devtool_finish_upgrade()
  2076. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  2077. self.assertIn('/meta-selftest/', recipedir)
  2078. # Try finish to a different layer - should create a bbappend
  2079. # This cleanup isn't strictly necessary but do it anyway just in case it goes wrong and writes to here
  2080. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  2081. oe_core_dir = os.path.join(get_bb_var('COREBASE'), 'meta')
  2082. newrecipedir = os.path.join(oe_core_dir, 'recipes-test', 'devtool')
  2083. newrecipefile = os.path.join(newrecipedir, '%s_%s.bb' % (recipe, newversion))
  2084. self.track_for_cleanup(newrecipedir)
  2085. result = runCmd('devtool finish %s oe-core' % recipe)
  2086. result = runCmd('devtool status')
  2087. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  2088. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  2089. self.assertExists(oldrecipefile, 'Old recipe file should not have been deleted')
  2090. self.assertExists(os.path.join(olddir, patchfn), 'Old patch file should not have been deleted')
  2091. self.assertExists(os.path.join(olddir, backportedpatchfn), 'Old backported patch file should not have been deleted')
  2092. newdir = os.path.join(newrecipedir, recipe + '-' + newversion)
  2093. self.assertExists(newrecipefile, 'New recipe file should have been copied into existing layer but wasn\'t')
  2094. self.assertExists(os.path.join(newdir, patchfn), 'Patch file should have been copied into new directory but wasn\'t')
  2095. self.assertNotExists(os.path.join(newdir, backportedpatchfn), 'Backported patch file should not have been copied into new directory but was')
  2096. self.assertExists(os.path.join(newdir, '0002-Add-a-comment-to-the-code.patch'), 'New patch file should have been created but wasn\'t')
  2097. with open(newrecipefile, 'r') as f:
  2098. newcontent = f.read()
  2099. self.assertNotIn(backportedpatchfn, newcontent, "Backported patch should have been removed from the recipe but wasn't")
  2100. self.assertIn(patchfn, newcontent, "Old patch should have not been removed from the recipe but was")
  2101. self.assertIn("0002-Add-a-comment-to-the-code.patch", newcontent, "New patch should have been added to the recipe but wasn't")
  2102. self.assertIn("http://www.ivarch.com/programs/sources/pv-${PV}.tar.gz", newcontent, "New recipe no longer has upstream source in SRC_URI")
  2103. def _setup_test_devtool_finish_modify(self):
  2104. # Check preconditions
  2105. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  2106. # Try modifying a recipe
  2107. self.track_for_cleanup(self.workspacedir)
  2108. recipe = 'mdadm'
  2109. oldrecipefile = get_bb_var('FILE', recipe)
  2110. recipedir = os.path.dirname(oldrecipefile)
  2111. result = runCmd('git status --porcelain .', cwd=recipedir)
  2112. if result.output.strip():
  2113. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  2114. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  2115. self.track_for_cleanup(tempdir)
  2116. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  2117. result = runCmd('devtool modify %s %s' % (recipe, tempdir))
  2118. self.assertExists(os.path.join(tempdir, 'Makefile'), 'Extracted source could not be found')
  2119. # Test devtool status
  2120. result = runCmd('devtool status')
  2121. self.assertIn(recipe, result.output)
  2122. self.assertIn(tempdir, result.output)
  2123. # Make a change to the source
  2124. result = runCmd('sed -i \'/^#include "mdadm.h"/a \\/* Here is a new comment *\\/\' maps.c', cwd=tempdir)
  2125. result = runCmd('git status --porcelain', cwd=tempdir)
  2126. self.assertIn('M maps.c', result.output)
  2127. result = runCmd('git commit maps.c -m "Add a comment to the code"', cwd=tempdir)
  2128. for entry in os.listdir(recipedir):
  2129. filesdir = os.path.join(recipedir, entry)
  2130. if os.path.isdir(filesdir):
  2131. break
  2132. else:
  2133. self.fail('Unable to find recipe files directory for %s' % recipe)
  2134. return recipe, oldrecipefile, recipedir, filesdir
  2135. def test_devtool_finish_modify_origlayer(self):
  2136. recipe, oldrecipefile, recipedir, filesdir = self._setup_test_devtool_finish_modify()
  2137. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  2138. self.assertIn('/meta/', recipedir)
  2139. # Try finish to the original layer
  2140. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  2141. result = runCmd('devtool finish %s meta' % recipe)
  2142. result = runCmd('devtool status')
  2143. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  2144. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  2145. expected_status = [(' M', '.*/%s$' % os.path.basename(oldrecipefile)),
  2146. ('??', '.*/.*-Add-a-comment-to-the-code.patch$')]
  2147. self._check_repo_status(recipedir, expected_status)
  2148. def test_devtool_finish_modify_otherlayer(self):
  2149. recipe, oldrecipefile, recipedir, filesdir = self._setup_test_devtool_finish_modify()
  2150. # Ensure the recipe is where we think it should be (so that cleanup doesn't trash things)
  2151. self.assertIn('/meta/', recipedir)
  2152. relpth = os.path.relpath(recipedir, os.path.join(get_bb_var('COREBASE'), 'meta'))
  2153. appenddir = os.path.join(get_test_layer(), relpth)
  2154. self.track_for_cleanup(appenddir)
  2155. # Try finish to the original layer
  2156. self.add_command_to_tearDown('rm -rf %s ; cd %s ; git checkout %s' % (recipedir, os.path.dirname(recipedir), recipedir))
  2157. result = runCmd('devtool finish %s meta-selftest' % recipe)
  2158. result = runCmd('devtool status')
  2159. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  2160. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  2161. result = runCmd('git status --porcelain .', cwd=recipedir)
  2162. if result.output.strip():
  2163. self.fail('Recipe directory for %s contains the following unexpected changes after finish:\n%s' % (recipe, result.output.strip()))
  2164. recipefn = os.path.splitext(os.path.basename(oldrecipefile))[0]
  2165. recipefn = recipefn.split('_')[0] + '_%'
  2166. appendfile = os.path.join(appenddir, recipefn + '.bbappend')
  2167. self.assertExists(appendfile, 'bbappend %s should have been created but wasn\'t' % appendfile)
  2168. newdir = os.path.join(appenddir, recipe)
  2169. files = os.listdir(newdir)
  2170. foundpatch = None
  2171. for fn in files:
  2172. if fnmatch.fnmatch(fn, '*-Add-a-comment-to-the-code.patch'):
  2173. foundpatch = fn
  2174. if not foundpatch:
  2175. self.fail('No patch file created next to bbappend')
  2176. files.remove(foundpatch)
  2177. if files:
  2178. self.fail('Unexpected file(s) copied next to bbappend: %s' % ', '.join(files))
  2179. def test_devtool_finish_update_patch(self):
  2180. # This test uses a modified version of the sysdig recipe from meta-oe.
  2181. # - The patches have been renamed.
  2182. # - The dependencies are commented out since the recipe is not being
  2183. # built.
  2184. #
  2185. # The sysdig recipe is interesting in that it fetches two different Git
  2186. # repositories, and there are patches for both. This leads to that
  2187. # devtool will create ignore commits as it uses Git submodules to keep
  2188. # track of the second repository.
  2189. #
  2190. # This test will verify that the ignored commits actually are ignored
  2191. # when a commit in between is modified. It will also verify that the
  2192. # updated patch keeps its original name.
  2193. # Check preconditions
  2194. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  2195. # Try modifying a recipe
  2196. self.track_for_cleanup(self.workspacedir)
  2197. recipe = 'sysdig-selftest'
  2198. recipefile = get_bb_var('FILE', recipe)
  2199. recipedir = os.path.dirname(recipefile)
  2200. result = runCmd('git status --porcelain .', cwd=recipedir)
  2201. if result.output.strip():
  2202. self.fail('Recipe directory for %s contains uncommitted changes' % recipe)
  2203. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  2204. self.track_for_cleanup(tempdir)
  2205. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  2206. result = runCmd('devtool modify %s %s' % (recipe, tempdir))
  2207. self.add_command_to_tearDown('cd %s; rm %s/*; git checkout %s %s' % (recipedir, recipe, recipe, os.path.basename(recipefile)))
  2208. self.assertExists(os.path.join(tempdir, 'CMakeLists.txt'), 'Extracted source could not be found')
  2209. # Make a change to one of the existing commits
  2210. result = runCmd('echo "# A comment " >> CMakeLists.txt', cwd=tempdir)
  2211. result = runCmd('git status --porcelain', cwd=tempdir)
  2212. self.assertIn('M CMakeLists.txt', result.output)
  2213. result = runCmd('git commit --fixup HEAD^ CMakeLists.txt', cwd=tempdir)
  2214. result = runCmd('git show -s --format=%s', cwd=tempdir)
  2215. self.assertIn('fixup! cmake: Pass PROBE_NAME via CFLAGS', result.output)
  2216. result = runCmd('GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash devtool-base', cwd=tempdir)
  2217. result = runCmd('devtool finish %s meta-selftest' % recipe)
  2218. result = runCmd('devtool status')
  2219. self.assertNotIn(recipe, result.output, 'Recipe should have been reset by finish but wasn\'t')
  2220. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipe), 'Recipe directory should not exist after finish')
  2221. expected_status = [(' M', '.*/0099-cmake-Pass-PROBE_NAME-via-CFLAGS.patch$')]
  2222. self._check_repo_status(recipedir, expected_status)
  2223. def test_devtool_rename(self):
  2224. # Check preconditions
  2225. self.assertTrue(not os.path.exists(self.workspacedir), 'This test cannot be run with a workspace directory under the build directory')
  2226. self.track_for_cleanup(self.workspacedir)
  2227. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  2228. # First run devtool add
  2229. # We already have this recipe in OE-Core, but that doesn't matter
  2230. recipename = 'i2c-tools'
  2231. recipever = '3.1.2'
  2232. recipefile = os.path.join(self.workspacedir, 'recipes', recipename, '%s_%s.bb' % (recipename, recipever))
  2233. url = 'http://downloads.yoctoproject.org/mirror/sources/i2c-tools-%s.tar.bz2' % recipever
  2234. def add_recipe():
  2235. result = runCmd('devtool add %s' % url)
  2236. self.assertExists(recipefile, 'Expected recipe file not created')
  2237. self.assertExists(os.path.join(self.workspacedir, 'sources', recipename), 'Source directory not created')
  2238. checkvars = {}
  2239. checkvars['S'] = None
  2240. checkvars['SRC_URI'] = url.replace(recipever, '${PV}')
  2241. self._test_recipe_contents(recipefile, checkvars, [])
  2242. add_recipe()
  2243. # Now rename it - change both name and version
  2244. newrecipename = 'mynewrecipe'
  2245. newrecipever = '456'
  2246. newrecipefile = os.path.join(self.workspacedir, 'recipes', newrecipename, '%s_%s.bb' % (newrecipename, newrecipever))
  2247. result = runCmd('devtool rename %s %s -V %s' % (recipename, newrecipename, newrecipever))
  2248. self.assertExists(newrecipefile, 'Recipe file not renamed')
  2249. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipename), 'Old recipe directory still exists')
  2250. newsrctree = os.path.join(self.workspacedir, 'sources', newrecipename)
  2251. self.assertExists(newsrctree, 'Source directory not renamed')
  2252. checkvars = {}
  2253. checkvars['S'] = '${WORKDIR}/%s-%s' % (recipename, recipever)
  2254. checkvars['SRC_URI'] = url
  2255. self._test_recipe_contents(newrecipefile, checkvars, [])
  2256. # Try again - change just name this time
  2257. result = runCmd('devtool reset -n %s' % newrecipename)
  2258. add_recipe()
  2259. newrecipefile = os.path.join(self.workspacedir, 'recipes', newrecipename, '%s_%s.bb' % (newrecipename, recipever))
  2260. result = runCmd('devtool rename %s %s' % (recipename, newrecipename))
  2261. self.assertExists(newrecipefile, 'Recipe file not renamed')
  2262. self.assertNotExists(os.path.join(self.workspacedir, 'recipes', recipename), 'Old recipe directory still exists')
  2263. self.assertExists(os.path.join(self.workspacedir, 'sources', newrecipename), 'Source directory not renamed')
  2264. checkvars = {}
  2265. checkvars['S'] = '${WORKDIR}/%s-${PV}' % recipename
  2266. checkvars['SRC_URI'] = url.replace(recipever, '${PV}')
  2267. self._test_recipe_contents(newrecipefile, checkvars, [])
  2268. # Try again - change just version this time
  2269. result = runCmd('devtool reset -n %s' % newrecipename)
  2270. add_recipe()
  2271. newrecipefile = os.path.join(self.workspacedir, 'recipes', recipename, '%s_%s.bb' % (recipename, newrecipever))
  2272. result = runCmd('devtool rename %s -V %s' % (recipename, newrecipever))
  2273. self.assertExists(newrecipefile, 'Recipe file not renamed')
  2274. self.assertExists(os.path.join(self.workspacedir, 'sources', recipename), 'Source directory no longer exists')
  2275. checkvars = {}
  2276. checkvars['S'] = '${WORKDIR}/${BPN}-%s' % recipever
  2277. checkvars['SRC_URI'] = url
  2278. self._test_recipe_contents(newrecipefile, checkvars, [])
  2279. def test_devtool_virtual_kernel_modify(self):
  2280. """
  2281. Summary: The purpose of this test case is to verify that
  2282. devtool modify works correctly when building
  2283. the kernel.
  2284. Dependencies: NA
  2285. Steps: 1. Build kernel with bitbake.
  2286. 2. Save the config file generated.
  2287. 3. Clean the environment.
  2288. 4. Use `devtool modify virtual/kernel` to validate following:
  2289. 4.1 The source is checked out correctly.
  2290. 4.2 The resulting configuration is the same as
  2291. what was get on step 2.
  2292. 4.3 The Kernel can be build correctly.
  2293. 4.4 Changes made on the source are reflected on the
  2294. subsequent builds.
  2295. 4.5 Changes on the configuration are reflected on the
  2296. subsequent builds
  2297. Expected: devtool modify is able to checkout the source of the kernel
  2298. and modification to the source and configurations are reflected
  2299. when building the kernel.
  2300. """
  2301. kernel_provider = self.td['PREFERRED_PROVIDER_virtual/kernel']
  2302. # Clean up the environment
  2303. bitbake('%s -c clean' % kernel_provider)
  2304. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  2305. tempdir_cfg = tempfile.mkdtemp(prefix='config_qa')
  2306. self.track_for_cleanup(tempdir)
  2307. self.track_for_cleanup(tempdir_cfg)
  2308. self.track_for_cleanup(self.workspacedir)
  2309. self.add_command_to_tearDown('bitbake -c clean %s' % kernel_provider)
  2310. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  2311. #Step 1
  2312. #Here is just generated the config file instead of all the kernel to optimize the
  2313. #time of executing this test case.
  2314. bitbake('%s -c configure' % kernel_provider)
  2315. bbconfig = os.path.join(get_bb_var('B', kernel_provider),'.config')
  2316. #Step 2
  2317. runCmd('cp %s %s' % (bbconfig, tempdir_cfg))
  2318. self.assertExists(os.path.join(tempdir_cfg, '.config'), 'Could not copy .config file from kernel')
  2319. tmpconfig = os.path.join(tempdir_cfg, '.config')
  2320. #Step 3
  2321. bitbake('%s -c clean' % kernel_provider)
  2322. #Step 4.1
  2323. runCmd('devtool modify virtual/kernel -x %s' % tempdir)
  2324. self.assertExists(os.path.join(tempdir, 'Makefile'), 'Extracted source could not be found')
  2325. #Step 4.2
  2326. configfile = os.path.join(tempdir,'.config')
  2327. runCmd('diff %s %s' % (tmpconfig, configfile))
  2328. #Step 4.3
  2329. #NOTE: virtual/kernel is mapped to kernel_provider
  2330. runCmd('devtool build %s' % kernel_provider)
  2331. kernelfile = os.path.join(get_bb_var('KBUILD_OUTPUT', kernel_provider), 'vmlinux')
  2332. self.assertExists(kernelfile, 'Kernel was not build correctly')
  2333. #Modify the kernel source
  2334. modfile = os.path.join(tempdir, 'init/version.c')
  2335. # Moved to uts.h in 6.1 onwards
  2336. modfile2 = os.path.join(tempdir, 'include/linux/uts.h')
  2337. runCmd("sed -i 's/Linux/LiNuX/g' %s %s" % (modfile, modfile2))
  2338. #Modify the configuration
  2339. codeconfigfile = os.path.join(tempdir, '.config.new')
  2340. modconfopt = "CONFIG_SG_POOL=n"
  2341. runCmd("sed -i 's/CONFIG_SG_POOL=y/%s/' %s" % (modconfopt, codeconfigfile))
  2342. #Build again kernel with devtool
  2343. runCmd('devtool build %s' % kernel_provider)
  2344. #Step 4.4
  2345. runCmd("grep '%s' %s" % ('LiNuX', kernelfile))
  2346. #Step 4.5
  2347. runCmd("grep %s %s" % (modconfopt, codeconfigfile))
  2348. class DevtoolIdeSdkTests(DevtoolBase):
  2349. def _write_bb_config(self, recipe_names):
  2350. """Helper to write the bitbake local.conf file"""
  2351. conf_lines = [
  2352. 'IMAGE_CLASSES += "image-combined-dbg"',
  2353. 'IMAGE_GEN_DEBUGFS = "1"',
  2354. 'IMAGE_INSTALL:append = " gdbserver %s"' % ' '.join(
  2355. [r + '-ptest' for r in recipe_names])
  2356. ]
  2357. self.write_config("\n".join(conf_lines))
  2358. def _check_workspace(self):
  2359. """Check if a workspace directory is available and setup the cleanup"""
  2360. self.assertTrue(not os.path.exists(self.workspacedir),
  2361. 'This test cannot be run with a workspace directory under the build directory')
  2362. self.track_for_cleanup(self.workspacedir)
  2363. self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
  2364. def _workspace_scripts_dir(self, recipe_name):
  2365. return os.path.realpath(os.path.join(self.builddir, 'workspace', 'ide-sdk', recipe_name, 'scripts'))
  2366. def _sources_scripts_dir(self, src_dir):
  2367. return os.path.realpath(os.path.join(src_dir, 'oe-scripts'))
  2368. def _workspace_gdbinit_dir(self, recipe_name):
  2369. return os.path.realpath(os.path.join(self.builddir, 'workspace', 'ide-sdk', recipe_name, 'scripts', 'gdbinit'))
  2370. def _sources_gdbinit_dir(self, src_dir):
  2371. return os.path.realpath(os.path.join(src_dir, 'oe-gdbinit'))
  2372. def _devtool_ide_sdk_recipe(self, recipe_name, build_file, testimage):
  2373. """Setup a recipe for working with devtool ide-sdk
  2374. Basically devtool modify -x followed by some tests
  2375. """
  2376. tempdir = tempfile.mkdtemp(prefix='devtoolqa')
  2377. self.track_for_cleanup(tempdir)
  2378. self.add_command_to_tearDown('bitbake -c clean %s' % recipe_name)
  2379. result = runCmd('devtool modify %s -x %s' % (recipe_name, tempdir))
  2380. self.assertExists(os.path.join(tempdir, build_file),
  2381. 'Extracted source could not be found')
  2382. self.assertExists(os.path.join(self.workspacedir, 'conf',
  2383. 'layer.conf'), 'Workspace directory not created')
  2384. matches = glob.glob(os.path.join(self.workspacedir,
  2385. 'appends', recipe_name + '.bbappend'))
  2386. self.assertTrue(matches, 'bbappend not created %s' % result.output)
  2387. # Test devtool status
  2388. result = runCmd('devtool status')
  2389. self.assertIn(recipe_name, result.output)
  2390. self.assertIn(tempdir, result.output)
  2391. self._check_src_repo(tempdir)
  2392. # Usually devtool ide-sdk would initiate the build of the SDK.
  2393. # But there is a circular dependency with starting Qemu and passing the IP of runqemu to devtool ide-sdk.
  2394. if testimage:
  2395. bitbake("%s qemu-native qemu-helper-native" % testimage)
  2396. deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
  2397. self.add_command_to_tearDown('bitbake -c clean %s' % testimage)
  2398. self.add_command_to_tearDown(
  2399. 'rm -f %s/%s*' % (deploy_dir_image, testimage))
  2400. return tempdir
  2401. def _get_recipe_ids(self, recipe_name):
  2402. """IDs needed to write recipe specific config entries into IDE config files"""
  2403. package_arch = get_bb_var('PACKAGE_ARCH', recipe_name)
  2404. recipe_id = recipe_name + "-" + package_arch
  2405. recipe_id_pretty = recipe_name + ": " + package_arch
  2406. return (recipe_id, recipe_id_pretty)
  2407. def _verify_install_script_code(self, tempdir, recipe_name):
  2408. """Verify the scripts referred by the tasks.json file are fine.
  2409. This function does not depend on Qemu. Therefore it verifies the scripts
  2410. exists and the delete step works as expected. But it does not try to
  2411. deploy to Qemu.
  2412. """
  2413. recipe_id, recipe_id_pretty = self._get_recipe_ids(recipe_name)
  2414. with open(os.path.join(tempdir, '.vscode', 'tasks.json')) as tasks_j:
  2415. tasks_d = json.load(tasks_j)
  2416. tasks = tasks_d["tasks"]
  2417. task_install = next(
  2418. (task for task in tasks if task["label"] == "install && deploy-target %s" % recipe_id_pretty), None)
  2419. self.assertIsNot(task_install, None)
  2420. # execute only the bb_run_do_install script since the deploy would require e.g. Qemu running.
  2421. i_and_d_script = "install_and_deploy_" + recipe_id
  2422. i_and_d_script_path = os.path.join(
  2423. self._workspace_scripts_dir(recipe_name), i_and_d_script)
  2424. self.assertExists(i_and_d_script_path)
  2425. del_script = "delete_package_dirs_" + recipe_id
  2426. del_script_path = os.path.join(
  2427. self._workspace_scripts_dir(recipe_name), del_script)
  2428. self.assertExists(del_script_path)
  2429. runCmd(del_script_path, cwd=tempdir)
  2430. def _devtool_ide_sdk_qemu(self, tempdir, qemu, recipe_name, example_exe):
  2431. """Verify deployment and execution in Qemu system work for one recipe.
  2432. This function checks the entire SDK workflow: changing the code, recompiling
  2433. it and deploying it back to Qemu, and checking that the changes have been
  2434. incorporated into the provided binaries. It also runs the tests of the recipe.
  2435. """
  2436. recipe_id, _ = self._get_recipe_ids(recipe_name)
  2437. i_and_d_script = "install_and_deploy_" + recipe_id
  2438. install_deploy_cmd = os.path.join(
  2439. self._workspace_scripts_dir(recipe_name), i_and_d_script)
  2440. self.assertExists(install_deploy_cmd,
  2441. '%s script not found' % install_deploy_cmd)
  2442. runCmd(install_deploy_cmd)
  2443. MAGIC_STRING_ORIG = "Magic: 123456789"
  2444. MAGIC_STRING_NEW = "Magic: 987654321"
  2445. ptest_cmd = "ptest-runner " + recipe_name
  2446. # validate that SSH is working
  2447. status, _ = qemu.run("uname")
  2448. self.assertEqual(
  2449. status, 0, msg="Failed to connect to the SSH server on Qemu")
  2450. # Verify the unmodified example prints the magic string
  2451. status, output = qemu.run(example_exe)
  2452. self.assertEqual(status, 0, msg="%s failed: %s" %
  2453. (example_exe, output))
  2454. self.assertIn(MAGIC_STRING_ORIG, output)
  2455. # Verify the unmodified ptests work
  2456. status, output = qemu.run(ptest_cmd)
  2457. self.assertEqual(status, 0, msg="%s failed: %s" % (ptest_cmd, output))
  2458. self.assertIn("PASS: cpp-example-lib", output)
  2459. # Verify remote debugging works
  2460. self._gdb_cross_debugging(
  2461. qemu, recipe_name, example_exe, MAGIC_STRING_ORIG)
  2462. # Replace the Magic String in the code, compile and deploy to Qemu
  2463. cpp_example_lib_hpp = os.path.join(tempdir, 'cpp-example-lib.hpp')
  2464. with open(cpp_example_lib_hpp, 'r') as file:
  2465. cpp_code = file.read()
  2466. cpp_code = cpp_code.replace(MAGIC_STRING_ORIG, MAGIC_STRING_NEW)
  2467. with open(cpp_example_lib_hpp, 'w') as file:
  2468. file.write(cpp_code)
  2469. runCmd(install_deploy_cmd, cwd=tempdir)
  2470. # Verify the modified example prints the modified magic string
  2471. status, output = qemu.run(example_exe)
  2472. self.assertEqual(status, 0, msg="%s failed: %s" %
  2473. (example_exe, output))
  2474. self.assertNotIn(MAGIC_STRING_ORIG, output)
  2475. self.assertIn(MAGIC_STRING_NEW, output)
  2476. # Verify the modified example ptests work
  2477. status, output = qemu.run(ptest_cmd)
  2478. self.assertEqual(status, 0, msg="%s failed: %s" % (ptest_cmd, output))
  2479. self.assertIn("PASS: cpp-example-lib", output)
  2480. # Verify remote debugging works wit the modified magic string
  2481. self._gdb_cross_debugging(
  2482. qemu, recipe_name, example_exe, MAGIC_STRING_NEW)
  2483. def _gdb_cross(self):
  2484. """Verify gdb-cross is provided by devtool ide-sdk"""
  2485. target_arch = self.td["TARGET_ARCH"]
  2486. target_sys = self.td["TARGET_SYS"]
  2487. gdb_recipe = "gdb-cross-" + target_arch
  2488. gdb_binary = target_sys + "-gdb"
  2489. native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", gdb_recipe)
  2490. r = runCmd("%s --version" % gdb_binary,
  2491. native_sysroot=native_sysroot, target_sys=target_sys)
  2492. self.assertEqual(r.status, 0)
  2493. self.assertIn("GNU gdb", r.output)
  2494. def _gdb_cross_debugging(self, qemu, recipe_name, example_exe, magic_string):
  2495. """Verify gdb-cross is working
  2496. Test remote debugging:
  2497. break main
  2498. run
  2499. continue
  2500. break CppExample::print_json()
  2501. continue
  2502. print CppExample::test_string.compare("cpp-example-lib Magic: 123456789")
  2503. $1 = 0
  2504. print CppExample::test_string.compare("cpp-example-lib Magic: 123456789aaa")
  2505. $2 = -3
  2506. list cpp-example-lib.hpp:13,13
  2507. 13 inline static const std::string test_string = "cpp-example-lib Magic: 123456789";
  2508. continue
  2509. """
  2510. sshargs = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
  2511. gdbserver_script = os.path.join(self._workspace_scripts_dir(
  2512. recipe_name), 'gdbserver_1234_usr-bin-' + example_exe + '_m')
  2513. gdb_script = os.path.join(self._workspace_scripts_dir(
  2514. recipe_name), 'gdb_1234_usr-bin-' + example_exe)
  2515. # Start a gdbserver
  2516. r = runCmd(gdbserver_script)
  2517. self.assertEqual(r.status, 0)
  2518. # Check there is a gdbserver running
  2519. r = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, 'ps'))
  2520. self.assertEqual(r.status, 0)
  2521. self.assertIn("gdbserver ", r.output)
  2522. # Check the pid file is correct
  2523. test_cmd = "cat /proc/$(cat /tmp/gdbserver_1234_usr-bin-" + \
  2524. example_exe + "/pid)/cmdline"
  2525. r = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, test_cmd))
  2526. self.assertEqual(r.status, 0)
  2527. self.assertIn("gdbserver", r.output)
  2528. # Test remote debugging works
  2529. gdb_batch_cmd = " --batch -ex 'break main' -ex 'run'"
  2530. gdb_batch_cmd += " -ex 'break CppExample::print_json()' -ex 'continue'"
  2531. gdb_batch_cmd += " -ex 'print CppExample::test_string.compare(\"cpp-example-lib %s\")'" % magic_string
  2532. gdb_batch_cmd += " -ex 'print CppExample::test_string.compare(\"cpp-example-lib %saaa\")'" % magic_string
  2533. gdb_batch_cmd += " -ex 'list cpp-example-lib.hpp:13,13'"
  2534. gdb_batch_cmd += " -ex 'continue'"
  2535. r = runCmd(gdb_script + gdb_batch_cmd)
  2536. self.logger.debug("%s %s returned: %s", gdb_script,
  2537. gdb_batch_cmd, r.output)
  2538. self.assertEqual(r.status, 0)
  2539. self.assertIn("Breakpoint 1, main", r.output)
  2540. self.assertIn("$1 = 0", r.output) # test.string.compare equal
  2541. self.assertIn("$2 = -3", r.output) # test.string.compare longer
  2542. self.assertIn(
  2543. 'inline static const std::string test_string = "cpp-example-lib %s";' % magic_string, r.output)
  2544. self.assertIn("exited normally", r.output)
  2545. # Stop the gdbserver
  2546. r = runCmd(gdbserver_script + ' stop')
  2547. self.assertEqual(r.status, 0)
  2548. # Check there is no gdbserver running
  2549. r = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, 'ps'))
  2550. self.assertEqual(r.status, 0)
  2551. self.assertNotIn("gdbserver ", r.output)
  2552. def _verify_cmake_preset(self, tempdir):
  2553. """Verify the generated cmake preset works as expected
  2554. Check if compiling works
  2555. Check if unit tests can be executed in qemu (not qemu-system)
  2556. """
  2557. with open(os.path.join(tempdir, 'CMakeUserPresets.json')) as cmake_preset_j:
  2558. cmake_preset_d = json.load(cmake_preset_j)
  2559. config_presets = cmake_preset_d["configurePresets"]
  2560. self.assertEqual(len(config_presets), 1)
  2561. cmake_exe = config_presets[0]["cmakeExecutable"]
  2562. preset_name = config_presets[0]["name"]
  2563. # Verify the wrapper for cmake native is available
  2564. self.assertExists(cmake_exe)
  2565. # Verify the cmake preset generated by devtool ide-sdk is available
  2566. result = runCmd('%s --list-presets' % cmake_exe, cwd=tempdir)
  2567. self.assertIn(preset_name, result.output)
  2568. # Verify cmake re-uses the o files compiled by bitbake
  2569. result = runCmd('%s --build --preset %s' %
  2570. (cmake_exe, preset_name), cwd=tempdir)
  2571. self.assertIn("ninja: no work to do.", result.output)
  2572. # Verify the unit tests work (in Qemu user mode)
  2573. result = runCmd('%s --build --preset %s --target test' %
  2574. (cmake_exe, preset_name), cwd=tempdir)
  2575. self.assertIn("100% tests passed", result.output)
  2576. # Verify re-building and testing works again
  2577. result = runCmd('%s --build --preset %s --target clean' %
  2578. (cmake_exe, preset_name), cwd=tempdir)
  2579. self.assertIn("Cleaning", result.output)
  2580. result = runCmd('%s --build --preset %s' %
  2581. (cmake_exe, preset_name), cwd=tempdir)
  2582. self.assertIn("Building", result.output)
  2583. self.assertIn("Linking", result.output)
  2584. result = runCmd('%s --build --preset %s --target test' %
  2585. (cmake_exe, preset_name), cwd=tempdir)
  2586. self.assertIn("Running tests...", result.output)
  2587. self.assertIn("100% tests passed", result.output)
  2588. @OETestTag("runqemu")
  2589. def test_devtool_ide_sdk_none_qemu(self):
  2590. """Start qemu-system and run tests for multiple recipes. ide=none is used."""
  2591. recipe_names = ["cmake-example", "meson-example"]
  2592. testimage = "oe-selftest-image"
  2593. self._check_workspace()
  2594. self._write_bb_config(recipe_names)
  2595. self._check_runqemu_prerequisites()
  2596. # Verify deployment to Qemu (system mode) works
  2597. bitbake(testimage)
  2598. with runqemu(testimage, runqemuparams="nographic") as qemu:
  2599. # cmake-example recipe
  2600. recipe_name = "cmake-example"
  2601. example_exe = "cmake-example"
  2602. build_file = "CMakeLists.txt"
  2603. tempdir = self._devtool_ide_sdk_recipe(
  2604. recipe_name, build_file, testimage)
  2605. bitbake_sdk_cmd = 'devtool ide-sdk %s %s -t root@%s -c --ide=none' % (
  2606. recipe_name, testimage, qemu.ip)
  2607. runCmd(bitbake_sdk_cmd)
  2608. self._gdb_cross()
  2609. self._verify_cmake_preset(tempdir)
  2610. self._devtool_ide_sdk_qemu(tempdir, qemu, recipe_name, example_exe)
  2611. # Verify the oe-scripts sym-link is valid
  2612. self.assertEqual(self._workspace_scripts_dir(
  2613. recipe_name), self._sources_scripts_dir(tempdir))
  2614. # meson-example recipe
  2615. recipe_name = "meson-example"
  2616. example_exe = "mesonex"
  2617. build_file = "meson.build"
  2618. tempdir = self._devtool_ide_sdk_recipe(
  2619. recipe_name, build_file, testimage)
  2620. bitbake_sdk_cmd = 'devtool ide-sdk %s %s -t root@%s -c --ide=none' % (
  2621. recipe_name, testimage, qemu.ip)
  2622. runCmd(bitbake_sdk_cmd)
  2623. self._gdb_cross()
  2624. self._devtool_ide_sdk_qemu(tempdir, qemu, recipe_name, example_exe)
  2625. # Verify the oe-scripts sym-link is valid
  2626. self.assertEqual(self._workspace_scripts_dir(
  2627. recipe_name), self._sources_scripts_dir(tempdir))
  2628. def test_devtool_ide_sdk_code_cmake(self):
  2629. """Verify a cmake recipe works with ide=code mode"""
  2630. recipe_name = "cmake-example"
  2631. build_file = "CMakeLists.txt"
  2632. testimage = "oe-selftest-image"
  2633. self._check_workspace()
  2634. self._write_bb_config([recipe_name])
  2635. tempdir = self._devtool_ide_sdk_recipe(
  2636. recipe_name, build_file, testimage)
  2637. bitbake_sdk_cmd = 'devtool ide-sdk %s %s -t root@192.168.17.17 -c --ide=code' % (
  2638. recipe_name, testimage)
  2639. runCmd(bitbake_sdk_cmd)
  2640. self._verify_cmake_preset(tempdir)
  2641. self._verify_install_script_code(tempdir, recipe_name)
  2642. self._gdb_cross()
  2643. def test_devtool_ide_sdk_code_meson(self):
  2644. """Verify a meson recipe works with ide=code mode"""
  2645. recipe_name = "meson-example"
  2646. build_file = "meson.build"
  2647. testimage = "oe-selftest-image"
  2648. self._check_workspace()
  2649. self._write_bb_config([recipe_name])
  2650. tempdir = self._devtool_ide_sdk_recipe(
  2651. recipe_name, build_file, testimage)
  2652. bitbake_sdk_cmd = 'devtool ide-sdk %s %s -t root@192.168.17.17 -c --ide=code' % (
  2653. recipe_name, testimage)
  2654. runCmd(bitbake_sdk_cmd)
  2655. with open(os.path.join(tempdir, '.vscode', 'settings.json')) as settings_j:
  2656. settings_d = json.load(settings_j)
  2657. meson_exe = settings_d["mesonbuild.mesonPath"]
  2658. meson_build_folder = settings_d["mesonbuild.buildFolder"]
  2659. # Verify the wrapper for meson native is available
  2660. self.assertExists(meson_exe)
  2661. # Verify meson re-uses the o files compiled by bitbake
  2662. result = runCmd('%s compile -C %s' %
  2663. (meson_exe, meson_build_folder), cwd=tempdir)
  2664. self.assertIn("ninja: no work to do.", result.output)
  2665. # Verify the unit tests work (in Qemu)
  2666. runCmd('%s test -C %s' % (meson_exe, meson_build_folder), cwd=tempdir)
  2667. # Verify re-building and testing works again
  2668. result = runCmd('%s compile -C %s --clean' %
  2669. (meson_exe, meson_build_folder), cwd=tempdir)
  2670. self.assertIn("Cleaning...", result.output)
  2671. result = runCmd('%s compile -C %s' %
  2672. (meson_exe, meson_build_folder), cwd=tempdir)
  2673. self.assertIn("Linking target", result.output)
  2674. runCmd('%s test -C %s' % (meson_exe, meson_build_folder), cwd=tempdir)
  2675. self._verify_install_script_code(tempdir, recipe_name)
  2676. self._gdb_cross()
  2677. def test_devtool_ide_sdk_shared_sysroots(self):
  2678. """Verify the shared sysroot SDK"""
  2679. # Handle the workspace (which is not needed by this test case)
  2680. self._check_workspace()
  2681. result_init = runCmd(
  2682. 'devtool ide-sdk -m shared oe-selftest-image cmake-example meson-example --ide=code')
  2683. bb_vars = get_bb_vars(
  2684. ['REAL_MULTIMACH_TARGET_SYS', 'DEPLOY_DIR_IMAGE', 'COREBASE'], "meta-ide-support")
  2685. environment_script = 'environment-setup-%s' % bb_vars['REAL_MULTIMACH_TARGET_SYS']
  2686. deploydir = bb_vars['DEPLOY_DIR_IMAGE']
  2687. environment_script_path = os.path.join(deploydir, environment_script)
  2688. cpp_example_src = os.path.join(
  2689. bb_vars['COREBASE'], 'meta-selftest', 'recipes-test', 'cpp', 'files')
  2690. # Verify the cross environment script is available
  2691. self.assertExists(environment_script_path)
  2692. def runCmdEnv(cmd, cwd):
  2693. cmd = '/bin/sh -c ". %s > /dev/null && %s"' % (
  2694. environment_script_path, cmd)
  2695. return runCmd(cmd, cwd)
  2696. # Verify building the C++ example works with CMake
  2697. tempdir_cmake = tempfile.mkdtemp(prefix='devtoolqa')
  2698. self.track_for_cleanup(tempdir_cmake)
  2699. result_cmake = runCmdEnv("which cmake", cwd=tempdir_cmake)
  2700. cmake_native = os.path.normpath(result_cmake.output.strip())
  2701. self.assertExists(cmake_native)
  2702. runCmdEnv('cmake %s' % cpp_example_src, cwd=tempdir_cmake)
  2703. runCmdEnv('cmake --build %s' % tempdir_cmake, cwd=tempdir_cmake)
  2704. # Verify the printed note really referres to a cmake executable
  2705. cmake_native_code = ""
  2706. for line in result_init.output.splitlines():
  2707. m = re.search(r'"cmake.cmakePath": "(.*)"', line)
  2708. if m:
  2709. cmake_native_code = m.group(1)
  2710. break
  2711. self.assertExists(cmake_native_code)
  2712. self.assertEqual(cmake_native, cmake_native_code)
  2713. # Verify building the C++ example works with Meson
  2714. tempdir_meson = tempfile.mkdtemp(prefix='devtoolqa')
  2715. self.track_for_cleanup(tempdir_meson)
  2716. result_cmake = runCmdEnv("which meson", cwd=tempdir_meson)
  2717. meson_native = os.path.normpath(result_cmake.output.strip())
  2718. self.assertExists(meson_native)
  2719. runCmdEnv('meson setup %s' % tempdir_meson, cwd=cpp_example_src)
  2720. runCmdEnv('meson compile', cwd=tempdir_meson)
  2721. def test_devtool_ide_sdk_plugins(self):
  2722. """Test that devtool ide-sdk can use plugins from other layers."""
  2723. # We need a workspace layer and a modified recipe (but no image)
  2724. modified_recipe_name = "meson-example"
  2725. modified_build_file = "meson.build"
  2726. testimage = "oe-selftest-image"
  2727. shared_recipe_name = "cmake-example"
  2728. self._check_workspace()
  2729. self._write_bb_config([modified_recipe_name])
  2730. tempdir = self._devtool_ide_sdk_recipe(
  2731. modified_recipe_name, modified_build_file, None)
  2732. IDE_RE = re.compile(r'.*--ide \{(.*)\}.*')
  2733. def get_ides_from_help(help_str):
  2734. m = IDE_RE.search(help_str)
  2735. return m.group(1).split(',')
  2736. # verify the default plugins are available but the foo plugin is not
  2737. result = runCmd('devtool ide-sdk -h')
  2738. found_ides = get_ides_from_help(result.output)
  2739. self.assertIn('code', found_ides)
  2740. self.assertIn('none', found_ides)
  2741. self.assertNotIn('foo', found_ides)
  2742. shared_config_file = os.path.join(tempdir, 'shared-config.txt')
  2743. shared_config_str = 'Dummy shared IDE config'
  2744. modified_config_file = os.path.join(tempdir, 'modified-config.txt')
  2745. modified_config_str = 'Dummy modified IDE config'
  2746. # Generate a foo plugin in the workspace layer
  2747. plugin_dir = os.path.join(
  2748. self.workspacedir, 'lib', 'devtool', 'ide_plugins')
  2749. os.makedirs(plugin_dir)
  2750. plugin_code = 'from devtool.ide_plugins import IdeBase\n\n'
  2751. plugin_code += 'class IdeFoo(IdeBase):\n'
  2752. plugin_code += ' def setup_shared_sysroots(self, shared_env):\n'
  2753. plugin_code += ' with open("%s", "w") as config_file:\n' % shared_config_file
  2754. plugin_code += ' config_file.write("%s")\n\n' % shared_config_str
  2755. plugin_code += ' def setup_modified_recipe(self, args, image_recipe, modified_recipe):\n'
  2756. plugin_code += ' with open("%s", "w") as config_file:\n' % modified_config_file
  2757. plugin_code += ' config_file.write("%s")\n\n' % modified_config_str
  2758. plugin_code += 'def register_ide_plugin(ide_plugins):\n'
  2759. plugin_code += ' ide_plugins["foo"] = IdeFoo\n'
  2760. plugin_py = os.path.join(plugin_dir, 'ide_foo.py')
  2761. with open(plugin_py, 'w') as plugin_file:
  2762. plugin_file.write(plugin_code)
  2763. # Verify the foo plugin is available as well
  2764. result = runCmd('devtool ide-sdk -h')
  2765. found_ides = get_ides_from_help(result.output)
  2766. self.assertIn('code', found_ides)
  2767. self.assertIn('none', found_ides)
  2768. self.assertIn('foo', found_ides)
  2769. # Verify the foo plugin generates a shared config
  2770. result = runCmd(
  2771. 'devtool ide-sdk -m shared --skip-bitbake --ide foo %s' % shared_recipe_name)
  2772. with open(shared_config_file) as shared_config:
  2773. shared_config_new = shared_config.read()
  2774. self.assertEqual(shared_config_str, shared_config_new)
  2775. # Verify the foo plugin generates a modified config
  2776. result = runCmd('devtool ide-sdk --skip-bitbake --ide foo %s %s' %
  2777. (modified_recipe_name, testimage))
  2778. with open(modified_config_file) as modified_config:
  2779. modified_config_new = modified_config.read()
  2780. self.assertEqual(modified_config_str, modified_config_new)