Commit 95811819 authored by Juan Antonio Navarro Perez's avatar Juan Antonio Navarro Perez Committed by Commit Bot

[tools/perf] Migrate clients to LegacyPageTestCase

This new class makes it easier to write tests for LegacyPageTest
implementations, and is compatible with the add hoc measurements that
they normally write.

Depends on catapult CL:
https://chromium-review.googlesource.com/c/catapult/+/1862517

Bug: 999484
Change-Id: I13c64fdf7cb7181ac34306a124868d408bc99742
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863292Reviewed-by: default avatarRavi Mistry <rmistry@chromium.org>
Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Commit-Queue: Juan Antonio Navarro Pérez <perezju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706470}
parent d819aa72
...@@ -3,41 +3,27 @@ ...@@ -3,41 +3,27 @@
# found in the LICENSE file. # found in the LICENSE file.
import os import os
import shutil
import tempfile
from telemetry import decorators from telemetry import decorators
from telemetry.testing import options_for_unittests from telemetry.testing import legacy_page_test_case
from telemetry.testing import page_test_test_case
from telemetry.util import image_util from telemetry.util import image_util
from contrib.cluster_telemetry import screenshot from contrib.cluster_telemetry import screenshot
class ScreenshotUnitTest(page_test_test_case.PageTestTestCase):
def setUp(self):
self._png_outdir = tempfile.mkdtemp('_png_test')
self._options = options_for_unittests.GetRunOptions(
output_dir=self._png_outdir)
def tearDown(self):
shutil.rmtree(self._png_outdir)
class ScreenshotUnitTest(legacy_page_test_case.LegacyPageTestCase):
@decorators.Enabled('linux') @decorators.Enabled('linux')
def testScreenshot(self): def testScreenshot(self):
# Screenshots for Cluster Telemetry purposes currently only supported on # Screenshots for Cluster Telemetry purposes currently only supported on
# Linux platform. # Linux platform.
story_set = self.CreateStorySetFromFileInUnittestDataDir( screenshot_test = screenshot.Screenshot(self.options.output_dir)
'screenshot_test.html') self.RunPageTest(screenshot_test, 'file://screenshot_test.html')
measurement = screenshot.Screenshot(self._png_outdir)
self.RunMeasurement(measurement, story_set, run_options=self._options)
path = os.path.join( filepath = os.path.join(self.options.output_dir, 'screenshot_test.png')
self._png_outdir, story_set.stories[0].file_safe_name + '.png') self.assertTrue(os.path.exists(filepath))
self.assertTrue(os.path.exists(path)) self.assertTrue(os.path.isfile(filepath))
self.assertTrue(os.path.isfile(path)) self.assertTrue(os.access(filepath, os.R_OK))
self.assertTrue(os.access(path, os.R_OK))
image = image_util.FromPngFile(path) image = image_util.FromPngFile(filepath)
screenshot_pixels = image_util.Pixels(image) screenshot_pixels = image_util.Pixels(image)
special_colored_pixel = bytearray([217, 115, 43]) special_colored_pixel = bytearray([217, 115, 43])
self.assertTrue(special_colored_pixel in screenshot_pixels) self.assertTrue(special_colored_pixel in screenshot_pixels)
......
...@@ -2,30 +2,17 @@ ...@@ -2,30 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators from telemetry import decorators
from telemetry.testing import options_for_unittests from telemetry.testing import legacy_page_test_case
from telemetry.testing import page_test_test_case
from measurements import multipage_skpicture_printer from measurements import multipage_skpicture_printer
class MultipageSkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase): class MultipageSkpicturePrinterUnitTest(
legacy_page_test_case.LegacyPageTestCase):
def setUp(self):
self._mskp_outdir = tempfile.mkdtemp('_mskp_test')
self._options = options_for_unittests.GetRunOptions(
output_dir=self._mskp_outdir)
def tearDown(self):
shutil.rmtree(self._mskp_outdir)
# Picture printing is not supported on all platforms. # Picture printing is not supported on all platforms.
@decorators.Disabled('android', 'chromeos') @decorators.Disabled('android', 'chromeos')
def testSkpicturePrinter(self): def testSkpicturePrinter(self):
story_set = self.CreateStorySetFromFileInUnittestDataDir('blank.html') page_test = multipage_skpicture_printer.MultipageSkpicturePrinter(
measurement = multipage_skpicture_printer.MultipageSkpicturePrinter( self.options.output_dir)
self._mskp_outdir) self.RunPageTest(page_test, 'file://blank.html')
self.RunMeasurement(measurement, story_set, run_options=self._options)
...@@ -2,20 +2,13 @@ ...@@ -2,20 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import logging
import shutil
import tempfile
from telemetry import decorators from telemetry import decorators
from telemetry.page import legacy_page_test from telemetry.testing import legacy_page_test_case
from telemetry.testing import options_for_unittests
from telemetry.testing import page_test_test_case
from telemetry.util import wpr_modes
from measurements import rasterize_and_record_micro from measurements import rasterize_and_record_micro
class RasterizeAndRecordMicroUnitTest(page_test_test_case.PageTestTestCase): class RasterizeAndRecordMicroUnitTest(legacy_page_test_case.LegacyPageTestCase):
"""Smoke test for rasterize_and_record_micro measurement """Smoke test for rasterize_and_record_micro measurement
Runs rasterize_and_record_micro measurement on a simple page and verifies Runs rasterize_and_record_micro measurement on a simple page and verifies
...@@ -23,92 +16,33 @@ class RasterizeAndRecordMicroUnitTest(page_test_test_case.PageTestTestCase): ...@@ -23,92 +16,33 @@ class RasterizeAndRecordMicroUnitTest(page_test_test_case.PageTestTestCase):
i.e. it only checks if the metrics are present and non-zero. i.e. it only checks if the metrics are present and non-zero.
""" """
def setUp(self):
self._options = options_for_unittests.GetRunOptions(
output_dir=tempfile.mkdtemp())
self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
def tearDown(self):
shutil.rmtree(self._options.output_dir)
@decorators.Disabled('win', 'chromeos', 'linux') @decorators.Disabled('win', 'chromeos', 'linux')
def testRasterizeAndRecordMicro(self): def testRasterizeAndRecordMicro(self):
story_set = self.CreateStorySetFromFileInUnittestDataDir('blank.html') pate_test = rasterize_and_record_micro.RasterizeAndRecordMicro(
measurement = rasterize_and_record_micro.RasterizeAndRecordMicro(
rasterize_repeat=1, record_repeat=1, start_wait_time=0.0, rasterize_repeat=1, record_repeat=1, start_wait_time=0.0,
report_detailed_results=True) report_detailed_results=True)
try: measurements = self.RunPageTest(pate_test, 'file://blank.html')
results = self.RunMeasurement(
measurement, story_set, run_options=self._options) # For these measurements, a single positive scalar value is expected.
except legacy_page_test.TestNotSupportedOnPlatformError as failure: expected_positve_scalar = [
logging.warning(str(failure)) 'rasterize_time',
return 'record_time',
self.assertFalse(results.had_failures) 'pixels_rasterized',
'pixels_recorded',
rasterize_time = results.FindAllPageSpecificValuesNamed('rasterize_time') 'pixels_rasterized_with_non_solid_color',
self.assertEquals(len(rasterize_time), 1) 'pixels_rasterized_as_opaque',
self.assertGreater(rasterize_time[0].value, 0) 'total_layers',
'total_picture_layers',
record_time = results.FindAllPageSpecificValuesNamed('record_time') 'total_picture_layers_with_no_content',
self.assertEquals(len(record_time), 1) 'painter_memory_usage',
self.assertGreater(record_time[0].value, 0) 'paint_op_memory_usage',
'paint_op_count',
rasterized_pixels = results.FindAllPageSpecificValuesNamed( ]
'pixels_rasterized') for name in expected_positve_scalar:
self.assertEquals(len(rasterized_pixels), 1) samples = measurements[name]['samples']
self.assertGreater(rasterized_pixels[0].value, 0) self.assertEqual(len(samples), 1)
self.assertGreater(samples[0], 0)
recorded_pixels = results.FindAllPageSpecificValuesNamed('pixels_recorded')
self.assertEquals(len(recorded_pixels), 1) samples = measurements['total_picture_layers_off_screen']['samples']
self.assertGreater(recorded_pixels[0].value, 0) self.assertEqual(len(samples), 1)
self.assertEqual(samples[0], 0)
pixels_rasterized_with_non_solid_color = \
results.FindAllPageSpecificValuesNamed(
'pixels_rasterized_with_non_solid_color')
self.assertEquals(len(pixels_rasterized_with_non_solid_color), 1)
self.assertGreater(
pixels_rasterized_with_non_solid_color[0].value, 0)
pixels_rasterized_as_opaque = \
results.FindAllPageSpecificValuesNamed('pixels_rasterized_as_opaque')
self.assertEquals(len(pixels_rasterized_as_opaque), 1)
self.assertGreater(
pixels_rasterized_as_opaque[0].value, 0)
total_layers = results.FindAllPageSpecificValuesNamed('total_layers')
self.assertEquals(len(total_layers), 1)
self.assertGreater(total_layers[0].value, 0)
total_picture_layers = \
results.FindAllPageSpecificValuesNamed('total_picture_layers')
self.assertEquals(len(total_picture_layers), 1)
self.assertGreater(total_picture_layers[0].value, 0)
total_picture_layers_with_no_content = \
results.FindAllPageSpecificValuesNamed(
'total_picture_layers_with_no_content')
self.assertEquals(len(total_picture_layers_with_no_content), 1)
self.assertGreater(
total_picture_layers_with_no_content[0].value, 0)
total_picture_layers_off_screen = \
results.FindAllPageSpecificValuesNamed(
'total_picture_layers_off_screen')
self.assertEquals(len(total_picture_layers_off_screen), 1)
self.assertEqual(
total_picture_layers_off_screen[0].value, 0)
painter_memory_usage = results.FindAllPageSpecificValuesNamed(
'painter_memory_usage')
self.assertEquals(len(painter_memory_usage), 1)
self.assertGreater(painter_memory_usage[0].value, 0)
paint_op_memory_usage = results.FindAllPageSpecificValuesNamed(
'paint_op_memory_usage')
self.assertEquals(len(paint_op_memory_usage), 1)
self.assertGreater(paint_op_memory_usage[0].value, 0)
paint_op_count = results.FindAllPageSpecificValuesNamed(
'paint_op_count')
self.assertEquals(len(paint_op_count), 1)
self.assertGreater(paint_op_count[0].value, 0)
...@@ -2,35 +2,18 @@ ...@@ -2,35 +2,18 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import shutil
import tempfile
from telemetry import decorators from telemetry import decorators
from telemetry.testing import options_for_unittests from telemetry.testing import legacy_page_test_case
from telemetry.testing import page_test_test_case
from measurements import skpicture_printer from measurements import skpicture_printer
class SkpicturePrinterUnitTest(page_test_test_case.PageTestTestCase): class SkpicturePrinterUnitTest(legacy_page_test_case.LegacyPageTestCase):
def setUp(self):
self._skp_outdir = tempfile.mkdtemp('_skp_test')
self._options = options_for_unittests.GetRunOptions(
output_dir=self._skp_outdir)
def tearDown(self):
shutil.rmtree(self._skp_outdir)
# Picture printing is not supported on all platforms. # Picture printing is not supported on all platforms.
@decorators.Disabled('android', 'chromeos') @decorators.Disabled('android', 'chromeos')
def testSkpicturePrinter(self): def testSkpicturePrinter(self):
story_set = self.CreateStorySetFromFileInUnittestDataDir('blank.html') page_test = skpicture_printer.SkpicturePrinter(self.options.output_dir)
measurement = skpicture_printer.SkpicturePrinter(self._skp_outdir) measurements = self.RunPageTest(page_test, 'file://blank.html')
results = self.RunMeasurement( saved_picture_count = measurements['saved_picture_count']['samples']
measurement, story_set, run_options=self._options)
saved_picture_count = results.FindAllPageSpecificValuesNamed(
'saved_picture_count')
self.assertEquals(len(saved_picture_count), 1) self.assertEquals(len(saved_picture_count), 1)
self.assertGreater(saved_picture_count[0].value, 0) self.assertGreater(saved_picture_count[0], 0)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment