Ejemplo n.º 1
0
    def RunPageTest(self, page_test, url, expect_status='PASS'):
        """Run a legacy page_test on a test url and return its measurements.

    Args:
      page_test: A legacy_page_test.LegacyPageTest instance.
      url: A URL for the test page to load, usually a local 'file://' URI to be
        served from telemetry/internal/testing. Clients can override the
        static method CreateStorySetForTestFile to change this behavior.
      expect_status: A string with the expected status of the test run.

    Returns:
      A dictionary with measurements recorded by the legacy_page_test.
    """
        self.assertIsInstance(page_test, legacy_page_test.LegacyPageTest)
        page_test.CustomizeBrowserOptions(self.options.browser_options)
        story_set = self.CreateStorySetForTest(url)
        self.assertEqual(len(story_set), 1)
        with results_options.CreateResults(self.options) as results:
            story_runner.RunStorySet(page_test, story_set, self.options,
                                     results)
        test_results = results_options.ReadTestResults(
            self.options.intermediate_dir)
        self.assertEqual(len(test_results), 1)
        self.test_result = test_results[0]
        self.assertEqual(self.test_result['status'], expect_status)
        return results_options.ReadMeasurements(self.test_result)
  def testAddMeasurementAsScalar(self):
    with self.CreateResults() as results:
      with results.CreateStoryRun(self.stories[0]):
        results.AddMeasurement('a', 'seconds', 3)

    test_results = results_options.ReadTestResults(self.intermediate_dir)
    self.assertTrue(len(test_results), 1)
    measurements = results_options.ReadMeasurements(test_results[0])
    self.assertEqual(measurements, {'a': {'unit': 'seconds', 'samples': [3]}})
  def testAddMeasurementAsScalar(self):
    with self.CreateResults() as results:
      results.WillRunPage(self.pages[0])
      results.AddMeasurement('a', 'seconds', 3)
      results.DidRunPage(self.pages[0])

    test_results = results_options.ReadIntermediateResults(
        self.intermediate_dir)['testResults']
    self.assertTrue(len(test_results), 1)
    measurements = results_options.ReadMeasurements(test_results[0])
    self.assertEqual(measurements, {'a': {'unit': 'seconds', 'samples': [3]}})
    def testAddMeasurementAsList(self):
        with self.CreateResults() as results:
            with results.CreateStoryRun(self.stories[0]):
                results.AddMeasurement('a', 'seconds', [1, 2, 3])

        test_results = self.ReadTestResults()
        self.assertTrue(len(test_results), 1)
        measurements = results_options.ReadMeasurements(test_results[0])
        self.assertEqual(measurements,
                         {'a': {
                             'unit': 'seconds',
                             'samples': [1, 2, 3]
                         }})
  def testAddMeasurementAsHistogram(self):
    # TODO(999484): Temporary test while we migrate benchmarks writing "ad hoc"
    # histograms to directly use measurements instead.
    with self.CreateResults() as results:
      results.WillRunPage(self.pages[0])
      results.AddHistogram(histogram_module.Histogram.Create(
          'a', 'ms', [1000, 2000, 3000]))
      results.DidRunPage(self.pages[0])

    test_results = results_options.ReadIntermediateResults(
        self.intermediate_dir)['testResults']
    self.assertTrue(len(test_results), 1)
    measurements = results_options.ReadMeasurements(test_results[0])
    self.assertEqual(measurements,
                     {'a': {'unit': 'ms', 'samples': [1000, 2000, 3000]}})