acrn-config: generate a scenario patch and apply to acrn-hypervisor

1.the script will parse the the board information which already
generated, $(scenario).xml modified by user, generate scenario
vm configuration and apply to the acrn-hypervisor source code base.

2.parse cpu/memory/ttys/rootfs information from native os and store it to
the source code

3.implemnt scenario_config and it's usage

usage: scenario_cfg_gen.py --board <board_info_file> -scenario <scenario_info_file>
board_info_file :  file name of the board info
scenario_info_file :  file name of the scenario info

sample:
	$ python3 scenario_cfg_gen.py --board ../board-xmls/apl-mrb.xml
--scenario ../config-xmls/scenarios/sdc.xml

Also improvement board config generate usage:
sample:
	$ python3 board_cfg_gen.py --board ../board-xmls/apl-mrb.xml
--scenario ../config-xmls/scenarios/sdc.xml

V1-V2:
    1). parse board_setting.xml was removed as these configuration will be
stitch into scenario configuration
    2). parse console for different formats
    3). parse epc sections
    4). add logical partition rootfs
    5). support to parse clos, while webui set to None type
    6). support to parse bootargs, while webui set to nul
    7). convert '-' to '_' for pci sub class name while generating source file

Tracked-On: #3602
Signed-off-by: Wei Liu <weix.w.liu@intel.com>
Acked-by: Terry Zou <terry.zou@intel.com>
This commit is contained in:
Wei Liu
2019-09-05 13:31:11 +08:00
committed by wenlingz
parent b73f97aaba
commit 28d1b909e6
21 changed files with 3909 additions and 276 deletions

View File

