From 0ad3dd46542b6e3a78e4019b58d05add961d4abe Mon Sep 17 00:00:00 2001 From: dongshen Date: Sat, 5 Sep 2020 19:03:47 -0700 Subject: [PATCH] acrn-config: use ordered dictionary to guarantee dict order For python versions prior to 3.7, dict order is not guaranteed. Use ordered dict to ensure consistent ordering for the same input, otherwise, the generated config files may change every time the config tool runs Fix some error messages in code/comment Tracked-On: #5229 Signed-off-by: dongshen --- misc/acrn-config/board_config/board_cfg_gen.py | 2 +- misc/acrn-config/library/board_cfg_lib.py | 11 ++++++----- misc/acrn-config/library/common.py | 2 +- misc/acrn-config/library/launch_cfg_lib.py | 16 ++++++++-------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/misc/acrn-config/board_config/board_cfg_gen.py b/misc/acrn-config/board_config/board_cfg_gen.py index 3c2376664..56337c177 100755 --- a/misc/acrn-config/board_config/board_cfg_gen.py +++ b/misc/acrn-config/board_config/board_cfg_gen.py @@ -63,7 +63,7 @@ def main(args): # check if this is the scenario config which matched board info (err_dic, status) = common.is_config_file_match() if not status: - err_dic['board config: Not match'] = "The board xml and scenario xml should be matched" + err_dic['board config'] = "The board xml file does not match scenario xml file!" return err_dic output = '' diff --git a/misc/acrn-config/library/board_cfg_lib.py b/misc/acrn-config/library/board_cfg_lib.py index a6006870f..2c997fd5a 100644 --- a/misc/acrn-config/library/board_cfg_lib.py +++ b/misc/acrn-config/library/board_cfg_lib.py @@ -365,12 +365,12 @@ class Bar_Attr: class Pci_Dev_Bar_Desc: def __init__(self): - self.pci_dev_dic = {} - self.pci_bar_dic = {} - self.shm_bar_dic = {} + self.pci_dev_dic = collections.OrderedDict() + self.pci_bar_dic = collections.OrderedDict() + self.shm_bar_dic = collections.OrderedDict() PCI_DEV_BAR_DESC = Pci_Dev_Bar_Desc() -SUB_NAME_COUNT = {} +SUB_NAME_COUNT = collections.OrderedDict() def get_value_after_str(line, key): @@ -471,7 +471,8 @@ def parser_pci(): tmp_bar_dic = {} # output all the pci device list to pci_device.h - SUB_NAME_COUNT = collections.Counter(cal_sub_pci_name) + for item in cal_sub_pci_name: + SUB_NAME_COUNT[item] = SUB_NAME_COUNT.get(item, 0) + 1 if tmp_bar_dic: PCI_DEV_BAR_DESC.pci_bar_dic[cur_bdf] = tmp_bar_dic diff --git a/misc/acrn-config/library/common.py b/misc/acrn-config/library/common.py index 788a89b92..07118771b 100644 --- a/misc/acrn-config/library/common.py +++ b/misc/acrn-config/library/common.py @@ -126,7 +126,7 @@ def get_param(args): return (err_dic, params) if not os.path.exists(par_v): - err_dic['wrong usage'] = "{} is not exist!".format(par_v) + err_dic['wrong usage'] = "{} does not exist!".format(par_v) return (err_dic, params) return (err_dic, params) diff --git a/misc/acrn-config/library/launch_cfg_lib.py b/misc/acrn-config/library/launch_cfg_lib.py index 8064593eb..0aba8ab75 100644 --- a/misc/acrn-config/library/launch_cfg_lib.py +++ b/misc/acrn-config/library/launch_cfg_lib.py @@ -84,7 +84,7 @@ def get_param(args): if arg_str not in args: usage(args[0]) - err_dic['common error: get wrong parameter'] = "wrong usage" + err_dic['common error: wrong parameter'] = "wrong usage" return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder) args_list = args[1:] @@ -102,24 +102,24 @@ def get_param(args): if arg_k == '--uosid': vm_th = arg_v if not vm_th.isnumeric(): - err_dic['common error: get wrong parameter'] = "--uosid should be a number" + err_dic['common error: wrong parameter'] = "--uosid should be a number" return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder) if not board_info_file or not scenario_info_file or not launch_info_file: usage(args[0]) - err_dic['common error: get wrong parameter'] = "wrong usage" + err_dic['common error: wrong parameter'] = "wrong usage" return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder) if not os.path.exists(board_info_file): - err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file) + err_dic['common error: wrong parameter'] = "{} does not exist!".format(board_info_file) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder) if not os.path.exists(scenario_info_file): - err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file) + err_dic['common error: wrong parameter'] = "{} does not exist!".format(scenario_info_file) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder) if not os.path.exists(launch_info_file): - err_dic['common error: get wrong parameter'] = "{} is not exist!".format(launch_info_file) + err_dic['common error: wrong parameter'] = "{} does not exist!".format(launch_info_file) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder) return (err_dic, board_info_file, scenario_info_file, launch_info_file, int(vm_th), output_folder) @@ -190,13 +190,13 @@ def is_config_file_match(): (err_dic, scenario_for_board) = common.get_xml_attrib(common.SCENARIO_INFO_FILE, "board") (err_dic, board_name) = common.get_xml_attrib(common.BOARD_INFO_FILE, "board") if scenario_for_board != board_name: - err_dic['scenario config: Not match'] = "The board xml and scenario xml should be matched!" + err_dic['scenario config'] = "The board xml file does not match scenario xml file!" match = False # check if the board config match launch config (err_dic, launch_for_board) = common.get_xml_attrib(common.LAUNCH_INFO_FILE, "board") if launch_for_board != board_name: - err_dic['launch config: Not match'] = "The board xml and launch xml should be matched!" + err_dic['launch config'] = "The board xml file does not match scenario xml file!" match = False return (err_dic, match)