test_metadata_src_uri.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Checks related to the patch's SRC_URI metadata variable
  2. #
  3. # Copyright (C) 2016 Intel Corporation
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. import subprocess
  7. import base
  8. import os
  9. import pyparsing
  10. from data import PatchTestInput, PatchTestDataStore
  11. class SrcUri(base.Metadata):
  12. metadata = 'SRC_URI'
  13. md5sum = 'md5sum'
  14. sha256sum = 'sha256sum'
  15. git_regex = pyparsing.Regex('^git\:\/\/.*')
  16. def setUp(self):
  17. # these tests just make sense on patches that can be merged
  18. if not PatchTestInput.repo.canbemerged:
  19. self.skip('Patch cannot be merged')
  20. def pretest_src_uri_left_files(self):
  21. if not self.modified:
  22. self.skip('No modified recipes, skipping pretest')
  23. # get the proper metadata values
  24. for pn in self.modified:
  25. # we are not interested in images
  26. if 'core-image' in pn:
  27. continue
  28. rd = self.tinfoil.parse_recipe(pn)
  29. PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata, pn)] = rd.getVar(self.metadata)
  30. def test_src_uri_left_files(self):
  31. if not self.modified:
  32. self.skip('No modified recipes, skipping pretest')
  33. # get the proper metadata values
  34. for pn in self.modified:
  35. # we are not interested in images
  36. if 'core-image' in pn:
  37. continue
  38. rd = self.tinfoil.parse_recipe(pn)
  39. PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata, pn)] = rd.getVar(self.metadata)
  40. for pn in self.modified:
  41. pretest_src_uri = PatchTestDataStore['pre%s-%s-%s' % (self.shortid(), self.metadata, pn)].split()
  42. test_src_uri = PatchTestDataStore['%s-%s-%s' % (self.shortid(), self.metadata, pn)].split()
  43. pretest_files = set([os.path.basename(patch) for patch in pretest_src_uri if patch.startswith('file://')])
  44. test_files = set([os.path.basename(patch) for patch in test_src_uri if patch.startswith('file://')])
  45. # check if files were removed
  46. if len(test_files) < len(pretest_files):
  47. # get removals from patchset
  48. filesremoved_from_patchset = set()
  49. for patch in self.patchset:
  50. if patch.is_removed_file:
  51. filesremoved_from_patchset.add(os.path.basename(patch.path))
  52. # get the deleted files from the SRC_URI
  53. filesremoved_from_usr_uri = pretest_files - test_files
  54. # finally, get those patches removed at SRC_URI and not removed from the patchset
  55. # TODO: we are not taking into account renames, so test may raise false positives
  56. not_removed = filesremoved_from_usr_uri - filesremoved_from_patchset
  57. if not_removed:
  58. self.fail('Patches not removed from tree. Remove them and amend the submitted mbox',
  59. data=[('Patch', f) for f in not_removed])