Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Side by Side Diff: scripts/slave/recipe_modules/chromium_tests/steps.py

Issue 1343873004: Add IsolatedScriptTest (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import re 5 import re
6 import string 6 import string
7 7
8 8
9 class Test(object): 9 class Test(object):
10 """ 10 """
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 def run_test_locally(self, api, suffix): 807 def run_test_locally(self, api, suffix):
808 isolate_file_path = (api.path['checkout'].join(self._android_isolate_path) 808 isolate_file_path = (api.path['checkout'].join(self._android_isolate_path)
809 if self._android_isolate_path else None) 809 if self._android_isolate_path else None)
810 return AndroidInstrumentationTest( 810 return AndroidInstrumentationTest(
811 name=self.name, 811 name=self.name,
812 compile_target=self._compile_target, 812 compile_target=self._compile_target,
813 adb_install_apk=self._apk_under_test, 813 adb_install_apk=self._apk_under_test,
814 isolate_file_path=isolate_file_path).run(api, suffix) 814 isolate_file_path=isolate_file_path).run(api, suffix)
815 815
816 816
817 class IsolatedScriptTest(Test):
818 def __init__(self, name, args=None, target_name=None, **runtest_kwargs):
819 """Constructs an instance of IsolatedScriptTest.
820
821 An IsolatedScriptTest knows how to invoke an isolate which obeys a certain
822 contract. The isolate's main target must be a wrapper script which must
823 interpret certain command line arguments as follows:
824
825 --isolated-script-test-output [FILENAME]
826
827 The wrapper script must write the simplified json output that the recipes
828 consume (similar to GTestTest and ScriptTest) into |FILENAME|.
829
830 The contract may be expanded later to support functionality like sharding
831 and retries of specific failed tests. Currently the examples of such wrapper
832 scripts live in src/testing/scripts/ in the Chromium workspace.
833
834 Args:
835 name: Displayed name of the test. May be modified by suffixes.
836 args: Arguments to be passed to the test.
837 target_name: Actual name of the test. Defaults to name.
838 runtest_kwargs: Additional keyword args forwarded to the runtest.
839 """
840 super(IsolatedScriptTest, self).__init__()
841 self._name = name
842 self._args = args or []
843 self._target_name = target_name
844 self._runtest_kwargs = runtest_kwargs
845
846 @property
847 def name(self):
848 return self._name
849
850 @property
851 def target_name(self):
852 return self._target_name or self._name
853
854 @property
855 def isolate_target(self):
856 return self.target_name
857
858 @property
859 def uses_swarming(self):
860 return True
861
862 def compile_targets(self, _):
863 return [self.target_name]
864
865 # TODO(nednguyen, kbr): figure out what to do with Android.
866 # (crbug.com/533480)
867 def run(self, api, suffix):
868 # Copy the list because run can be invoked multiple times and we modify
869 # the local copy.
870 args = self._args[:]
871
872 kwargs = {}
873 # TODO(nednguyen, kbr): define contract with the wrapper script to rerun
874 # a subset of the tests. (crbug.com/533481)
875 json_results_file = api.json.output()
876 step_test_data = lambda: api.json.test_api.output(
877 {'valid': True, 'failures': []})
878 kwargs['name'] = self._step_name(suffix)
879 kwargs['args'] = args
880 kwargs['args'].extend(
881 ['--isolated-script-test-output', json_results_file])
882 kwargs['step_test_data'] = step_test_data
883 kwargs['xvfb'] = True
884 kwargs['test_type'] = self.name
885 kwargs.update(self._runtest_kwargs)
886
887 try:
888 # TODO(nednguyen, kbr):
889 # Replace runtest usage here with a better alternative.
890 # (crbug.com/533479)
891 # Figure out whether we need to get revision and webkit_revision, and
892 # if so, where to get them from. (crbug.com/533141)
893 api.isolate.runtest(self.target_name, None, None, **kwargs)
894 finally:
895 self._test_runs[suffix] = api.step.active_result
896 if self.has_valid_results(api, suffix):
897 self._test_runs[suffix].presentation.step_text += (
898 api.test_utils.format_step_text([
899 ['failures:', self.failures(api, suffix)]
900 ]))
901
902 return self._test_runs[suffix]
903
904 def has_valid_results(self, api, suffix):
905 try:
906 # Make sure the JSON includes all necessary data.
907 self.failures(api, suffix)
908
909 return self._test_runs[suffix].json.output['valid']
910 except Exception: # pragma: no cover
911 return False
912
913 def failures(self, api, suffix):
914 return self._test_runs[suffix].json.output['failures']
915
916
917 def generate_isolated_script(api, mastername, buildername, test_spec,
918 enable_swarming=False,
919 scripts_compile_targets=None):
920 for spec in test_spec.get(buildername, {}).get(
921 'isolated_scripts', []):
922 yield IsolatedScriptTest(
923 str(spec['name']),
924 args=spec.get('args', []),
925 target_name=spec['isolate_name'])
926
927
817 class GTestTest(Test): 928 class GTestTest(Test):
818 def __init__(self, name, args=None, target_name=None, enable_swarming=False, 929 def __init__(self, name, args=None, target_name=None, enable_swarming=False,
819 swarming_shards=1, swarming_dimensions=None, swarming_tags=None, 930 swarming_shards=1, swarming_dimensions=None, swarming_tags=None,
820 swarming_extra_suffix=None, **runtest_kwargs): 931 swarming_extra_suffix=None, **runtest_kwargs):
821 super(GTestTest, self).__init__() 932 super(GTestTest, self).__init__()
822 if enable_swarming: 933 if enable_swarming:
823 self._test = SwarmingGTestTest( 934 self._test = SwarmingGTestTest(
824 name, args, target_name, swarming_shards, swarming_dimensions, 935 name, args, target_name, swarming_shards, swarming_dimensions,
825 swarming_tags, swarming_extra_suffix) 936 swarming_tags, swarming_extra_suffix)
826 else: 937 else:
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 def run(self, api, suffix): 1579 def run(self, api, suffix):
1469 api.chromium_android.coverage_report(upload=False) 1580 api.chromium_android.coverage_report(upload=False)
1470 api.chromium_android.get_changed_lines_for_revision() 1581 api.chromium_android.get_changed_lines_for_revision()
1471 api.chromium_android.incremental_coverage_report() 1582 api.chromium_android.incremental_coverage_report()
1472 1583
1473 1584
1474 GOMA_TESTS = [ 1585 GOMA_TESTS = [
1475 GTestTest('base_unittests'), 1586 GTestTest('base_unittests'),
1476 GTestTest('content_unittests'), 1587 GTestTest('content_unittests'),
1477 ] 1588 ]
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/chromium_tests/chromium_linux.py ('k') | scripts/slave/recipes/chromium_trybot.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698