PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/content/test/gpu/gpu_tests/gpu_test_expectations_unittest.py

https://gitlab.com/jonnialva90/iridium-browser
Python | 183 lines | 172 code | 8 blank | 3 comment | 0 complexity | ad79f3be5beef527053b4a4da37f3c21 MD5 | raw file
  1. # Copyright 2015 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import unittest
  5. from telemetry.internal.platform import system_info
  6. from telemetry.page import page as page_module
  7. from telemetry.story import story_set
  8. import gpu_test_expectations
  9. VENDOR_NVIDIA = 0x10DE
  10. VENDOR_AMD = 0x1002
  11. VENDOR_INTEL = 0x8086
  12. VENDOR_STRING_IMAGINATION = 'Imagination Technologies'
  13. DEVICE_STRING_SGX = 'PowerVR SGX 554'
  14. class StubPlatform(object):
  15. def __init__(self, os_name, os_version_name=None):
  16. self.os_name = os_name
  17. self.os_version_name = os_version_name
  18. def GetOSName(self):
  19. return self.os_name
  20. def GetOSVersionName(self):
  21. return self.os_version_name
  22. class StubBrowser(object):
  23. def __init__(self, platform, gpu, device, vendor_string, device_string,
  24. browser_type=None, gl_renderer=None):
  25. self.platform = platform
  26. self.browser_type = browser_type
  27. sys_info = {
  28. 'model_name': '',
  29. 'gpu': {
  30. 'devices': [
  31. {'vendor_id': gpu, 'device_id': device,
  32. 'vendor_string': vendor_string, 'device_string': device_string},
  33. ]
  34. }
  35. }
  36. if gl_renderer:
  37. sys_info['gpu']['aux_attributes'] = {
  38. 'gl_renderer': gl_renderer
  39. }
  40. self.system_info = system_info.SystemInfo.FromDict(sys_info)
  41. @property
  42. def supports_system_info(self):
  43. return False if not self.system_info else True
  44. def GetSystemInfo(self):
  45. return self.system_info
  46. class SampleTestExpectations(gpu_test_expectations.GpuTestExpectations):
  47. def SetExpectations(self):
  48. # Test GPU conditions.
  49. self.Fail('test1.html', ['nvidia', 'intel'], bug=123)
  50. self.Fail('test2.html', [('nvidia', 0x1001), ('nvidia', 0x1002)], bug=123)
  51. self.Fail('test3.html', ['win', 'intel', ('amd', 0x1001)], bug=123)
  52. self.Fail('test4.html', ['imagination'])
  53. self.Fail('test5.html', [('imagination', 'PowerVR SGX 554')])
  54. # Test ANGLE conditions.
  55. self.Fail('test6.html', ['win', 'd3d9'], bug=345)
  56. # Test flaky expectations.
  57. self.Flaky('test7.html', bug=123, max_num_retries=5)
  58. self.Flaky('test8.html', ['win'], bug=123, max_num_retries=6)
  59. self.Flaky('wildcardtest*.html', ['win'], bug=123, max_num_retries=7)
  60. class GpuTestExpectationsTest(unittest.TestCase):
  61. def setUp(self):
  62. self.expectations = SampleTestExpectations()
  63. def assertExpectationEquals(self, expected, page, platform=StubPlatform(''),
  64. gpu=0, device=0, vendor_string='',
  65. device_string='', browser_type=None,
  66. gl_renderer=None):
  67. self.expectations.ClearExpectationsCacheForTesting()
  68. result = self.expectations.GetExpectationForPage(StubBrowser(
  69. platform, gpu, device, vendor_string, device_string,
  70. browser_type=browser_type, gl_renderer=gl_renderer), page)
  71. self.assertEquals(expected, result)
  72. def getRetriesForPage(self, page, platform=StubPlatform(''), gpu=0,
  73. device=0, vendor_string='', device_string=''):
  74. self.expectations.ClearExpectationsCacheForTesting()
  75. return self.expectations.GetFlakyRetriesForPage(StubBrowser(
  76. platform, gpu, device, vendor_string, device_string), page)
  77. # Pages with expectations for a GPU should only return them when running with
  78. # that GPU
  79. def testGpuExpectations(self):
  80. ps = story_set.StorySet()
  81. page = page_module.Page('http://test.com/test1.html', ps)
  82. self.assertExpectationEquals('fail', page, gpu=VENDOR_NVIDIA)
  83. self.assertExpectationEquals('fail', page, gpu=VENDOR_INTEL)
  84. self.assertExpectationEquals('pass', page, gpu=VENDOR_AMD)
  85. # Pages with expectations for a GPU should only return them when running with
  86. # that GPU
  87. def testGpuDeviceIdExpectations(self):
  88. ps = story_set.StorySet()
  89. page = page_module.Page('http://test.com/test2.html', ps)
  90. self.assertExpectationEquals('fail', page, gpu=VENDOR_NVIDIA, device=0x1001)
  91. self.assertExpectationEquals('fail', page, gpu=VENDOR_NVIDIA, device=0x1002)
  92. self.assertExpectationEquals('pass', page, gpu=VENDOR_NVIDIA, device=0x1003)
  93. self.assertExpectationEquals('pass', page, gpu=VENDOR_AMD, device=0x1001)
  94. # Pages with multiple expectations should only return them when all criteria
  95. # are met
  96. def testMultipleExpectations(self):
  97. ps = story_set.StorySet()
  98. page = page_module.Page('http://test.com/test3.html', ps)
  99. self.assertExpectationEquals('fail', page,
  100. StubPlatform('win'), VENDOR_AMD, 0x1001)
  101. self.assertExpectationEquals('fail', page,
  102. StubPlatform('win'), VENDOR_INTEL, 0x1002)
  103. self.assertExpectationEquals('pass', page,
  104. StubPlatform('win'), VENDOR_NVIDIA, 0x1001)
  105. self.assertExpectationEquals('pass', page,
  106. StubPlatform('mac'), VENDOR_AMD, 0x1001)
  107. self.assertExpectationEquals('pass', page,
  108. StubPlatform('win'), VENDOR_AMD, 0x1002)
  109. # Pages with expectations based on GPU vendor string.
  110. def testGpuVendorStringExpectations(self):
  111. ps = story_set.StorySet()
  112. page = page_module.Page('http://test.com/test4.html', ps)
  113. self.assertExpectationEquals('fail', page,
  114. vendor_string=VENDOR_STRING_IMAGINATION,
  115. device_string=DEVICE_STRING_SGX)
  116. self.assertExpectationEquals('fail', page,
  117. vendor_string=VENDOR_STRING_IMAGINATION,
  118. device_string='Triangle Monster 3000')
  119. self.assertExpectationEquals('pass', page,
  120. vendor_string='Acme',
  121. device_string=DEVICE_STRING_SGX)
  122. # Pages with expectations based on GPU vendor and renderer string pairs.
  123. def testGpuDeviceStringExpectations(self):
  124. ps = story_set.StorySet()
  125. page = page_module.Page('http://test.com/test5.html', ps)
  126. self.assertExpectationEquals('fail', page,
  127. vendor_string=VENDOR_STRING_IMAGINATION,
  128. device_string=DEVICE_STRING_SGX)
  129. self.assertExpectationEquals('pass', page,
  130. vendor_string=VENDOR_STRING_IMAGINATION,
  131. device_string='Triangle Monster 3000')
  132. self.assertExpectationEquals('pass', page,
  133. vendor_string='Acme',
  134. device_string=DEVICE_STRING_SGX)
  135. # Test ANGLE conditions.
  136. def testANGLEConditions(self):
  137. ps = story_set.StorySet()
  138. page = page_module.Page('http://test.com/test6.html', ps)
  139. self.assertExpectationEquals('pass', page, StubPlatform('win'),
  140. gl_renderer='Direct3D11')
  141. self.assertExpectationEquals('fail', page, StubPlatform('win'),
  142. gl_renderer='Direct3D9')
  143. # Ensure retry mechanism is working.
  144. def testFlakyExpectation(self):
  145. ps = story_set.StorySet()
  146. page = page_module.Page('http://test.com/test7.html', ps)
  147. self.assertExpectationEquals('flaky', page)
  148. self.assertEquals(5, self.getRetriesForPage(page))
  149. # Ensure the filtering from the TestExpectations superclass still works.
  150. def testFlakyPerPlatformExpectation(self):
  151. ps = story_set.StorySet()
  152. page1 = page_module.Page('http://test.com/test8.html', ps)
  153. self.assertExpectationEquals('flaky', page1, StubPlatform('win'))
  154. self.assertEquals(6, self.getRetriesForPage(page1, StubPlatform('win')))
  155. self.assertExpectationEquals('pass', page1, StubPlatform('mac'))
  156. self.assertEquals(0, self.getRetriesForPage(page1, StubPlatform('mac')))
  157. page2 = page_module.Page('http://test.com/wildcardtest1.html', ps)
  158. self.assertExpectationEquals('flaky', page2, StubPlatform('win'))
  159. self.assertEquals(7, self.getRetriesForPage(page2, StubPlatform('win')))
  160. self.assertExpectationEquals('pass', page2, StubPlatform('mac'))
  161. self.assertEquals(0, self.getRetriesForPage(page2, StubPlatform('mac')))