devtool.py 162 KB

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