Debian Codegraph @

bin/pick/core_test.py

raw
1 # Copyright © 2019-2020 Intel Corporation
2
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20
21 """Tests for pick's core data structures and routines."""
22
23 from unittest import mock
24 import textwrap
25 import typing
26
27 import attr
28 import pytest
29
30 from . import core
31
32
33 class TestCommit:
34
35 @pytest.fixture
36 def unnominated_commit(self) -> 'core.Commit':
37 return core.Commit('abc123', 'sub: A commit', main_sha='45678')
38
39 @pytest.fixture
40 def nominated_commit(self) -> 'core.Commit':
41 return core.Commit('abc123', 'sub: A commit', True,
42 core.NominationType.CC, core.Resolution.UNRESOLVED)
43
44 class TestToJson:
45
46 def test_not_nominated(self, unnominated_commit: 'core.Commit'):
47 c = unnominated_commit
48 v = c.to_json()
49 assert v == {
50 'sha': 'abc123',
51 'description': 'sub: A commit',
52 'nominated': False,
53 'nomination_type': core.NominationType.NONE.value,
54 'resolution': core.Resolution.UNRESOLVED.value,
55 'main_sha': '45678',
56 'because_sha': None,
57 'notes': None,
58 }
59
60 def test_nominated(self, nominated_commit: 'core.Commit'):
61 c = nominated_commit
62 v = c.to_json()
63 assert v == {
64 'sha': 'abc123',
65 'description': 'sub: A commit',
66 'nominated': True,
67 'nomination_type': core.NominationType.CC.value,
68 'resolution': core.Resolution.UNRESOLVED.value,
69 'main_sha': None,
70 'because_sha': None,
71 'notes': None,
72 }
73
74 class TestFromJson:
75
76 def test_not_nominated(self, unnominated_commit: 'core.Commit'):
77 c = unnominated_commit
78 v = c.to_json()
79 c2 = core.Commit.from_json(v)
80 assert c == c2
81
82 def test_nominated(self, nominated_commit: 'core.Commit'):
83 c = nominated_commit
84 v = c.to_json()
85 c2 = core.Commit.from_json(v)
86 assert c == c2
87
88
89 class TestRE:
90
91 """Tests for the regular expressions used to identify commits."""
92
93 class TestFixes:
94
95 def test_simple(self):
96 message = textwrap.dedent("""\
97 etnaviv: fix vertex buffer state emission for single stream GPUs
98
99 GPUs with a single supported vertex stream must use the single state
100 address to program the stream.
101
102 Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)
103 Signed-off-by: Lucas Stach <[email protected]>
104 Reviewed-by: Jonathan Marek <[email protected]>
105 """)
106
107 fix_for_commit = core.IS_FIX.search(message)
108 assert fix_for_commit is not None
109 assert fix_for_commit.group(1) == '3d09bb390a39'
110
111 class TestCC:
112
113 def test_single_branch(self):
114 """Tests commit meant for a single branch, ie, 19.1"""
115 message = textwrap.dedent("""\
116 radv: fix DCC fast clear code for intensity formats
117
118 This fixes a rendering issue with DiRT 4 on GFX10. Only GFX10 was
119 affected because intensity formats are different.
120
121 Cc: 19.2 <[email protected]>
122 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1923
123 Signed-off-by: Samuel Pitoiset <[email protected]>
124 Reviewed-by: Bas Nieuwenhuizen <[email protected]>
125 """)
126
127 cc_to = core.IS_CC.search(message)
128 assert cc_to is not None
129 assert cc_to.group(1) == '19.2'
130
131 def test_multiple_branches(self):
132 """Tests commit with more than one branch specified"""
133 message = textwrap.dedent("""\
134 radeonsi: enable zerovram for Rocket League
135
136 Fixes corruption on game startup.
137 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1888
138
139 Cc: 19.1 19.2 <[email protected]>
140 Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
141 """)
142
143 cc_to = core.IS_CC.search(message)
144 assert cc_to is not None
145 assert cc_to.group(1) == '19.1'
146 assert cc_to.group(2) == '19.2'
147
148 def test_no_branch(self):
149 """Tests commit with no branch specification"""
150 message = textwrap.dedent("""\
151 anv/android: fix images created with external format support
152
153 This fixes a case where user first creates image and then later binds it
154 with memory created from AHW buffer.
155
156 Cc: <[email protected]>
157 Signed-off-by: Tapani Pälli <[email protected]>
158 Reviewed-by: Lionel Landwerlin <[email protected]>
159 """)
160
161 cc_to = core.IS_CC.search(message)
162 assert cc_to is not None
163
164 def test_quotes(self):
165 """Tests commit with quotes around the versions"""
166 message = textwrap.dedent("""\
167 anv: Always fill out the AUX table even if CCS is disabled
168
169 Cc: "20.0" [email protected]
170 Reviewed-by: Kenneth Graunke <[email protected]>
171 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
172 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
173 """)
174
175 cc_to = core.IS_CC.search(message)
176 assert cc_to is not None
177 assert cc_to.group(1) == '20.0'
178
179 def test_multiple_quotes(self):
180 """Tests commit with quotes around the versions"""
181 message = textwrap.dedent("""\
182 anv: Always fill out the AUX table even if CCS is disabled
183
184 Cc: "20.0" "20.1" [email protected]
185 Reviewed-by: Kenneth Graunke <[email protected]>
186 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
187 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
188 """)
189
190 cc_to = core.IS_CC.search(message)
191 assert cc_to is not None
192 assert cc_to.group(1) == '20.0'
193 assert cc_to.group(2) == '20.1'
194
195 def test_single_quotes(self):
196 """Tests commit with quotes around the versions"""
197 message = textwrap.dedent("""\
198 anv: Always fill out the AUX table even if CCS is disabled
199
200 Cc: '20.0' [email protected]
201 Reviewed-by: Kenneth Graunke <[email protected]>
202 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
203 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
204 """)
205
206 cc_to = core.IS_CC.search(message)
207 assert cc_to is not None
208 assert cc_to.group(1) == '20.0'
209
210 def test_multiple_single_quotes(self):
211 """Tests commit with quotes around the versions"""
212 message = textwrap.dedent("""\
213 anv: Always fill out the AUX table even if CCS is disabled
214
215 Cc: '20.0' '20.1' [email protected]
216 Reviewed-by: Kenneth Graunke <[email protected]>
217 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
218 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
219 """)
220
221 cc_to = core.IS_CC.search(message)
222 assert cc_to is not None
223 assert cc_to.group(1) == '20.0'
224 assert cc_to.group(2) == '20.1'
225
226 class TestRevert:
227
228 def test_simple(self):
229 message = textwrap.dedent("""\
230 Revert "radv: do not emit PKT3_CONTEXT_CONTROL with AMDGPU 3.6.0+"
231
232 This reverts commit 2ca8629fa9b303e24783b76a7b3b0c2513e32fbd.
233
234 This was initially ported from RadeonSI, but in the meantime it has
235 been reverted because it might hang. Be conservative and re-introduce
236 this packet emission.
237
238 Unfortunately this doesn't fix anything known.
239
240 Cc: 19.2 <[email protected]>
241 Signed-off-by: Samuel Pitoiset <[email protected]>
242 Reviewed-by: Bas Nieuwenhuizen <[email protected]>
243 """)
244
245 revert_of = core.IS_REVERT.search(message)
246 assert revert_of is not None
247 assert revert_of.group(1) == '2ca8629fa9b303e24783b76a7b3b0c2513e32fbd'
248
249 class TestBackportTo:
250
251 def test_single_release(self):
252 """Tests commit meant for a single branch, ie, 19.1"""
253 message = textwrap.dedent("""\
254 radv: fix DCC fast clear code for intensity formats
255
256 This fixes a rendering issue with DiRT 4 on GFX10. Only GFX10 was
257 affected because intensity formats are different.
258
259 Backport-to: 19.2
260 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1923
261 Signed-off-by: Samuel Pitoiset <[email protected]>
262 Reviewed-by: Bas Nieuwenhuizen <[email protected]>
263 """)
264
265 backport_to = core.IS_BACKPORT.findall(message)
266 assert backport_to == [('19.2', '', '')]
267
268 def test_multiple_release_space(self):
269 """Tests commit with more than one branch specified"""
270 message = textwrap.dedent("""\
271 radeonsi: enable zerovram for Rocket League
272
273 Fixes corruption on game startup.
274 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1888
275
276 Backport-to: 19.1 19.2
277 Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
278 """)
279
280 backport_to = core.IS_BACKPORT.findall(message)
281 assert backport_to == [('19.1', '19.2', '')]
282
283 def test_multiple_release_comma(self):
284 """Tests commit with more than one branch specified"""
285 message = textwrap.dedent("""\
286 radeonsi: enable zerovram for Rocket League
287
288 Fixes corruption on game startup.
289 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1888
290
291 Backport-to: 19.1, 19.2
292 Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
293 """)
294
295 backport_to = core.IS_BACKPORT.findall(message)
296 assert backport_to == [('19.1', '19.2', '')]
297
298 def test_multiple_release_lines(self):
299 """Tests commit with more than one branch specified in mulitple tags"""
300 message = textwrap.dedent("""\
301 commit title
302
303 Backport-to: 19.0
304 Backport-to: 19.1, 19.2
305 """)
306
307 backport_to = core.IS_BACKPORT.findall(message)
308 assert backport_to == [('19.0', '', ''), ('19.1', '19.2', '')]
309
310
311 class TestResolveNomination:
312
313 @attr.s(slots=True)
314 class FakeSubprocess:
315
316 """A fake asyncio.subprocess like class for use with mock."""
317
318 out: typing.Optional[bytes] = attr.ib(None)
319 returncode: int = attr.ib(0)
320
321 async def mock(self, *_, **__):
322 """A dirtly little helper for mocking."""
323 return self
324
325 async def communicate(self) -> typing.Tuple[bytes, bytes]:
326 assert self.out is not None
327 return self.out, b''
328
329 async def wait(self) -> int:
330 return self.returncode
331
332 @staticmethod
333 async def return_true(*_, **__) -> bool:
334 return True
335
336 @staticmethod
337 async def return_false(*_, **__) -> bool:
338 return False
339
340 @pytest.mark.asyncio
341 async def test_fix_is_nominated(self):
342 s = self.FakeSubprocess(b'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)')
343 c = core.Commit('abcdef1234567890', 'a commit')
344
345 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
346 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_true):
347 await core.resolve_nomination(c, '')
348
349 assert c.nominated
350 assert c.nomination_type is core.NominationType.FIXES
351
352 @pytest.mark.asyncio
353 async def test_fix_is_not_nominated(self):
354 s = self.FakeSubprocess(b'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)')
355 c = core.Commit('abcdef1234567890', 'a commit')
356
357 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
358 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_false):
359 await core.resolve_nomination(c, '')
360
361 assert not c.nominated
362 assert c.nomination_type is core.NominationType.FIXES
363
364 @pytest.mark.asyncio
365 async def test_cc_is_nominated(self):
366 s = self.FakeSubprocess(b'Cc: 16.2 <[email protected]>')
367 c = core.Commit('abcdef1234567890', 'a commit')
368
369 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
370 await core.resolve_nomination(c, '16.2')
371
372 assert c.nominated
373 assert c.nomination_type is core.NominationType.CC
374
375 @pytest.mark.asyncio
376 async def test_cc_is_nominated2(self):
377 s = self.FakeSubprocess(b'Cc: [email protected]')
378 c = core.Commit('abcdef1234567890', 'a commit')
379
380 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
381 await core.resolve_nomination(c, '16.2')
382
383 assert c.nominated
384 assert c.nomination_type is core.NominationType.CC
385
386 @pytest.mark.asyncio
387 async def test_cc_is_not_nominated(self):
388 s = self.FakeSubprocess(b'Cc: 16.2 <[email protected]>')
389 c = core.Commit('abcdef1234567890', 'a commit')
390
391 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
392 await core.resolve_nomination(c, '16.1')
393
394 assert not c.nominated
395 assert c.nomination_type is core.NominationType.NONE
396
397 @pytest.mark.asyncio
398 async def test_backport_is_nominated(self):
399 s = self.FakeSubprocess(b'Backport-to: 16.2')
400 c = core.Commit('abcdef1234567890', 'a commit')
401
402 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
403 await core.resolve_nomination(c, '16.2')
404
405 assert c.nominated
406 assert c.nomination_type is core.NominationType.BACKPORT
407
408 @pytest.mark.asyncio
409 async def test_backport_all_is_nominated(self):
410 s = self.FakeSubprocess(b'Backport-to: *')
411 c = core.Commit('abcdef1234567890', 'a commit')
412
413 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
414 await core.resolve_nomination(c, '0.0')
415
416 assert c.nominated
417 assert c.nomination_type is core.NominationType.BACKPORT
418
419 @pytest.mark.asyncio
420 async def test_backport_is_nominated_after(self):
421 s = self.FakeSubprocess(b'Backport-to: 16.2')
422 c = core.Commit('abcdef1234567890', 'a commit')
423
424 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
425 await core.resolve_nomination(c, '16.3')
426
427 assert c.nominated
428 assert c.nomination_type is core.NominationType.BACKPORT
429
430 @pytest.mark.asyncio
431 async def test_backport_is_not_nominated(self):
432 s = self.FakeSubprocess(b'Backport-to: 16.2')
433 c = core.Commit('abcdef1234567890', 'a commit')
434
435 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
436 await core.resolve_nomination(c, '16.1')
437
438 assert not c.nominated
439 assert c.nomination_type is core.NominationType.NONE
440
441 @pytest.mark.asyncio
442 async def test_revert_is_nominated(self):
443 s = self.FakeSubprocess(b'This reverts commit 1234567890123456789012345678901234567890.')
444 c = core.Commit('abcdef1234567890', 'a commit')
445
446 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
447 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_true):
448 await core.resolve_nomination(c, '')
449
450 assert c.nominated
451 assert c.nomination_type is core.NominationType.REVERT
452
453 @pytest.mark.asyncio
454 async def test_revert_is_not_nominated(self):
455 s = self.FakeSubprocess(b'This reverts commit 1234567890123456789012345678901234567890.')
456 c = core.Commit('abcdef1234567890', 'a commit')
457
458 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
459 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_false):
460 await core.resolve_nomination(c, '')
461
462 assert not c.nominated
463 assert c.nomination_type is core.NominationType.REVERT
464
465 @pytest.mark.asyncio
466 async def test_is_fix_and_backport(self):
467 s = self.FakeSubprocess(
468 b'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)\n'
469 b'Backport-to: 16.1'
470 )
471 c = core.Commit('abcdef1234567890', 'a commit')
472
473 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
474 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_true):
475 await core.resolve_nomination(c, '16.1')
476
477 assert c.nominated
478 assert c.nomination_type is core.NominationType.FIXES
479
480 @pytest.mark.asyncio
481 async def test_is_fix_and_cc(self):
482 s = self.FakeSubprocess(
483 b'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)\n'
484 b'Cc: 16.1 <[email protected]>'
485 )
486 c = core.Commit('abcdef1234567890', 'a commit')
487
488 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
489 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_true):
490 await core.resolve_nomination(c, '16.1')
491
492 assert c.nominated
493 assert c.nomination_type is core.NominationType.FIXES
494
495 @pytest.mark.asyncio
496 async def test_is_fix_and_revert(self):
497 s = self.FakeSubprocess(
498 b'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)\n'
499 b'This reverts commit 1234567890123456789012345678901234567890.'
500 )
501 c = core.Commit('abcdef1234567890', 'a commit')
502
503 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
504 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_true):
505 await core.resolve_nomination(c, '16.1')
506
507 assert c.nominated
508 assert c.nomination_type is core.NominationType.FIXES
509
510 @pytest.mark.asyncio
511 async def test_is_cc_and_revert(self):
512 s = self.FakeSubprocess(
513 b'This reverts commit 1234567890123456789012345678901234567890.\n'
514 b'Cc: 16.1 <[email protected]>'
515 )
516 c = core.Commit('abcdef1234567890', 'a commit')
517
518 with mock.patch('bin.pick.core.asyncio.create_subprocess_exec', s.mock):
519 with mock.patch('bin.pick.core.is_commit_in_branch', self.return_true):
520 await core.resolve_nomination(c, '16.1')
521
522 assert c.nominated
523 assert c.nomination_type is core.NominationType.CC
524
525
526 class TestResolveFixes:
527
528 @pytest.mark.asyncio
529 async def test_in_new(self):
530 """Because commit abcd is nominated, so f123 should be as well."""
531 c = [
532 core.Commit('f123', 'desc', nomination_type=core.NominationType.FIXES, because_sha='abcd'),
533 core.Commit('abcd', 'desc', True),
534 ]
535 await core.resolve_fixes(c, [])
536 assert c[1].nominated
537
538 @pytest.mark.asyncio
539 async def test_not_in_new(self):
540 """Because commit abcd is not nominated, commit f123 shouldn't be either."""
541 c = [
542 core.Commit('f123', 'desc', nomination_type=core.NominationType.FIXES, because_sha='abcd'),
543 core.Commit('abcd', 'desc'),
544 ]
545 await core.resolve_fixes(c, [])
546 assert not c[0].nominated
547
548 @pytest.mark.asyncio
549 async def test_in_previous(self):
550 """Because commit abcd is nominated, so f123 should be as well."""
551 p = [
552 core.Commit('abcd', 'desc', True),
553 ]
554 c = [
555 core.Commit('f123', 'desc', nomination_type=core.NominationType.FIXES, because_sha='abcd'),
556 ]
557 await core.resolve_fixes(c, p)
558 assert c[0].nominated
559
560 @pytest.mark.asyncio
561 async def test_not_in_previous(self):
562 """Because commit abcd is not nominated, commit f123 shouldn't be either."""
563 p = [
564 core.Commit('abcd', 'desc'),
565 ]
566 c = [
567 core.Commit('f123', 'desc', nomination_type=core.NominationType.FIXES, because_sha='abcd'),
568 ]
569 await core.resolve_fixes(c, p)
570 assert not c[0].nominated
571
572
573 class TestIsCommitInBranch:
574
575 @pytest.mark.asyncio
576 async def test_no(self):
577 # Hopefully this is never true?
578 value = await core.is_commit_in_branch('ffffffffffffffffffffffffffffff')
579 assert not value
580
581 @pytest.mark.asyncio
582 async def test_yes(self):
583 # This commit is from 2000, it better always be in the branch
584 value = await core.is_commit_in_branch('88f3b89a2cb77766d2009b9868c44e03abe2dbb2')
585 assert value
586
587
588 class TestFullSha:
589
590 @pytest.mark.asyncio
591 async def test_basic(self):
592 # This commit is from 2000, it better always be in the branch
593 value = await core.full_sha('88f3b89a2cb777')
594 assert value
595
596 @pytest.mark.asyncio
597 async def test_invalid(self):
598 # This commit is from 2000, it better always be in the branch
599 with pytest.raises(core.PickUIException):
600 await core.full_sha('fffffffffffffffffffffffffffffffffff')