ci: support keyword `nightly_run` in decorator

The test case with keyword `nightly_run` would be skipped in normal CI
pipelines. only would be triggered when `NIGHTLY_RUN` in environment
variables.
pull/7855/head
Fu Hanxi 2021-11-03 11:11:38 +08:00
rodzic ea6a0dde5a
commit 636b311ec0
2 zmienionych plików z 35 dodań i 13 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import errno
import json
import os
import re
from copy import deepcopy
import yaml
@ -23,7 +24,7 @@ except ImportError:
SUPPORTED_TARGETS = []
PREVIEW_TARGETS = []
IDF_PATH_FROM_ENV = os.getenv('IDF_PATH')
IDF_PATH_FROM_ENV = os.getenv('IDF_PATH', '')
class IDFCaseGroup(CIAssignTest.Group):
@ -41,6 +42,13 @@ class IDFCaseGroup(CIAssignTest.Group):
class IDFAssignTest(CIAssignTest.AssignTest):
DEFAULT_FILTER = {
'category': 'function',
'ignore': False,
'supported_in_ci': True,
'nightly_run': False,
}
def __init__(self, test_case_path, ci_config_file, case_group=IDFCaseGroup):
super(IDFAssignTest, self).__init__(test_case_path, ci_config_file, case_group)
@ -75,6 +83,12 @@ class IDFAssignTest(CIAssignTest.AssignTest):
with open(artifact_index_file, 'w') as f:
json.dump(artifact_index_list, f)
def search_cases(self, case_filter=None):
_filter = deepcopy(case_filter) if case_filter else {}
if 'NIGHTLY_RUN' in os.environ:
_filter.update({'nightly_run': True})
return super().search_cases(_filter)
class ExampleGroup(IDFCaseGroup):
SORT_KEYS = CI_JOB_MATCH_KEYS = ['env_tag', 'target']
@ -315,7 +329,8 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('case_group', choices=['example_test', 'custom_test', 'unit_test', 'component_ut'])
parser.add_argument('test_case_paths', nargs='+', help='test case folder or file')
parser.add_argument('-c', '--config', help='gitlab ci config file')
parser.add_argument('-c', '--config', default=os.path.join(IDF_PATH_FROM_ENV, '.gitlab', 'ci', 'target-test.yml'),
help='gitlab ci config file')
parser.add_argument('-o', '--output', help='output path of config files')
parser.add_argument('--pipeline_id', '-p', type=int, default=None, help='pipeline_id')
parser.add_argument('--test-case-file-pattern', help='file name pattern used to find Python test case files')
@ -323,7 +338,8 @@ if __name__ == '__main__':
SUPPORTED_TARGETS.extend(PREVIEW_TARGETS)
test_case_paths = [os.path.join(IDF_PATH_FROM_ENV, path) if not os.path.isabs(path) else path for path in args.test_case_paths] # type: ignore
test_case_paths = [os.path.join(IDF_PATH_FROM_ENV, path) if not os.path.isabs(path) else path for path in
args.test_case_paths] # type: ignore
args_list = [test_case_paths, args.config]
if args.case_group == 'example_test':
assigner = ExampleAssignTest(*args_list)

Wyświetl plik

@ -110,7 +110,7 @@ def ci_target_check(func):
return wrapper
def test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, **kwargs):
def test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, nightly_run, **kwargs):
target = upper_list_or_str(target)
test_target = local_test_check(target)
if 'additional_duts' in kwargs:
@ -122,7 +122,7 @@ def test_func_generator(func, app, target, ci_target, module, execution_time, le
original_method = TinyFW.test_method(
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,
dut_dict=dut_classes, **kwargs
dut_dict=dut_classes, nightly_run=nightly_run, **kwargs
)
test_func = original_method(func)
return test_func
@ -130,7 +130,7 @@ def test_func_generator(func, app, target, ci_target, module, execution_time, le
@ci_target_check
def idf_example_test(app=Example, target='ESP32', ci_target=None, module='examples', execution_time=1,
level='example', erase_nvs=True, config_name=None, **kwargs):
level='example', erase_nvs=True, config_name=None, nightly_run=False, **kwargs):
"""
decorator for testing idf examples (with default values for some keyword args).
@ -146,13 +146,14 @@ def idf_example_test(app=Example, target='ESP32', ci_target=None, module='exampl
:return: test method
"""
def test(func):
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, **kwargs)
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, nightly_run,
**kwargs)
return test
@ci_target_check
def idf_unit_test(app=UT, target='ESP32', ci_target=None, module='unit-test', execution_time=1,
level='unit', erase_nvs=True, **kwargs):
level='unit', erase_nvs=True, nightly_run=False, **kwargs):
"""
decorator for testing idf unit tests (with default values for some keyword args).
@ -166,14 +167,16 @@ def idf_unit_test(app=UT, target='ESP32', ci_target=None, module='unit-test', ex
:param kwargs: other keyword args
:return: test method
"""
def test(func):
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, **kwargs)
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, nightly_run,
**kwargs)
return test
@ci_target_check
def idf_custom_test(app=TestApp, target='ESP32', ci_target=None, module='misc', execution_time=1,
level='integration', erase_nvs=True, config_name=None, **kwargs):
level='integration', erase_nvs=True, config_name=None, nightly_run=False, **kwargs):
"""
decorator for idf custom tests (with default values for some keyword args).
@ -188,14 +191,16 @@ def idf_custom_test(app=TestApp, target='ESP32', ci_target=None, module='misc',
:param kwargs: other keyword args
:return: test method
"""
def test(func):
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, **kwargs)
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, nightly_run,
**kwargs)
return test
@ci_target_check
def idf_component_unit_test(app=ComponentUTApp, target='ESP32', ci_target=None, module='misc', execution_time=1,
level='integration', erase_nvs=True, config_name=None, **kwargs):
level='integration', erase_nvs=True, config_name=None, nightly_run=False, **kwargs):
"""
decorator for idf custom tests (with default values for some keyword args).
@ -212,7 +217,8 @@ def idf_component_unit_test(app=ComponentUTApp, target='ESP32', ci_target=None,
"""
def test(func):
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, **kwargs)
return test_func_generator(func, app, target, ci_target, module, execution_time, level, erase_nvs, nightly_run,
**kwargs)
return test