1# Copyright 2021 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import unittest 6import json 7 8import run_performance_tests 9from run_performance_tests import TelemetryCommandGenerator 10 11# The path where the output of a wpt run was written. This is the file that 12# gets processed by BaseWptScriptAdapter. 13OUTPUT_JSON_FILENAME = "out.json" 14 15 16class TelemetryCommandGeneratorTest(unittest.TestCase): 17 def setUp(self): 18 fake_args = [ 19 './run_benchmark', 20 '--isolated-script-test-output=output.json' 21 ] 22 self._fake_options = run_performance_tests.parse_arguments(fake_args) 23 24 def testStorySelectionBeginEnd(self): 25 story_selection_config = json.loads( 26 '{"begin": 11, "end": 21, "abridged": false}') 27 generator = TelemetryCommandGenerator( 28 'benchmark_name', self._fake_options, story_selection_config 29 ) 30 command = generator.generate('output_dir') 31 self.assertIn('--story-shard-begin-index=11', command) 32 self.assertIn('--story-shard-end-index=21', command) 33 self.assertNotIn('--run-abridged-story-set', command) 34 35 36 def testStorySelectionAbridgedDefault(self): 37 story_selection_config = json.loads( 38 '{"begin": 11, "end": 21}') 39 generator = TelemetryCommandGenerator( 40 'benchmark_name', self._fake_options, story_selection_config 41 ) 42 command = generator.generate('output_dir') 43 self.assertIn('--run-abridged-story-set', command) 44 45 def testStorySelectionIndexSectionsSingleIndex(self): 46 story_selection_config = json.loads( 47 '{"sections": [{"begin": 11, "end": 21}, {"begin": 25, "end": 26}]}') 48 generator = TelemetryCommandGenerator( 49 'benchmark_name', self._fake_options, story_selection_config 50 ) 51 command = generator.generate('output_dir') 52 self.assertIn('--story-shard-indexes=11-21,25', command) 53 54 def testStorySelectionIndexSectionsOpenEnds(self): 55 story_selection_config = json.loads( 56 '{"sections": [{"end": 10}, {"begin": 15, "end": 16}, {"begin": 20}]}') 57 generator = TelemetryCommandGenerator( 58 'benchmark_name', self._fake_options, story_selection_config 59 ) 60 command = generator.generate('output_dir') 61 self.assertIn('--story-shard-indexes=-10,15,20-', command) 62 63 64 def testStorySelectionIndexSectionsIllegalRange(self): 65 with self.assertRaises(ValueError): 66 story_selection_config = json.loads( 67 '{"sections": [{"begin": 15, "end": 16}, {"foo": "bar"}]}') 68 generator = TelemetryCommandGenerator( 69 'benchmark_name', self._fake_options, story_selection_config 70 ) 71 generator.generate('output_dir') 72 73 def testStorySelectionIndexSectionsEmpty(self): 74 story_selection_config = json.loads( 75 '{"sections": []}') 76 generator = TelemetryCommandGenerator( 77 'benchmark_name', self._fake_options, story_selection_config 78 ) 79 command = generator.generate('output_dir') 80 self.assertNotIn('--story-shard-indexes=', command)