run_performance_tests_unittest.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (c) 2021 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. import json
  6. import run_performance_tests
  7. from run_performance_tests import TelemetryCommandGenerator
  8. # The path where the output of a wpt run was written. This is the file that
  9. # gets processed by BaseWptScriptAdapter.
  10. OUTPUT_JSON_FILENAME = "out.json"
  11. class TelemetryCommandGeneratorTest(unittest.TestCase):
  12. def setUp(self):
  13. fake_args = [
  14. './run_benchmark',
  15. '--isolated-script-test-output=output.json'
  16. ]
  17. self._fake_options = run_performance_tests.parse_arguments(fake_args)
  18. def testStorySelectionBeginEnd(self):
  19. story_selection_config = json.loads(
  20. '{"begin": 11, "end": 21, "abridged": false}')
  21. generator = TelemetryCommandGenerator(
  22. 'benchmark_name', self._fake_options, story_selection_config
  23. )
  24. command = generator.generate('output_dir')
  25. self.assertIn('--story-shard-begin-index=11', command)
  26. self.assertIn('--story-shard-end-index=21', command)
  27. self.assertNotIn('--run-abridged-story-set', command)
  28. def testStorySelectionAbridgedDefault(self):
  29. story_selection_config = json.loads(
  30. '{"begin": 11, "end": 21}')
  31. generator = TelemetryCommandGenerator(
  32. 'benchmark_name', self._fake_options, story_selection_config
  33. )
  34. command = generator.generate('output_dir')
  35. self.assertIn('--run-abridged-story-set', command)
  36. def testStorySelectionIndexSectionsSingleIndex(self):
  37. story_selection_config = json.loads(
  38. '{"sections": [{"begin": 11, "end": 21}, {"begin": 25, "end": 26}]}')
  39. generator = TelemetryCommandGenerator(
  40. 'benchmark_name', self._fake_options, story_selection_config
  41. )
  42. command = generator.generate('output_dir')
  43. self.assertIn('--story-shard-indexes=11-21,25', command)
  44. def testStorySelectionIndexSectionsOpenEnds(self):
  45. story_selection_config = json.loads(
  46. '{"sections": [{"end": 10}, {"begin": 15, "end": 16}, {"begin": 20}]}')
  47. generator = TelemetryCommandGenerator(
  48. 'benchmark_name', self._fake_options, story_selection_config
  49. )
  50. command = generator.generate('output_dir')
  51. self.assertIn('--story-shard-indexes=-10,15,20-', command)
  52. def testStorySelectionIndexSectionsIllegalRange(self):
  53. with self.assertRaises(ValueError):
  54. story_selection_config = json.loads(
  55. '{"sections": [{"begin": 15, "end": 16}, {"foo": "bar"}]}')
  56. generator = TelemetryCommandGenerator(
  57. 'benchmark_name', self._fake_options, story_selection_config
  58. )
  59. generator.generate('output_dir')
  60. def testStorySelectionIndexSectionsEmpty(self):
  61. story_selection_config = json.loads(
  62. '{"sections": []}')
  63. generator = TelemetryCommandGenerator(
  64. 'benchmark_name', self._fake_options, story_selection_config
  65. )
  66. command = generator.generate('output_dir')
  67. self.assertNotIn('--story-shard-indexes=', command)