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