diff --git a/ancert b/ancert index 1158e905e89e16f3173702f4ad6862f18915d211..8eff2c1262bdb0834a89610ef2003f245bf12e1c 100755 --- a/ancert +++ b/ancert @@ -96,7 +96,7 @@ def main(args): print(e) return 1 else: - save_device_info(selected_components, dstree, logdir) + save_device_info(selected_components, dstree, args, logdir) if args.list_hardware: print('Hardware Information:') @@ -167,11 +167,12 @@ def main(args): else: ret = 'FAIL' RESULT = False + logging.info('test case %s %sed on %s' % (t.name, ret, t.test.controller.name.strip())) print('{:<12}{:22}{:<12}{:<52}'.format(t.test.controller.component.category, \ t.name, ret, t.test.controller.name.strip())) print('') - if RESULT: + if RESULT and save_test_result(selected_components, args, logdir, RESULT): return 0 return 1 diff --git a/lib/device.py b/lib/device.py index 8bf6e258ab9d9e8616aae8887bd99fb31f6e27d3..6761077cef29b02ffb54daa93e34eededf02fc39 100644 --- a/lib/device.py +++ b/lib/device.py @@ -152,6 +152,7 @@ class Controller(): self.available_devices = list() self.bus_device = self.syspath.rsplit('.', 1)[0] self.bdf = self.syspath.rsplit('/')[-1] + self.device_inst.properties.update({'PCI_BDF': self.bdf}) self.is_raid = is_sub_class_code(['000104'], self.classcode) self.is_boot_ctr = False if not self.device_inst.name: diff --git a/lib/utils.py b/lib/utils.py index a215a1c04d6745c960fe1fbdb0460ad5f325f1d4..7b9a1448ac198318dd3e38fb301c1d42419a997d 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -442,7 +442,7 @@ def dump_dmidecode(cmd, ty, spt): return info -def save_device_info(comp_insts, dstree, logdir): +def save_device_info(comp_insts, dstree, args, logdir): def dump_os_relase(): info = {} cmd = 'cat /etc/os-release' @@ -483,7 +483,6 @@ def save_device_info(comp_insts, dstree, logdir): driver_info.update(info) return driver_info - info_file = os.path.join(logdir, ALL_DEVICE_INFO) all_info = {} for inst in comp_insts: for key, val in inst.dump_device_info().items(): @@ -535,10 +534,46 @@ def save_device_info(comp_insts, dstree, logdir): else: logging.warning('failed to get boot disk info!') + all_info['test_info'] = {} + all_info['test_info']['option'] = vars(args) + + info_file = os.path.join(logdir, ALL_DEVICE_INFO) with open(info_file, 'w') as fd: fd.write(json.dumps(all_info, indent=4)) +def save_test_result(comp_insts, args, logdir, result): + info, detail = {}, {} + info['test_info'] = {} + info['test_info']['all_test_result'] = 'PASS' if result else 'FAIL' + info['test_info']['detail'] = detail + logging.info('current test info: %s' % info) + for cpt in comp_insts: + if cpt.name not in detail: + detail[cpt.name] = [] + for gname, tasks in cpt.next_tasks(): + for t in tasks: + t_info = {'case': t.name, + 'result': 'PASS' if t.result() == 0 else 'FAIL', + 'driver': t.test.controller.driver, + 'ctr_name': t.test.controller.name.strip(), + 'ctr_bdf': t.test.controller.bdf, + 'ctr_syspath': t.test.controller.syspath} + detail[cpt.name].append(t_info) + + all_info = {} + info_file = os.path.join(logdir, ALL_DEVICE_INFO) + with open(info_file, 'r') as fd: + all_info = json.loads(fd.read()) + if not all_info or 'test_info' not in all_info: + logging.error('failed to load info file %s!' % info_file) + print('Failed to save log to %s' % info_file) + return False + all_info['test_info'].update(info) + with open(info_file, 'w') as fd: + fd.write(json.dumps(all_info, indent=4)) + return True + def get_int_value_from_file(filepath): cmd = 'cat %s' % filepath _, ret = run_local_cmd(cmd, exit_msg='Failed to get %s value' % filepath, shell=True)