blob: 02d46ae5f73107511ca0b41ca6b94c8abfb0e1a9 [file] [log] [blame]
Simon Glass6e87ae12017-05-29 15:31:31 -06001# -*- coding: utf-8 -*-
Tom Rini83d290c2018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glass6e87ae12017-05-29 15:31:31 -06003#
4# Copyright 2017 Google, Inc
5#
Simon Glass6e87ae12017-05-29 15:31:31 -06006
Simon Glassfca99112020-10-29 21:46:15 -06007"""Functional tests for checking that patman behaves correctly"""
8
Simon Glass6e87ae12017-05-29 15:31:31 -06009import os
10import re
11import shutil
12import sys
13import tempfile
14import unittest
15
Simon Glassfd709862020-07-05 21:41:50 -060016from patman import control
Simon Glassbf776672020-04-17 18:09:04 -060017from patman import gitutil
18from patman import patchstream
Simon Glass47f62952020-10-29 21:46:26 -060019from patman.patchstream import PatchStream
Simon Glassbf776672020-04-17 18:09:04 -060020from patman import settings
Simon Glassfd709862020-07-05 21:41:50 -060021from patman import terminal
Simon Glassbf776672020-04-17 18:09:04 -060022from patman import tools
Simon Glassfd709862020-07-05 21:41:50 -060023from patman.test_util import capture_sys_output
24
25try:
26 import pygit2
Simon Glass427b0282020-10-29 21:46:13 -060027 HAVE_PYGIT2 = True
Simon Glassfd709862020-07-05 21:41:50 -060028except ModuleNotFoundError:
29 HAVE_PYGIT2 = False
Simon Glass6e87ae12017-05-29 15:31:31 -060030
31
Simon Glass6e87ae12017-05-29 15:31:31 -060032class TestFunctional(unittest.TestCase):
Simon Glassfca99112020-10-29 21:46:15 -060033 """Functional tests for checking that patman behaves correctly"""
Simon Glass74570512020-10-29 21:46:27 -060034 leb = (b'Lord Edmund Blackadd\xc3\xabr <weasel@blackadder.org>'.
35 decode('utf-8'))
Simon Glass4af99872020-10-29 21:46:28 -060036 fred = 'Fred Bloggs <f.bloggs@napier.net>'
37 joe = 'Joe Bloggs <joe@napierwallies.co.nz>'
38 mary = 'Mary Bloggs <mary@napierwallies.co.nz>'
Simon Glass74570512020-10-29 21:46:27 -060039
Simon Glass6e87ae12017-05-29 15:31:31 -060040 def setUp(self):
41 self.tmpdir = tempfile.mkdtemp(prefix='patman.')
Simon Glassfd709862020-07-05 21:41:50 -060042 self.gitdir = os.path.join(self.tmpdir, 'git')
43 self.repo = None
Simon Glass6e87ae12017-05-29 15:31:31 -060044
45 def tearDown(self):
46 shutil.rmtree(self.tmpdir)
47
48 @staticmethod
Simon Glassfca99112020-10-29 21:46:15 -060049 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 Glass6e87ae12017-05-29 15:31:31 -060058 return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
59 'test', fname)
60
61 @classmethod
Simon Glassfca99112020-10-29 21:46:15 -060062 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 Glass6e87ae12017-05-29 15:31:31 -060072
73 @classmethod
Simon Glassfca99112020-10-29 21:46:15 -060074 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 Glass6e87ae12017-05-29 15:31:31 -060083 fname = re.sub('[ :]', '-', subject)
84 return fname.replace('--', '-')
85
Simon Glassfca99112020-10-29 21:46:15 -060086 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 Glass6e87ae12017-05-29 15:31:31 -060099 cover_fname = None
100 fname_list = []
101 for i, commit in enumerate(series.commits):
Simon Glassfca99112020-10-29 21:46:15 -0600102 clean_subject = self._get_patch_name(commit.subject)
Simon Glass6e87ae12017-05-29 15:31:31 -0600103 src_fname = '%04d-%s.patch' % (i + 1, clean_subject[:52])
104 fname = os.path.join(self.tmpdir, src_fname)
Simon Glassfca99112020-10-29 21:46:15 -0600105 shutil.copy(self._get_path(src_fname), fname)
Simon Glass6e87ae12017-05-29 15:31:31 -0600106 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 Glassfca99112020-10-29 21:46:15 -0600111 shutil.copy(self._get_path(src_fname), fname)
Simon Glass6e87ae12017-05-29 15:31:31 -0600112
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 Andersondc03ba42020-05-04 16:28:36 -0400125 Series-version: 3
126 Patch-cc: fred
127 Series-process-log: sort, uniq
Simon Glass6e87ae12017-05-29 15:31:31 -0600128 Series-changes: 4
129 - Some changes
Sean Andersondc03ba42020-05-04 16:28:36 -0400130 - 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 Glass6e87ae12017-05-29 15:31:31 -0600139
140 Cover-letter:
141 test: A test patch series
142 This is a test of how the cover
Sean Andersondc03ba42020-05-04 16:28:36 -0400143 letter
Simon Glass6e87ae12017-05-29 15:31:31 -0600144 works
145 END
146
147 and this in the first commit:
148
Sean Andersondc03ba42020-05-04 16:28:36 -0400149 Commit-changes: 2
150 - second revision change
151
Simon Glass6e87ae12017-05-29 15:31:31 -0600152 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 Glasse6dca5e2019-05-14 15:53:53 -0600183 stefan = b'Stefan Br\xc3\xbcns <stefan.bruens@rwth-aachen.de>'.decode('utf-8')
Simon Glass6e87ae12017-05-29 15:31:31 -0600184 rick = 'Richard III <richard@palace.gov>'
Simon Glasse6dca5e2019-05-14 15:53:53 -0600185 mel = b'Lord M\xc3\xablchett <clergy@palace.gov>'.decode('utf-8')
Simon Glass6e87ae12017-05-29 15:31:31 -0600186 add_maintainers = [stefan, rick]
187 dry_run = True
188 in_reply_to = mel
189 count = 2
190 settings.alias = {
Simon Glass427b0282020-10-29 21:46:13 -0600191 'fdt': ['simon'],
192 'u-boot': ['u-boot@lists.denx.de'],
Simon Glass74570512020-10-29 21:46:27 -0600193 'simon': [self.leb],
Simon Glass4af99872020-10-29 21:46:28 -0600194 'fred': [self.fred],
Simon Glass6e87ae12017-05-29 15:31:31 -0600195 }
196
Simon Glassfca99112020-10-29 21:46:15 -0600197 text = self._get_text('test01.txt')
Simon Glassd93720e2020-10-29 21:46:19 -0600198 series = patchstream.get_metadata_for_test(text)
Simon Glassfca99112020-10-29 21:46:15 -0600199 cover_fname, args = self._create_patches_for_test(series)
Simon Glass366954f2020-10-29 21:46:14 -0600200 with capture_sys_output() as out:
Simon Glassd93720e2020-10-29 21:46:19 -0600201 patchstream.fix_patches(series, args)
Simon Glass6e87ae12017-05-29 15:31:31 -0600202 if cover_fname and series.get('cover'):
Simon Glassd93720e2020-10-29 21:46:19 -0600203 patchstream.insert_cover_letter(cover_fname, series, count)
Simon Glass6e87ae12017-05-29 15:31:31 -0600204 series.DoChecks()
205 cc_file = series.MakeCcFile(process_tags, cover_fname,
Chris Packham4fb35022018-06-07 20:45:06 +1200206 not ignore_bad_tags, add_maintainers,
207 None)
Simon Glass427b0282020-10-29 21:46:13 -0600208 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 Glass6e87ae12017-05-29 15:31:31 -0600211 series.ShowActions(args, cmd, process_tags)
Simon Glass272cd852019-10-31 07:42:51 -0600212 cc_lines = open(cc_file, encoding='utf-8').read().splitlines()
Simon Glass6e87ae12017-05-29 15:31:31 -0600213 os.remove(cc_file)
214
Simon Glass366954f2020-10-29 21:46:14 -0600215 lines = out[0].getvalue().splitlines()
Simon Glass6e87ae12017-05-29 15:31:31 -0600216 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 Glassfca99112020-10-29 21:46:15 -0600224 for i in range(len(series.commits)):
Simon Glass6e87ae12017-05-29 15:31:31 -0600225 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 Glasse6dca5e2019-05-14 15:53:53 -0600230 self.assertEqual('Cc: %s' % tools.FromUnicode(stefan),
231 lines[line + 1])
Simon Glass6e87ae12017-05-29 15:31:31 -0600232 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 Glass4af99872020-10-29 21:46:28 -0600236 self.assertEqual(' Cc: %s' % self.fred, lines[line + 0])
Simon Glass74570512020-10-29 21:46:27 -0600237 self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb),
Simon Glasse6dca5e2019-05-14 15:53:53 -0600238 lines[line + 1])
239 self.assertEqual(' Cc: %s' % tools.FromUnicode(mel),
240 lines[line + 2])
Simon Glassb644c662019-05-14 15:53:51 -0600241 self.assertEqual(' Cc: %s' % rick, lines[line + 3])
Simon Glass6e87ae12017-05-29 15:31:31 -0600242 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 Glasse6dca5e2019-05-14 15:53:53 -0600246 ' '.join(args)))
Simon Glass6e87ae12017-05-29 15:31:31 -0600247 line += 4
Simon Glasse6dca5e2019-05-14 15:53:53 -0600248 self.assertEqual(expected, tools.ToUnicode(lines[line]))
Simon Glass6e87ae12017-05-29 15:31:31 -0600249
Dmitry Torokhov8ab452d2019-10-21 20:09:56 -0700250 self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)),
Simon Glasse6dca5e2019-05-14 15:53:53 -0600251 tools.ToUnicode(cc_lines[0]))
Simon Glass427b0282020-10-29 21:46:13 -0600252 self.assertEqual(
Simon Glass4af99872020-10-29 21:46:28 -0600253 '%s %s\0%s\0%s\0%s' % (args[1], self.fred, self.leb, rick, stefan),
Simon Glass427b0282020-10-29 21:46:13 -0600254 tools.ToUnicode(cc_lines[1]))
Simon Glass6e87ae12017-05-29 15:31:31 -0600255
256 expected = '''
257This is a test of how the cover
Sean Andersondc03ba42020-05-04 16:28:36 -0400258letter
Simon Glass6e87ae12017-05-29 15:31:31 -0600259works
260
261some notes
262about some things
263from the first commit
264
265Changes in v4:
Sean Andersondc03ba42020-05-04 16:28:36 -0400266- Multi
267 line
268 change
Simon Glass6e87ae12017-05-29 15:31:31 -0600269- Some changes
Sean Andersondc03ba42020-05-04 16:28:36 -0400270- Some notes for the cover letter
Simon Glass6e87ae12017-05-29 15:31:31 -0600271
272Simon Glass (2):
273 pci: Correct cast for sandbox
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +0530274 fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base()
Simon Glass6e87ae12017-05-29 15:31:31 -0600275
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
2832.7.4
284
285'''
Simon Glass272cd852019-10-31 07:42:51 -0600286 lines = open(cover_fname, encoding='utf-8').read().splitlines()
Simon Glass6e87ae12017-05-29 15:31:31 -0600287 self.assertEqual(
Simon Glass427b0282020-10-29 21:46:13 -0600288 'Subject: [RFC PATCH v3 0/2] test: A test patch series',
289 lines[3])
Simon Glass6e87ae12017-05-29 15:31:31 -0600290 self.assertEqual(expected.splitlines(), lines[7:])
291
292 for i, fname in enumerate(args):
Simon Glass272cd852019-10-31 07:42:51 -0600293 lines = open(fname, encoding='utf-8').read().splitlines()
Simon Glass6e87ae12017-05-29 15:31:31 -0600294 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 Andersondc03ba42020-05-04 16:28:36 -0400297
298 # Check that we got our commit notes
299 start = 0
300 expected = ''
301
Simon Glass6e87ae12017-05-29 15:31:31 -0600302 if i == 0:
Sean Andersondc03ba42020-05-04 16:28:36 -0400303 start = 17
304 expected = '''---
305Some notes about
306the first commit
307
308(no changes since v2)
309
310Changes in v2:
311- second revision change'''
312 elif i == 1:
313 start = 17
314 expected = '''---
315
316Changes in v4:
317- Multi
318 line
319 change
320- Some changes
321
322Changes 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 Glassfd709862020-07-05 21:41:50 -0600328
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 Glass427b0282020-10-29 21:46:13 -0600342 author = pygit2.Signature('Test user', 'test@email.com')
Simon Glassfd709862020-07-05 21:41:50 -0600343 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 Glassfca99112020-10-29 21:46:15 -0600358 pygit2.Repository: repository
Simon Glassfd709862020-07-05 21:41:50 -0600359 """
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 Glassfca99112020-10-29 21:46:15 -0600366 _ = repo.create_commit('HEAD', author, committer, 'Created master',
367 new_tree, [])
Simon Glassfd709862020-07-05 21:41:50 -0600368
369 self.make_commit_with_file('Initial commit', '''
370Add a README
371
372''', 'README', '''This is the README file
373describing this project
374in very little detail''')
375
376 self.make_commit_with_file('pci: PCI implementation', '''
377Here is a basic PCI implementation
378
379''', 'pci.c', '''This is a file
380it has some contents
381and some more things''')
382 self.make_commit_with_file('main: Main program', '''
383Hello here is the second commit.
384''', 'main.c', '''This is the main file
385there is very little here
386but we can always add more later
387if we want to
388
389Series-to: u-boot
390Series-cc: Barry Crump <bcrump@whataroa.nz>
391''')
392 base_target = repo.revparse_single('HEAD')
393 self.make_commit_with_file('i2c: I2C things', '''
394This has some stuff to do with I2C
395''', 'i2c.c', '''And this is the file contents
396with some I2C-related things in it''')
397 self.make_commit_with_file('spi: SPI fixes', '''
398SPI needs some fixes
399and here they are
400''', 'spi.c', '''Some fixes for SPI in this
401file to make SPI work
402better 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', '''
408Fix up the video so that
409it looks more purple. Purple is
410a very nice colour.
411''', 'video.c', '''More purple here
412Purple and purple
413Even more purple
414Could not be any more purple''')
415 self.make_commit_with_file('serial: Add a serial driver', '''
416Here is the serial driver
417for my chip.
418
419Cover-letter:
420Series for my board
421This series implements support
422for my glorious board.
423END
Simon Glassf9e42842020-10-29 21:46:16 -0600424Series-links: 183237
Simon Glassfd709862020-07-05 21:41:50 -0600425''', 'serial.c', '''The code for the
426serial driver is here''')
427 self.make_commit_with_file('bootm: Make it boot', '''
428This makes my board boot
429with a fix to the bootm
430command
431''', 'bootm.c', '''Fix up the bootm
432command to make the code as
433complicated 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 Glass262130f2020-07-05 21:41:51 -0600459 self.assertEqual(2, gitutil.CountCommitsToBranch(None))
Simon Glassfd709862020-07-05 21:41:50 -0600460 col = terminal.Color()
461 with capture_sys_output() as _:
462 _, cover_fname, patch_files = control.prepare_patches(
Simon Glass137947e2020-07-05 21:41:52 -0600463 col, branch=None, count=-1, start=0, end=0,
464 ignore_binary=False)
Simon Glassfd709862020-07-05 21:41:50 -0600465 self.assertIsNone(cover_fname)
466 self.assertEqual(2, len(patch_files))
Simon Glass262130f2020-07-05 21:41:51 -0600467
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 Glass137947e2020-07-05 21:41:52 -0600472 col, branch='second', count=-1, start=0, end=0,
Simon Glass262130f2020-07-05 21:41:51 -0600473 ignore_binary=False)
474 self.assertIsNotNone(cover_fname)
475 self.assertEqual(3, len(patch_files))
Simon Glass137947e2020-07-05 21:41:52 -0600476
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 Glassfd709862020-07-05 21:41:50 -0600484 finally:
485 os.chdir(orig_dir)
Simon Glass74570512020-10-29 21:46:27 -0600486
487 def testTags(self):
488 """Test collection of tags in a patchstream"""
489 text = '''This is a patch
490
491Signed-off-by: Terminator
Simon Glass4af99872020-10-29 21:46:28 -0600492Reviewed-by: %s
493Reviewed-by: %s
Simon Glass74570512020-10-29 21:46:27 -0600494Tested-by: %s
Simon Glass4af99872020-10-29 21:46:28 -0600495''' % (self.joe, self.mary, self.leb)
Simon Glass74570512020-10-29 21:46:27 -0600496 pstrm = PatchStream.process_text(text)
497 self.assertEqual(pstrm.commit.rtags, {
Simon Glass4af99872020-10-29 21:46:28 -0600498 'Reviewed-by': {self.joe, self.mary},
Simon Glass74570512020-10-29 21:46:27 -0600499 'Tested-by': {self.leb}})
Simon Glass4af99872020-10-29 21:46:28 -0600500
501 def testMissingEnd(self):
502 """Test a missing END tag"""
503 text = '''This is a patch
504
505Cover-letter:
506This is the title
507missing END after this line
508Signed-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
518Series-changes: 2
519- First line of changes
520- Missing blank line after this line
521Signed-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
531Commit-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
559TEST=sometest
560more lines
561here
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
570diff --git a/lib/fdtdec.c b/lib/fdtdec.c
571index 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+
582diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
583
584--
5852.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)