Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
|
mikecase (-- gone --)
2016/06/01 17:40:28
nit 2016
rnephew (Reviews Here)
2016/06/01 20:32:05
Done.
| |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import json | |
| 6 import logging | |
| 7 import os | |
| 8 import pickle | |
| 9 | |
| 10 from pylib import constants | |
| 11 from pylib.base import test_instance | |
| 12 from pylib.constants import exit_codes | |
| 13 | |
| 14 | |
| 15 def _GetPersistedResult(test_name): | |
| 16 file_name = os.path.join(constants.PERF_OUTPUT_DIR, test_name) | |
| 17 if not os.path.exists(file_name): | |
| 18 logging.error('File not found %s', file_name) | |
| 19 return None | |
| 20 | |
| 21 with file(file_name, 'r') as f: | |
| 22 return pickle.loads(f.read()) | |
| 23 | |
| 24 | |
| 25 class PerfTestInstance(test_instance.TestInstance): | |
| 26 def __init__(self, args, _): | |
| 27 self._STR = 'Local Device Perf Test Instance: ' | |
|
jbudorick
2016/06/01 17:44:11
Nothing in here should be specific to a local devi
rnephew (Reviews Here)
2016/06/01 20:32:05
This is just left over debuggign information anywa
| |
| 28 super(PerfTestInstance, self).__init__() | |
| 29 | |
| 30 if args.single_step: | |
| 31 args.single_step = ' '.join(args.single_step_command) | |
| 32 self.steps = args.steps | |
|
jbudorick
2016/06/01 17:44:11
1) Why is so much of this public? It really should
rnephew (Reviews Here)
2016/06/01 20:32:05
Woops. I meant to do a pass through this and make
| |
| 33 self.flaky_steps = args.flaky_steps | |
| 34 self.output_json_list = args.output_json_list | |
| 35 self.print_step = args.print_step | |
| 36 self.single_step = args.single_step | |
| 37 self.no_timeout = args.no_timeout | |
| 38 self.test_filter = args.test_filter | |
| 39 self.dry_run = args.dry_run | |
| 40 self.collect_chartjson_data = args.collect_chartjson_data | |
| 41 self._output_chartjson_data = args.output_chartjson_data | |
| 42 self._get_output_dir_archive = args.get_output_dir_archive | |
| 43 self.max_battery_temp = args.max_battery_temp | |
| 44 self.min_battery_level = args.min_battery_level | |
| 45 self.known_devices_file = args.known_devices_file | |
| 46 | |
| 47 def SetUp(self): | |
| 48 pass | |
| 49 | |
| 50 def TearDown(self): | |
| 51 pass | |
| 52 | |
| 53 def OutputJsonList(self): | |
| 54 with file(self.steps, 'r') as i: | |
| 55 all_steps = json.load(i) | |
| 56 | |
| 57 step_values = [] | |
| 58 for k, v in all_steps['steps'].iteritems(): | |
| 59 data = {'test': k, 'device_affinity': v['device_affinity']} | |
| 60 | |
| 61 persisted_result = _GetPersistedResult(k) | |
| 62 if persisted_result: | |
| 63 data['start_time'] = persisted_result['start_time'] | |
| 64 data['end_time'] = persisted_result['end_time'] | |
| 65 data['total_time'] = persisted_result['total_time'] | |
| 66 data['has_archive'] = persisted_result['archive_bytes'] is not None | |
| 67 step_values.append(data) | |
| 68 | |
| 69 with file(self.output_json_list, 'w') as o: | |
| 70 o.write(json.dumps(step_values)) | |
| 71 return 0 | |
| 72 | |
|
jbudorick
2016/06/01 17:44:11
nit: only one line between member functions
rnephew (Reviews Here)
2016/06/01 20:32:05
Done.
| |
| 73 | |
| 74 def PrintTestOutput(self): | |
| 75 """Helper method to print the output of previously executed test_name. | |
| 76 | |
| 77 Test_name is passed from the command line as print_step | |
| 78 | |
| 79 Returns: | |
| 80 exit code generated by the test step. | |
| 81 """ | |
| 82 persisted_result = _GetPersistedResult(self.print_step) | |
| 83 if not persisted_result: | |
| 84 return exit_codes.INFRA | |
| 85 logging.info('*' * 80) | |
| 86 logging.info('Output from:') | |
| 87 logging.info(persisted_result['cmd']) | |
| 88 logging.info('*' * 80) | |
| 89 | |
| 90 output_formatted = '' | |
| 91 persisted_outputs = persisted_result['output'] | |
| 92 for i in xrange(len(persisted_outputs)): | |
| 93 output_formatted += '\n\nOutput from run #%d:\n\n%s' % ( | |
| 94 i, persisted_outputs[i]) | |
| 95 print output_formatted | |
| 96 | |
| 97 if self._output_chartjson_data: | |
| 98 with file(self._output_chartjson_data, 'w') as f: | |
| 99 f.write(persisted_result['chartjson']) | |
| 100 | |
| 101 if self._get_output_dir_archive: | |
| 102 if persisted_result['archive_bytes'] is not None: | |
| 103 with file(self._get_output_dir_archive, 'wb') as f: | |
| 104 f.write(persisted_result['archive_bytes']) | |
| 105 else: | |
| 106 logging.error('The output dir was not archived.') | |
| 107 | |
| 108 return persisted_result['exit_code'] | |
| 109 | |
| 110 #override | |
| 111 def TestType(self): | |
| 112 return 'Perf' | |
| 113 | |
| OLD | NEW |