OLD | NEW |
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 logging | |
6 import datetime | 5 import datetime |
7 import functools | 6 import functools |
8 | 7 |
9 from recipe_engine import recipe_api | 8 from recipe_engine import recipe_api |
10 | 9 |
11 | 10 |
12 # Minimally supported version of swarming.py script (reported by --version). | 11 # Minimally supported version of swarming.py script (reported by --version). |
13 MINIMAL_SWARMING_VERSION = (0, 8, 6) | 12 MINIMAL_SWARMING_VERSION = (0, 8, 6) |
14 | 13 |
15 | 14 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 extra_args.append( | 400 extra_args.append( |
402 '--test-launcher-summary-output=${ISOLATED_OUTDIR}/output.json') | 401 '--test-launcher-summary-output=${ISOLATED_OUTDIR}/output.json') |
403 | 402 |
404 # Make a task, configure it to be collected through shim script. | 403 # Make a task, configure it to be collected through shim script. |
405 task = self.task(title, isolated_hash, extra_args=extra_args, | 404 task = self.task(title, isolated_hash, extra_args=extra_args, |
406 cipd_packages=cipd_packages, **kwargs) | 405 cipd_packages=cipd_packages, **kwargs) |
407 task.collect_step = lambda *args, **kw: ( | 406 task.collect_step = lambda *args, **kw: ( |
408 self._gtest_collect_step(test_launcher_summary_output, *args, **kw)) | 407 self._gtest_collect_step(test_launcher_summary_output, *args, **kw)) |
409 return task | 408 return task |
410 | 409 |
411 def _check_and_set_output_flag(self, extra_args, flag, output_file_name): | |
412 extra_args = list(extra_args or []) | |
413 # Ensure flag is not already passed. We are going to overwrite it. | |
414 flag_value = '--%s=' % flag | |
415 bad_args = any(x.startswith(flag_value) for x in extra_args) | |
416 if bad_args: # pragma: no cover | |
417 raise ValueError('--%s should not be used' % flag) | |
418 | |
419 # Append it. | |
420 output_arg = '--%s=${ISOLATED_OUTDIR}/%s' % (flag, output_file_name) | |
421 extra_args.append(output_arg) | |
422 return extra_args | |
423 | |
424 def isolated_script_task(self, title, isolated_hash, extra_args=None, | 410 def isolated_script_task(self, title, isolated_hash, extra_args=None, |
425 idempotent=False, **kwargs): | 411 idempotent=False, **kwargs): |
426 """Returns a new SwarmingTask to run an isolated script test on Swarming. | 412 """Returns a new SwarmingTask to run an isolated script test on Swarming. |
427 | 413 |
428 Swarming recipe module knows how collect JSON file with test execution | 414 Swarming recipe module knows how collect JSON file with test execution |
429 summary produced by isolated script tests launcher. Since isolated script | 415 summary produced by isolated script tests launcher. Since isolated script |
430 tests do not support sharding, no merging of the results is performed. | 416 tests do not support sharding, no merging of the results is performed. |
431 Parsed JSON summary is returned from the collect step. | 417 Parsed JSON summary is returned from the collect step. |
432 | 418 |
433 For meaning of the rest of the arguments see 'task' method. | 419 For meaning of the rest of the arguments see 'task' method. |
434 """ | 420 """ |
| 421 extra_args = list(extra_args or []) |
435 | 422 |
436 # Ensure output flags are not already passed. We are going | 423 # Ensure --isolated-script-test-output is not already passed. We are going |
437 # to overwrite them. | 424 # to overwrite it. |
438 # output.json name is expected by collect_gtest_task.py. | 425 bad_args = any( |
439 extra_args = self._check_and_set_output_flag( | 426 x.startswith('--isolated-script-test-output=') for x in extra_args) |
440 extra_args, 'isolated-script-test-output', 'output.json') | 427 if bad_args: # pragma: no cover |
441 # chartjson-output.json name is expected by benchmarks generating chartjson | 428 raise ValueError('--isolated-script-test-output should not be used.') |
442 # output | 429 |
443 extra_args = self._check_and_set_output_flag( | 430 # Append it. output.json name is expected by collect_gtest_task.py. |
444 extra_args, | 431 extra_args.append( |
445 'isolated-script-test-chartjson-output', | 432 '--isolated-script-test-output=${ISOLATED_OUTDIR}/output.json') |
446 'chartjson-output.json') | |
447 | 433 |
448 task = self.task(title, isolated_hash, extra_args=extra_args, | 434 task = self.task(title, isolated_hash, extra_args=extra_args, |
449 idempotent=idempotent, **kwargs) | 435 idempotent=idempotent, **kwargs) |
450 task.collect_step = self._isolated_script_collect_step | 436 task.collect_step = self._isolated_script_collect_step |
451 return task | 437 return task |
452 | 438 |
453 def check_client_version(self, step_test_data=None): | 439 def check_client_version(self, step_test_data=None): |
454 """Yields steps to verify compatibility with swarming_client version.""" | 440 """Yields steps to verify compatibility with swarming_client version.""" |
455 return self.m.swarming_client.ensure_script_version( | 441 return self.m.swarming_client.ensure_script_version( |
456 'swarming.py', MINIMAL_SWARMING_VERSION, step_test_data) | 442 'swarming.py', MINIMAL_SWARMING_VERSION, step_test_data) |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 # Show any remaining isolated outputs (such as logcats). | 710 # Show any remaining isolated outputs (such as logcats). |
725 # Note that collect_gtest_task.py uses the default summary.json, which | 711 # Note that collect_gtest_task.py uses the default summary.json, which |
726 # only has 'outputs_ref' instead of the deprecated 'isolated_out'. | 712 # only has 'outputs_ref' instead of the deprecated 'isolated_out'. |
727 for index, shard in enumerate(swarming_summary.get('shards', [])): | 713 for index, shard in enumerate(swarming_summary.get('shards', [])): |
728 outputs_ref = shard.get('outputs_ref') | 714 outputs_ref = shard.get('outputs_ref') |
729 if outputs_ref: | 715 if outputs_ref: |
730 link_name = 'shard #%d isolated out' % index | 716 link_name = 'shard #%d isolated out' % index |
731 p.links[link_name] = outputs_ref['view_url'] | 717 p.links[link_name] = outputs_ref['view_url'] |
732 | 718 |
733 | 719 |
734 def _merge_isolated_script_chartjson_ouput_shards(self, task, step_result): | |
735 # Taken from third_party/catapult/telemetry/telemetry/internal/results/ | |
736 # chart_json_output_formatter.py, the json entries are as follows: | |
737 # result_dict = { | |
738 # 'format_version': '0.1', | |
739 # 'next_version': '0.2', | |
740 # 'benchmark_name': benchmark_metadata.name, | |
741 # 'benchmark_description': benchmark_metadata.description, | |
742 # 'trace_rerun_options': benchmark_metadata.rerun_options, | |
743 # 'benchmark_metadata': benchmark_metadata.AsDict(), | |
744 # 'charts': charts, | |
745 # } | |
746 # | |
747 # Therefore, all entries should be the same and we should only need to merge | |
748 # the chart from each shard. | |
749 merged_results = {} | |
750 seen_first_shard = False | |
751 for i in xrange(task.shards): | |
752 path = self.m.path.join(str(i), 'chartjson-output.json') | |
753 if path not in step_result.raw_io.output_dir: | |
754 # chartjson results were not written for this shard, not an error, | |
755 # just return | |
756 continue | |
757 results_raw = step_result.raw_io.output_dir[path] | |
758 try: | |
759 chartjson_results_json = self.m.json.loads(results_raw) | |
760 except Exception as e: | |
761 raise Exception('error decoding JSON results from shard #%d' % i) | |
762 if not seen_first_shard: | |
763 merged_results = chartjson_results_json | |
764 seen_first_shard = True | |
765 continue | |
766 for key in chartjson_results_json: | |
767 if key == 'charts': | |
768 # Append each additional chart to our merged results | |
769 for add_key in chartjson_results_json[key]: | |
770 merged_results[key][add_key] = chartjson_results_json[key][add_key] | |
771 return merged_results | |
772 | |
773 | |
774 def _merge_isolated_script_shards(self, task, step_result): | 720 def _merge_isolated_script_shards(self, task, step_result): |
775 # This code is unfortunately specialized to the "simplified" | 721 # This code is unfortunately specialized to the "simplified" |
776 # JSON format that used to be the standard for recipes. The | 722 # JSON format that used to be the standard for recipes. The |
777 # isolated scripts should be changed to use the now-standard | 723 # isolated scripts should be changed to use the now-standard |
778 # Chromium JSON test results format: | 724 # Chromium JSON test results format: |
779 # https://www.chromium.org/developers/the-json-test-results-format | 725 # https://www.chromium.org/developers/the-json-test-results-format |
780 # . Note that gtests, above, don't seem to conform to this | 726 # . Note that gtests, above, don't seem to conform to this |
781 # format yet, so it didn't seem like a good prerequisite to | 727 # format yet, so it didn't seem like a good prerequisite to |
782 # switch the isolated tests over when adding sharding support. | 728 # switch the isolated tests over when adding sharding support. |
783 # | 729 # |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 # in recipe runs.) | 792 # in recipe runs.) |
847 links = step_result.presentation.links | 793 links = step_result.presentation.links |
848 for index in xrange(task.shards): | 794 for index in xrange(task.shards): |
849 url = task.get_shard_view_url(index) | 795 url = task.get_shard_view_url(index) |
850 if url: | 796 if url: |
851 links['shard #%d' % index] = url | 797 links['shard #%d' % index] = url |
852 | 798 |
853 step_result.isolated_script_results = \ | 799 step_result.isolated_script_results = \ |
854 self._merge_isolated_script_shards(task, step_result) | 800 self._merge_isolated_script_shards(task, step_result) |
855 | 801 |
856 # Obtain chartjson results if present | |
857 step_result.isolated_script_chartjson_results = \ | |
858 self._merge_isolated_script_chartjson_ouput_shards(task, step_result) | |
859 | |
860 self._display_pending(summary, step_result.presentation) | 802 self._display_pending(summary, step_result.presentation) |
861 except Exception as e: | 803 except Exception as e: |
862 self.m.step.active_result.presentation.logs['no_results_exc'] = [str(e)] | 804 self.m.step.active_result.presentation.logs['no_results_exc'] = [str(e)] |
863 self.m.step.active_result.isolated_script_results = None | 805 self.m.step.active_result.isolated_script_results = None |
864 | 806 |
865 def _get_step_name(self, prefix, task): | 807 def _get_step_name(self, prefix, task): |
866 """SwarmingTask -> name of a step of a waterfall. | 808 """SwarmingTask -> name of a step of a waterfall. |
867 | 809 |
868 Will take a task title (+ step name prefix) and append OS dimension to it. | 810 Will take a task title (+ step name prefix) and append OS dimension to it. |
869 | 811 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 | 989 |
1048 def get_shard_view_url(self, index): | 990 def get_shard_view_url(self, index): |
1049 """Returns URL of HTML page with shard details or None if not available. | 991 """Returns URL of HTML page with shard details or None if not available. |
1050 | 992 |
1051 Works only after the task has been successfully triggered. | 993 Works only after the task has been successfully triggered. |
1052 """ | 994 """ |
1053 if self._trigger_output and self._trigger_output.get('tasks'): | 995 if self._trigger_output and self._trigger_output.get('tasks'): |
1054 for shard_dict in self._trigger_output['tasks'].itervalues(): | 996 for shard_dict in self._trigger_output['tasks'].itervalues(): |
1055 if shard_dict['shard_index'] == index: | 997 if shard_dict['shard_index'] == index: |
1056 return shard_dict['view_url'] | 998 return shard_dict['view_url'] |
OLD | NEW |