1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117

content / test / gpu / unexpected_passes / gpu_expectations_unittest.py [blame]

#!/usr/bin/env vpython3
# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function

import datetime
from typing import Dict
import unittest
from unittest import mock

from unexpected_passes import gpu_expectations
from unexpected_passes_common import data_types

# pylint: disable=protected-access


class CreateTestExpectationMapUnittest(unittest.TestCase):
  def setUp(self) -> None:
    self.instance = gpu_expectations.GpuExpectations()

    self._expectation_content: Dict[str, str] = {}
    self._content_patcher = mock.patch.object(
        self.instance, '_GetNonRecentExpectationContent')
    self._content_mock = self._content_patcher.start()
    self.addCleanup(self._content_patcher.stop)

    def SideEffect(filepath, _):
      return self._expectation_content[filepath]

    self._content_mock.side_effect = SideEffect

  def testSlowExpectationsDropped(self) -> None:
    """Tests that slow expectations get dropped from the generated map."""
    filename = '/tmp/foo'
    self._expectation_content[filename] = """\
# tags: [ win linux ]
# tags: [ nvidia intel ]
# results: [ Failure Slow ]

[ win intel ] foo/test [ Failure ]
[ win nvidia ] foo/test [ Slow ]
[ linux nvidia ] foo/test [ Slow ]
[ linux intel ] foo/test [ Failure ]
"""
    expectation_map = self.instance.CreateTestExpectationMap(
        filename, None, datetime.timedelta(days=0))
    # The Slow expectations should be omitted.
    expected_expectation_map = {
        filename: {
            data_types.Expectation('foo/test', ['win', 'intel'], ['Failure']):
            {},
            data_types.Expectation('foo/test', ['linux', 'intel'], ['Failure']):
            {},
        },
    }
    self.assertEqual(expectation_map, expected_expectation_map)
    self.assertIsInstance(expectation_map, data_types.TestExpectationMap)


class GetExpectationFilepathsUnittest(unittest.TestCase):
  def testGetExpectationFilepathsFindsSomething(self) -> None:
    """Tests that the _GetExpectationFilepaths finds something in the dir."""
    expectations = gpu_expectations.GpuExpectations()
    self.assertTrue(len(expectations.GetExpectationFilepaths()) > 0)


class ConsolidateKnownOverlappingTagsUnittest(unittest.TestCase):
  def setUp(self) -> None:
    self.expectations = gpu_expectations.GpuExpectations()

  def testNoOp(self) -> None:
    """Tests that consolidation is a no-op if there is no overlap."""
    tags = frozenset(['mac', 'amd', 'amd-0x6821', 'release'])
    consolidated_tags = self.expectations._ConsolidateKnownOverlappingTags(tags)
    self.assertEqual(consolidated_tags, tags)

  def testMacbookPro2015(self) -> None:
    """Tests that Macbook Pro 2015 tags are properly consolidated."""
    tags = frozenset(
        ['mac', 'amd', 'amd-0x6821', 'release', 'intel', 'intel-0xd26'])
    consolidated_tags = self.expectations._ConsolidateKnownOverlappingTags(tags)
    self.assertEqual(consolidated_tags, {'mac', 'amd', 'amd-0x6821', 'release'})

  def test15InchMacbookPro2019(self) -> None:
    """Tests that 15" Macbook Pro 2019 tags are properly consolidated."""
    tags = frozenset([
        'mac', 'amd', 'amd-0x67ef', 'release', 'intel', 'intel-0x3e9b',
        'intel-gen-9'
    ])
    consolidated_tags = self.expectations._ConsolidateKnownOverlappingTags(tags)
    self.assertEqual(consolidated_tags, {'mac', 'amd', 'amd-0x67ef', 'release'})

  def test16InchMacbookPro2019(self) -> None:
    """Tests that 16" Macbook Pro 2019 tags are properly consolidated."""
    tags = frozenset([
        'mac', 'amd', 'amd-0x7340', 'release', 'intel', 'intel-0x3e9b',
        'intel-gen-9'
    ])
    consolidated_tags = self.expectations._ConsolidateKnownOverlappingTags(tags)
    self.assertEqual(consolidated_tags, {'mac', 'amd', 'amd-0x7340', 'release'})

  def testSpecificMacVersion(self) -> None:
    """Tests that specific Mac versions can be used for IDing dual GPUs."""
    tags = frozenset([
        'angle-metal', 'amd-0x67ef', 'sonoma', 'intel-gen-9', 'amd',
        'passthrough'
    ])
    consolidated_tags = self.expectations._ConsolidateKnownOverlappingTags(tags)
    self.assertEqual(
        consolidated_tags,
        {'angle-metal', 'amd-0x67ef', 'sonoma', 'amd', 'passthrough'})


if __name__ == '__main__':
  unittest.main(verbosity=2)