PageRenderTime 45ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/perf/core/results_processor/formatters/json3_output_unittest.py

https://github.com/chromium/chromium
Python | 205 lines | 166 code | 33 blank | 6 comment | 1 complexity | 125e64be4b5c058a4f5d0b26ac808618 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause
  1. # Copyright 2019 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 copy
  5. import unittest
  6. from core.results_processor.formatters import json3_output
  7. from core.results_processor import testing
  8. class Json3OutputTest(unittest.TestCase):
  9. def setUp(self):
  10. self.base_dir = 'base_dir'
  11. self.test_path_format = 'telemetry'
  12. def Convert(self, test_results):
  13. test_results_copy = copy.deepcopy(test_results)
  14. results = json3_output.Convert(
  15. test_results_copy, self.base_dir, self.test_path_format)
  16. # Convert should not modify the original intermediate results.
  17. self.assertEqual(test_results_copy, test_results)
  18. return results
  19. def FindTestResult(self, results, benchmark, story):
  20. node = results['tests']
  21. for key in (benchmark, story):
  22. self.assertIn(key, node)
  23. node = node[key]
  24. return node
  25. def testStartTime(self):
  26. results = self.Convert([
  27. testing.TestResult('benchmark/story',
  28. start_time='2009-02-13T23:31:30.987000Z')
  29. ])
  30. self.assertFalse(results['interrupted'])
  31. self.assertEqual(results['path_delimiter'], '/')
  32. self.assertEqual(results['seconds_since_epoch'], 1234567890.987)
  33. self.assertEqual(results['version'], 3)
  34. def testSingleTestCase(self):
  35. results = self.Convert([
  36. testing.TestResult('benchmark/story', run_duration='1.2s')
  37. ])
  38. test_result = self.FindTestResult(results, 'benchmark', 'story')
  39. self.assertEqual(test_result['actual'], 'PASS')
  40. self.assertEqual(test_result['expected'], 'PASS')
  41. self.assertEqual(test_result['times'], [1.2])
  42. self.assertEqual(test_result['time'], 1.2)
  43. self.assertNotIn('shard', test_result)
  44. self.assertEqual(results['num_failures_by_type'], {'PASS': 1})
  45. # TODO(crbug.com/983993): Remove this test when all stories have
  46. # url-friendly names without special characters.
  47. def testUrlAsStoryName(self):
  48. results = self.Convert([
  49. testing.TestResult('benchmark/http://example.com')
  50. ])
  51. test_result = self.FindTestResult(
  52. results, 'benchmark', 'http://example.com')
  53. self.assertEqual(test_result['actual'], 'PASS')
  54. def testTwoTestCases(self):
  55. results = self.Convert([
  56. testing.TestResult('benchmark/story1', tags=['shard:7']),
  57. testing.TestResult('benchmark/story2', tags=['shard:3'])
  58. ])
  59. test_result = self.FindTestResult(results, 'benchmark', 'story1')
  60. self.assertEqual(test_result['actual'], 'PASS')
  61. self.assertEqual(test_result['expected'], 'PASS')
  62. self.assertEqual(test_result['shard'], 7)
  63. test_result = self.FindTestResult(results, 'benchmark', 'story2')
  64. self.assertEqual(test_result['actual'], 'PASS')
  65. self.assertEqual(test_result['expected'], 'PASS')
  66. self.assertEqual(test_result['shard'], 3)
  67. self.assertEqual(results['num_failures_by_type'], {'PASS': 2})
  68. def testRepeatedTestCases(self):
  69. results = self.Convert([
  70. testing.TestResult('benchmark/story1', status='PASS',
  71. run_duration='1.2s'),
  72. testing.TestResult('benchmark/story2', status='SKIP'),
  73. testing.TestResult('benchmark/story1', status='PASS',
  74. run_duration='3.4s'),
  75. testing.TestResult('benchmark/story2', status='SKIP'),
  76. ])
  77. test_result = self.FindTestResult(results, 'benchmark', 'story1')
  78. self.assertEqual(test_result['actual'], 'PASS')
  79. self.assertEqual(test_result['expected'], 'PASS')
  80. self.assertEqual(test_result['times'], [1.2, 3.4])
  81. self.assertEqual(test_result['time'], 1.2)
  82. test_result = self.FindTestResult(results, 'benchmark', 'story2')
  83. self.assertEqual(test_result['actual'], 'SKIP')
  84. self.assertEqual(test_result['expected'], 'SKIP')
  85. self.assertEqual(results['num_failures_by_type'], {'PASS': 2, 'SKIP': 2})
  86. def testFailedAndSkippedTestCases(self):
  87. results = self.Convert([
  88. testing.TestResult('benchmark/story1', status='PASS'),
  89. testing.TestResult('benchmark/story2', status='PASS'),
  90. testing.TestResult('benchmark/story1', status='FAIL'),
  91. testing.TestResult('benchmark/story2', status='SKIP',
  92. expected=False),
  93. ])
  94. test_result = self.FindTestResult(results, 'benchmark', 'story1')
  95. self.assertEqual(test_result['actual'], 'FAIL')
  96. self.assertEqual(test_result['expected'], 'PASS')
  97. self.assertTrue(test_result['is_unexpected'])
  98. test_result = self.FindTestResult(results, 'benchmark', 'story2')
  99. self.assertEqual(test_result['actual'], 'PASS SKIP')
  100. self.assertEqual(test_result['expected'], 'PASS')
  101. self.assertTrue(test_result['is_unexpected'])
  102. self.assertEqual(results['num_failures_by_type'],
  103. {'PASS': 2, 'SKIP': 1, 'FAIL': 1})
  104. def testDedupedStatus(self):
  105. results = self.Convert([
  106. testing.TestResult('benchmark/story1', status='PASS'),
  107. testing.TestResult('benchmark/story2', status='SKIP'),
  108. testing.TestResult('benchmark/story3', status='FAIL'),
  109. testing.TestResult('benchmark/story1', status='PASS'),
  110. testing.TestResult('benchmark/story2', status='SKIP'),
  111. testing.TestResult('benchmark/story3', status='FAIL'),
  112. ])
  113. test_result = self.FindTestResult(results, 'benchmark', 'story1')
  114. self.assertEqual(test_result['actual'], 'PASS')
  115. self.assertEqual(test_result['expected'], 'PASS')
  116. self.assertFalse(test_result['is_unexpected'])
  117. test_result = self.FindTestResult(results, 'benchmark', 'story2')
  118. self.assertEqual(test_result['actual'], 'SKIP')
  119. self.assertEqual(test_result['expected'], 'SKIP')
  120. self.assertFalse(test_result['is_unexpected'])
  121. test_result = self.FindTestResult(results, 'benchmark', 'story3')
  122. self.assertEqual(test_result['actual'], 'FAIL')
  123. self.assertEqual(test_result['expected'], 'PASS')
  124. self.assertTrue(test_result['is_unexpected'])
  125. self.assertEqual(results['num_failures_by_type'],
  126. {'PASS': 2, 'SKIP': 2, 'FAIL': 2})
  127. def testRepeatedTestCaseWithArtifacts(self):
  128. self.base_dir = 'base'
  129. results = self.Convert([
  130. testing.TestResult('benchmark/story1', output_artifacts={
  131. 'logs.txt': testing.Artifact('base/artifacts/logs1.txt')
  132. }),
  133. testing.TestResult('benchmark/story1', output_artifacts={
  134. 'logs.txt': testing.Artifact('base/artifacts/logs2.txt'),
  135. 'trace.json': testing.Artifact('base/artifacts/trace2.json')
  136. }),
  137. ])
  138. test_result = self.FindTestResult(results, 'benchmark', 'story1')
  139. self.assertEqual(test_result['actual'], 'PASS')
  140. self.assertEqual(test_result['expected'], 'PASS')
  141. self.assertEqual(test_result['artifacts'], {
  142. 'logs.txt': ['artifacts/logs1.txt', 'artifacts/logs2.txt'],
  143. 'trace.json': ['artifacts/trace2.json']
  144. })
  145. def testRemoteArtifacts(self):
  146. results = self.Convert([
  147. testing.TestResult('benchmark/story1', output_artifacts={
  148. 'logs.txt': testing.Artifact(
  149. 'base/artifacts/logs1.txt',
  150. fetch_url='gs://artifacts/logs1.txt')
  151. }),
  152. testing.TestResult('benchmark/story1', output_artifacts={
  153. 'logs.txt': testing.Artifact(
  154. 'base/artifacts/logs2.txt',
  155. fetch_url='gs://artifacts/logs2.txt'),
  156. 'trace.json': testing.Artifact(
  157. 'base/artifacts/trace2.json',
  158. fetch_url='gs://artifacts/trace2.json')
  159. }),
  160. ])
  161. test_result = self.FindTestResult(results, 'benchmark', 'story1')
  162. self.assertEqual(test_result['actual'], 'PASS')
  163. self.assertEqual(test_result['expected'], 'PASS')
  164. self.assertEqual(test_result['artifacts'], {
  165. 'logs.txt': [
  166. 'gs://artifacts/logs1.txt',
  167. 'gs://artifacts/logs2.txt'
  168. ],
  169. 'trace.json': [
  170. 'gs://artifacts/trace2.json'
  171. ]
  172. })