1 # Copyright © 2019-2020 Intel Corporation
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:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
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
21 """Tests for pick's core data structures and routines."""
23 from unittest
import mock
36 def unnominated_commit(self
) -> 'core.Commit':
37 return core
.Commit('abc123', 'sub: A commit', master_sha
='45678')
40 def nominated_commit(self
) -> 'core.Commit':
41 return core
.Commit('abc123', 'sub: A commit', True,
42 core
.NominationType
.CC
, core
.Resolution
.UNRESOLVED
)
46 def test_not_nominated(self
, unnominated_commit
: 'core.Commit'):
47 c
= unnominated_commit
49 assert v
== {'sha': 'abc123', 'description': 'sub: A commit', 'nominated': False,
50 'nomination_type': None, 'resolution': core
.Resolution
.UNRESOLVED
.value
,
51 'master_sha': '45678', 'because_sha': None}
53 def test_nominated(self
, nominated_commit
: 'core.Commit'):
56 assert v
== {'sha': 'abc123',
57 'description': 'sub: A commit',
59 'nomination_type': core
.NominationType
.CC
.value
,
60 'resolution': core
.Resolution
.UNRESOLVED
.value
,
66 def test_not_nominated(self
, unnominated_commit
: 'core.Commit'):
67 c
= unnominated_commit
69 c2
= core
.Commit
.from_json(v
)
72 def test_nominated(self
, nominated_commit
: 'core.Commit'):
75 c2
= core
.Commit
.from_json(v
)
81 """Tests for the regular expressions used to identify commits."""
85 def test_simple(self
):
86 message
= textwrap
.dedent("""\
87 etnaviv: fix vertex buffer state emission for single stream GPUs
89 GPUs with a single supported vertex stream must use the single state
90 address to program the stream.
92 Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)
93 Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
94 Reviewed-by: Jonathan Marek <jonathan@marek.ca>
97 m
= core
.IS_FIX
.search(message
)
99 assert m
.group(1) == '3d09bb390a39'
103 def test_single_branch(self
):
104 """Tests commit meant for a single branch, ie, 19.1"""
105 message
= textwrap
.dedent("""\
106 radv: fix DCC fast clear code for intensity formats
108 This fixes a rendering issue with DiRT 4 on GFX10. Only GFX10 was
109 affected because intensity formats are different.
111 Cc: 19.2 <mesa-stable@lists.freedesktop.org>
112 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1923
113 Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
114 Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
117 m
= core
.IS_CC
.search(message
)
119 assert m
.group(1) == '19.2'
121 def test_multiple_branches(self
):
122 """Tests commit with more than one branch specified"""
123 message
= textwrap
.dedent("""\
124 radeonsi: enable zerovram for Rocket League
126 Fixes corruption on game startup.
127 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/1888
129 Cc: 19.1 19.2 <mesa-stable@lists.freedesktop.org>
130 Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
133 m
= core
.IS_CC
.search(message
)
135 assert m
.group(1) == '19.1'
136 assert m
.group(2) == '19.2'
138 def test_no_branch(self
):
139 """Tests commit with no branch specification"""
140 message
= textwrap
.dedent("""\
141 anv/android: fix images created with external format support
143 This fixes a case where user first creates image and then later binds it
144 with memory created from AHW buffer.
146 Cc: <mesa-stable@lists.freedesktop.org>
147 Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
148 Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
151 m
= core
.IS_CC
.search(message
)
154 def test_quotes(self
):
155 """Tests commit with quotes around the versions"""
156 message
= textwrap
.dedent("""\
157 anv: Always fill out the AUX table even if CCS is disabled
159 Cc: "20.0" mesa-stable@lists.freedesktop.org
160 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
161 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
162 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
165 m
= core
.IS_CC
.search(message
)
167 assert m
.group(1) == '20.0'
169 def test_multiple_quotes(self
):
170 """Tests commit with quotes around the versions"""
171 message
= textwrap
.dedent("""\
172 anv: Always fill out the AUX table even if CCS is disabled
174 Cc: "20.0" "20.1" mesa-stable@lists.freedesktop.org
175 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
176 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
177 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
180 m
= core
.IS_CC
.search(message
)
182 assert m
.group(1) == '20.0'
183 assert m
.group(2) == '20.1'
185 def test_single_quotes(self
):
186 """Tests commit with quotes around the versions"""
187 message
= textwrap
.dedent("""\
188 anv: Always fill out the AUX table even if CCS is disabled
190 Cc: '20.0' mesa-stable@lists.freedesktop.org
191 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
192 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
193 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
196 m
= core
.IS_CC
.search(message
)
198 assert m
.group(1) == '20.0'
200 def test_multiple_single_quotes(self
):
201 """Tests commit with quotes around the versions"""
202 message
= textwrap
.dedent("""\
203 anv: Always fill out the AUX table even if CCS is disabled
205 Cc: '20.0' '20.1' mesa-stable@lists.freedesktop.org
206 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
207 Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
208 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3454>
211 m
= core
.IS_CC
.search(message
)
213 assert m
.group(1) == '20.0'
214 assert m
.group(2) == '20.1'
218 def test_simple(self
):
219 message
= textwrap
.dedent("""\
220 Revert "radv: do not emit PKT3_CONTEXT_CONTROL with AMDGPU 3.6.0+"
222 This reverts commit 2ca8629fa9b303e24783b76a7b3b0c2513e32fbd.
224 This was initially ported from RadeonSI, but in the meantime it has
225 been reverted because it might hang. Be conservative and re-introduce
226 this packet emission.
228 Unfortunately this doesn't fix anything known.
230 Cc: 19.2 <mesa-stable@lists.freedesktop.org>
231 Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
232 Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
235 m
= core
.IS_REVERT
.search(message
)
237 assert m
.group(1) == '2ca8629fa9b303e24783b76a7b3b0c2513e32fbd'
240 class TestResolveNomination
:
243 class FakeSubprocess
:
245 """A fake asyncio.subprocess like classe for use with mock."""
247 out
: typing
.Optional
[bytes
] = attr
.ib(None)
248 returncode
: int = attr
.ib(0)
250 async def mock(self
, *_
, **__
):
251 """A dirtly little helper for mocking."""
254 async def communicate(self
) -> typing
.Tuple
[bytes
, bytes
]:
255 assert self
.out
is not None
258 async def wait(self
) -> int:
259 return self
.returncode
262 async def return_true(*_
, **__
) -> bool:
266 async def return_false(*_
, **__
) -> bool:
270 async def test_fix_is_nominated(self
):
271 s
= self
.FakeSubprocess(b
'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)')
272 c
= core
.Commit('abcdef1234567890', 'a commit')
274 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
275 with mock
.patch('bin.pick.core.is_commit_in_branch', self
.return_true
):
276 await core
.resolve_nomination(c
, '')
279 assert c
.nomination_type
is core
.NominationType
.FIXES
282 async def test_fix_is_not_nominated(self
):
283 s
= self
.FakeSubprocess(b
'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)')
284 c
= core
.Commit('abcdef1234567890', 'a commit')
286 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
287 with mock
.patch('bin.pick.core.is_commit_in_branch', self
.return_false
):
288 await core
.resolve_nomination(c
, '')
290 assert not c
.nominated
291 assert c
.nomination_type
is core
.NominationType
.FIXES
294 async def test_cc_is_nominated(self
):
295 s
= self
.FakeSubprocess(b
'Cc: 16.2 <mesa-stable@lists.freedesktop.org>')
296 c
= core
.Commit('abcdef1234567890', 'a commit')
298 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
299 await core
.resolve_nomination(c
, '16.2')
302 assert c
.nomination_type
is core
.NominationType
.CC
305 async def test_cc_is_nominated2(self
):
306 s
= self
.FakeSubprocess(b
'Cc: mesa-stable@lists.freedesktop.org')
307 c
= core
.Commit('abcdef1234567890', 'a commit')
309 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
310 await core
.resolve_nomination(c
, '16.2')
313 assert c
.nomination_type
is core
.NominationType
.CC
316 async def test_cc_is_not_nominated(self
):
317 s
= self
.FakeSubprocess(b
'Cc: 16.2 <mesa-stable@lists.freedesktop.org>')
318 c
= core
.Commit('abcdef1234567890', 'a commit')
320 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
321 await core
.resolve_nomination(c
, '16.1')
323 assert not c
.nominated
324 assert c
.nomination_type
is None
327 async def test_revert_is_nominated(self
):
328 s
= self
.FakeSubprocess(b
'This reverts commit 1234567890123456789012345678901234567890.')
329 c
= core
.Commit('abcdef1234567890', 'a commit')
331 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
332 with mock
.patch('bin.pick.core.is_commit_in_branch', self
.return_true
):
333 await core
.resolve_nomination(c
, '')
336 assert c
.nomination_type
is core
.NominationType
.REVERT
339 async def test_revert_is_not_nominated(self
):
340 s
= self
.FakeSubprocess(b
'This reverts commit 1234567890123456789012345678901234567890.')
341 c
= core
.Commit('abcdef1234567890', 'a commit')
343 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
344 with mock
.patch('bin.pick.core.is_commit_in_branch', self
.return_false
):
345 await core
.resolve_nomination(c
, '')
347 assert not c
.nominated
348 assert c
.nomination_type
is core
.NominationType
.REVERT
351 async def test_is_fix_and_cc(self
):
352 s
= self
.FakeSubprocess(
353 b
'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)\n'
354 b
'Cc: 16.1 <mesa-stable@lists.freedesktop.org>'
356 c
= core
.Commit('abcdef1234567890', 'a commit')
358 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
359 with mock
.patch('bin.pick.core.is_commit_in_branch', self
.return_true
):
360 await core
.resolve_nomination(c
, '16.1')
363 assert c
.nomination_type
is core
.NominationType
.FIXES
366 async def test_is_fix_and_revert(self
):
367 s
= self
.FakeSubprocess(
368 b
'Fixes: 3d09bb390a39 (etnaviv: GC7000: State changes for HALTI3..5)\n'
369 b
'This reverts commit 1234567890123456789012345678901234567890.'
371 c
= core
.Commit('abcdef1234567890', 'a commit')
373 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
374 with mock
.patch('bin.pick.core.is_commit_in_branch', self
.return_true
):
375 await core
.resolve_nomination(c
, '16.1')
378 assert c
.nomination_type
is core
.NominationType
.FIXES
381 async def test_is_cc_and_revert(self
):
382 s
= self
.FakeSubprocess(
383 b
'This reverts commit 1234567890123456789012345678901234567890.\n'
384 b
'Cc: 16.1 <mesa-stable@lists.freedesktop.org>'
386 c
= core
.Commit('abcdef1234567890', 'a commit')
388 with mock
.patch('bin.pick.core.asyncio.create_subprocess_exec', s
.mock
):
389 with mock
.patch('bin.pick.core.is_commit_in_branch', self
.return_true
):
390 await core
.resolve_nomination(c
, '16.1')
393 assert c
.nomination_type
is core
.NominationType
.CC
396 class TestResolveFixes
:
399 async def test_in_new(self
):
400 """Because commit abcd is nominated, so f123 should be as well."""
402 core
.Commit('f123', 'desc', nomination_type
=core
.NominationType
.FIXES
, because_sha
='abcd'),
403 core
.Commit('abcd', 'desc', True),
405 await core
.resolve_fixes(c
, [])
406 assert c
[1].nominated
409 async def test_not_in_new(self
):
410 """Because commit abcd is not nominated, commit f123 shouldn't be either."""
412 core
.Commit('f123', 'desc', nomination_type
=core
.NominationType
.FIXES
, because_sha
='abcd'),
413 core
.Commit('abcd', 'desc'),
415 await core
.resolve_fixes(c
, [])
416 assert not c
[0].nominated
419 async def test_in_previous(self
):
420 """Because commit abcd is nominated, so f123 should be as well."""
422 core
.Commit('abcd', 'desc', True),
425 core
.Commit('f123', 'desc', nomination_type
=core
.NominationType
.FIXES
, because_sha
='abcd'),
427 await core
.resolve_fixes(c
, p
)
428 assert c
[0].nominated
431 async def test_not_in_previous(self
):
432 """Because commit abcd is not nominated, commit f123 shouldn't be either."""
434 core
.Commit('abcd', 'desc'),
437 core
.Commit('f123', 'desc', nomination_type
=core
.NominationType
.FIXES
, because_sha
='abcd'),
439 await core
.resolve_fixes(c
, p
)
440 assert not c
[0].nominated
443 class TestIsCommitInBranch
:
446 async def test_no(self
):
447 # Hopefully this is never true?
448 value
= await core
.is_commit_in_branch('ffffffffffffffffffffffffffffff')
452 async def test_yes(self
):
453 # This commit is from 2000, it better always be in the branch
454 value
= await core
.is_commit_in_branch('88f3b89a2cb77766d2009b9868c44e03abe2dbb2')
461 async def test_basic(self
):
462 # This commit is from 2000, it better always be in the branch
463 value
= await core
.full_sha('88f3b89a2cb777')
467 async def test_invalid(self
):
468 # This commit is from 2000, it better always be in the branch
469 with pytest
.raises(core
.PickUIException
):
470 await core
.full_sha('fffffffffffffffffffffffffffffffffff')