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