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 | 366954f | 2020-10-29 21:46:14 -0600 | [diff] [blame] | 215 | lines = out[0].getvalue().splitlines() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 216 | self.assertEqual('Cleaned %s patches' % len(series.commits), lines[0]) |
| 217 | self.assertEqual('Change log missing for v2', lines[1]) |
| 218 | self.assertEqual('Change log missing for v3', lines[2]) |
| 219 | self.assertEqual('Change log for unknown version v4', lines[3]) |
| 220 | self.assertEqual("Alias 'pci' not found", lines[4]) |
| 221 | self.assertIn('Dry run', lines[5]) |
| 222 | self.assertIn('Send a total of %d patches' % count, lines[7]) |
| 223 | line = 8 |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 224 | for i in range(len(series.commits)): |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 225 | self.assertEqual(' %s' % args[i], lines[line + 0]) |
| 226 | line += 1 |
| 227 | while 'Cc:' in lines[line]: |
| 228 | line += 1 |
| 229 | self.assertEqual('To: u-boot@lists.denx.de', lines[line]) |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 230 | self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), |
| 231 | lines[line + 1]) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 232 | self.assertEqual('Version: 3', lines[line + 2]) |
| 233 | self.assertEqual('Prefix:\t RFC', lines[line + 3]) |
| 234 | self.assertEqual('Cover: 4 lines', lines[line + 4]) |
| 235 | line += 5 |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame^] | 236 | self.assertEqual(' Cc: %s' % self.fred, lines[line + 0]) |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 237 | self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb), |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 238 | lines[line + 1]) |
| 239 | self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), |
| 240 | lines[line + 2]) |
Simon Glass | b644c66 | 2019-05-14 15:53:51 -0600 | [diff] [blame] | 241 | self.assertEqual(' Cc: %s' % rick, lines[line + 3]) |
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 | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 247 | line += 4 |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 248 | self.assertEqual(expected, tools.ToUnicode(lines[line])) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 249 | |
Dmitry Torokhov | 8ab452d | 2019-10-21 20:09:56 -0700 | [diff] [blame] | 250 | self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), |
Simon Glass | e6dca5e | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 251 | tools.ToUnicode(cc_lines[0])) |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 252 | self.assertEqual( |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame^] | 253 | '%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] | 254 | tools.ToUnicode(cc_lines[1])) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 255 | |
| 256 | expected = ''' |
| 257 | This is a test of how the cover |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 258 | letter |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 259 | works |
| 260 | |
| 261 | some notes |
| 262 | about some things |
| 263 | from the first commit |
| 264 | |
| 265 | Changes in v4: |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 266 | - Multi |
| 267 | line |
| 268 | change |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 269 | - Some changes |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 270 | - Some notes for the cover letter |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 271 | |
| 272 | Simon Glass (2): |
| 273 | pci: Correct cast for sandbox |
Siva Durga Prasad Paladugu | 12308b1 | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 274 | fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 275 | |
| 276 | cmd/pci.c | 3 ++- |
| 277 | fs/fat/fat.c | 1 + |
| 278 | lib/efi_loader/efi_memory.c | 1 + |
| 279 | lib/fdtdec.c | 3 ++- |
| 280 | 4 files changed, 6 insertions(+), 2 deletions(-) |
| 281 | |
| 282 | --\x20 |
| 283 | 2.7.4 |
| 284 | |
| 285 | ''' |
Simon Glass | 272cd85 | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 286 | lines = open(cover_fname, encoding='utf-8').read().splitlines() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 287 | self.assertEqual( |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 288 | 'Subject: [RFC PATCH v3 0/2] test: A test patch series', |
| 289 | lines[3]) |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 290 | self.assertEqual(expected.splitlines(), lines[7:]) |
| 291 | |
| 292 | for i, fname in enumerate(args): |
Simon Glass | 272cd85 | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 293 | lines = open(fname, encoding='utf-8').read().splitlines() |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 294 | subject = [line for line in lines if line.startswith('Subject')] |
| 295 | self.assertEqual('Subject: [RFC %d/%d]' % (i + 1, count), |
| 296 | subject[0][:18]) |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 297 | |
| 298 | # Check that we got our commit notes |
| 299 | start = 0 |
| 300 | expected = '' |
| 301 | |
Simon Glass | 6e87ae1 | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 302 | if i == 0: |
Sean Anderson | dc03ba4 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 303 | start = 17 |
| 304 | expected = '''--- |
| 305 | Some notes about |
| 306 | the first commit |
| 307 | |
| 308 | (no changes since v2) |
| 309 | |
| 310 | Changes in v2: |
| 311 | - second revision change''' |
| 312 | elif i == 1: |
| 313 | start = 17 |
| 314 | expected = '''--- |
| 315 | |
| 316 | Changes in v4: |
| 317 | - Multi |
| 318 | line |
| 319 | change |
| 320 | - Some changes |
| 321 | |
| 322 | Changes in v2: |
| 323 | - Changes only for this commit''' |
| 324 | |
| 325 | if expected: |
| 326 | expected = expected.splitlines() |
| 327 | self.assertEqual(expected, lines[start:(start+len(expected))]) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 328 | |
| 329 | def make_commit_with_file(self, subject, body, fname, text): |
| 330 | """Create a file and add it to the git repo with a new commit |
| 331 | |
| 332 | Args: |
| 333 | subject (str): Subject for the commit |
| 334 | body (str): Body text of the commit |
| 335 | fname (str): Filename of file to create |
| 336 | text (str): Text to put into the file |
| 337 | """ |
| 338 | path = os.path.join(self.gitdir, fname) |
| 339 | tools.WriteFile(path, text, binary=False) |
| 340 | index = self.repo.index |
| 341 | index.add(fname) |
Simon Glass | 427b028 | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 342 | author = pygit2.Signature('Test user', 'test@email.com') |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 343 | committer = author |
| 344 | tree = index.write_tree() |
| 345 | message = subject + '\n' + body |
| 346 | self.repo.create_commit('HEAD', author, committer, message, tree, |
| 347 | [self.repo.head.target]) |
| 348 | |
| 349 | def make_git_tree(self): |
| 350 | """Make a simple git tree suitable for testing |
| 351 | |
| 352 | It has three branches: |
| 353 | 'base' has two commits: PCI, main |
| 354 | 'first' has base as upstream and two more commits: I2C, SPI |
| 355 | 'second' has base as upstream and three more: video, serial, bootm |
| 356 | |
| 357 | Returns: |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 358 | pygit2.Repository: repository |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 359 | """ |
| 360 | repo = pygit2.init_repository(self.gitdir) |
| 361 | self.repo = repo |
| 362 | new_tree = repo.TreeBuilder().write() |
| 363 | |
| 364 | author = pygit2.Signature('Test user', 'test@email.com') |
| 365 | committer = author |
Simon Glass | fca9911 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 366 | _ = repo.create_commit('HEAD', author, committer, 'Created master', |
| 367 | new_tree, []) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 368 | |
| 369 | self.make_commit_with_file('Initial commit', ''' |
| 370 | Add a README |
| 371 | |
| 372 | ''', 'README', '''This is the README file |
| 373 | describing this project |
| 374 | in very little detail''') |
| 375 | |
| 376 | self.make_commit_with_file('pci: PCI implementation', ''' |
| 377 | Here is a basic PCI implementation |
| 378 | |
| 379 | ''', 'pci.c', '''This is a file |
| 380 | it has some contents |
| 381 | and some more things''') |
| 382 | self.make_commit_with_file('main: Main program', ''' |
| 383 | Hello here is the second commit. |
| 384 | ''', 'main.c', '''This is the main file |
| 385 | there is very little here |
| 386 | but we can always add more later |
| 387 | if we want to |
| 388 | |
| 389 | Series-to: u-boot |
| 390 | Series-cc: Barry Crump <bcrump@whataroa.nz> |
| 391 | ''') |
| 392 | base_target = repo.revparse_single('HEAD') |
| 393 | self.make_commit_with_file('i2c: I2C things', ''' |
| 394 | This has some stuff to do with I2C |
| 395 | ''', 'i2c.c', '''And this is the file contents |
| 396 | with some I2C-related things in it''') |
| 397 | self.make_commit_with_file('spi: SPI fixes', ''' |
| 398 | SPI needs some fixes |
| 399 | and here they are |
| 400 | ''', 'spi.c', '''Some fixes for SPI in this |
| 401 | file to make SPI work |
| 402 | better than before''') |
| 403 | first_target = repo.revparse_single('HEAD') |
| 404 | |
| 405 | target = repo.revparse_single('HEAD~2') |
| 406 | repo.reset(target.oid, pygit2.GIT_CHECKOUT_FORCE) |
| 407 | self.make_commit_with_file('video: Some video improvements', ''' |
| 408 | Fix up the video so that |
| 409 | it looks more purple. Purple is |
| 410 | a very nice colour. |
| 411 | ''', 'video.c', '''More purple here |
| 412 | Purple and purple |
| 413 | Even more purple |
| 414 | Could not be any more purple''') |
| 415 | self.make_commit_with_file('serial: Add a serial driver', ''' |
| 416 | Here is the serial driver |
| 417 | for my chip. |
| 418 | |
| 419 | Cover-letter: |
| 420 | Series for my board |
| 421 | This series implements support |
| 422 | for my glorious board. |
| 423 | END |
Simon Glass | f9e4284 | 2020-10-29 21:46:16 -0600 | [diff] [blame] | 424 | Series-links: 183237 |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 425 | ''', 'serial.c', '''The code for the |
| 426 | serial driver is here''') |
| 427 | self.make_commit_with_file('bootm: Make it boot', ''' |
| 428 | This makes my board boot |
| 429 | with a fix to the bootm |
| 430 | command |
| 431 | ''', 'bootm.c', '''Fix up the bootm |
| 432 | command to make the code as |
| 433 | complicated as possible''') |
| 434 | second_target = repo.revparse_single('HEAD') |
| 435 | |
| 436 | repo.branches.local.create('first', first_target) |
| 437 | repo.config.set_multivar('branch.first.remote', '', '.') |
| 438 | repo.config.set_multivar('branch.first.merge', '', 'refs/heads/base') |
| 439 | |
| 440 | repo.branches.local.create('second', second_target) |
| 441 | repo.config.set_multivar('branch.second.remote', '', '.') |
| 442 | repo.config.set_multivar('branch.second.merge', '', 'refs/heads/base') |
| 443 | |
| 444 | repo.branches.local.create('base', base_target) |
| 445 | return repo |
| 446 | |
| 447 | @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2') |
| 448 | def testBranch(self): |
| 449 | """Test creating patches from a branch""" |
| 450 | repo = self.make_git_tree() |
| 451 | target = repo.lookup_reference('refs/heads/first') |
| 452 | self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE) |
| 453 | control.setup() |
| 454 | try: |
| 455 | orig_dir = os.getcwd() |
| 456 | os.chdir(self.gitdir) |
| 457 | |
| 458 | # Check that it can detect the current branch |
Simon Glass | 262130f | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 459 | self.assertEqual(2, gitutil.CountCommitsToBranch(None)) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 460 | col = terminal.Color() |
| 461 | with capture_sys_output() as _: |
| 462 | _, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | 137947e | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 463 | col, branch=None, count=-1, start=0, end=0, |
| 464 | ignore_binary=False) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 465 | self.assertIsNone(cover_fname) |
| 466 | self.assertEqual(2, len(patch_files)) |
Simon Glass | 262130f | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 467 | |
| 468 | # Check that it can detect a different branch |
| 469 | self.assertEqual(3, gitutil.CountCommitsToBranch('second')) |
| 470 | with capture_sys_output() as _: |
| 471 | _, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | 137947e | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 472 | col, branch='second', count=-1, start=0, end=0, |
Simon Glass | 262130f | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 473 | ignore_binary=False) |
| 474 | self.assertIsNotNone(cover_fname) |
| 475 | self.assertEqual(3, len(patch_files)) |
Simon Glass | 137947e | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 476 | |
| 477 | # Check that it can skip patches at the end |
| 478 | with capture_sys_output() as _: |
| 479 | _, cover_fname, patch_files = control.prepare_patches( |
| 480 | col, branch='second', count=-1, start=0, end=1, |
| 481 | ignore_binary=False) |
| 482 | self.assertIsNotNone(cover_fname) |
| 483 | self.assertEqual(2, len(patch_files)) |
Simon Glass | fd70986 | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 484 | finally: |
| 485 | os.chdir(orig_dir) |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 486 | |
| 487 | def testTags(self): |
| 488 | """Test collection of tags in a patchstream""" |
| 489 | text = '''This is a patch |
| 490 | |
| 491 | Signed-off-by: Terminator |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame^] | 492 | Reviewed-by: %s |
| 493 | Reviewed-by: %s |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 494 | Tested-by: %s |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame^] | 495 | ''' % (self.joe, self.mary, self.leb) |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 496 | pstrm = PatchStream.process_text(text) |
| 497 | self.assertEqual(pstrm.commit.rtags, { |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame^] | 498 | 'Reviewed-by': {self.joe, self.mary}, |
Simon Glass | 7457051 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 499 | 'Tested-by': {self.leb}}) |
Simon Glass | 4af9987 | 2020-10-29 21:46:28 -0600 | [diff] [blame^] | 500 | |
| 501 | def testMissingEnd(self): |
| 502 | """Test a missing END tag""" |
| 503 | text = '''This is a patch |
| 504 | |
| 505 | Cover-letter: |
| 506 | This is the title |
| 507 | missing END after this line |
| 508 | Signed-off-by: Fred |
| 509 | ''' |
| 510 | pstrm = PatchStream.process_text(text) |
| 511 | self.assertEqual(["Missing 'END' in section 'cover'"], |
| 512 | pstrm.commit.warn) |
| 513 | |
| 514 | def testMissingBlankLine(self): |
| 515 | """Test a missing blank line after a tag""" |
| 516 | text = '''This is a patch |
| 517 | |
| 518 | Series-changes: 2 |
| 519 | - First line of changes |
| 520 | - Missing blank line after this line |
| 521 | Signed-off-by: Fred |
| 522 | ''' |
| 523 | pstrm = PatchStream.process_text(text) |
| 524 | self.assertEqual(["Missing 'blank line' in section 'Series-changes'"], |
| 525 | pstrm.commit.warn) |
| 526 | |
| 527 | def testInvalidCommitTag(self): |
| 528 | """Test an invalid Commit-xxx tag""" |
| 529 | text = '''This is a patch |
| 530 | |
| 531 | Commit-fred: testing |
| 532 | ''' |
| 533 | pstrm = PatchStream.process_text(text) |
| 534 | self.assertEqual(["Line 3: Ignoring Commit-fred"], pstrm.commit.warn) |
| 535 | |
| 536 | def testSelfTest(self): |
| 537 | """Test a tested by tag by this user""" |
| 538 | test_line = 'Tested-by: %s@napier.com' % os.getenv('USER') |
| 539 | text = '''This is a patch |
| 540 | |
| 541 | %s |
| 542 | ''' % test_line |
| 543 | pstrm = PatchStream.process_text(text) |
| 544 | self.assertEqual(["Ignoring '%s'" % test_line], pstrm.commit.warn) |
| 545 | |
| 546 | def testSpaceBeforeTab(self): |
| 547 | """Test a space before a tab""" |
| 548 | text = '''This is a patch |
| 549 | |
| 550 | + \tSomething |
| 551 | ''' |
| 552 | pstrm = PatchStream.process_text(text) |
| 553 | self.assertEqual(["Line 3/0 has space before tab"], pstrm.commit.warn) |
| 554 | |
| 555 | def testLinesAfterTest(self): |
| 556 | """Test detecting lines after TEST= line""" |
| 557 | text = '''This is a patch |
| 558 | |
| 559 | TEST=sometest |
| 560 | more lines |
| 561 | here |
| 562 | ''' |
| 563 | pstrm = PatchStream.process_text(text) |
| 564 | self.assertEqual(["Found 2 lines after TEST="], pstrm.commit.warn) |
| 565 | |
| 566 | def testBlankLineAtEnd(self): |
| 567 | """Test detecting a blank line at the end of a file""" |
| 568 | text = '''This is a patch |
| 569 | |
| 570 | diff --git a/lib/fdtdec.c b/lib/fdtdec.c |
| 571 | index c072e54..942244f 100644 |
| 572 | --- a/lib/fdtdec.c |
| 573 | +++ b/lib/fdtdec.c |
| 574 | @@ -1200,7 +1200,8 @@ int fdtdec_setup_mem_size_base(void) |
| 575 | } |
| 576 | |
| 577 | gd->ram_size = (phys_size_t)(res.end - res.start + 1); |
| 578 | - debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size); |
| 579 | + debug("%s: Initial DRAM size %llx\n", __func__, |
| 580 | + (unsigned long long)gd->ram_size); |
| 581 | + |
| 582 | diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c |
| 583 | |
| 584 | -- |
| 585 | 2.7.4 |
| 586 | |
| 587 | ''' |
| 588 | pstrm = PatchStream.process_text(text) |
| 589 | self.assertEqual( |
| 590 | ["Found possible blank line(s) at end of file 'lib/fdtdec.c'"], |
| 591 | pstrm.commit.warn) |