Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 3 | # |
| 4 | # Copyright 2017 Google, Inc |
| 5 | # |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 6 | |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 7 | """Functional tests for checking that patman behaves correctly""" |
| 8 | |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 9 | import os |
| 10 | import re |
| 11 | import shutil |
| 12 | import sys |
| 13 | import tempfile |
| 14 | import unittest |
| 15 | |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 16 | from patman import control |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 17 | from patman import gitutil |
| 18 | from patman import patchstream |
Simon Glass | 47f6295 | 2020-10-29 21:46:26 -0600 | [diff] [blame] | 19 | from patman.patchstream import PatchStream |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 20 | from patman import settings |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 21 | from patman import terminal |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 22 | from patman import tools |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 23 | from patman.test_util import capture_sys_output |
| 24 | |
| 25 | try: |
| 26 | import pygit2 |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 27 | HAVE_PYGIT2 = True |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 28 | except ModuleNotFoundError: |
| 29 | HAVE_PYGIT2 = False |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 30 | |
| 31 | |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 32 | class TestFunctional(unittest.TestCase): |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 33 | """Functional tests for checking that patman behaves correctly""" |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 34 | leb = (b'Lord Edmund Blackadd\xc3\xabr <weasel@blackadder.org>'. |
| 35 | decode('utf-8')) |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 36 | fred = 'Fred Bloggs <f.bloggs@napier.net>' |
| 37 | joe = 'Joe Bloggs <joe@napierwallies.co.nz>' |
| 38 | mary = 'Mary Bloggs <mary@napierwallies.co.nz>' |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 39 | |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 40 | def setUp(self): |
| 41 | self.tmpdir = tempfile.mkdtemp(prefix='patman.') |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 42 | self.gitdir = os.path.join(self.tmpdir, 'git') |
| 43 | self.repo = None |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 44 | |
| 45 | def tearDown(self): |
| 46 | shutil.rmtree(self.tmpdir) |
| 47 | |
| 48 | @staticmethod |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 49 | def _get_path(fname): |
| 50 | """Get the path to a test file |
| 51 | |
| 52 | Args: |
| 53 | fname (str): Filename to obtain |
| 54 | |
| 55 | Returns: |
| 56 | str: Full path to file in the test directory |
| 57 | """ |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 58 | return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), |
| 59 | 'test', fname) |
| 60 | |
| 61 | @classmethod |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 62 | def _get_text(cls, fname): |
| 63 | """Read a file as text |
| 64 | |
| 65 | Args: |
| 66 | fname (str): Filename to read |
| 67 | |
| 68 | Returns: |
| 69 | str: Contents of file |
| 70 | """ |
| 71 | return open(cls._get_path(fname), encoding='utf-8').read() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 72 | |
| 73 | @classmethod |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 74 | def _get_patch_name(cls, subject): |
| 75 | """Get the filename of a patch given its subject |
| 76 | |
| 77 | Args: |
| 78 | subject (str): Patch subject |
| 79 | |
| 80 | Returns: |
| 81 | str: Filename for that patch |
| 82 | """ |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 83 | fname = re.sub('[ :]', '-', subject) |
| 84 | return fname.replace('--', '-') |
| 85 | |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 86 | def _create_patches_for_test(self, series): |
| 87 | """Create patch files for use by tests |
| 88 | |
| 89 | This copies patch files from the test directory as needed by the series |
| 90 | |
| 91 | Args: |
| 92 | series (Series): Series containing commits to convert |
| 93 | |
| 94 | Returns: |
| 95 | tuple: |
| 96 | str: Cover-letter filename, or None if none |
| 97 | fname_list: list of str, each a patch filename |
| 98 | """ |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 99 | cover_fname = None |
| 100 | fname_list = [] |
| 101 | for i, commit in enumerate(series.commits): |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 102 | clean_subject = self._get_patch_name(commit.subject) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 103 | src_fname = '%04d-%s.patch' % (i + 1, clean_subject[:52]) |
| 104 | fname = os.path.join(self.tmpdir, src_fname) |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 105 | shutil.copy(self._get_path(src_fname), fname) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 106 | fname_list.append(fname) |
| 107 | if series.get('cover'): |
| 108 | src_fname = '0000-cover-letter.patch' |
| 109 | cover_fname = os.path.join(self.tmpdir, src_fname) |
| 110 | fname = os.path.join(self.tmpdir, src_fname) |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 111 | shutil.copy(self._get_path(src_fname), fname) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 112 | |
| 113 | return cover_fname, fname_list |
| 114 | |
| 115 | def testBasic(self): |
| 116 | """Tests the basic flow of patman |
| 117 | |
| 118 | This creates a series from some hard-coded patches build from a simple |
| 119 | tree with the following metadata in the top commit: |
| 120 | |
| 121 | Series-to: u-boot |
| 122 | Series-prefix: RFC |
| 123 | Series-cc: Stefan Brüns <stefan.bruens@rwth-aachen.de> |
| 124 | Cover-letter-cc: Lord Mëlchett <clergy@palace.gov> |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 125 | Series-version: 3 |
| 126 | Patch-cc: fred |
| 127 | Series-process-log: sort, uniq |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 128 | Series-changes: 4 |
| 129 | - Some changes |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 130 | - Multi |
| 131 | line |
| 132 | change |
| 133 | |
| 134 | Commit-changes: 2 |
| 135 | - Changes only for this commit |
| 136 | |
| 137 | Cover-changes: 4 |
| 138 | - Some notes for the cover letter |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 139 | |
| 140 | Cover-letter: |
| 141 | test: A test patch series |
| 142 | This is a test of how the cover |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 143 | letter |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 144 | works |
| 145 | END |
| 146 | |
| 147 | and this in the first commit: |
| 148 | |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 149 | Commit-changes: 2 |
| 150 | - second revision change |
| 151 | |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 152 | Series-notes: |
| 153 | some notes |
| 154 | about some things |
| 155 | from the first commit |
| 156 | END |
| 157 | |
| 158 | Commit-notes: |
| 159 | Some notes about |
| 160 | the first commit |
| 161 | END |
| 162 | |
| 163 | with the following commands: |
| 164 | |
| 165 | git log -n2 --reverse >/path/to/tools/patman/test/test01.txt |
| 166 | git format-patch --subject-prefix RFC --cover-letter HEAD~2 |
| 167 | mv 00* /path/to/tools/patman/test |
| 168 | |
| 169 | It checks these aspects: |
| 170 | - git log can be processed by patchstream |
| 171 | - emailing patches uses the correct command |
| 172 | - CC file has information on each commit |
| 173 | - cover letter has the expected text and subject |
| 174 | - each patch has the correct subject |
| 175 | - dry-run information prints out correctly |
| 176 | - unicode is handled correctly |
| 177 | - Series-to, Series-cc, Series-prefix, Cover-letter |
| 178 | - Cover-letter-cc, Series-version, Series-changes, Series-notes |
| 179 | - Commit-notes |
| 180 | """ |
| 181 | process_tags = True |
| 182 | ignore_bad_tags = True |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 183 | stefan = b'Stefan Br\xc3\xbcns <stefan.bruens@rwth-aachen.de>'.decode('utf-8') |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 184 | rick = 'Richard III <richard@palace.gov>' |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 185 | mel = b'Lord M\xc3\xablchett <clergy@palace.gov>'.decode('utf-8') |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 186 | add_maintainers = [stefan, rick] |
| 187 | dry_run = True |
| 188 | in_reply_to = mel |
| 189 | count = 2 |
| 190 | settings.alias = { |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 191 | 'fdt': ['simon'], |
| 192 | 'u-boot': ['u-boot@lists.denx.de'], |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 193 | 'simon': [self.leb], |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 194 | 'fred': [self.fred], |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 195 | } |
| 196 | |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 197 | text = self._get_text('test01.txt') |
Simon Glass | d93720e | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 198 | series = patchstream.get_metadata_for_test(text) |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 199 | cover_fname, args = self._create_patches_for_test(series) |
Simon Glass | 366954f | 2020-10-29 21:46:14 -0600 | [diff] [blame] | 200 | with capture_sys_output() as out: |
Simon Glass | d93720e | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 201 | patchstream.fix_patches(series, args) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 202 | if cover_fname and series.get('cover'): |
Simon Glass | d93720e | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 203 | patchstream.insert_cover_letter(cover_fname, series, count) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 204 | series.DoChecks() |
| 205 | cc_file = series.MakeCcFile(process_tags, cover_fname, |
Chris Packham | 4fb3502 | 2018-06-07 20:45:06 +1200 | [diff] [blame] | 206 | not ignore_bad_tags, add_maintainers, |
| 207 | None) |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 208 | cmd = gitutil.EmailPatches( |
| 209 | series, cover_fname, args, dry_run, not ignore_bad_tags, |
| 210 | cc_file, in_reply_to=in_reply_to, thread=None) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 211 | series.ShowActions(args, cmd, process_tags) |
Simon Glass | 272cd85 | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 212 | cc_lines = open(cc_file, encoding='utf-8').read().splitlines() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 213 | os.remove(cc_file) |
| 214 | |
Simon Glass | 8c17f8c | 2020-10-29 21:46:29 -0600 | [diff] [blame^] | 215 | lines = iter(out[0].getvalue().splitlines()) |
| 216 | self.assertEqual('Cleaned %s patches' % len(series.commits), |
| 217 | next(lines)) |
| 218 | self.assertEqual('Change log missing for v2', next(lines)) |
| 219 | self.assertEqual('Change log missing for v3', next(lines)) |
| 220 | self.assertEqual('Change log for unknown version v4', next(lines)) |
| 221 | self.assertEqual("Alias 'pci' not found", next(lines)) |
| 222 | self.assertIn('Dry run', next(lines)) |
| 223 | self.assertEqual('', next(lines)) |
| 224 | self.assertIn('Send a total of %d patches' % count, next(lines)) |
| 225 | prev = next(lines) |
| 226 | for i, commit in enumerate(series.commits): |
| 227 | self.assertEqual(' %s' % args[i], prev) |
| 228 | while True: |
| 229 | prev = next(lines) |
| 230 | if 'Cc:' not in prev: |
| 231 | break |
| 232 | self.assertEqual('To: u-boot@lists.denx.de', prev) |
| 233 | self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), next(lines)) |
| 234 | self.assertEqual('Version: 3', next(lines)) |
| 235 | self.assertEqual('Prefix:\t RFC', next(lines)) |
| 236 | self.assertEqual('Cover: 4 lines', next(lines)) |
| 237 | self.assertEqual(' Cc: %s' % self.fred, next(lines)) |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 238 | self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb), |
Simon Glass | 8c17f8c | 2020-10-29 21:46:29 -0600 | [diff] [blame^] | 239 | next(lines)) |
| 240 | self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), next(lines)) |
| 241 | self.assertEqual(' Cc: %s' % rick, next(lines)) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 242 | expected = ('Git command: git send-email --annotate ' |
| 243 | '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' |
| 244 | '--cc "%s" --cc-cmd "%s --cc-cmd %s" %s %s' |
| 245 | % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 246 | ' '.join(args))) |
Simon Glass | 8c17f8c | 2020-10-29 21:46:29 -0600 | [diff] [blame^] | 247 | self.assertEqual(expected, tools.ToUnicode(next(lines))) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 248 | |
Dmitry Torokhov | 8ab452d | 2019-10-21 20:09:56 -0700 | [diff] [blame] | 249 | self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 250 | tools.ToUnicode(cc_lines[0])) |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 251 | self.assertEqual( |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 252 | '%s %s\0%s\0%s\0%s' % (args[1], self.fred, self.leb, rick, stefan), |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 253 | tools.ToUnicode(cc_lines[1])) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 254 | |
| 255 | expected = ''' |
| 256 | This is a test of how the cover |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 257 | letter |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 258 | works |
| 259 | |
| 260 | some notes |
| 261 | about some things |
| 262 | from the first commit |
| 263 | |
| 264 | Changes in v4: |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 265 | - Multi |
| 266 | line |
| 267 | change |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 268 | - Some changes |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 269 | - Some notes for the cover letter |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 270 | |
| 271 | Simon Glass (2): |
| 272 | pci: Correct cast for sandbox |
Siva Durga Prasad Paladugu | 12308b1 | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 273 | fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 274 | |
| 275 | cmd/pci.c | 3 ++- |
| 276 | fs/fat/fat.c | 1 + |
| 277 | lib/efi_loader/efi_memory.c | 1 + |
| 278 | lib/fdtdec.c | 3 ++- |
| 279 | 4 files changed, 6 insertions(+), 2 deletions(-) |
| 280 | |
| 281 | --\x20 |
| 282 | 2.7.4 |
| 283 | |
| 284 | ''' |
Simon Glass | 272cd85 | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 285 | lines = open(cover_fname, encoding='utf-8').read().splitlines() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 286 | self.assertEqual( |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 287 | 'Subject: [RFC PATCH v3 0/2] test: A test patch series', |
| 288 | lines[3]) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 289 | self.assertEqual(expected.splitlines(), lines[7:]) |
| 290 | |
| 291 | for i, fname in enumerate(args): |
Simon Glass | 272cd85 | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 292 | lines = open(fname, encoding='utf-8').read().splitlines() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 293 | subject = [line for line in lines if line.startswith('Subject')] |
| 294 | self.assertEqual('Subject: [RFC %d/%d]' % (i + 1, count), |
| 295 | subject[0][:18]) |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 296 | |
| 297 | # Check that we got our commit notes |
| 298 | start = 0 |
| 299 | expected = '' |
| 300 | |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 301 | if i == 0: |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 302 | start = 17 |
| 303 | expected = '''--- |
| 304 | Some notes about |
| 305 | the first commit |
| 306 | |
| 307 | (no changes since v2) |
| 308 | |
| 309 | Changes in v2: |
| 310 | - second revision change''' |
| 311 | elif i == 1: |
| 312 | start = 17 |
| 313 | expected = '''--- |
| 314 | |
| 315 | Changes in v4: |
| 316 | - Multi |
| 317 | line |
| 318 | change |
| 319 | - Some changes |
| 320 | |
| 321 | Changes in v2: |
| 322 | - Changes only for this commit''' |
| 323 | |
| 324 | if expected: |
| 325 | expected = expected.splitlines() |
| 326 | self.assertEqual(expected, lines[start:(start+len(expected))]) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 327 | |
| 328 | def make_commit_with_file(self, subject, body, fname, text): |
| 329 | """Create a file and add it to the git repo with a new commit |
| 330 | |
| 331 | Args: |
| 332 | subject (str): Subject for the commit |
| 333 | body (str): Body text of the commit |
| 334 | fname (str): Filename of file to create |
| 335 | text (str): Text to put into the file |
| 336 | """ |
| 337 | path = os.path.join(self.gitdir, fname) |
| 338 | tools.WriteFile(path, text, binary=False) |
| 339 | index = self.repo.index |
| 340 | index.add(fname) |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 341 | author = pygit2.Signature('Test user', 'test@email.com') |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 342 | committer = author |
| 343 | tree = index.write_tree() |
| 344 | message = subject + '\n' + body |
| 345 | self.repo.create_commit('HEAD', author, committer, message, tree, |
| 346 | [self.repo.head.target]) |
| 347 | |
| 348 | def make_git_tree(self): |
| 349 | """Make a simple git tree suitable for testing |
| 350 | |
| 351 | It has three branches: |
| 352 | 'base' has two commits: PCI, main |
| 353 | 'first' has base as upstream and two more commits: I2C, SPI |
| 354 | 'second' has base as upstream and three more: video, serial, bootm |
| 355 | |
| 356 | Returns: |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 357 | pygit2.Repository: repository |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 358 | """ |
| 359 | repo = pygit2.init_repository(self.gitdir) |
| 360 | self.repo = repo |
| 361 | new_tree = repo.TreeBuilder().write() |
| 362 | |
| 363 | author = pygit2.Signature('Test user', 'test@email.com') |
| 364 | committer = author |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 365 | _ = repo.create_commit('HEAD', author, committer, 'Created master', |
| 366 | new_tree, []) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 367 | |
| 368 | self.make_commit_with_file('Initial commit', ''' |
| 369 | Add a README |
| 370 | |
| 371 | ''', 'README', '''This is the README file |
| 372 | describing this project |
| 373 | in very little detail''') |
| 374 | |
| 375 | self.make_commit_with_file('pci: PCI implementation', ''' |
| 376 | Here is a basic PCI implementation |
| 377 | |
| 378 | ''', 'pci.c', '''This is a file |
| 379 | it has some contents |
| 380 | and some more things''') |
| 381 | self.make_commit_with_file('main: Main program', ''' |
| 382 | Hello here is the second commit. |
| 383 | ''', 'main.c', '''This is the main file |
| 384 | there is very little here |
| 385 | but we can always add more later |
| 386 | if we want to |
| 387 | |
| 388 | Series-to: u-boot |
| 389 | Series-cc: Barry Crump <bcrump@whataroa.nz> |
| 390 | ''') |
| 391 | base_target = repo.revparse_single('HEAD') |
| 392 | self.make_commit_with_file('i2c: I2C things', ''' |
| 393 | This has some stuff to do with I2C |
| 394 | ''', 'i2c.c', '''And this is the file contents |
| 395 | with some I2C-related things in it''') |
| 396 | self.make_commit_with_file('spi: SPI fixes', ''' |
| 397 | SPI needs some fixes |
| 398 | and here they are |
| 399 | ''', 'spi.c', '''Some fixes for SPI in this |
| 400 | file to make SPI work |
| 401 | better than before''') |
| 402 | first_target = repo.revparse_single('HEAD') |
| 403 | |
| 404 | target = repo.revparse_single('HEAD~2') |
| 405 | repo.reset(target.oid, pygit2.GIT_CHECKOUT_FORCE) |
| 406 | self.make_commit_with_file('video: Some video improvements', ''' |
| 407 | Fix up the video so that |
| 408 | it looks more purple. Purple is |
| 409 | a very nice colour. |
| 410 | ''', 'video.c', '''More purple here |
| 411 | Purple and purple |
| 412 | Even more purple |
| 413 | Could not be any more purple''') |
| 414 | self.make_commit_with_file('serial: Add a serial driver', ''' |
| 415 | Here is the serial driver |
| 416 | for my chip. |
| 417 | |
| 418 | Cover-letter: |
| 419 | Series for my board |
| 420 | This series implements support |
| 421 | for my glorious board. |
| 422 | END |
Simon Glass | f9e4284 | 2020-10-29 21:46:16 -0600 | [diff] [blame] | 423 | Series-links: 183237 |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 424 | ''', 'serial.c', '''The code for the |
| 425 | serial driver is here''') |
| 426 | self.make_commit_with_file('bootm: Make it boot', ''' |
| 427 | This makes my board boot |
| 428 | with a fix to the bootm |
| 429 | command |
| 430 | ''', 'bootm.c', '''Fix up the bootm |
| 431 | command to make the code as |
| 432 | complicated as possible''') |
| 433 | second_target = repo.revparse_single('HEAD') |
| 434 | |
| 435 | repo.branches.local.create('first', first_target) |
| 436 | repo.config.set_multivar('branch.first.remote', '', '.') |
| 437 | repo.config.set_multivar('branch.first.merge', '', 'refs/heads/base') |
| 438 | |
| 439 | repo.branches.local.create('second', second_target) |
| 440 | repo.config.set_multivar('branch.second.remote', '', '.') |
| 441 | repo.config.set_multivar('branch.second.merge', '', 'refs/heads/base') |
| 442 | |
| 443 | repo.branches.local.create('base', base_target) |
| 444 | return repo |
| 445 | |
| 446 | @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2') |
| 447 | def testBranch(self): |
| 448 | """Test creating patches from a branch""" |
| 449 | repo = self.make_git_tree() |
| 450 | target = repo.lookup_reference('refs/heads/first') |
| 451 | self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE) |
| 452 | control.setup() |
| 453 | try: |
| 454 | orig_dir = os.getcwd() |
| 455 | os.chdir(self.gitdir) |
| 456 | |
| 457 | # Check that it can detect the current branch |
Simon Glass | 262130f | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 458 | self.assertEqual(2, gitutil.CountCommitsToBranch(None)) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 459 | col = terminal.Color() |
| 460 | with capture_sys_output() as _: |
| 461 | _, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | 137947e | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 462 | col, branch=None, count=-1, start=0, end=0, |
| 463 | ignore_binary=False) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 464 | self.assertIsNone(cover_fname) |
| 465 | self.assertEqual(2, len(patch_files)) |
Simon Glass | 262130f | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 466 | |
| 467 | # Check that it can detect a different branch |
| 468 | self.assertEqual(3, gitutil.CountCommitsToBranch('second')) |
| 469 | with capture_sys_output() as _: |
| 470 | _, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | 137947e | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 471 | col, branch='second', count=-1, start=0, end=0, |
Simon Glass | 262130f | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 472 | ignore_binary=False) |
| 473 | self.assertIsNotNone(cover_fname) |
| 474 | self.assertEqual(3, len(patch_files)) |
Simon Glass | 137947e | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 475 | |
| 476 | # Check that it can skip patches at the end |
| 477 | with capture_sys_output() as _: |
| 478 | _, cover_fname, patch_files = control.prepare_patches( |
| 479 | col, branch='second', count=-1, start=0, end=1, |
| 480 | ignore_binary=False) |
| 481 | self.assertIsNotNone(cover_fname) |
| 482 | self.assertEqual(2, len(patch_files)) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 483 | finally: |
| 484 | os.chdir(orig_dir) |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 485 | |
| 486 | def testTags(self): |
| 487 | """Test collection of tags in a patchstream""" |
| 488 | text = '''This is a patch |
| 489 | |
| 490 | Signed-off-by: Terminator |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 491 | Reviewed-by: %s |
| 492 | Reviewed-by: %s |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 493 | Tested-by: %s |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 494 | ''' % (self.joe, self.mary, self.leb) |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 495 | pstrm = PatchStream.process_text(text) |
| 496 | self.assertEqual(pstrm.commit.rtags, { |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 497 | 'Reviewed-by': {self.joe, self.mary}, |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 498 | 'Tested-by': {self.leb}}) |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 499 | |
| 500 | def testMissingEnd(self): |
| 501 | """Test a missing END tag""" |
| 502 | text = '''This is a patch |
| 503 | |
| 504 | Cover-letter: |
| 505 | This is the title |
| 506 | missing END after this line |
| 507 | Signed-off-by: Fred |
| 508 | ''' |
| 509 | pstrm = PatchStream.process_text(text) |
| 510 | self.assertEqual(["Missing 'END' in section 'cover'"], |
| 511 | pstrm.commit.warn) |
| 512 | |
| 513 | def testMissingBlankLine(self): |
| 514 | """Test a missing blank line after a tag""" |
| 515 | text = '''This is a patch |
| 516 | |
| 517 | Series-changes: 2 |
| 518 | - First line of changes |
| 519 | - Missing blank line after this line |
| 520 | Signed-off-by: Fred |
| 521 | ''' |
| 522 | pstrm = PatchStream.process_text(text) |
| 523 | self.assertEqual(["Missing 'blank line' in section 'Series-changes'"], |
| 524 | pstrm.commit.warn) |
| 525 | |
| 526 | def testInvalidCommitTag(self): |
| 527 | """Test an invalid Commit-xxx tag""" |
| 528 | text = '''This is a patch |
| 529 | |
| 530 | Commit-fred: testing |
| 531 | ''' |
| 532 | pstrm = PatchStream.process_text(text) |
| 533 | self.assertEqual(["Line 3: Ignoring Commit-fred"], pstrm.commit.warn) |
| 534 | |
| 535 | def testSelfTest(self): |
| 536 | """Test a tested by tag by this user""" |
| 537 | test_line = 'Tested-by: %s@napier.com' % os.getenv('USER') |
| 538 | text = '''This is a patch |
| 539 | |
| 540 | %s |
| 541 | ''' % test_line |
| 542 | pstrm = PatchStream.process_text(text) |
| 543 | self.assertEqual(["Ignoring '%s'" % test_line], pstrm.commit.warn) |
| 544 | |
| 545 | def testSpaceBeforeTab(self): |
| 546 | """Test a space before a tab""" |
| 547 | text = '''This is a patch |
| 548 | |
| 549 | + \tSomething |
| 550 | ''' |
| 551 | pstrm = PatchStream.process_text(text) |
| 552 | self.assertEqual(["Line 3/0 has space before tab"], pstrm.commit.warn) |
| 553 | |
| 554 | def testLinesAfterTest(self): |
| 555 | """Test detecting lines after TEST= line""" |
| 556 | text = '''This is a patch |
| 557 | |
| 558 | TEST=sometest |
| 559 | more lines |
| 560 | here |
| 561 | ''' |
| 562 | pstrm = PatchStream.process_text(text) |
| 563 | self.assertEqual(["Found 2 lines after TEST="], pstrm.commit.warn) |
| 564 | |
| 565 | def testBlankLineAtEnd(self): |
| 566 | """Test detecting a blank line at the end of a file""" |
| 567 | text = '''This is a patch |
| 568 | |
| 569 | diff --git a/lib/fdtdec.c b/lib/fdtdec.c |
| 570 | index c072e54..942244f 100644 |
| 571 | --- a/lib/fdtdec.c |
| 572 | +++ b/lib/fdtdec.c |
| 573 | @@ -1200,7 +1200,8 @@ int fdtdec_setup_mem_size_base(void) |
| 574 | } |
| 575 | |
| 576 | gd->ram_size = (phys_size_t)(res.end - res.start + 1); |
| 577 | - debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size); |
| 578 | + debug("%s: Initial DRAM size %llx\n", __func__, |
| 579 | + (unsigned long long)gd->ram_size); |
| 580 | + |
| 581 | diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c |
| 582 | |
| 583 | -- |
| 584 | 2.7.4 |
| 585 | |
| 586 | ''' |
| 587 | pstrm = PatchStream.process_text(text) |
| 588 | self.assertEqual( |
| 589 | ["Found possible blank line(s) at end of file 'lib/fdtdec.c'"], |
| 590 | pstrm.commit.warn) |