Add multi target support for search examples

drop keyword `dut`, use `target` instead to assign`dut_class` to `Env`
This commit is contained in:
Fu Hanxi
2020-04-03 16:16:40 +08:00
parent ba48120931
commit 6c98d7e4bd
4 changed files with 68 additions and 52 deletions

View File

@@ -63,7 +63,6 @@ class DefaultEnvConfig(object):
set_default_config = DefaultEnvConfig.set_default_config
get_default_config = DefaultEnvConfig.get_default_config
MANDATORY_INFO = {
"execution_time": 1,
"env_tag": "default",
@@ -158,6 +157,7 @@ def test_method(**kwargs):
In some cases, one test function might test many test cases.
If this flag is set, test case can update junit report by its own.
"""
def test(test_func):
case_info = MANDATORY_INFO.copy()
@@ -181,6 +181,27 @@ def test_method(**kwargs):
env_config[key] = kwargs[key]
env_config.update(overwrite)
# FIXME: CI need more variable here. add `if CI_TARGET: ...` later with CI.
target = env_config['target'] if 'target' in env_config else kwargs['target']
dut_dict = kwargs['dut_dict']
if isinstance(target, list):
target = target[0]
elif isinstance(target, str):
target = target
else:
raise TypeError('keyword targets can only be list or str')
if target not in dut_dict:
raise Exception('target can only be {%s}' % ', '.join(dut_dict.keys()))
dut = dut_dict[target]
try:
# try to config the default behavior of erase nvs
dut.ERASE_NVS = kwargs['erase_nvs']
except AttributeError:
pass
env_config['dut'] = dut
env_inst = Env.Env(**env_config)
# prepare for xunit test results
@@ -227,4 +248,5 @@ def test_method(**kwargs):
handle_test.case_info = case_info
handle_test.test_method = True
return handle_test
return test

View File

@@ -42,9 +42,14 @@ class Search(object):
continue
except ImportError as e:
print("ImportError: \r\n\tFile:" + file_name + "\r\n\tError:" + str(e))
for i, test_function in enumerate(test_functions):
test_functions_out = []
for case in test_functions:
test_functions_out += cls.replicate_case(case)
for i, test_function in enumerate(test_functions_out):
print("\t{}. ".format(i + 1) + test_function.case_info["name"])
return test_functions
return test_functions_out
@classmethod
def _search_test_case_files(cls, test_case, file_pattern):
@@ -77,17 +82,26 @@ class Search(object):
if isinstance(case.case_info[key], (list, tuple)):
replicate_config.append(key)
def _replicate_for_key(case_list, replicate_key, replicate_list):
def _replicate_for_key(cases, replicate_key, replicate_list):
def deepcopy_func(f, name=None):
fn = types.FunctionType(f.__code__, f.__globals__, name if name else f.__name__,
f.__defaults__, f.__closure__)
fn.__dict__.update(copy.deepcopy(f.__dict__))
return fn
case_out = []
for _case in case_list:
for inner_case in cases:
for value in replicate_list:
new_case = copy.deepcopy(_case)
new_case = deepcopy_func(inner_case)
new_case.case_info[replicate_key] = value
case_out.append(new_case)
return case_out
replicated_cases = [case]
for key in replicate_config:
while replicate_config:
if not replicate_config:
break
key = replicate_config.pop()
replicated_cases = _replicate_for_key(replicated_cases, key, case.case_info[key])
return replicated_cases
@@ -104,8 +118,4 @@ class Search(object):
test_cases = []
for test_case_file in test_case_files:
test_cases += cls._search_cases_from_file(test_case_file)
# handle replicate cases
test_case_out = []
for case in test_cases:
test_case_out += cls.replicate_case(case)
return test_case_out
return test_cases