@@ -0,0 +1,422 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys
import common
SOURCE_ROOT_DIR = common.SOURCE_PATH
BOARD_NAME = ''
BOARD_INFO_FILE = "board_info.txt"
SCENARIO_INFO_FILE = ""
BIOS_INFO = ['BIOS Information', 'Vendor:', 'Version:', 'Release Date:', 'BIOS Revision:']
BASE_BOARD = ['Base Board Information', 'Manufacturer:', 'Product Name:', 'Version:']
TTY_CONSOLE = {
'ttyS0':'0x3F8',
'ttyS1':'0x2F8',
'ttyS2':'0x3E8',
'ttyS3':'0x2E8',
}
NATIVE_CONSOLE_DIC = {}
VALID_LEGACY_IRQ = []
VM_COUNT = 0
ERR_LIST = {}
HEADER_LICENSE = common.open_license() + "\n"
def prepare():
""" check environment """
return common.check_env()
def print_yel(msg, warn=False):
"""
Print the message with color of yellow
:param msg: the stings which will be output to STDOUT
:param warn: the condition if needs to be output the color of yellow with 'Warning'
"""
common.print_if_yel(msg, warn)
def print_red(msg, err=False):
"""
Print the message with color of red
:param msg: the stings which will be output to STDOUT
:param err: the condition if needs to be output the color of red with 'Error'
"""
common.print_if_red(msg, err)
def get_board_name():
"""
Get board name from board.xml at fist line
:param board_info: it is a file what contains board information for script to read from
"""
(err_dic, board) = common.get_xml_attrib(BOARD_INFO_FILE, "board")
return (err_dic, board)
def get_scenario_name():
"""
Get scenario name from scenario.xml at fist line
:param scenario_info: it is a file what contains board information for script to read from
"""
(err_dic, board) = common.get_xml_attrib(SCENARIO_INFO_FILE, "scenario")
return (err_dic, board)
def is_config_file_match():
(err_dic, scenario_for_board) = common.get_xml_attrib(SCENARIO_INFO_FILE, "board")
(err_dic, board_name) = common.get_xml_attrib(BOARD_INFO_FILE, "board")
if scenario_for_board == board_name:
return (err_dic, True)
else:
return (err_dic, False)
def usage(file_name):
""" This is usage for how to use this tool """
common.usage(file_name)
def get_param(args):
"""
Get the script parameters from command line
:param args: this the command line of string for the script without script name
"""
return common.get_param(args)
def get_info(board_info, msg_s, msg_e):
"""
Get information which specify by argument
:param board_info: it is a file what contains information for script to read from
:param msg_s: it is a pattern of key stings what start to match from board information
:param msg_e: it is a pattern of key stings what end to match from board information
"""
info_lines = common.get_board_info(board_info, msg_s, msg_e)
return info_lines
def handle_bios_info(config):
"""
Handle bios information
:param config: it is a file pointer of bios information for writing to
"""
bios_lines = get_info(BOARD_INFO_FILE, "<BIOS_INFO>", "</BIOS_INFO>")
board_lines = get_info(BOARD_INFO_FILE, "<BASE_BOARD_INFO>", "</BASE_BOARD_INFO>")
print("/*", file=config)
if not bios_lines or not board_lines:
print(" * DMI info is not found", file=config)
else:
i_cnt = 0
bios_board = BIOS_INFO + BASE_BOARD
# remove the same value and keep origin sort
bios_board_info = list(set(bios_board))
bios_board_info.sort(key=bios_board.index)
bios_board_lines = bios_lines + board_lines
bios_info_len = len(bios_lines)
for line in bios_board_lines:
if i_cnt == bios_info_len:
print(" *", file=config)
i_cnt += 1
for misc_info in bios_board_info:
if misc_info == " ".join(line.split()[0:1]) or misc_info == \
" ".join(line.split()[0:2]) or misc_info == " ".join(line.split()[0:3]):
print(" * {0}".format(line.strip()), file=config)
print(" */", file=config)
def get_tree_tag(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item
"""
return common.get_tree_tag_val(config_file, tag_str)
def get_sub_tree_tag(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item
"""
return common.get_branch_tag_val(config_file, tag_str)
def get_sub_leaf_tag(config_file, branch_tag, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param branch_tag: it is key of patter to config file branch tag item
:param tag_str: it is key of pattern to config file leaf tag item
:return: value of tag_str item
"""
return common.get_leaf_tag_val(config_file, branch_tag, tag_str)
def gen_patch(srcs_list, board_name):
"""
Generate patch and apply to local source code
:param srcs_list: it is a list what contains source files
:param board_name: board name
"""
err_dic = common.add_to_patch(srcs_list, board_name)
return err_dic
def is_hpa_size(hpa_size_list):
"""
This is identify if the host physical size list is correct format
:param hpa_size_list: host physical size list
:return: True if good format
"""
ret = common.check_hpa_size(hpa_size_list)
return ret
def get_rootfs(config_file):
"""
This will get rootfs partition from board information
:param config_file: it is a file which contain board information
:return: rootfs partition list
"""
rootfs_lines = get_info(config_file, "<ROOT_DEVICE_INFO>", "</ROOT_DEVICE_INFO>")
root_dev_list = []
for rootfs_line in rootfs_lines:
root_dev = rootfs_line.strip().split(':')[0]
root_dev_list.append(root_dev)
return (root_dev_list, len(root_dev_list))
def clos_info_parser(board_info):
""" Parse CLOS information """
return common.get_max_clos(board_info)
def get_pre_launch_cnt(config_file):
"""
This is get pre launched vm count
:param config_file: it is a file what contains vm information for script to read from
:return: number of per launched vm
"""
pre_launch_cnt = common.vm_pre_launch_cnt(config_file)
return pre_launch_cnt
def get_vm_count(config_file):
"""
This is get vm count
:param config_file: it is a file what contains vm information for script to read from
:return: number of vm
"""
global VM_COUNT
VM_COUNT = common.get_vm_count(config_file)
def get_order_type_by_vmid(idx):
"""
This is get pre launched vm count
:param idx: index of vm id
:return: idx and vm type mapping
"""
(err_dic, order_id_dic) = common.get_load_order_by_vmid(SCENARIO_INFO_FILE, VM_COUNT, idx)
if err_dic:
ERR_LIST.update(err_dic)
return order_id_dic
def get_valid_irq(board_info):
"""
This is get available irq from board info file
:param board_info: it is a file what contains board information for script to read from
:return: None
"""
global VALID_LEGACY_IRQ
val_irq = []
irq_info_lines = get_info(board_info, "<AVAILABLE_IRQ_INFO>", "</AVAILABLE_IRQ_INFO>")
for irq_string in irq_info_lines:
val_irq = [x.strip() for x in irq_string.split(',')]
VALID_LEGACY_IRQ = val_irq
def alloc_irq():
"""
This is allocated an available irq
:return: free irq
"""
irq_val = VALID_LEGACY_IRQ.pop(0)
return irq_val
def get_valid_console():
""" Get valid console with mapping {ttyS:irq} returned """
used_console_lines = get_info(BOARD_INFO_FILE, "<TTYS_INFO>", "</TTYS_INFO>")
vuart0_valid_console = []
vuart1_valid_console = ['ttyS0', 'ttyS1', 'ttyS2', 'ttyS3', 'ttyS4', 'ttyS5', 'ttyS6', 'ttyS7']
if used_console_lines:
vuart0_valid_console.clear()
for console in used_console_lines:
tty = console.split('/')[2].split()[0]
ttys_irq = console.split(':')[-1].strip()
NATIVE_CONSOLE_DIC[tty] = ttys_irq
vuart0_valid_console.append(tty)
if tty:
vuart1_valid_console.remove(tty)
return (vuart0_valid_console, vuart1_valid_console)
def console_to_show(board_info):
"""
This is get available console from board info file
:param board_info: it is a file what contains board information for script to read from
:return: available console
"""
show_vuart1 = False
(vuart0_valid_console, vuart1_valid_console) = get_valid_console()
if not vuart1_valid_console:
print_yel("Console are full used, sos_console/vuart1 have to chose one:", warn=True)
vuart0_valid_console = ['ttyS0', 'ttyS1', 'ttyS2', 'ttyS3']
vuart1_valid_console = ['ttyS0', 'ttyS1', 'ttyS2', 'ttyS3']
show_vuart1 = True
return (vuart0_valid_console, vuart1_valid_console, show_vuart1)
def parser_vuart_console():
"""
There may be 3 types in the console item
1. BDF:(00:18.2) seri:/dev/ttyS2
2. /dev/ttyS2
3. ttyS2
"""
ttys_n = ''
(err_dic, scenario_name) = get_scenario_name()
if scenario_name != "logical_partition":
ttys = get_sub_leaf_tag(SCENARIO_INFO_FILE, "board_private", "console")
else:
ttys = get_sub_leaf_tag(SCENARIO_INFO_FILE, "os_config", "console")
if ttys and 'BDF' in ttys[0] or '/dev' in ttys[0]:
ttys_n = ttys[0].split('/')[2]
else:
# sdc/sdc2 is different from logical_partition
ttys_n = ttys[0]
return (err_dic, ttys_n)
def get_board_private_vuart(branch_tag, tag_console):
"""
Get vuart_console from board setting
:param tag_console: TTYS_INFO
:return: vuart0/vuart1 console dictionary
"""
err_dic = {}
vuart0_console_dic = {}
vuart1_console_dic = {}
(err_dic, ttys_n) = parser_vuart_console()
if err_dic:
return err_dic
if not ttys_n or ttys_n not in list(TTY_CONSOLE.keys()):
err_dic["board config: ttyS not available"] = "console should be set in scenario.xml of board_private section"
return (err_dic, vuart0_console_dic, vuart1_console_dic)
(vuart0_valid_console, vuart1_valid_console, show_vuart1) = console_to_show(BOARD_INFO_FILE)
# VUART0
if ttys_n not in list(NATIVE_CONSOLE_DIC.keys()):
vuart0_console_dic[ttys_n] = alloc_irq()
else:
if int(NATIVE_CONSOLE_DIC[ttys_n]) >= 16:
vuart0_console_dic[ttys_n] = alloc_irq()
else:
vuart0_console_dic[ttys_n] = NATIVE_CONSOLE_DIC[ttys_n]
# VUART1
if len(vuart1_valid_console) == 4:
ttys_n = get_sub_leaf_tag(SCENARIO_INFO_FILE, branch_tag, "vuart1_console")
vuart1_console_dic[ttys_n] = alloc_irq()
else:
vuart1_console_dic[vuart1_valid_console[0]] = alloc_irq()
return (err_dic, vuart0_console_dic, vuart1_console_dic)
def get_vuart_id(tmp_vuart, leaf_tag, leaf_text):
"""
Get all vuart id member of class
:param leaf_tag: key pattern of item tag
:param tmp_vuart: a dictionary to store member:value
:param leaf_text: key pattern of item tag's value
:return: a dictionary to which stored member:value
"""
if leaf_tag == "type":
tmp_vuart['type'] = leaf_text
if leaf_tag == "base":
tmp_vuart['base'] = leaf_text
if leaf_tag == "irq":
tmp_vuart['irq'] = leaf_text
if leaf_tag == "target_vm_id":
tmp_vuart['target_vm_id'] = leaf_text
if leaf_tag == "target_uart_id":
tmp_vuart['target_uart_id'] = leaf_text
return tmp_vuart
def get_vuart_info_id(config_file, idx):
"""
Get vuart information by vuart id indexx
:param config_file: it is a file what contains information for script to read from
:param idx: vuart index in range: [0,1]
:return: dictionary which stored the vuart-id
"""
tmp_tag = []
vm_id = 0
root = common.get_config_root(config_file)
for item in root:
for sub in item:
tmp_vuart = {}
for leaf in sub:
if sub.tag == "vuart" and int(sub.attrib['id']) == idx:
tmp_vuart = get_vuart_id(tmp_vuart, leaf.tag, leaf.text)
# append vuart for each vm
if tmp_vuart and sub.tag == "vuart":
#tmp_vuart[vm_id] = tmp_vuart
tmp_tag.append(tmp_vuart)
if item.tag == "vm":
vm_id += 1
return tmp_tag

View File

@@ -0,0 +1,555 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import os
import sys
import getopt
import shutil
import subprocess
import xml.etree.ElementTree as ET
SOURCE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')
HV_LICENSE_FILE = SOURCE_PATH + 'misc/acrn-config/library/hypervisor_license'
PY_CACHES = ["__pycache__", "../board_config/__pycache__", "../scenario_config/__pycache__"]
BIN_LIST = ['git']
GUEST_FLAG = ["0UL", "GUEST_FLAG_SECURE_WORLD_ENABLED", "GUEST_FLAG_LAPIC_PASSTHROUGH",
"GUEST_FLAG_IO_COMPLETION_POLLING", "GUEST_FLAG_CLOS_REQUIRED",
"GUEST_FLAG_HIDE_MTRR", "GUEST_FLAG_RT", "GUEST_FLAG_HIGHEST_SEVERITY"]
# Support 512M, 1G, 2G
# pre launch less then 2G, sos vm less than 24G
START_HPA_SIZE_LIST = ['0x20000000', '0x40000000', '0x80000000', 'CONFIG_SOS_RAM_SIZE', 'VM0_MEM_SIZE']
def open_license():
""" Get the license """
with open(HV_LICENSE_FILE, 'r') as f_licence:
license_s = f_licence.read().strip()
return license_s
def print_if_yel(msg, warn=False):
"""
Print the message with 'Warning' if warn is true
:param msg: the stings which will be output to STDOUT
:param warn: the condition if needs to be output the color of yellow with 'Warning'
"""
if warn:
print("\033[1;33mWarning\033[0m: "+msg)
else:
print("\033[1;33m{0}\033[0m".format(msg))
def print_if_red(msg, err=False):
"""
Print the message with 'Error' if err is true
:param msg: the stings which will be output to STDOUT
:param err: the condition if needs to be output the color of red with 'Error'
"""
if err:
print("\033[1;31mError\033[0m: "+msg)
else:
print("\033[1;31m{0}\033[0m".format(msg))
def usage(file_name):
""" This is usage for how to use this tool """
print("usage= {} [h] ".format(file_name), end="")
print("--board <board_info_file> --scenario <scenario_info_file>")
print('board_info_file : file name of the board info')
print('scenario_info_file : file name of the scenario info')
def get_param(args):
"""
Get the script parameters from command line
:param args: this the command line of string for the script without script name
"""
err_dic = {}
board_info_file = False
scenario_info_file = False
if '--board' not in args or '--scenario' not in args:
usage(args[0])
err_dic['common error: get wrong parameter'] = "wrong usage"
return (err_dic, board_info_file, scenario_info_file)
args_list = args[1:]
(optlist, args_list) = getopt.getopt(args_list, '', ['board=', 'scenario='])
for arg_k, arg_v in optlist:
if arg_k == '--board':
board_info_file = arg_v
if arg_k == '--scenario':
scenario_info_file = arg_v
if not board_info_file or not scenario_info_file:
usage(args[0])
err_dic['common error: get wrong parameter'] = "wrong usage"
return (err_dic, board_info_file, scenario_info_file)
if not os.path.exists(board_info_file):
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(board_info_file)
return (err_dic, board_info_file, scenario_info_file)
if not os.path.exists(scenario_info_file):
err_dic['common error: get wrong parameter'] = "{} is not exist!".format(scenario_info_file)
return (err_dic, board_info_file, scenario_info_file)
return (err_dic, board_info_file, scenario_info_file)
def check_env():
""" Prepare to check the environment """
err_dic = {}
for excute in BIN_LIST:
res = subprocess.Popen("which {}".format(excute), shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
line = res.stdout.readline().decode('ascii')
if not line:
err_dic['commn error: check env failed'] = "'{}' not found, please install it!".format(excute)
if excute == "git":
res = subprocess.Popen("git tag -l", shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
line = res.stdout.readline().decode("ascii")
if "acrn" not in line:
err_dic['commn error: check env failed'] = "Run this tool in acrn-hypervisor mainline source code!"
usr_dir = os.environ['HOME']
if not os.path.isfile("{}/.gitconfig".format(usr_dir)):
err_dic['commn error: check env failed'] = "git not configured!"
for py_cache in PY_CACHES:
if os.path.exists(py_cache):
shutil.rmtree(py_cache)
return err_dic
def check_hpa_size(hpa_size_list):
"""
This is identify if the host physical size list is correct format
:param hpa_size_list: host physical size list
:return: True if good format
"""
for hpa_size in hpa_size_list:
hpa_sz_strip_ul = hpa_size.strip('UL')
hpa_sz_strip_u = hpa_size.strip('U')
if hpa_sz_strip_u not in START_HPA_SIZE_LIST and hpa_sz_strip_ul not in START_HPA_SIZE_LIST:
if '0x' not in hpa_size and '0X' not in hpa_size:
return False
return True
def get_xml_attrib(config_file, attrib):
"""
Get attribute from xml at fist line
:param config_file: it is a file what contains board information for script to read from
:param attrib: attribute of item in xml
"""
value = ''
err_dic = {}
with open(config_file, 'rt') as fp_info:
while True:
line = fp_info.readline()
if not line:
break
if 'board=' in line or 'scenario=' in line:
if attrib not in line:
err_dic['common error: Not match'] = "The root item is not in xml file"
return (err_dic, value)
attrib_list = line.split()
for attrib_value in attrib_list:
if attrib in attrib_value:
value = attrib_value.split('"')[1].strip('"')
return (err_dic, value)
def get_board_info(board_info, msg_s, msg_e):
"""
Get information which specify by argument
:param board_info: it is a file what contains board information for script to read from
:param msg_s: it is a pattern of key stings what start to match from board information
:param msg_e: it is a pattern of key stings what end to match from board information
"""
info_start = False
info_end = False
info_lines = []
num = len(msg_s.split())
with open(board_info, 'rt') as f_board:
while True:
line = f_board.readline()
if not line:
break
if " ".join(line.split()[0:num]) == msg_s:
info_start = True
info_end = False
continue
if " ".join(line.split()[0:num]) == msg_e:
info_start = False
info_end = True
continue
if info_start and not info_end:
info_lines.append(line)
continue
if not info_start and info_end:
return info_lines
def find_index_guest_flag(flag):
"""
Find the index in GUEST_FLAG by flag
:param flag: flag contained by GUEST_FLAG
:return: index of GUEST_FLAG
"""
if not flag or flag == '0':
return '0'
if not flag.isnumeric():
for i in range(len(GUEST_FLAG)):
if flag == GUEST_FLAG[i]:
flag_str = i
return flag_str
def find_tmp_flag(leaf_text):
"""
Get flag and append the value
:param leaf_text: it is a value of guest flag item
:return: a list of flag or none
"""
tmp_flag = []
tmp_flag = find_index_guest_flag(leaf_text)
#flag_index = find_index_guest_flag(leaf_text)
#if flag_index == '0':
# tmp_flag.append(0)
#else:
# tmp_flag.append(flag_index)
return tmp_flag
def get_config_root(config_file):
"""
This is get root of xml config
:param config_file: it is a file what contains information for script to read from
:return: top of root entry
"""
# create element tree object
tree = ET.parse(config_file)
# get root element
root = tree.getroot()
return root
def get_vm_count(config_file):
"""
Get vm number
:param config_file: it is a file what contains information for script to read from
:return: total vm number
"""
vm_count = 0
root = get_config_root(config_file)
for item in root:
# vm number in scenario
if item.tag == "vm":
vm_count += 1
return vm_count
def get_post_vm_count(config_file):
"""
Get post vm number
:param config_file: it is a file what contains information for script to read from
:return: total post vm number in launch file
"""
post_vm_count = 0
# get post vm number
root = get_config_root(config_file)
for item in root:
for sub in item:
if sub.tag == "load_order" and sub.text == "POST_LAUNCHED_VM":
post_vm_count += 1
return post_vm_count
def get_tree_tag_val(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item
"""
root = get_config_root(config_file)
for item in root:
if item.tag == tag_str:
return item.text
return False
def get_branch_tag(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item list
"""
tmp_tag = []
root = get_config_root(config_file)
for item in root:
for sub in item:
if sub.tag == tag_str:
tmp_tag.append(sub.text)
return tmp_tag
def get_branch_tag_val(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item list
"""
tmp_tag = []
root = get_config_root(config_file)
for item in root:
for sub in item:
if sub.tag == tag_str:
tmp_tag.append(sub.text)
return tmp_tag
def get_branch_tag_map(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item dictionary
"""
tmp_tag = {}
vm_id = 0
root = get_config_root(config_file)
for item in root:
for sub in item:
if sub.tag == tag_str:
tmp_tag[vm_id] = sub.text
if item.tag == "vm":
vm_id += 1
return tmp_tag
def get_leaf_tag_val(config_file, branch_tag, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param branch_tag: it is key of patter to config file branch tag item
:param tag_str: it is key of pattern to config file leaf tag item
:return: value of tag_str item
"""
tmp_tag = []
root = get_config_root(config_file)
for item in root:
for sub in item:
tmp_flag = []
tmp_cpus = []
if sub.tag == branch_tag:
for leaf in sub:
if leaf.tag == tag_str and tag_str != "guest_flag" and tag_str != "pcpu_id" and\
sub.tag != "vuart":
tmp_tag.append(leaf.text)
continue
# get guest flag for logical partition vm1
if leaf.tag == "guest_flag" and tag_str == "guest_flag":
t_flag = find_tmp_flag(leaf.text)
tmp_flag.append(t_flag)
#continue
# get cpu for vm
if leaf.tag == "pcpu_id" and tag_str == "pcpu_id":
tmp_cpus.append(leaf.text)
continue
# append guest flags for each vm
if tmp_flag and tag_str == "guest_flag":
tmp_tag.append(tmp_flag)
continue
# append cpus for vm
if tmp_cpus and tag_str == "pcpu_id":
tmp_tag.append(tmp_cpus)
continue
return tmp_tag
def get_leaf_tag_map(config_file, branch_tag, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param branch_tag: it is key of patter to config file branch tag item
:param tag_str: it is key of pattern to config file leaf tag item
:return: value of tag_str item map
"""
tmp_tag = {}
vm_id = 0
root = get_config_root(config_file)
for item in root:
for sub in item:
tmp_flag = []
tmp_cpus = []
if sub.tag == branch_tag:
for leaf in sub:
if leaf.tag == tag_str and tag_str != "guest_flag" and tag_str != "pcpu_id"\
and sub.tag != "vuart":
tmp_tag[vm_id] = leaf.text
continue
# get guest flag for logical partition vm1
if leaf.tag == "guest_flag" and tag_str == "guest_flag":
tmp_flag = find_tmp_flag(tmp_flag, leaf.text)
continue
# get cpu for vm
if leaf.tag == "pcpu_id" and tag_str == "pcpu_id":
tmp_cpus.append(leaf.text)
continue
# append guest flags for each vm
if tmp_flag and tag_str == "guest_flag":
tmp_tag[vm_id] = tmp_flag
continue
# append cpus for vm
if tmp_cpus and tag_str == "pcpu_id":
tmp_tag[vm_id] = tmp_cpus
continue
if item.tag == "vm":
vm_id += 1
return tmp_tag
def order_type_map_vmid(config_file, vm_count):
"""
This is mapping table for {id:order type}
:param config_file: it is a file what contains information for script to read from
:param vm_count: vm number
:return: table of id:order type dictionary
"""
order_id_dic = {}
load_type_list = get_branch_tag_val(config_file, "load_order")
for i in range(vm_count):
order_id_dic[i] = load_type_list[i]
return order_id_dic
def get_load_order_by_vmid(config_file, vm_count, idx):
"""
Get load order by vm id
:param config_file: it is a file what contains information for script to read from
:param vm_count: vm number
:param idx: index of vm id
:return: table of id:order type dictionary
"""
err_dic = {}
order_id_dic = order_type_map_vmid(config_file, vm_count)
if idx >= vm_count or not order_id_dic:
err_dic['vm number: failue'] = "Toatal vm number is less than index number"
return (err_dic, order_id_dic[idx])
def add_to_patch(srcs_list, commit_name):
"""
Generate patch and apply to local source code
:param srcs_list: it is a list what contains source files
:param commit_name: distinguish the key commit message for the patch
"""
err_dic = {}
changes = ' '.join(srcs_list)
git_add = "git add {}".format(changes)
ret = subprocess.call(git_add, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
if ret:
err_dic['add patch: failue'] = "Add patch failue"
return err_dic
# commit this changes
git_commit = 'git commit -sm "acrn-config: config board patch for {}"'.format(commit_name)
try:
ret = subprocess.call(git_commit, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
if ret < 0:
err_dic['commit patch: commit patch failue'] = "Commit patch failue"
except (OSError, subprocess.CalledProcessError) as e:
err_dic['commit patch: commit patch failue'] = "Commit patch failue"
return err_dic
def vm_pre_launch_cnt(config_file):
"""
Calculate the pre launched vm number
:param config_file: it is a file what contains information for script to read from
:return: number of pre launched vm
"""
pre_launch_cnt = 0
load_type_list = get_branch_tag_val(config_file, "load_order")
for vm_type in load_type_list:
if vm_type == "PRE_LAUNCHED_VM":
pre_launch_cnt += 1
return pre_launch_cnt
def get_max_clos(board_file):
"""
Parse CLOS information
:param board_file: it is a file what contains board information for script to read from
:return: type of cache support for clos and clos max number
"""
cache_support = False
clos_max = 0
cat_lines = get_board_info(board_file, "<CLOS_INFO>", "</CLOS_INFO>")
for line in cat_lines:
if line.split(':')[0].strip() == "clos supported by cache":
cache_support = line.split(':')[1].strip()
elif line.split(':')[0].strip() == "clos max":
clos_max = int(line.split(':')[1])
return (cache_support, clos_max)

View File

@@ -0,0 +1,785 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import common
SOURCE_ROOT_DIR = common.SOURCE_PATH
HEADER_LICENSE = common.open_license()
BOARD_INFO_FILE = "board_info.txt"
SCENARIO_INFO_FILE = ""
VM_COUNT = 0
LOAD_ORDER_TYPE = ['PRE_LAUNCHED_VM', 'SOS_VM', 'POST_LAUNCHED_VM']
START_HPA_LIST = ['0', '0x100000000', '0x120000000']
KERN_TYPE_LIST = ['KERNEL_BZIMAGE', 'KERNEL_ZEPHYR']
KERN_BOOT_ADDR_LIST = ['0x100000']
GUEST_FLAG = common.GUEST_FLAG
VUART_TYPE = ['VUART_LEGACY_PIO', 'VUART_PCI']
VUART_BASE = ['SOS_COM1_BASE', 'SOS_COM2_BASE', 'COM1_BASE',
'COM2_BASE', 'COM3_BASE', 'COM4_BASE', 'INVALID_COM_BASE']
AVALIBLE_COM1_BASE = ['INVALID_COM_BASE', 'COM1_BASE']
AVALIBLE_COM2_BASE = ['INVALID_COM_BASE', 'COM2_BASE']
VUART_IRQ = ['SOS_COM1_IRQ', 'SOS_COM2_IRQ', 'COM1_IRQ', 'COM2_IRQ', 'COM3_IRQ',
'COM4_IRQ', 'CONFIG_COM_IRQ', '3', '4', '6', '7']
PCI_DEV_NUM_LIST = ['SOS_EMULATED_PCI_DEV_NUM', 'VM0_CONFIG_PCI_DEV_NUM', 'VM1_CONFIG_PCI_DEV_NUM']
PCI_DEVS_LIST = ['sos_pci_devs', 'vm0_pci_devs', 'vm1_pci_devs']
COMMUNICATE_VM_ID = []
ERR_LIST = {}
def prepare():
""" Check environment """
return common.check_env()
def print_yel(msg, warn=False):
"""
Print the message with color of yellow
:param msg: the stings which will be output to STDOUT
:param warn: the condition if needs to be output the color of yellow with 'Warning'
"""
common.print_if_yel(msg, warn)
def print_red(msg, err=False):
"""
Print the message with color of red
:param msg: the stings which will be output to STDOUT
:param err: the condition if needs to be output the color of red with 'Error'
"""
common.print_if_red(msg, err)
def usage(file_name):
""" This is usage for how to use this tool """
common.usage(file_name)
def get_param(args):
"""
Get the script parameters from command line
:param args: this the command line of string for the script without script name
"""
return common.get_param(args)
def get_scenario_name():
"""
Get board name from scenario.xml at fist line
:param scenario_file: it is a file what contains scenario information for script to read from
"""
(err_dic, scenario) = common.get_xml_attrib(SCENARIO_INFO_FILE, "scenario")
return (err_dic, scenario)
def is_config_file_match():
(err_dic, scenario_for_board) = common.get_xml_attrib(SCENARIO_INFO_FILE, "board")
(err_dic, board_name) = common.get_xml_attrib(BOARD_INFO_FILE, "board")
if scenario_for_board == board_name:
return (err_dic, True)
else:
return (err_dic, False)
def get_info(board_info, msg_s, msg_e):
"""
Get information which specify by argument
:param board_info: it is a file what contains board information for script to read from
:param msg_s: it is a pattern of key stings what start to match from board information
:param msg_e: it is a pattern of key stings what end to match from board information
"""
info_lines = common.get_board_info(board_info, msg_s, msg_e)
return info_lines
def get_processor_info(board_info):
"""
Get cpu core list
:param board_info: it is a file what contains board information for script to read from
:return: cpu processor which one cpu has
"""
processor_list = []
tmp_list = []
processor_info = get_info(board_info, "<CPU_PROCESSOR_INFO>", "</CPU_PROCESSOR_INFO>")
if not processor_info:
key = "vm:id=0,pcpu_ids"
ERR_LIST[key] = "CPU core is not exists"
return processor_list
for processor_line in processor_info:
if not processor_line:
break
processor_list = processor_line.strip().split(',')
for processor in processor_list:
tmp_list.append(processor.strip())
break
return tmp_list
def get_rootdev_info(board_info):
"""
Get root devices from board info
:param board_info: it is a file what contains board information for script to read from
:return: root devices list
"""
rootdev_list = []
rootdev_info = get_info(board_info, "<ROOT_DEVICE_INFO>", "</ROOT_DEVICE_INFO>")
for rootdev_line in rootdev_info:
if not rootdev_line:
break
root_dev = rootdev_line.strip().split(':')[0]
rootdev_list.append(root_dev)
return rootdev_list
def get_ttys_info(board_info):
"""
Get ttySn from board info
:param board_info: it is a file what contains board information for script to read from
:return: serial console list
"""
ttys_list = []
ttys_info = get_info(board_info, "<TTYS_INFO>", "</TTYS_INFO>")
for ttys_line in ttys_info:
if not ttys_line:
break
#ttys_dev = " ".join(ttys_line.strip().split()[:-2])
ttys_dev = ttys_line.split()[1].split(':')[1]
ttys_list.append(ttys_dev)
return ttys_list
def get_board_private_info(config_file):
(err_dic, scenario_name) = get_scenario_name()
if scenario_name == "logical_partition":
branch_tag = "os_config"
else:
branch_tag = "board_private"
private_info = {}
dev_private_tags = ['rootfs', 'console']
for tag_str in dev_private_tags:
dev_setting = get_sub_leaf_tag(config_file, branch_tag, tag_str)
#dev_info = get_sub_tree_tag(config_file, )
if not dev_setting and tag_str == "console":
continue
private_info[tag_str] = dev_setting
return (err_dic, private_info)
def check_board_private_info():
(err_dic, private_info) = get_board_private_info(SCENARIO_INFO_FILE)
if not private_info['rootfs'] and err_dic:
ERR_LIST['vm,id=0,boot_private,rootfs'] = "The board have to chose one rootfs partition"
ERR_LIST.update(err_dic)
def get_vm_num(config_file):
"""
This is get vm count
:param config_file: it is a file what contains vm information for script to read from
:return: number of vm
"""
return common.get_vm_count(config_file)
def get_sub_tree_tag(config_file, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param tag_str: it is key of pattern to config file item
:return: value of tag_str item
"""
return common.get_branch_tag_val(config_file, tag_str)
def get_sub_leaf_tag(config_file, branch_tag, tag_str):
"""
This is get tag value by tag_str from config file
:param config_file: it is a file what contains information for script to read from
:param branch_tag: it is key of patter to config file branch tag item
:param tag_str: it is key of pattern to config file leaf tag item
:return: value of tag_str item
"""
return common.get_leaf_tag_val(config_file, branch_tag, tag_str)
def get_order_type_by_vmid(idx):
"""
Get load order by vm id
:param idx: index of vm id
:return: load order type of vm
"""
(err_dic, order_id_dic) = common.get_load_order_by_vmid(SCENARIO_INFO_FILE, VM_COUNT, idx)
if err_dic:
ERR_LIST.update(err_dic)
return order_id_dic
def get_vmid_by_order_type(type_str):
"""
This is mapping table for {id:order type}
:param type_str: vm loader type
:return: table of id:order type dictionary
"""
idx_list = []
order_id_dic = common.order_type_map_vmid(SCENARIO_INFO_FILE, VM_COUNT)
for idx, order_type in order_id_dic.items():
if type_str == order_type:
idx_list.append(idx)
return idx_list
def is_pre_launch_vm(idx):
"""
Identification the vm id loader type is pre launched
:param idx: vm id number
:return: True if it is a pre launched vm
"""
order_type = get_order_type_by_vmid(idx)
if order_type == "PRE_LAUNCHED_VM":
status = True
else:
status = False
return status
def pre_launch_vm_ids():
""" Get pre launched vm ids as list """
pre_vm = []
for i in range(VM_COUNT):
if is_pre_launch_vm(i):
pre_vm.append(i)
return pre_vm
def vm_name_check(vm_names, item):
"""
Check vm name
:param vm_names: list of vm name
:param item: vm name item in xml
:return: None
"""
for name_i in range(len(vm_names)):
name_len = len(vm_names[name_i])
if name_len > 32 or name_len == 0:
key = "vm:id={},{}".format(name_i, item)
ERR_LIST[key] = "VM name length should be in range [1,32] bytes"
def load_order_check(load_orders, item):
"""
Check load order type
:param load_orders: list of vm load_order
:param item: vm name item in xml
:return: None
"""
for order_i in range(len(load_orders)):
load_str = load_orders[order_i]
if not load_str:
key = "vm:id={},{}".format(order_i, item)
ERR_LIST[key] = "VM load should not empty"
return
if load_str not in LOAD_ORDER_TYPE:
key = "vm:id={},{}".format(order_i, item)
ERR_LIST[key] = "VM load order unknown"
def guest_flag_check(guest_flag_idx, branch_tag, leaf_tag):
guest_flag_len = len(common.GUEST_FLAG)
guest_num = len(guest_flag_idx)
for vm_i in range(guest_num):
flag_len = len(guest_flag_idx[vm_i])
if flag_len <= guest_flag_len:
continue
else:
key = "vm:id={},{},{}".format(vm_i, branch_tag, leaf_tag)
ERR_LIST[key] = "Unknow guest flag"
# for flag_i in range(flag_len):
# if guest_flag_idx[vm_i][flag_i] in common.GUEST_FLAG:
# continue
# else:
# key = "vm:id={},{},{}".format(vm_i, branch_tag, leaf_tag)
# ERR_LIST[key] = "Invalid guest flag"
def uuid_format_check(uuid_lists, item):
"""
Check uuid
:param uuid_lists: list of vm uuid
:param item: vm uuid item in xml
:return: None
"""
uuid_len = 36
for uuid_i in range(len(uuid_lists)):
uuid_str = uuid_lists[uuid_i]
if not uuid_str:
key = "vm:id={},{}".format(uuid_i, item)
ERR_LIST[key] = "VM uuid should not empty"
return
uuid_str_list = list(uuid_str)
key = "vm:id={},{}".format(uuid_i, item)
if len(uuid_str) != uuid_len:
ERR_LIST[key] = "VM uuid length should be 36 bytes"
if uuid_str_list[8] != '-':
ERR_LIST[key] = "VM uuid format unknown"
def cpus_per_vm_check(item):
"""
Check cpu of per vm
:param item: vm pcpu_id item in xml
:return: None
"""
prime_item = "pcpu_ids"
id_cpus_per_vm_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key in id_cpus_per_vm_dic.keys():
vm_type = get_order_type_by_vmid(id_key)
cpus_vm_i = id_cpus_per_vm_dic[id_key]
if not cpus_vm_i and vm_type == "PRE_LAUNCHED_VM":
key = "vm:id={},{}".format(id_key, item)
ERR_LIST[key] = "VM have no assignment cpus"
def mem_start_hpa_check(item):
"""
Check host physical address
:param item: vm start_hpa item in xml
:return: None
"""
prime_item = "memory"
id_start_hpa_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, hpa_str in id_start_hpa_dic.items():
hpa_strip_ul = hpa_str.strip('UL')
hpa_strip_u = hpa_str.strip('U')
if not hpa_str:
key = "vm:id={},{}".format(id_key, item)
ERR_LIST[key] = "VM start host physical memory address should not empty"
return
if hpa_strip_ul not in START_HPA_LIST and hpa_strip_u not in START_HPA_LIST:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
if '0x' not in hpa_str and '0X' not in hpa_str:
ERR_LIST[key] = "Address should be Hex format"
def mem_size_check(item):
"""
Check host physical size
:param item: vm size item in xml
:return: None
"""
prime_item = "memory"
id_hpa_size_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, hpa_size in id_hpa_size_dic.items():
hpa_sz_strip_ul = hpa_size.strip('UL')
hpa_sz_strip_u = hpa_size.strip('U')
if not hpa_size:
key = "vm:id={},{}".format(id_key, item)
ERR_LIST[key] = "VM start host physical memory size should not empty"
return
if hpa_sz_strip_ul not in common.START_HPA_SIZE_LIST and hpa_sz_strip_u not in \
common.START_HPA_SIZE_LIST:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
mem_max = 2 * 1024 * 1024 * 1024
if '0x' not in hpa_size and '0X' not in hpa_size:
ERR_LIST[key] = "Mem size should be Hex format"
elif int(hpa_sz_strip_ul, 16) > mem_max or int(hpa_sz_strip_u, 16) > mem_max:
ERR_LIST[key] = "Mem size should less than 2GB"
def os_kern_name_check(item):
"""
Check os kernel name
:param item: vm os config name item in xml
:return: None
"""
prime_item = "os_config"
id_kern_name_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_name in id_kern_name_dic.items():
if len(kern_name) > 32 or len(kern_name) == 0:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel name length should be in range [1,32] bytes"
def os_kern_type_check(item):
"""
Check os kernel type
:param item: vm os config type item in xml
:return: None
"""
prime_item = "os_config"
id_kern_type_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_type in id_kern_type_dic.items():
if not kern_type:
key = "vm:id={},{}".format(id_key, item)
ERR_LIST[key] = "VM os config kernel type should not empty"
return
if kern_type not in KERN_TYPE_LIST:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel type unknown"
def os_kern_mod_check(item):
"""
Check os kernel mod
:param item: vm os config mod item in xml
:return: None
"""
prime_item = "os_config"
id_kern_mod_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_mod in id_kern_mod_dic.items():
if len(kern_mod) > 32 or len(kern_mod) == 0:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel mod tag should be in range [1,32] bytes"
def os_kern_args_check(item):
"""
Check os kernel args
:param item: vm os config args item in xml
:return: None
"""
prime_item = "os_config"
id_kern_args_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_args in id_kern_args_dic.items():
vm_type = get_order_type_by_vmid(id_key)
if vm_type == "SOS_VM" and kern_args != "SOS_VM_BOOTARGS":
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel service os should be SOS_VM_BOOTARGS"
def os_kern_console_check(item):
"""
Check os kernel console
:param item: vm os config console item in xml
:return: None
"""
prime_item = "os_config"
id_kern_console_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_console in id_kern_console_dic.items():
if kern_console and "ttyS" not in kern_console:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel console should be ttyS[0..3]"
def os_kern_load_addr_check(item):
"""
Check os kernel load address
:param item: vm os config load address item in xml
:return: None
"""
prime_item = "os_config"
id_kern_load_addr_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_load_addr in id_kern_load_addr_dic.items():
if not kern_load_addr:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel load address should not empty"
return
if '0x' not in kern_load_addr and '0X' not in kern_load_addr:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel load address should Hex format"
def os_kern_entry_addr_check(item):
"""
Check os kernel entry address
:param item: vm os config entry address item in xml
:return: None
"""
prime_item = "os_config"
id_kern_entry_addr_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_entry_addr in id_kern_entry_addr_dic.items():
if not kern_entry_addr:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel entry address should not empty"
return
if '0x' not in kern_entry_addr and '0X' not in kern_entry_addr:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel entry address should Hex format"
def os_kern_root_dev_check(item):
"""
Check os kernel rootfs partitions
:param item: vm os config rootdev item in xml
:return: None
"""
prime_item = "os_config"
id_kern_rootdev_dic = common.get_leaf_tag_map(SCENARIO_INFO_FILE, prime_item, item)
for id_key, kern_rootdev in id_kern_rootdev_dic.items():
if not kern_rootdev:
key = "vm:id={},{},{}".format(id_key, prime_item, item)
ERR_LIST[key] = "VM os config kernel root device should not empty"
def pci_dev_num_check(item):
"""
Check vm pci device number
:param item: vm pci_dev_num item in xml
:return: None
"""
id_dev_num_dic = common.get_branch_tag_map(SCENARIO_INFO_FILE, item)
for id_key, pci_dev_num in id_dev_num_dic.items():
vm_type = get_order_type_by_vmid(id_key)
if vm_type != "POST_LAUNCHED_VM" and pci_dev_num:
if pci_dev_num not in PCI_DEV_NUM_LIST:
key = "vm:id={},{}".format(id_key, item)
ERR_LIST[key] = "VM pci device number shoud be one of {}".format(PCI_DEV_NUM_LIST)
def pci_devs_check(item):
"""
Check vm pci devices
:param item: vm pci_devs item in xml
:return: None
"""
id_devs_dic = common.get_branch_tag_map(SCENARIO_INFO_FILE, item)
for id_key, pci_dev in id_devs_dic.items():
vm_type = get_order_type_by_vmid(id_key)
if vm_type != "POST_LAUNCHED_VM" and pci_dev:
if pci_dev not in PCI_DEVS_LIST:
key = "vm:id={},{}".format(id_key, item)
ERR_LIST[key] = "VM pci device shoud be one of {}".format(PCI_DEVS_LIST)
def get_vuart1_vmid(vm_vuart1):
"""
Get vmid:vuart1 dictionary
:param vm_vuart1: vm_vuart1 setting from xml
:return: dictionary of vmid:vuart1
"""
vm_id_dic = {}
for i in range(VM_COUNT):
for key in vm_vuart1[i].keys():
if key == "target_vm_id":
vm_id_dic[i] = vm_vuart1[i][key]
# remove the unavailable vimid:target_vmid from dictonary
vmid_list = list(vm_id_dic.keys())
for vmid in vmid_list:
new_vmid = vm_id_dic[vmid]
if int(new_vmid) in vmid_list and vmid == int(vm_id_dic[int(new_vmid)]):
continue
else:
vm_id_dic.pop(vmid)
return vm_id_dic
def cpus_assignment(cpus_per_vm, index):
"""
Get cpu id assignment for vm by vm index
:param cpus_per_vm: a dictionary by vmid:cpus
:param index: vm index
:return: cpu assignment string
"""
vm_cpu_bmp = {}
for i in range(len(cpus_per_vm[index])):
if i == 0:
if len(cpus_per_vm[index]) == 1:
cpu_str = "(PLUG_CPU({0}))".format(cpus_per_vm[index][0])
else:
cpu_str = "(PLUG_CPU({0})".format(cpus_per_vm[index][0])
else:
if i == len(cpus_per_vm[index]) - 1:
cpu_str = cpu_str + " | PLUG_CPU({0}))".format(cpus_per_vm[index][i])
else:
cpu_str = cpu_str + " | PLUG_CPU({0})".format(cpus_per_vm[index][i])
vm_cpu_bmp['cpu_map'] = cpu_str
vm_cpu_bmp['cpu_num'] = len(cpus_per_vm[index])
return vm_cpu_bmp
def gen_patch(srcs_list, scenario_name):
"""
Generate patch and apply to local source code
:param srcs_list: it is a list what contains source files
:param scenario_name: scenario name
"""
err_dic = common.add_to_patch(srcs_list, scenario_name)
return err_dic
def get_vuart_id(tmp_vuart, leaf_tag, leaf_text):
"""
Get all vuart id member of class
:param tmp_vuart: a dictionary to store member:value
:param leaf_tag: key pattern of item tag
:param leaf_text: key pattern of item tag's value
:return: a dictionary to which stored member:value
"""
if leaf_tag == "type":
tmp_vuart['type'] = leaf_text
if leaf_tag == "base":
tmp_vuart['base'] = leaf_text
if leaf_tag == "irq":
tmp_vuart['irq'] = leaf_text
if leaf_tag == "target_vm_id":
tmp_vuart['target_vm_id'] = leaf_text
if leaf_tag == "target_uart_id":
tmp_vuart['target_uart_id'] = leaf_text
return tmp_vuart
def get_vuart_info_id(config_file, idx):
"""
Get vuart information by vuart id indexx
:param config_file: it is a file what contains information for script to read from
:param idx: vuart index in range: [0,1]
:return: dictionary which stored the vuart-id
"""
tmp_tag = {}
vm_id = 0
root = common.get_config_root(config_file)
for item in root:
for sub in item:
tmp_vuart = {}
for leaf in sub:
if sub.tag == "vuart" and int(sub.attrib['id']) == idx:
tmp_vuart = get_vuart_id(tmp_vuart, leaf.tag, leaf.text)
# append vuart for each vm
if tmp_vuart and sub.tag == "vuart":
tmp_tag[vm_id] = tmp_vuart
if item.tag == "vm":
vm_id += 1
return tmp_tag
def avl_vuart_ui_select(scenario_info):
vm_num = get_vm_num(scenario_info)
tmp_vuart = {}
for vm_i in range(vm_num):
vm_type = get_order_type_by_vmid(vm_i)
if vm_type == "SOS_VM":
key = "vm={},vuart=0,base".format(vm_i)
tmp_vuart[key] = ['SOS_COM1_BASE', 'INVALID_COM_BASE']
key = "vm={},vuart=1,base".format(vm_i)
tmp_vuart[key] = ['SOS_COM2_BASE', 'INVALID_COM_BASE']
else:
key = "vm={},vuart=0,base".format(vm_i)
tmp_vuart[key] = ['INVALID_COM_BASE', 'COM1_BASE']
key = "vm={},vuart=1,base".format(vm_i)
tmp_vuart[key] = ['INVALID_COM_BASE', 'COM2_BASE']
#print(tmp_vuart)
return tmp_vuart
def vmid_map_epc(config_file, tag, item):
"""
This is mapping table for {id:item}
:param config_file: it is a file what contains information for script to read from
:param item: the item in xml file
:return: table of id:item type dictionary
"""
epc_order = {}
vm_cnt = VM_COUNT
item_list = common.get_leaf_tag_val(config_file, tag, item)
load_type_list = common.get_branch_tag_val(config_file, "load_order")
if 'SOS_VM' in load_type_list:
vm_cnt = VM_COUNT - 1
for i in range(vm_cnt):
epc_order[i] = item_list[i]
return epc_order
def get_epc_base(scenario_info):
base_dic = {}
base_dic = vmid_map_epc(scenario_info, "epc_section", "base")
return base_dic
def get_epc_size(scenario_info):
size_dic = {}
size_dic = vmid_map_epc(scenario_info, "epc_section", "size")
return size_dic
def get_first_post_vm():
for i in range(VM_COUNT):
(err_dic, vm_type) = common.get_load_order_by_vmid(SCENARIO_INFO_FILE, VM_COUNT, i)
if vm_type == "POST_LAUNCHED_VM":
break
return (err_dic, i)