| Index: content/test/gpu/unittest_data/integration_tests.py
|
| diff --git a/content/test/gpu/gpu_tests/gpu_integration_test_unittest.py b/content/test/gpu/unittest_data/integration_tests.py
|
| similarity index 59%
|
| copy from content/test/gpu/gpu_tests/gpu_integration_test_unittest.py
|
| copy to content/test/gpu/unittest_data/integration_tests.py
|
| index 49462559374651b17e4cfad87a852e783c95c6a5..bc0589b4e3349e09010c966e731ae4c4b1459e9b 100644
|
| --- a/content/test/gpu/gpu_tests/gpu_integration_test_unittest.py
|
| +++ b/content/test/gpu/unittest_data/integration_tests.py
|
| @@ -2,36 +2,58 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +
|
| import json
|
| import logging
|
| import mock
|
| import os
|
| +import sys
|
| import tempfile
|
| import unittest
|
|
|
| from telemetry.testing import fakes
|
| from telemetry.testing import browser_test_runner
|
| +from telemetry.testing import browser_test_context
|
|
|
| import gpu_project_config
|
|
|
| from gpu_tests import gpu_integration_test
|
| from gpu_tests import gpu_test_expectations
|
|
|
| -class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest):
|
| - # Must be class-scoped since instances aren't reused across runs.
|
| - _num_flaky_runs_to_fail = 2
|
|
|
| - _num_browser_starts = 0
|
| +class _BaseSampleIntegrationTest(gpu_integration_test.GpuIntegrationTest):
|
| + _test_state = {}
|
| + @classmethod
|
| + def AddCommandlineArgs(cls, parser):
|
| + parser.add_option('--test-state-json-path',
|
| + help=('Where to dump the test state json (this is used by '
|
| + 'gpu_integration_test_unittest)'))
|
| +
|
| + @classmethod
|
| + def TearDownProcess(cls):
|
| + actual_finder_options = browser_test_context.GetCopy().finder_options
|
| + test_state_json_path = actual_finder_options.test_state_json_path
|
| + with open(test_state_json_path, 'w') as f:
|
| + json.dump(cls._test_state, f)
|
| + super(_BaseSampleIntegrationTest, cls).TearDownProcess()
|
| +
|
| +
|
| +class SimpleTest(_BaseSampleIntegrationTest):
|
| + _test_state = {
|
| + 'num_flaky_runs_to_fail': 2,
|
| + 'num_browser_starts': 0
|
| + }
|
| +
|
|
|
| @classmethod
|
| def Name(cls):
|
| return 'simple_integration_unittest'
|
|
|
| def setUp(self):
|
| - super(SimpleIntegrationUnittest, self).setUp()
|
| + super(SimpleTest, self).setUp()
|
|
|
| @classmethod
|
| - def setUpClass(cls):
|
| + def SetUpProcess(cls):
|
| finder_options = fakes.CreateBrowserFinderOptions()
|
| finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
|
| finder_options.output_formats = ['none']
|
| @@ -63,29 +85,30 @@ class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest):
|
|
|
| @classmethod
|
| def StartBrowser(cls):
|
| - super(SimpleIntegrationUnittest, cls).StartBrowser()
|
| - cls._num_browser_starts += 1
|
| + super(SimpleTest, cls).StartBrowser()
|
| + cls._test_state['num_browser_starts'] += 1
|
|
|
| def RunActualGpuTest(self, file_path, *args):
|
| logging.warn('Running ' + file_path)
|
| if file_path == 'failure.html':
|
| self.fail('Expected failure')
|
| elif file_path == 'flaky.html':
|
| - if self.__class__._num_flaky_runs_to_fail > 0:
|
| - self.__class__._num_flaky_runs_to_fail -= 1
|
| + if self._test_state['num_flaky_runs_to_fail'] > 0:
|
| + self._test_state['num_flaky_runs_to_fail'] -= 1
|
| self.fail('Expected flaky failure')
|
| elif file_path == 'error.html':
|
| raise Exception('Expected exception')
|
|
|
|
|
| -class BrowserStartFailureIntegrationUnittest(
|
| - gpu_integration_test.GpuIntegrationTest):
|
| +class BrowserStartFailureTest(_BaseSampleIntegrationTest):
|
|
|
| - _num_browser_crashes = 0
|
| - _num_browser_starts = 0
|
| + _test_state = {
|
| + 'num_browser_crashes': 0,
|
| + 'num_browser_starts': 0
|
| + }
|
|
|
| @classmethod
|
| - def setUpClass(cls):
|
| + def SetUpProcess(cls):
|
| cls._fake_browser_options = \
|
| fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart)
|
| cls._fake_browser_options.browser_options.platform = \
|
| @@ -107,9 +130,9 @@ class BrowserStartFailureIntegrationUnittest(
|
|
|
| @classmethod
|
| def CrashOnStart(cls):
|
| - cls._num_browser_starts += 1
|
| - if cls._num_browser_crashes < 2:
|
| - cls._num_browser_crashes += 1
|
| + cls._test_state['num_browser_starts'] += 1
|
| + if cls._test_state['num_browser_crashes'] < 2:
|
| + cls._test_state['num_browser_crashes'] += 1
|
| raise
|
|
|
| @classmethod
|
| @@ -128,14 +151,15 @@ class BrowserStartFailureIntegrationUnittest(
|
| pass
|
|
|
|
|
| -class BrowserCrashAfterStartIntegrationUnittest(
|
| - gpu_integration_test.GpuIntegrationTest):
|
| +class BrowserCrashAfterStartTest(_BaseSampleIntegrationTest):
|
|
|
| - _num_browser_crashes = 0
|
| - _num_browser_starts = 0
|
| + _test_state = {
|
| + 'num_browser_crashes': 0,
|
| + 'num_browser_starts': 0,
|
| + }
|
|
|
| @classmethod
|
| - def setUpClass(cls):
|
| + def SetUpProcess(cls):
|
| cls._fake_browser_options = fakes.CreateBrowserFinderOptions(
|
| execute_after_browser_creation=cls.CrashAfterStart)
|
| cls._fake_browser_options.browser_options.platform = \
|
| @@ -157,9 +181,9 @@ class BrowserCrashAfterStartIntegrationUnittest(
|
|
|
| @classmethod
|
| def CrashAfterStart(cls, browser):
|
| - cls._num_browser_starts += 1
|
| - if cls._num_browser_crashes < 2:
|
| - cls._num_browser_crashes += 1
|
| + cls._test_state['num_browser_starts'] += 1
|
| + if cls._test_state['num_browser_crashes'] < 2:
|
| + cls._test_state['num_browser_crashes'] += 1
|
| # This simulates the first tab's renderer process crashing upon
|
| # startup. The try/catch forces the GpuIntegrationTest's first
|
| # fetch of this tab to fail. crbug.com/682819
|
| @@ -184,59 +208,6 @@ class BrowserCrashAfterStartIntegrationUnittest(
|
| pass
|
|
|
|
|
| -class GpuIntegrationTestUnittest(unittest.TestCase):
|
| - @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
|
| - def testSimpleIntegrationUnittest(self, mockInitDependencyManager):
|
| - self._RunIntegrationTest(
|
| - 'simple_integration_unittest', [
|
| - 'unexpected_error',
|
| - 'unexpected_failure'
|
| - ], [
|
| - 'expected_failure',
|
| - 'expected_flaky',
|
| - ])
|
| - # It might be nice to be more precise about the order of operations
|
| - # with these browser restarts, but this is at least a start.
|
| - self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6)
|
| -
|
| - @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
|
| - def testIntegrationUnittestWithBrowserFailure(
|
| - self, mockInitDependencyManager):
|
| - self._RunIntegrationTest(
|
| - 'browser_start_failure_integration_unittest', [], ['restart'])
|
| - self.assertEquals( \
|
| - BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2)
|
| - self.assertEquals( \
|
| - BrowserStartFailureIntegrationUnittest._num_browser_starts, 3)
|
| -
|
| - @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
|
| - def testIntegrationUnittestWithBrowserCrashUponStart(
|
| - self, mockInitDependencyManager):
|
| - self._RunIntegrationTest(
|
| - 'browser_crash_after_start_integration_unittest', [], ['restart'])
|
| - self.assertEquals( \
|
| - BrowserCrashAfterStartIntegrationUnittest._num_browser_crashes, 2)
|
| - self.assertEquals( \
|
| - BrowserCrashAfterStartIntegrationUnittest._num_browser_starts, 3)
|
| -
|
| - def _RunIntegrationTest(self, test_name, failures, successes):
|
| - options = browser_test_runner.TestRunOptions()
|
| - # Suppress printing out information for passing tests.
|
| - options.verbosity = 0
|
| - config = gpu_project_config.CONFIG
|
| - temp_file = tempfile.NamedTemporaryFile(delete=False)
|
| - temp_file.close()
|
| - temp_file_name = temp_file.name
|
| - try:
|
| - browser_test_runner.Run(
|
| - config, options,
|
| - [test_name,
|
| - '--write-abbreviated-json-results-to=%s' % temp_file_name])
|
| - with open(temp_file_name) as f:
|
| - test_result = json.load(f)
|
| - self.assertEquals(test_result['failures'], failures)
|
| - self.assertEquals(test_result['successes'], successes)
|
| - self.assertEquals(test_result['valid'], True)
|
| -
|
| - finally:
|
| - os.remove(temp_file_name)
|
| +def load_tests(loader, tests, pattern):
|
| + del loader, tests, pattern # Unused.
|
| + return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__])
|
|
|