use "additional_duts" to overwrite dut class for different targets

This commit is contained in:
Fu Hanxi
2020-12-03 16:32:54 +08:00
parent a16d1e8f1a
commit a5bcaea9cc

View File

@@ -16,6 +16,7 @@ import json
import logging import logging
import os import os
import re import re
from copy import deepcopy
import junit_xml import junit_xml
@@ -73,11 +74,11 @@ def local_test_check(decorator_target):
try: try:
idf_target = sdkconfig['IDF_TARGET'].upper() idf_target = sdkconfig['IDF_TARGET'].upper()
except KeyError: except KeyError:
logging.warning('IDF_TARGET not in {}. IDF_TARGET set to esp32'.format(os.path.abspath(expected_json_path))) logging.debug('IDF_TARGET not in {}. IDF_TARGET set to esp32'.format(os.path.abspath(expected_json_path)))
else: else:
logging.info('IDF_TARGET: {}'.format(idf_target)) logging.debug('IDF_TARGET: {}'.format(idf_target))
else: else:
logging.warning('{} not found. IDF_TARGET set to esp32'.format(os.path.abspath(expected_json_path))) logging.debug('{} not found. IDF_TARGET set to esp32'.format(os.path.abspath(expected_json_path)))
if isinstance(decorator_target, list): if isinstance(decorator_target, list):
if idf_target not in decorator_target: if idf_target not in decorator_target:
@@ -88,11 +89,11 @@ def local_test_check(decorator_target):
return idf_target return idf_target
def get_dut_class(target, erase_nvs=None): def get_dut_class(target, dut_class_dict, erase_nvs=None):
if target not in TARGET_DUT_CLS_DICT: if target not in dut_class_dict:
raise Exception('target can only be {%s} (case insensitive)' % ', '.join(TARGET_DUT_CLS_DICT.keys())) raise Exception('target can only be {%s} (case insensitive)' % ', '.join(dut_class_dict.keys()))
dut = TARGET_DUT_CLS_DICT[target.upper()] dut = dut_class_dict[target.upper()]
if erase_nvs: if erase_nvs:
dut.ERASE_NVS = 'erase_nvs' dut.ERASE_NVS = 'erase_nvs'
return dut return dut
@@ -111,16 +112,19 @@ def ci_target_check(func):
return wrapper return wrapper
def test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, drop_kwargs_dut=False, **kwargs): def test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, **kwargs):
target = upper_list_or_str(target)
test_target = local_test_check(target) test_target = local_test_check(target)
dut = get_dut_class(test_target, erase_nvs) if 'additional_duts' in kwargs:
if drop_kwargs_dut and 'dut' in kwargs: # panic_test() will inject dut, resolve conflicts here dut_classes = deepcopy(TARGET_DUT_CLS_DICT)
dut = kwargs['dut'] dut_classes.update(kwargs['additional_duts'])
del kwargs['dut'] else:
dut_classes = TARGET_DUT_CLS_DICT
dut = get_dut_class(test_target, dut_classes, erase_nvs)
original_method = TinyFW.test_method( original_method = TinyFW.test_method(
app=app, dut=dut, target=upper_list_or_str(target), ci_target=upper_list_or_str(ci_target), app=app, dut=dut, target=target, ci_target=upper_list_or_str(ci_target),
module=module, execution_time=execution_time, level=level, erase_nvs=erase_nvs, module=module, execution_time=execution_time, level=level, erase_nvs=erase_nvs,
dut_dict=TARGET_DUT_CLS_DICT, **kwargs dut_dict=dut_classes, **kwargs
) )
test_func = original_method(func) test_func = original_method(func)
test_func.case_info["ID"] = format_case_id(target, test_func.case_info["name"]) test_func.case_info["ID"] = format_case_id(target, test_func.case_info["name"])
@@ -188,7 +192,7 @@ def idf_custom_test(app=TestApp, target="ESP32", ci_target=None, module="misc",
:return: test method :return: test method
""" """
def test(func): def test(func):
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, drop_kwargs_dut=True, **kwargs) return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, **kwargs)
return test return test