mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
ci: apply common-scripts CI refactor
Squashes these original commits for release/v5.4 backport traceability: - 9b289dc5ad6 ci: apply idf-ci 1.x - 381df980d57 ci: remove pip-cache and other unused jobs - 32375a0a15e ci: apply common-scripts CI refactor
This commit is contained in:
@@ -11,6 +11,13 @@ set -euo pipefail
|
||||
|
||||
TEMPLATE_APP_PATH="esp-idf-template"
|
||||
|
||||
# Set default paths for template app builds
|
||||
BUILD_PATH="${IDF_PATH}/build_template_app"
|
||||
BUILD_DIR="${BUILD_PATH}/@t/@w"
|
||||
|
||||
LOG_PATH="${IDF_PATH}/log_template_app"
|
||||
BUILD_LOG_CMAKE="${LOG_PATH}/cmake_@t_@w.txt"
|
||||
|
||||
gen_configs() {
|
||||
# CONFIG_COMPILER_OPTIMIZATION_NONE with flag -O0
|
||||
echo "CONFIG_COMPILER_OPTIMIZATION_NONE=y" > ${TEMPLATE_APP_PATH}/sdkconfig.ci.O0
|
||||
@@ -54,30 +61,23 @@ build_stage2() {
|
||||
# Override EXTRA_CFLAGS and EXTRA_CXXFLAGS in the environment
|
||||
export EXTRA_CFLAGS=${PEDANTIC_CFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
|
||||
export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS/-Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function/}
|
||||
python -m idf_build_apps build -v \
|
||||
idf-build-apps build \
|
||||
-p ${TEMPLATE_APP_PATH} \
|
||||
-t all \
|
||||
${CONFIG_STR} \
|
||||
--work-dir ${BUILD_PATH}/cmake \
|
||||
--build-dir ${BUILD_DIR} \
|
||||
--build-log ${BUILD_LOG_CMAKE} \
|
||||
--size-file size.json \
|
||||
--keep-going \
|
||||
--collect-size-info size_info.txt \
|
||||
--default-build-targets esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c5 esp32c6 esp32h2 esp32p4
|
||||
}
|
||||
|
||||
build_stage1() {
|
||||
CONFIG_STR=$(get_config_str sdkconfig.ci2.*=)
|
||||
python -m idf_build_apps build -v \
|
||||
idf-build-apps build \
|
||||
-p ${TEMPLATE_APP_PATH} \
|
||||
-t all \
|
||||
${CONFIG_STR} \
|
||||
--work-dir ${BUILD_PATH}/cmake \
|
||||
--build-dir ${BUILD_DIR} \
|
||||
--build-log ${BUILD_LOG_CMAKE} \
|
||||
--size-file size.json \
|
||||
--collect-size-info size_info.txt \
|
||||
--default-build-targets esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c5 esp32c6 esp32h2 esp32p4
|
||||
}
|
||||
|
||||
|
||||
+270
-396
@@ -1,33 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import inspect
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
import yaml
|
||||
from idf_ci_utils import get_all_manifest_files
|
||||
from idf_build_apps import App
|
||||
from idf_build_apps import find_apps
|
||||
from idf_build_apps.constants import SUPPORTED_TARGETS
|
||||
from idf_ci_utils import IDF_PATH
|
||||
|
||||
# Copy of the constant from idf_pytest.constants, to avoid installing
|
||||
# additional dependencies (pytest, pytest-embedded) in pre-commit hooks
|
||||
DEFAULT_CONFIG_RULES_STR = ['sdkconfig.ci=default', 'sdkconfig.ci.*=', '=default']
|
||||
|
||||
YES = u'\u2713'
|
||||
NO = u'\u2717'
|
||||
from idf_ci_utils import idf_relpath
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
# | Supported Target | ... |
|
||||
# | ---------------- | --- |
|
||||
SUPPORTED_TARGETS_TABLE_REGEX = re.compile(
|
||||
r'^\|\s*Supported Targets.+$\n^\|(?:\s*|-).+$\n?', re.MULTILINE
|
||||
)
|
||||
SUPPORTED_TARGETS_TABLE_REGEX = re.compile(r'^\|\s*Supported Targets.+$\n^\|(?:\s*|-).+$\n?', re.MULTILINE)
|
||||
|
||||
USUAL_TO_FORMAL = {
|
||||
'esp32': 'ESP32',
|
||||
@@ -43,350 +37,265 @@ USUAL_TO_FORMAL = {
|
||||
'linux': 'Linux',
|
||||
}
|
||||
|
||||
FORMAL_TO_USUAL = {
|
||||
'ESP32': 'esp32',
|
||||
'ESP32-S2': 'esp32s2',
|
||||
'ESP32-S3': 'esp32s3',
|
||||
'ESP32-C3': 'esp32c3',
|
||||
'ESP32-C2': 'esp32c2',
|
||||
'ESP32-C6': 'esp32c6',
|
||||
'ESP32-C5': 'esp32c5',
|
||||
'ESP32-H2': 'esp32h2',
|
||||
'ESP32-P4': 'esp32p4',
|
||||
'ESP32-C61': 'esp32c61',
|
||||
'Linux': 'linux',
|
||||
}
|
||||
FORMAL_TO_USUAL = {v: k for k, v in USUAL_TO_FORMAL.items()}
|
||||
|
||||
# Targets under bringup: suppress check-test-scripts warnings for these.
|
||||
# Reset to [] once bringup is complete.
|
||||
BYPASS_CHECK_TEST_TARGETS: list[str] = [
|
||||
'esp32c5',
|
||||
'esp32c61',
|
||||
]
|
||||
|
||||
|
||||
def doublequote(s: str) -> str:
|
||||
if s.startswith('"') and s.endswith('"'):
|
||||
return s
|
||||
def print_diff_table(
|
||||
list1: list[str],
|
||||
list2: list[str],
|
||||
title1: str,
|
||||
title2: str,
|
||||
excluded: list[str] | None = None,
|
||||
) -> None:
|
||||
left_set = set(list1)
|
||||
right_set = set(list2)
|
||||
|
||||
return f'"{s}"'
|
||||
if left_set == right_set:
|
||||
return
|
||||
|
||||
all_items = sorted(left_set.union(right_set))
|
||||
left_column = []
|
||||
right_column = []
|
||||
|
||||
for item in all_items:
|
||||
if item in left_set and item not in right_set:
|
||||
if excluded and item in excluded:
|
||||
left_column.append(f'[red]{item}[/red] (excluded)')
|
||||
else:
|
||||
left_column.append(f'[red]{item}[/red]')
|
||||
right_column.append('')
|
||||
elif item in right_set and item not in left_set:
|
||||
if excluded and item in excluded:
|
||||
right_column.append(f'[green]{item}[/green] (excluded)')
|
||||
else:
|
||||
right_column.append(f'[green]{item}[/green]')
|
||||
left_column.append('')
|
||||
else:
|
||||
left_column.append(item)
|
||||
right_column.append(item)
|
||||
|
||||
table = Table(show_header=True, header_style='bold magenta')
|
||||
table.add_column(title1.strip(), justify='left')
|
||||
table.add_column(title2.strip(), justify='left')
|
||||
|
||||
for l_col, r_col in zip(left_column, right_column):
|
||||
table.add_row(l_col, r_col)
|
||||
|
||||
console = Console()
|
||||
console.print(table)
|
||||
|
||||
|
||||
def get_readme_path(app_dir: str) -> str | None:
|
||||
readme_path = os.path.join(app_dir, 'README.md')
|
||||
|
||||
if not os.path.isfile(readme_path):
|
||||
readme_path = os.path.join(app_dir, '..', 'README.md')
|
||||
|
||||
if not os.path.isfile(readme_path):
|
||||
readme_path = None # type: ignore
|
||||
|
||||
return readme_path
|
||||
|
||||
|
||||
def generate_new_support_table(targets: list[str]) -> str:
|
||||
# extra space here
|
||||
table_headers = [f'{USUAL_TO_FORMAL[target]}' for target in targets]
|
||||
table_headers = ['Supported Targets'] + table_headers
|
||||
|
||||
res = '| ' + ' | '.join(table_headers) + ' |\n'
|
||||
res += '| ' + ' | '.join(['-' * len(item) for item in table_headers]) + ' |'
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def parse_existing_table(app_dir: str) -> tuple[str | None, list[str]]:
|
||||
readme_path = get_readme_path(app_dir)
|
||||
if not readme_path:
|
||||
return None, SUPPORTED_TARGETS
|
||||
|
||||
with open(readme_path, encoding='utf8') as _fr:
|
||||
readme_str = _fr.read()
|
||||
|
||||
support_string = SUPPORTED_TARGETS_TABLE_REGEX.findall(readme_str)
|
||||
if not support_string:
|
||||
return None, SUPPORTED_TARGETS
|
||||
|
||||
# old style
|
||||
parts = [part.strip() for part in support_string[0].split('\n', 1)[0].split('|') if part.strip()]
|
||||
return support_string[0].strip(), [FORMAL_TO_USUAL[part] for part in parts[1:] if part in FORMAL_TO_USUAL]
|
||||
|
||||
|
||||
def get_grouped_apps(
|
||||
paths: list[str],
|
||||
exclude_dirs: list[str] | None = None,
|
||||
) -> dict[str, list[App]]:
|
||||
apps = sorted(
|
||||
find_apps(
|
||||
paths,
|
||||
'all',
|
||||
exclude_list=exclude_dirs or [],
|
||||
)
|
||||
)
|
||||
|
||||
grouped_apps: dict[str, list[App]] = defaultdict(list)
|
||||
for app in apps:
|
||||
grouped_apps[app.app_dir].append(app)
|
||||
|
||||
return grouped_apps
|
||||
|
||||
|
||||
def check_readme(
|
||||
paths: List[str],
|
||||
exclude_dirs: Optional[List[str]] = None,
|
||||
extra_default_build_targets: Optional[List[str]] = None,
|
||||
paths: list[str],
|
||||
exclude_dirs: list[str] | None = None,
|
||||
) -> None:
|
||||
from idf_build_apps import App, find_apps
|
||||
from idf_build_apps.constants import SUPPORTED_TARGETS
|
||||
grouped_apps = get_grouped_apps(paths, exclude_dirs)
|
||||
exit_code = 0
|
||||
|
||||
def app_build_targets(_app: App) -> List[str]:
|
||||
return sorted(
|
||||
for app_dir, apps in grouped_apps.items():
|
||||
old_table, old_targets = parse_existing_table(app_dir)
|
||||
manifest_targets = sorted(
|
||||
{
|
||||
target
|
||||
for app in apps
|
||||
for target in (
|
||||
App.MANIFEST.enable_build_targets(_app.app_dir)
|
||||
+ App.MANIFEST.enable_build_targets(_app.app_dir, config_name=_app.config_name)
|
||||
App.MANIFEST.enable_build_targets(app_dir)
|
||||
+ App.MANIFEST.enable_build_targets(app_dir, config_name=app.config_name)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
def get_readme_path(_app: App) -> Optional[str]:
|
||||
_readme_path = os.path.join(_app.app_dir, 'README.md')
|
||||
|
||||
if not os.path.isfile(_readme_path):
|
||||
_readme_path = os.path.join(_app.app_dir, '..', 'README.md')
|
||||
|
||||
if not os.path.isfile(_readme_path):
|
||||
_readme_path = None # type: ignore
|
||||
|
||||
return _readme_path
|
||||
|
||||
def _generate_new_support_table_str(_app: App) -> str:
|
||||
manifest_targets = app_build_targets(_app)
|
||||
# extra space here
|
||||
table_headers = [
|
||||
f'{USUAL_TO_FORMAL[target]}' for target in manifest_targets
|
||||
]
|
||||
table_headers = ['Supported Targets'] + table_headers
|
||||
|
||||
res = '| ' + ' | '.join(table_headers) + ' |\n'
|
||||
res += '| ' + ' | '.join(['-' * len(item) for item in table_headers]) + ' |'
|
||||
|
||||
return res
|
||||
|
||||
def _parse_existing_support_table_str(_app: App) -> Tuple[Optional[str], List[str]]:
|
||||
_readme_path = get_readme_path(_app)
|
||||
if not _readme_path:
|
||||
return None, SUPPORTED_TARGETS
|
||||
|
||||
with open(_readme_path, encoding='utf8') as _fr:
|
||||
_readme_str = _fr.read()
|
||||
|
||||
support_string = SUPPORTED_TARGETS_TABLE_REGEX.findall(_readme_str)
|
||||
if not support_string:
|
||||
return None, SUPPORTED_TARGETS
|
||||
|
||||
# old style
|
||||
parts = [
|
||||
part.strip()
|
||||
for part in support_string[0].split('\n', 1)[0].split('|')
|
||||
if part.strip()
|
||||
]
|
||||
return support_string[0].strip(), [FORMAL_TO_USUAL[part] for part in parts[1:] if part in FORMAL_TO_USUAL]
|
||||
|
||||
def check_enable_build(_app: App, _old_supported_targets: List[str]) -> bool:
|
||||
manifest_targets = app_build_targets(_app)
|
||||
|
||||
if manifest_targets == sorted(_old_supported_targets):
|
||||
return True
|
||||
|
||||
_readme_path = get_readme_path(_app)
|
||||
if_clause = f'IDF_TARGET in [{", ".join([doublequote(target) for target in sorted(_old_supported_targets)])}]'
|
||||
|
||||
print(
|
||||
inspect.cleandoc(
|
||||
f'''
|
||||
{_app.app_dir}:
|
||||
- enable build targets according to the manifest file: {manifest_targets}
|
||||
- enable build targets according to the old Supported Targets table under readme "{_readme_path}": {_old_supported_targets}
|
||||
|
||||
If you want to disable some targets, please use the following snippet:
|
||||
|
||||
# Please combine this with the original one
|
||||
#
|
||||
# Notes:
|
||||
# - please keep in mind to avoid duplicated folders as yaml keys
|
||||
# - please use parentheses to group conditions, the "or" and "and" operators could only accept two operands
|
||||
{_app.app_dir}:
|
||||
enable:
|
||||
- if: {if_clause}
|
||||
temporary: true
|
||||
reason: <why only enable build jobs for these targets>
|
||||
|
||||
'''
|
||||
)
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
apps = sorted(
|
||||
find_apps(
|
||||
paths,
|
||||
'all',
|
||||
recursive=True,
|
||||
exclude_list=exclude_dirs or [],
|
||||
manifest_files=get_all_manifest_files(),
|
||||
default_build_targets=SUPPORTED_TARGETS + extra_default_build_targets,
|
||||
config_rules_str=DEFAULT_CONFIG_RULES_STR,
|
||||
)
|
||||
)
|
||||
exit_code = 0
|
||||
|
||||
checked_app_dirs = set()
|
||||
for app in apps:
|
||||
if app.app_dir not in checked_app_dirs:
|
||||
checked_app_dirs.add(app.app_dir)
|
||||
else:
|
||||
continue
|
||||
|
||||
replace_str, old_supported_targets = _parse_existing_support_table_str(app)
|
||||
success = check_enable_build(app, old_supported_targets)
|
||||
if not success:
|
||||
print(f'check_enable_build failed for app: {app}')
|
||||
print('-' * 80)
|
||||
if sorted(manifest_targets) != sorted(old_targets):
|
||||
print(f'Build target MISMATCH!!!: {app_dir}')
|
||||
print_diff_table(manifest_targets, old_targets, 'Manifest', 'README')
|
||||
print(f'Corresponding manifest file: {App.MANIFEST.most_suitable_rule(app_dir).by_manifest_file}')
|
||||
exit_code = 1
|
||||
|
||||
readme_path = get_readme_path(app)
|
||||
readme_path = get_readme_path(app_dir)
|
||||
new_table = generate_new_support_table(manifest_targets)
|
||||
# no readme, create a new file
|
||||
if not readme_path:
|
||||
with open(os.path.join(app.app_dir, 'README.md'), 'w') as fw:
|
||||
fw.write(_generate_new_support_table_str(app) + '\n')
|
||||
print(f'Added new README file: {os.path.join(app.app_dir, "README.md")}')
|
||||
print('-' * 80)
|
||||
with open(os.path.join(app_dir, 'README.md'), 'w') as fw:
|
||||
fw.write(new_table + '\n')
|
||||
print(f'Auto-fixing: Added new README: {os.path.join(app_dir, "README.md")}')
|
||||
exit_code = 1
|
||||
# has old table, but different string
|
||||
elif replace_str and replace_str != _generate_new_support_table_str(app):
|
||||
elif old_table and old_table != new_table:
|
||||
with open(readme_path) as fr:
|
||||
readme_str = fr.read()
|
||||
|
||||
with open(readme_path, 'w') as fw:
|
||||
fw.write(
|
||||
readme_str.replace(
|
||||
replace_str, _generate_new_support_table_str(app)
|
||||
)
|
||||
)
|
||||
print(f'Modified README file: {readme_path}')
|
||||
print('-' * 80)
|
||||
fw.write(readme_str.replace(old_table, new_table))
|
||||
print(f'Auto-fixing: Updated README: {readme_path}')
|
||||
exit_code = 1
|
||||
# does not have old table
|
||||
elif not replace_str:
|
||||
elif not old_table:
|
||||
with open(readme_path) as fr:
|
||||
readme_str = fr.read()
|
||||
|
||||
with open(readme_path, 'w') as fw:
|
||||
fw.write(
|
||||
_generate_new_support_table_str(app) + '\n\n' + readme_str
|
||||
) # extra new line
|
||||
|
||||
print(f'Modified README file: {readme_path}')
|
||||
print('-' * 80)
|
||||
fw.write(new_table + '\n\n' + readme_str) # extra new line
|
||||
print(f'Auto-fixing: Modified README: {readme_path}')
|
||||
exit_code = 1
|
||||
|
||||
if exit_code != 0:
|
||||
print('') # extra new line for readability
|
||||
print('Related documentation:')
|
||||
print(
|
||||
'\t- https://docs.espressif.com/projects/idf-build-apps/en/latest/references/manifest.html#enable-disable-rules'
|
||||
)
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def get_grouped_cases(paths: list[str]) -> dict[str, dict[str, set[str]]]:
|
||||
"""
|
||||
return something like this:
|
||||
{
|
||||
app_dir: {
|
||||
'script_paths': {'path/to/script1', 'path/to/script2'},
|
||||
'targets': {'esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c2', 'linux'},
|
||||
}
|
||||
}
|
||||
"""
|
||||
from idf_ci import get_pytest_cases
|
||||
|
||||
pytest_cases = get_pytest_cases(
|
||||
paths=paths,
|
||||
marker_expr=None, # don't filter host_test
|
||||
)
|
||||
|
||||
grouped_cases = {}
|
||||
for case in pytest_cases:
|
||||
for pytest_app in case.apps:
|
||||
app_dir = idf_relpath(pytest_app.path)
|
||||
if app_dir not in grouped_cases:
|
||||
grouped_cases[app_dir] = {
|
||||
'script_paths': {case.path},
|
||||
'targets': {pytest_app.target},
|
||||
}
|
||||
else:
|
||||
grouped_cases[app_dir]['script_paths'].add(case.path)
|
||||
grouped_cases[app_dir]['targets'].add(pytest_app.target)
|
||||
|
||||
return grouped_cases
|
||||
|
||||
|
||||
def check_test_scripts(
|
||||
paths: List[str],
|
||||
exclude_dirs: Optional[List[str]] = None,
|
||||
bypass_check_test_targets: Optional[List[str]] = None,
|
||||
extra_default_build_targets: Optional[List[str]] = None,
|
||||
paths: list[str],
|
||||
exclude_dirs: list[str] | None = None,
|
||||
*,
|
||||
bypass_targets: list[str] | None = None,
|
||||
) -> None:
|
||||
from idf_build_apps import App, find_apps
|
||||
from idf_build_apps.constants import SUPPORTED_TARGETS
|
||||
from idf_pytest.script import get_pytest_cases
|
||||
|
||||
# takes long time, run only in CI
|
||||
# dict:
|
||||
# {
|
||||
# app_dir: {
|
||||
# 'script_path': 'path/to/script',
|
||||
# 'targets': ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c2', 'linux'],
|
||||
# }
|
||||
# }
|
||||
def check_enable_test(
|
||||
_app: App,
|
||||
_pytest_app_dir_targets_dict: Dict[str, Dict[str, str]],
|
||||
) -> bool:
|
||||
if _app.app_dir in _pytest_app_dir_targets_dict:
|
||||
test_script_path = _pytest_app_dir_targets_dict[_app.app_dir]['script_path']
|
||||
actual_verified_targets = sorted(
|
||||
set(_pytest_app_dir_targets_dict[_app.app_dir]['targets'])
|
||||
)
|
||||
else:
|
||||
return True # no test case
|
||||
grouped_apps = get_grouped_apps(paths, exclude_dirs)
|
||||
grouped_cases = get_grouped_cases(paths)
|
||||
exit_code = 0
|
||||
|
||||
manifest_targets = sorted({
|
||||
target for target in (
|
||||
App.MANIFEST.enable_test_targets(_app.app_dir)
|
||||
+ App.MANIFEST.enable_test_targets(_app.app_dir, config_name=_app.config_name)
|
||||
)
|
||||
})
|
||||
for app_dir, apps in grouped_apps.items():
|
||||
if app_dir not in grouped_cases:
|
||||
continue
|
||||
|
||||
actual_extra_tested_targets = set(actual_verified_targets) - set(manifest_targets)
|
||||
if actual_extra_tested_targets - set(bypass_check_test_targets or []):
|
||||
print(
|
||||
inspect.cleandoc(
|
||||
f'''
|
||||
{_app.app_dir}:
|
||||
- enable test targets according to the manifest file: {manifest_targets}
|
||||
- enable test targets according to the test scripts: {actual_verified_targets}
|
||||
|
||||
test scripts enabled targets should be a subset of the manifest file declared ones.
|
||||
Please check the test script: {test_script_path}.
|
||||
|
||||
'''
|
||||
# manifest defined ones
|
||||
manifest_targets = sorted(
|
||||
{
|
||||
target
|
||||
for app in apps
|
||||
for target in (
|
||||
App.MANIFEST.enable_test_targets(app_dir)
|
||||
+ App.MANIFEST.enable_test_targets(app_dir, config_name=app.config_name)
|
||||
)
|
||||
)
|
||||
return False
|
||||
}
|
||||
)
|
||||
actual_targets = sorted(grouped_cases[app_dir]['targets'])
|
||||
|
||||
if manifest_targets == actual_verified_targets:
|
||||
return True
|
||||
if not ((set(manifest_targets) ^ set(actual_verified_targets)) - set(bypass_check_test_targets or [])):
|
||||
print(f'WARNING: bypass test script check on {_app.app_dir} for targets {bypass_check_test_targets} ')
|
||||
return True
|
||||
if manifest_targets == actual_targets:
|
||||
continue
|
||||
if not ((set(manifest_targets) ^ set(actual_targets)) - set(bypass_targets or [])):
|
||||
continue
|
||||
|
||||
if_clause = f'IDF_TARGET in [{", ".join([doublequote(target) for target in sorted(set(manifest_targets) - set(actual_verified_targets))])}]'
|
||||
print(f'Test target MISMATCH!!!: {app_dir}')
|
||||
print_diff_table(manifest_targets, actual_targets, 'Manifest', 'Test Scripts', bypass_targets)
|
||||
print(f'Corresponding manifest file: {App.MANIFEST.most_suitable_rule(app_dir).by_manifest_file}')
|
||||
print('Corresponding test scripts:')
|
||||
for script_path in grouped_cases[app_dir]['script_paths']:
|
||||
print(' - ' + script_path)
|
||||
exit_code = 1
|
||||
|
||||
if exit_code != 0:
|
||||
print('') # extra new line for readability
|
||||
print('Related documentation:')
|
||||
print(
|
||||
inspect.cleandoc(
|
||||
f'''
|
||||
{_app.app_dir}:
|
||||
- enable test targets according to the manifest file: {manifest_targets}
|
||||
- enable test targets according to the test scripts: {actual_verified_targets}
|
||||
|
||||
the test scripts enabled test targets should be the same with the manifest file enabled ones. Please check
|
||||
the test script manually: {test_script_path}.
|
||||
|
||||
If you want to enable test targets in the pytest test scripts, please add `@pytest.mark.MISSING_TARGET`
|
||||
marker above the test case function.
|
||||
|
||||
If you want to disable the test targets in the manifest file, please modify your manifest file with
|
||||
the following code snippet:
|
||||
|
||||
# Please combine this with the original one
|
||||
#
|
||||
# Notes:
|
||||
# - please keep in mind to avoid duplicated folders as yaml keys
|
||||
# - please use parentheses to group conditions, the "or" and "and" operators could only accept two operands
|
||||
{_app.app_dir}:
|
||||
disable_test:
|
||||
- if: {if_clause}
|
||||
temporary: true
|
||||
reason: <why you disable this test>
|
||||
|
||||
'''
|
||||
)
|
||||
'\t- https://docs.espressif.com/projects/idf-build-apps/en/latest/references/manifest.html#enable-disable-rules'
|
||||
)
|
||||
return False
|
||||
|
||||
apps = sorted(
|
||||
find_apps(
|
||||
paths,
|
||||
'all',
|
||||
recursive=True,
|
||||
exclude_list=exclude_dirs or [],
|
||||
manifest_files=get_all_manifest_files(),
|
||||
default_build_targets=SUPPORTED_TARGETS + extra_default_build_targets,
|
||||
config_rules_str=DEFAULT_CONFIG_RULES_STR,
|
||||
print(
|
||||
'\t- https://docs.espressif.com/projects/esp-idf/en/latest/esp32/contribute/esp-idf-tests-with-pytest.html'
|
||||
)
|
||||
)
|
||||
exit_code = 0
|
||||
|
||||
pytest_cases = get_pytest_cases(paths)
|
||||
|
||||
pytest_app_dir_targets_dict = {}
|
||||
for case in pytest_cases:
|
||||
for pytest_app in case.apps:
|
||||
app_dir = os.path.relpath(pytest_app.path, IDF_PATH)
|
||||
if app_dir not in pytest_app_dir_targets_dict:
|
||||
pytest_app_dir_targets_dict[app_dir] = {
|
||||
'script_path': case.path,
|
||||
'targets': [pytest_app.target],
|
||||
}
|
||||
else:
|
||||
pytest_app_dir_targets_dict[app_dir]['targets'].append(
|
||||
pytest_app.target
|
||||
)
|
||||
|
||||
checked_app_dirs = set()
|
||||
for app in apps:
|
||||
if app.app_dir not in checked_app_dirs:
|
||||
checked_app_dirs.add(app.app_dir)
|
||||
else:
|
||||
continue
|
||||
|
||||
success = check_enable_test(
|
||||
app, pytest_app_dir_targets_dict
|
||||
)
|
||||
if not success:
|
||||
print(f'check_enable_test failed for app: {app}')
|
||||
print('-' * 80)
|
||||
exit_code = 1
|
||||
continue
|
||||
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def check_exist() -> None:
|
||||
exit_code = 0
|
||||
|
||||
config_files = get_all_manifest_files()
|
||||
for file in config_files:
|
||||
if 'managed_components' in Path(file).parts:
|
||||
continue
|
||||
|
||||
with open(file) as fr:
|
||||
configs = yaml.safe_load(fr)
|
||||
for path in configs.keys():
|
||||
if path.startswith('.'):
|
||||
continue
|
||||
if not os.path.isdir(path):
|
||||
print(f'Path \'{path}\' referred in \'{file}\' does not exist!')
|
||||
exit_code = 1
|
||||
|
||||
sys.exit(exit_code)
|
||||
|
||||
@@ -398,92 +307,57 @@ if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='ESP-IDF apps build/test checker')
|
||||
action = parser.add_subparsers(dest='action')
|
||||
|
||||
_check_readme = action.add_parser('check-readmes')
|
||||
_check_readme.add_argument('paths', nargs='+', help='check under paths')
|
||||
_check_readme.add_argument(
|
||||
'-c',
|
||||
'--config',
|
||||
default=os.path.join(IDF_PATH, '.gitlab', 'ci', 'default-build-test-rules.yml'),
|
||||
help='default build test rules config file',
|
||||
)
|
||||
|
||||
_check_test_scripts = action.add_parser('check-test-scripts')
|
||||
_check_test_scripts.add_argument('paths', nargs='+', help='check under paths')
|
||||
_check_test_scripts.add_argument(
|
||||
'-c',
|
||||
'--config',
|
||||
default=os.path.join(IDF_PATH, '.gitlab', 'ci', 'default-build-test-rules.yml'),
|
||||
help='default build test rules config file',
|
||||
)
|
||||
|
||||
_check_exist = action.add_parser('check-exist')
|
||||
readme_parser = action.add_parser('check-readmes')
|
||||
readme_parser.add_argument('paths', nargs='+', help='check under paths')
|
||||
|
||||
test_parser = action.add_parser('check-test-scripts')
|
||||
test_parser.add_argument('paths', nargs='+', help='check under paths')
|
||||
arg = parser.parse_args()
|
||||
|
||||
# Since this script is executed from the pre-commit hook environment, make sure IDF_PATH is set
|
||||
os.environ['IDF_PATH'] = os.path.realpath(
|
||||
os.path.join(os.path.dirname(__file__), '..', '..')
|
||||
check_dirs = set()
|
||||
|
||||
# check if *_caps.h files changed
|
||||
check_all = False
|
||||
soc_caps_header_files = list((Path(IDF_PATH) / 'components' / 'soc').glob('**/*_caps.h'))
|
||||
for p in arg.paths:
|
||||
if Path(p).resolve() in soc_caps_header_files:
|
||||
check_all = True
|
||||
break
|
||||
|
||||
if os.path.isfile(p):
|
||||
check_dirs.add(os.path.dirname(p))
|
||||
else:
|
||||
check_dirs.add(p)
|
||||
|
||||
if 'tools/idf_py_actions/constants.py' in arg.paths or 'tools/ci/check_build_test_rules.py' in arg.paths:
|
||||
check_all = True
|
||||
|
||||
if check_all:
|
||||
check_dirs = {IDF_PATH}
|
||||
|
||||
_exclude_dirs = [
|
||||
os.path.join(IDF_PATH, 'tools', 'unit-test-app'),
|
||||
os.path.join(IDF_PATH, 'tools', 'test_build_system'),
|
||||
os.path.join(IDF_PATH, 'tools', 'templates', 'sample_project'),
|
||||
os.path.join(IDF_PATH, 'tools', 'cmakev2', 'test'),
|
||||
]
|
||||
|
||||
os.environ.update(
|
||||
{
|
||||
'IDF_PATH': IDF_PATH,
|
||||
'INCLUDE_NIGHTLY_RUN': '1',
|
||||
'NIGHTLY_RUN': '1',
|
||||
}
|
||||
)
|
||||
|
||||
if arg.action == 'check-exist':
|
||||
check_exist()
|
||||
else:
|
||||
check_dirs = set()
|
||||
|
||||
# check if *_caps.h files changed
|
||||
check_all = False
|
||||
soc_caps_header_files = list(
|
||||
(Path(IDF_PATH) / 'components' / 'soc').glob('**/*_caps.h')
|
||||
if arg.action == 'check-readmes':
|
||||
check_readme(
|
||||
list(check_dirs),
|
||||
_exclude_dirs,
|
||||
)
|
||||
elif arg.action == 'check-test-scripts':
|
||||
check_test_scripts(
|
||||
list(check_dirs),
|
||||
_exclude_dirs,
|
||||
bypass_targets=BYPASS_CHECK_TEST_TARGETS,
|
||||
)
|
||||
for p in arg.paths:
|
||||
if Path(p).resolve() in soc_caps_header_files:
|
||||
check_all = True
|
||||
break
|
||||
|
||||
if os.path.isfile(p):
|
||||
check_dirs.add(os.path.dirname(p))
|
||||
else:
|
||||
check_dirs.add(p)
|
||||
|
||||
if 'tools/idf_py_actions/constants.py' in arg.paths or 'tools/ci/check_build_test_rules.py' in arg.paths:
|
||||
check_all = True
|
||||
|
||||
if check_all:
|
||||
check_dirs = {IDF_PATH}
|
||||
_exclude_dirs = [os.path.join(IDF_PATH, 'tools', 'unit-test-app'),
|
||||
os.path.join(IDF_PATH, 'tools', 'test_build_system', 'build_test_app'),
|
||||
os.path.join(IDF_PATH, 'tools', 'templates', 'sample_project')]
|
||||
else:
|
||||
_exclude_dirs = [os.path.join(IDF_PATH, 'tools', 'templates', 'sample_project')]
|
||||
|
||||
extra_default_build_targets_list: List[str] = []
|
||||
bypass_check_test_targets_list: List[str] = []
|
||||
if arg.config:
|
||||
with open(arg.config) as fr:
|
||||
configs = yaml.safe_load(fr)
|
||||
|
||||
if configs:
|
||||
extra_default_build_targets_list = (
|
||||
configs.get('extra_default_build_targets') or []
|
||||
)
|
||||
bypass_check_test_targets_list = (
|
||||
configs.get('bypass_check_test_targets') or []
|
||||
)
|
||||
|
||||
if arg.action == 'check-readmes':
|
||||
os.environ['INCLUDE_NIGHTLY_RUN'] = '1'
|
||||
os.environ['NIGHTLY_RUN'] = '1'
|
||||
check_readme(
|
||||
list(check_dirs),
|
||||
exclude_dirs=_exclude_dirs,
|
||||
extra_default_build_targets=extra_default_build_targets_list,
|
||||
)
|
||||
elif arg.action == 'check-test-scripts':
|
||||
os.environ['INCLUDE_NIGHTLY_RUN'] = '1'
|
||||
os.environ['NIGHTLY_RUN'] = '1'
|
||||
check_test_scripts(
|
||||
list(check_dirs),
|
||||
exclude_dirs=_exclude_dirs,
|
||||
bypass_check_test_targets=bypass_check_test_targets_list,
|
||||
extra_default_build_targets=extra_default_build_targets_list,
|
||||
)
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# internal use only for CI
|
||||
# get latest MR information by source branch
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import typing as t
|
||||
from pathlib import Path
|
||||
|
||||
from gitlab_api import Gitlab
|
||||
from idf_ci_utils import IDF_PATH
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from gitlab.v4.objects import ProjectCommit, ProjectMergeRequest
|
||||
|
||||
|
||||
def _get_mr_obj(source_branch: str) -> t.Optional['ProjectMergeRequest']:
|
||||
gl = Gitlab(os.getenv('CI_PROJECT_ID', 'espressif/esp-idf'))
|
||||
if not gl.project:
|
||||
return None
|
||||
|
||||
mrs = gl.project.mergerequests.list(state='opened', source_branch=source_branch)
|
||||
if mrs:
|
||||
return mrs[0] # one source branch can only have one opened MR at one moment
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_mr_iid(source_branch: str) -> str:
|
||||
mr = _get_mr_obj(source_branch)
|
||||
if not mr:
|
||||
return ''
|
||||
else:
|
||||
return str(mr.iid)
|
||||
|
||||
|
||||
def get_mr_changed_files(source_branch: str) -> t.List[str]:
|
||||
mr = _get_mr_obj(source_branch)
|
||||
if not mr:
|
||||
return []
|
||||
|
||||
git_output = subprocess.check_output(
|
||||
['git', 'diff', '--name-only', '--diff-filter=d', f'origin/{mr.target_branch}...origin/{source_branch}']
|
||||
).decode('utf8')
|
||||
|
||||
return [line.strip() for line in git_output.splitlines() if line.strip()]
|
||||
|
||||
|
||||
def get_mr_commits(source_branch: str) -> t.List['ProjectCommit']:
|
||||
mr = _get_mr_obj(source_branch)
|
||||
if not mr:
|
||||
return []
|
||||
|
||||
return list(mr.commits())
|
||||
|
||||
|
||||
_COMPONENT_NAME_DIR_RECORDS = {}
|
||||
|
||||
|
||||
def get_modified_component(filepath: str) -> t.Optional[str]:
|
||||
"""Return the component name if the file is in a component directory, otherwise None."""
|
||||
try:
|
||||
f_path = Path(filepath).resolve().relative_to(IDF_PATH)
|
||||
except ValueError: # not in IDF_PATH
|
||||
return None
|
||||
|
||||
# skip md files, etc.
|
||||
if f_path.suffix in ['.md', '.yml']:
|
||||
return None
|
||||
|
||||
# skip test_apps files
|
||||
if 'test_apps' in f_path.parts:
|
||||
return None
|
||||
|
||||
component_parent_dirs = [f_path.parts[0]]
|
||||
for part in f_path.parts[1:]:
|
||||
if component_parent_dirs[-1] == 'components' or component_parent_dirs[-1].endswith('common_components'):
|
||||
if part not in _COMPONENT_NAME_DIR_RECORDS:
|
||||
logging.debug('Found component "%s" in path "%s"' % (part, component_parent_dirs))
|
||||
_COMPONENT_NAME_DIR_RECORDS[part] = component_parent_dirs
|
||||
elif _COMPONENT_NAME_DIR_RECORDS.get(part) != component_parent_dirs:
|
||||
logging.debug(
|
||||
'WARNING!!! Found component "%s" in path "%s" and "%s"'
|
||||
% (part, component_parent_dirs, _COMPONENT_NAME_DIR_RECORDS.get(part))
|
||||
)
|
||||
|
||||
return part
|
||||
|
||||
component_parent_dirs.append(part)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_mr_components(
|
||||
source_branch: t.Optional[str] = None, modified_files: t.Optional[t.List[str]] = None
|
||||
) -> t.List[str]:
|
||||
components: t.Set[str] = set()
|
||||
if modified_files is None:
|
||||
if not source_branch:
|
||||
raise RuntimeError('--src-branch is required if --modified-files is not provided')
|
||||
|
||||
modified_files = get_mr_changed_files(source_branch)
|
||||
|
||||
for f in modified_files:
|
||||
modified_component = get_modified_component(f)
|
||||
if modified_component:
|
||||
components.add(modified_component)
|
||||
|
||||
return list(components)
|
||||
|
||||
|
||||
def get_target_in_tags(tags: str) -> str:
|
||||
from idf_pytest.constants import TARGET_MARKERS
|
||||
|
||||
for x in tags.split(','):
|
||||
if x in TARGET_MARKERS:
|
||||
return x
|
||||
|
||||
raise RuntimeError(f'No target marker found in {tags}')
|
||||
|
||||
|
||||
def _print_list(_list: t.List[str], separator: str = '\n') -> None:
|
||||
print(separator.join(_list))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Get the latest merge request info by pipeline')
|
||||
actions = parser.add_subparsers(dest='action', help='info type', required=True)
|
||||
|
||||
common_args = argparse.ArgumentParser(add_help=False)
|
||||
common_args.add_argument('--src-branch', help='source branch')
|
||||
common_args.add_argument(
|
||||
'--modified-files',
|
||||
nargs='+',
|
||||
help='space-separated list specifies the modified files. will be detected by --src-branch if not provided',
|
||||
)
|
||||
|
||||
actions.add_parser('id', parents=[common_args])
|
||||
actions.add_parser('commits', parents=[common_args])
|
||||
actions.add_parser('components', parents=[common_args])
|
||||
target = actions.add_parser('target_in_tags')
|
||||
target.add_argument('tags', help='comma separated tags, e.g., esp32,generic')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.action == 'id':
|
||||
if not args.src_branch:
|
||||
raise RuntimeError('--src-branch is required')
|
||||
print(get_mr_iid(args.src_branch))
|
||||
elif args.action == 'commits':
|
||||
if not args.src_branch:
|
||||
raise RuntimeError('--src-branch is required')
|
||||
_print_list([commit.id for commit in get_mr_commits(args.src_branch)])
|
||||
elif args.action == 'components':
|
||||
_print_list(get_mr_components(args.src_branch, args.modified_files))
|
||||
elif args.action == 'target_in_tags':
|
||||
print(get_target_in_tags(args.tags))
|
||||
else:
|
||||
raise NotImplementedError('not possible to get here')
|
||||
@@ -1,217 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# CI script to deploy docs to a webserver. Not useful outside of CI environment
|
||||
#
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
import glob
|
||||
import os
|
||||
import os.path
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
from typing import Any, List, Tuple
|
||||
|
||||
import packaging.version
|
||||
|
||||
|
||||
def env(variable: str, default: str=None) -> str:
|
||||
""" Shortcut to return the expanded version of an environment variable """
|
||||
return os.path.expandvars(os.environ.get(variable, default) if default else os.environ[variable])
|
||||
|
||||
|
||||
# import sanitize_version from the docs directory, shared with here
|
||||
sys.path.append(os.path.join(env('IDF_PATH'), 'docs'))
|
||||
from sanitize_version import sanitize_version # noqa
|
||||
|
||||
|
||||
def main() -> None:
|
||||
# if you get KeyErrors on the following lines, it's probably because you're not running in Gitlab CI
|
||||
git_ver = env('GIT_VER') # output of git describe --always
|
||||
ci_ver = env('CI_COMMIT_REF_NAME', git_ver) # branch or tag we're building for (used for 'release' & URL)
|
||||
|
||||
version = sanitize_version(ci_ver)
|
||||
print('Git version: {}'.format(git_ver))
|
||||
print('CI Version: {}'.format(ci_ver))
|
||||
print('Deployment version: {}'.format(version))
|
||||
|
||||
if not version:
|
||||
raise RuntimeError('A version is needed to deploy')
|
||||
|
||||
build_dir = env('DOCS_BUILD_DIR') # top-level local build dir, where docs have already been built
|
||||
|
||||
if not build_dir:
|
||||
raise RuntimeError('Valid DOCS_BUILD_DIR is needed to deploy')
|
||||
|
||||
url_base = env('DOCS_DEPLOY_URL_BASE') # base for HTTP URLs, used to print the URL to the log after deploying
|
||||
|
||||
docs_server = env('DOCS_DEPLOY_SERVER') # ssh server to deploy to
|
||||
docs_user = env('DOCS_DEPLOY_SERVER_USER')
|
||||
docs_path = env('DOCS_DEPLOY_PATH') # filesystem path on DOCS_SERVER
|
||||
|
||||
if not docs_server:
|
||||
raise RuntimeError('Valid DOCS_DEPLOY_SERVER is needed to deploy')
|
||||
|
||||
if not docs_user:
|
||||
raise RuntimeError('Valid DOCS_DEPLOY_SERVER_USER is needed to deploy')
|
||||
|
||||
docs_server = '{}@{}'.format(docs_user, docs_server)
|
||||
|
||||
if not docs_path:
|
||||
raise RuntimeError('Valid DOCS_DEPLOY_PATH is needed to deploy')
|
||||
|
||||
print('DOCS_DEPLOY_SERVER {} DOCS_DEPLOY_PATH {}'.format(docs_server, docs_path))
|
||||
|
||||
tarball_path, version_urls = build_doc_tarball(version, git_ver, build_dir)
|
||||
|
||||
deploy(version, tarball_path, docs_path, docs_server)
|
||||
|
||||
print('Docs URLs:')
|
||||
doc_deploy_type = os.getenv('TYPE')
|
||||
for vurl in version_urls:
|
||||
language, _, target = vurl.split('/')
|
||||
tag = '{}_{}'.format(language, target)
|
||||
url = '{}/{}/index.html'.format(url_base, vurl) # (index.html needed for the preview server)
|
||||
url = re.sub(r'([^:])//', r'\1/', url) # get rid of any // that isn't in the https:// part
|
||||
print('[document {}][{}] {}'.format(doc_deploy_type, tag, url))
|
||||
|
||||
# note: it would be neater to use symlinks for stable, but because of the directory order
|
||||
# (language first) it's kind of a pain to do on a remote server, so we just repeat the
|
||||
# process but call the version 'stable' this time
|
||||
if is_stable_version(version):
|
||||
print('Deploying again as stable version...')
|
||||
tarball_path, version_urls = build_doc_tarball('stable', git_ver, build_dir)
|
||||
deploy('stable', tarball_path, docs_path, docs_server)
|
||||
|
||||
|
||||
def deploy(version: str, tarball_path: str, docs_path: str, docs_server: str) -> None:
|
||||
def run_ssh(commands: List) -> None:
|
||||
""" Log into docs_server and run a sequence of commands using ssh """
|
||||
print('Running ssh: {}'.format(commands))
|
||||
subprocess.run(['ssh', '-o', 'BatchMode=yes', docs_server, '-x', ' && '.join(commands)], check=True)
|
||||
|
||||
# copy the version tarball to the server
|
||||
run_ssh(['mkdir -p {}'.format(docs_path)])
|
||||
print('Running scp {} to {}'.format(tarball_path, '{}:{}'.format(docs_server, docs_path)))
|
||||
subprocess.run(['scp', '-B', tarball_path, '{}:{}'.format(docs_server, docs_path)], check=True)
|
||||
|
||||
tarball_name = os.path.basename(tarball_path)
|
||||
|
||||
run_ssh(['cd {}'.format(docs_path),
|
||||
'rm -rf ./*/{}'.format(version), # remove any pre-existing docs matching this version
|
||||
'tar -zxvf {}'.format(tarball_name), # untar the archive with the new docs
|
||||
'rm {}'.format(tarball_name)])
|
||||
|
||||
# Note: deleting and then extracting the archive is a bit awkward for updating stable/latest/etc
|
||||
# as the version will be invalid for a window of time. Better to do it atomically, but this is
|
||||
# another thing made much more complex by the directory structure putting language before version...
|
||||
|
||||
|
||||
def build_doc_tarball(version: str, git_ver: str, build_dir: str) -> Tuple[str, List]:
|
||||
""" Make a tar.gz archive of the docs, in the directory structure used to deploy as
|
||||
the given version """
|
||||
version_paths = []
|
||||
tarball_path = '{}/{}.tar.gz'.format(build_dir, version)
|
||||
|
||||
# find all the 'html/' directories under build_dir
|
||||
html_dirs = glob.glob('{}/**/html/'.format(build_dir), recursive=True)
|
||||
print('Found %d html directories' % len(html_dirs))
|
||||
|
||||
pdfs = glob.glob('{}/**/latex/build/*.pdf'.format(build_dir), recursive=True)
|
||||
print('Found %d PDFs in latex directories' % len(pdfs))
|
||||
|
||||
# add symlink for stable and latest and adds them to PDF blob
|
||||
symlinks = create_and_add_symlinks(version, git_ver, pdfs)
|
||||
|
||||
def not_sources_dir(ti: Any) -> Any:
|
||||
print(type(ti))
|
||||
""" Filter the _sources directories out of the tarballs """
|
||||
if ti.name.endswith('/_sources'):
|
||||
return None
|
||||
|
||||
ti.mode |= stat.S_IWGRP # make everything group-writeable
|
||||
return ti
|
||||
|
||||
try:
|
||||
os.remove(tarball_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
with tarfile.open(tarball_path, 'w:gz') as tarball:
|
||||
for html_dir in html_dirs:
|
||||
# html_dir has the form '<ignored>/<language>/<target>/html/'
|
||||
target_dirname = os.path.dirname(os.path.dirname(html_dir))
|
||||
target = os.path.basename(target_dirname)
|
||||
language = os.path.basename(os.path.dirname(target_dirname))
|
||||
|
||||
# when deploying, we want the top-level directory layout 'language/version/target'
|
||||
archive_path = '{}/{}/{}'.format(language, version, target)
|
||||
print("Archiving '{}' as '{}'...".format(html_dir, archive_path))
|
||||
tarball.add(html_dir, archive_path, filter=not_sources_dir)
|
||||
version_paths.append(archive_path)
|
||||
|
||||
for pdf_path in pdfs:
|
||||
# pdf_path has the form '<ignored>/<language>/<target>/latex/build'
|
||||
latex_dirname = os.path.dirname(pdf_path)
|
||||
pdf_filename = os.path.basename(pdf_path)
|
||||
target_dirname = os.path.dirname(os.path.dirname(latex_dirname))
|
||||
target = os.path.basename(target_dirname)
|
||||
language = os.path.basename(os.path.dirname(target_dirname))
|
||||
|
||||
# when deploying, we want the layout 'language/version/target/pdf'
|
||||
archive_path = '{}/{}/{}/{}'.format(language, version, target, pdf_filename)
|
||||
print("Archiving '{}' as '{}'...".format(pdf_path, archive_path))
|
||||
tarball.add(pdf_path, archive_path)
|
||||
|
||||
for symlink in symlinks:
|
||||
os.unlink(symlink)
|
||||
|
||||
return (os.path.abspath(tarball_path), version_paths)
|
||||
|
||||
|
||||
def create_and_add_symlinks(version: str, git_ver: str, pdfs: List) -> List:
|
||||
""" Create symbolic links for PDFs for 'latest' and 'stable' releases """
|
||||
|
||||
symlinks = []
|
||||
if 'stable' in version or 'latest' in version:
|
||||
for pdf_path in pdfs:
|
||||
symlink_path = pdf_path.replace(git_ver, version)
|
||||
os.symlink(pdf_path, symlink_path)
|
||||
symlinks.append(symlink_path)
|
||||
|
||||
pdfs.extend(symlinks)
|
||||
print('Found %d PDFs in latex directories after adding symlink' % len(pdfs))
|
||||
|
||||
return symlinks
|
||||
|
||||
|
||||
def is_stable_version(version: str) -> bool:
|
||||
""" Heuristic for whether this is the latest stable release """
|
||||
if not version.startswith('v'):
|
||||
return False # branch name
|
||||
if '-' in version:
|
||||
return False # prerelease tag
|
||||
|
||||
git_out = subprocess.check_output(['git', 'tag', '-l']).decode('utf-8')
|
||||
|
||||
versions = [v.strip() for v in git_out.split('\n')]
|
||||
versions = [v for v in versions if re.match(r'^v[\d\.]+$', v.strip())] # include vX.Y.Z only
|
||||
|
||||
versions_pack = [packaging.version.parse(v) for v in versions]
|
||||
|
||||
max_version = max(versions_pack)
|
||||
|
||||
if max_version.public != version[1:]:
|
||||
print('Stable version is v{}. This version is {}.'.format(max_version.public, version))
|
||||
return False
|
||||
else:
|
||||
print('This version {} is the stable version'.format(version))
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,49 +1,9 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import os
|
||||
|
||||
from idf_ci_utils import IDF_PATH
|
||||
|
||||
# use relative path to avoid absolute path in pipeline
|
||||
DEFAULT_TEST_PATHS = [
|
||||
'examples',
|
||||
os.path.join('tools', 'test_apps'),
|
||||
'components',
|
||||
]
|
||||
|
||||
DEFAULT_APPS_BUILD_PER_JOB = 60
|
||||
DEFAULT_CASES_TEST_PER_JOB = 30
|
||||
|
||||
DEFAULT_BUILD_CHILD_PIPELINE_FILEPATH = os.path.join(IDF_PATH, 'build_child_pipeline.yml')
|
||||
DEFAULT_TARGET_TEST_CHILD_PIPELINE_FILEPATH = os.path.join(IDF_PATH, 'target_test_child_pipeline.yml')
|
||||
|
||||
DEFAULT_BUILD_CHILD_PIPELINE_NAME = 'Build Child Pipeline'
|
||||
DEFAULT_TARGET_TEST_CHILD_PIPELINE_NAME = 'Target Test Child Pipeline'
|
||||
|
||||
TEST_RELATED_BUILD_JOB_NAME = 'build_test_related_apps'
|
||||
NON_TEST_RELATED_BUILD_JOB_NAME = 'build_non_test_related_apps'
|
||||
|
||||
COMMENT_START_MARKER = '### Dynamic Pipeline Report'
|
||||
TEST_RELATED_APPS_FILENAME = 'test_related_apps.txt'
|
||||
NON_TEST_RELATED_APPS_FILENAME = 'non_test_related_apps.txt'
|
||||
|
||||
TEST_RELATED_APPS_DOWNLOAD_URLS_FILENAME = 'test_related_apps_download_urls.yml'
|
||||
REPORT_TEMPLATE_FILEPATH = os.path.join(
|
||||
IDF_PATH, 'tools', 'ci', 'dynamic_pipelines', 'templates', 'report.template.html'
|
||||
)
|
||||
|
||||
RETRY_JOB_PICTURE_PATH = 'tools/ci/dynamic_pipelines/templates/retry-jobs.png'
|
||||
RETRY_JOB_TITLE = '\n\nRetry failed jobs with with help of "retry_failed_jobs" stage of the pipeline:'
|
||||
RETRY_JOB_PICTURE_LINK = ''
|
||||
|
||||
BUILD_ONLY_LABEL = 'For Maintainers: Only Build Tests'
|
||||
|
||||
KNOWN_GENERATE_TEST_CHILD_PIPELINE_WARNINGS_FILEPATH = os.path.join(
|
||||
IDF_PATH, 'tools', 'ci', 'dynamic_pipelines', 'templates', 'known_generate_test_child_pipeline_warnings.yml'
|
||||
)
|
||||
|
||||
CI_JOB_TOKEN = os.getenv('CI_JOB_TOKEN', '')
|
||||
CI_DASHBOARD_API = os.getenv('CI_DASHBOARD_API', '')
|
||||
CI_PAGES_URL = os.getenv('CI_PAGES_URL', '')
|
||||
CI_PROJECT_URL = os.getenv('CI_PROJECT_URL', '')
|
||||
CI_MERGE_REQUEST_SOURCE_BRANCH_SHA = os.getenv('CI_MERGE_REQUEST_SOURCE_BRANCH_SHA', '')
|
||||
|
||||
@@ -1,226 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import inspect
|
||||
import os
|
||||
import typing as t
|
||||
import urllib.parse
|
||||
from dataclasses import dataclass
|
||||
from xml.etree.ElementTree import Element
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
class Job:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
name: str,
|
||||
extends: t.Optional[t.List[str]] = None,
|
||||
tags: t.Optional[t.List[str]] = None,
|
||||
stage: t.Optional[str] = None,
|
||||
parallel: int = 1,
|
||||
variables: t.Optional[t.Dict[str, str]] = None,
|
||||
script: t.Optional[t.List[str]] = None,
|
||||
before_script: t.Optional[t.List[str]] = None,
|
||||
after_script: t.Optional[t.List[str]] = None,
|
||||
needs: t.Optional[t.List[str]] = None,
|
||||
**kwargs: t.Any,
|
||||
) -> None:
|
||||
self.name = name
|
||||
self.extends = extends
|
||||
self.tags = tags
|
||||
self.stage = stage
|
||||
self.parallel = parallel
|
||||
self.variables = variables or {}
|
||||
self.script = script
|
||||
self.before_script = before_script
|
||||
self.after_script = after_script
|
||||
self.needs = needs
|
||||
|
||||
for k, v in kwargs.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return yaml.dump(self.to_dict()) # type: ignore
|
||||
|
||||
def set_variable(self, key: str, value: str) -> None:
|
||||
self.variables[key] = value
|
||||
|
||||
def to_dict(self) -> t.Dict[str, t.Any]:
|
||||
res = {}
|
||||
for k, v in inspect.getmembers(self):
|
||||
if k.startswith('_'):
|
||||
continue
|
||||
|
||||
# name is the dict key
|
||||
if k == 'name':
|
||||
continue
|
||||
|
||||
# parallel 1 is not allowed
|
||||
if k == 'parallel' and v == 1:
|
||||
continue
|
||||
|
||||
if v is None:
|
||||
continue
|
||||
|
||||
if inspect.ismethod(v) or inspect.isfunction(v):
|
||||
continue
|
||||
|
||||
res[k] = v
|
||||
|
||||
return {self.name: res}
|
||||
|
||||
|
||||
class EmptyJob(Job):
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
name: t.Optional[str] = None,
|
||||
tags: t.Optional[t.List[str]] = None,
|
||||
stage: t.Optional[str] = None,
|
||||
before_script: t.Optional[t.List[str]] = None,
|
||||
after_script: t.Optional[t.List[str]] = None,
|
||||
**kwargs: t.Any,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
name=name or 'fake_pass_job',
|
||||
tags=tags or ['fast_run', 'shiny'],
|
||||
stage=stage or 'build',
|
||||
script=['echo "This is a fake job to pass the pipeline"'],
|
||||
before_script=before_script or [],
|
||||
after_script=after_script or [],
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
class BuildJob(Job):
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
extends: t.Optional[t.List[str]] = None,
|
||||
tags: t.Optional[t.List[str]] = None,
|
||||
stage: t.Optional[str] = None,
|
||||
**kwargs: t.Any,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
extends=extends or ['.dynamic_build_template'],
|
||||
tags=tags or ['build', 'shiny'],
|
||||
stage=stage or 'build',
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
class TargetTestJob(Job):
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
extends: t.Optional[t.List[str]] = None,
|
||||
stage: t.Optional[str] = None,
|
||||
**kwargs: t.Any,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
extends=extends or ['.dynamic_target_test_template'],
|
||||
stage=stage or 'target_test',
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TestCase:
|
||||
name: str
|
||||
file: str
|
||||
time: float
|
||||
failure: t.Optional[str] = None
|
||||
skipped: t.Optional[str] = None
|
||||
ci_job_url: t.Optional[str] = None
|
||||
ci_dashboard_url: t.Optional[str] = None
|
||||
dut_log_url: t.Optional[str] = None
|
||||
latest_total_count: int = 0
|
||||
latest_failed_count: int = 0
|
||||
|
||||
@property
|
||||
def is_failure(self) -> bool:
|
||||
return self.failure is not None
|
||||
|
||||
@property
|
||||
def is_skipped(self) -> bool:
|
||||
return self.skipped is not None
|
||||
|
||||
@property
|
||||
def is_success(self) -> bool:
|
||||
return not self.is_failure and not self.is_skipped
|
||||
|
||||
@classmethod
|
||||
def from_test_case_node(cls, node: Element) -> t.Optional['TestCase']:
|
||||
if 'name' not in node.attrib:
|
||||
print('WARNING: Node Invalid: ', node)
|
||||
return None
|
||||
|
||||
# url to test cases dashboard
|
||||
grafana_base_url = urllib.parse.urljoin(os.getenv('CI_DASHBOARD_HOST', ''), '/d/Ucg477Fnz/case-list')
|
||||
encoded_params = urllib.parse.urlencode({'var-case_id': node.attrib['name']}, quote_via=urllib.parse.quote)
|
||||
|
||||
kwargs = {
|
||||
'name': node.attrib['name'],
|
||||
'file': node.attrib.get('file'),
|
||||
'time': float(node.attrib.get('time') or 0),
|
||||
'ci_job_url': node.attrib.get('ci_job_url') or 'Not found',
|
||||
'ci_dashboard_url': f'{grafana_base_url}?{encoded_params}',
|
||||
'dut_log_url': node.attrib.get('dut_log_url') or 'Not found',
|
||||
}
|
||||
|
||||
failure_node = node.find('failure')
|
||||
# bool(failure_node) is False, so compare with None
|
||||
if failure_node is None:
|
||||
failure_node = node.find('error')
|
||||
if failure_node is not None:
|
||||
message = failure_node.attrib.get('message', '')
|
||||
kwargs['failure'] = message
|
||||
|
||||
skipped_node = node.find('skipped')
|
||||
if skipped_node is not None:
|
||||
kwargs['skipped'] = skipped_node.attrib['message']
|
||||
|
||||
return cls(**kwargs) # type: ignore
|
||||
|
||||
|
||||
@dataclass
|
||||
class GitlabJob:
|
||||
id: int
|
||||
name: str
|
||||
stage: str
|
||||
status: str
|
||||
url: str
|
||||
ci_dashboard_url: str
|
||||
failure_reason: t.Optional[str] = None
|
||||
failure_log: t.Optional[str] = None
|
||||
latest_total_count: int = 0
|
||||
latest_failed_count: int = 0
|
||||
|
||||
@property
|
||||
def is_failed(self) -> bool:
|
||||
return self.status == 'failed'
|
||||
|
||||
@property
|
||||
def is_success(self) -> bool:
|
||||
return self.status == 'success'
|
||||
|
||||
@classmethod
|
||||
def from_json_data(cls, job_data: dict, failure_data: dict) -> t.Optional['GitlabJob']:
|
||||
grafana_base_url = urllib.parse.urljoin(os.getenv('CI_DASHBOARD_HOST', ''), '/d/LoUa-qLWz/job-list')
|
||||
encoded_params = urllib.parse.urlencode({'var-job_name': job_data['name']}, quote_via=urllib.parse.quote)
|
||||
|
||||
kwargs = {
|
||||
'id': job_data['id'],
|
||||
'name': job_data['name'],
|
||||
'stage': job_data['stage'],
|
||||
'status': job_data['status'],
|
||||
'url': job_data['url'],
|
||||
'ci_dashboard_url': f'{grafana_base_url}?{encoded_params}',
|
||||
'failure_reason': job_data['failure_reason'],
|
||||
'failure_log': job_data['failure_log'],
|
||||
'latest_total_count': failure_data.get('total_count', 0),
|
||||
'latest_failed_count': failure_data.get('failed_count', 0),
|
||||
}
|
||||
|
||||
return cls(**kwargs) # type: ignore
|
||||
@@ -1,739 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import abc
|
||||
import copy
|
||||
import fnmatch
|
||||
import html
|
||||
import os
|
||||
import re
|
||||
import typing as t
|
||||
from textwrap import dedent
|
||||
|
||||
import yaml
|
||||
from artifacts_handler import ArtifactType
|
||||
from gitlab import GitlabUpdateError
|
||||
from gitlab_api import Gitlab
|
||||
from idf_build_apps import App
|
||||
from idf_build_apps.constants import BuildStatus
|
||||
from idf_ci_local.uploader import AppUploader
|
||||
from prettytable import PrettyTable
|
||||
|
||||
from .constants import COMMENT_START_MARKER
|
||||
from .constants import REPORT_TEMPLATE_FILEPATH
|
||||
from .constants import RETRY_JOB_PICTURE_LINK
|
||||
from .constants import RETRY_JOB_PICTURE_PATH
|
||||
from .constants import RETRY_JOB_TITLE
|
||||
from .constants import TEST_RELATED_APPS_DOWNLOAD_URLS_FILENAME
|
||||
from .models import GitlabJob
|
||||
from .models import TestCase
|
||||
from .utils import fetch_failed_testcases_failure_ratio
|
||||
from .utils import format_permalink
|
||||
from .utils import get_artifacts_url
|
||||
from .utils import get_repository_file_url
|
||||
from .utils import is_url
|
||||
from .utils import load_known_failure_cases
|
||||
|
||||
|
||||
class ReportGenerator:
|
||||
REGEX_PATTERN = r'#### {}\n[\s\S]*?(?=\n#### |$)'
|
||||
|
||||
def __init__(self, project_id: int, mr_iid: int, pipeline_id: int, job_id: int, commit_id: str, *, title: str):
|
||||
gl_project = Gitlab(project_id).project
|
||||
if mr_iid is not None:
|
||||
self.mr = gl_project.mergerequests.get(mr_iid)
|
||||
else:
|
||||
self.mr = None
|
||||
self.pipeline_id = pipeline_id
|
||||
self.job_id = job_id
|
||||
self.commit_id = commit_id
|
||||
|
||||
self.title = title
|
||||
self.output_filepath = self.title.lower().replace(' ', '_') + '.html'
|
||||
self.additional_info = ''
|
||||
|
||||
@staticmethod
|
||||
def get_download_link_for_url(url: str) -> str:
|
||||
if url:
|
||||
return f'<a href="{url}">Download</a>'
|
||||
|
||||
return ''
|
||||
|
||||
def write_report_to_file(self, report_str: str, job_id: int, output_filepath: str) -> t.Optional[str]:
|
||||
"""
|
||||
Writes the report to a file and constructs a modified URL based on environment settings.
|
||||
|
||||
:param report_str: The report content to be written to the file.
|
||||
:param job_id: The job identifier used to construct the URL.
|
||||
:param output_filepath: The path to the output file.
|
||||
:return: The modified URL pointing to the job's artifacts.
|
||||
"""
|
||||
if not report_str:
|
||||
return None
|
||||
with open(output_filepath, 'w') as file:
|
||||
file.write(report_str)
|
||||
|
||||
# for example, {URL}/-/esp-idf/-/jobs/{id}/artifacts/list_job_84.txt
|
||||
# CI_PAGES_URL is {URL}/esp-idf, which missed one `-`
|
||||
report_url: str = get_artifacts_url(job_id, output_filepath)
|
||||
return report_url
|
||||
|
||||
def generate_html_report(self, table_str: str) -> str:
|
||||
# we're using bootstrap table
|
||||
table_str = table_str.replace(
|
||||
'<table>',
|
||||
'<table data-toggle="table" data-search-align="left" data-search="true" data-sticky-header="true">',
|
||||
)
|
||||
with open(REPORT_TEMPLATE_FILEPATH) as fr:
|
||||
template = fr.read()
|
||||
|
||||
return template.replace('{{title}}', self.title).replace('{{table}}', table_str)
|
||||
|
||||
@staticmethod
|
||||
def table_to_html_str(table: PrettyTable) -> str:
|
||||
return html.unescape(table.get_html_string()) # type: ignore
|
||||
|
||||
def create_table_section(
|
||||
self,
|
||||
title: str,
|
||||
items: list,
|
||||
headers: list,
|
||||
row_attrs: list,
|
||||
value_functions: t.Optional[list] = None,
|
||||
) -> t.List:
|
||||
"""
|
||||
Appends a formatted section to a report based on the provided items. This section includes
|
||||
a header and a table constructed from the items list with specified headers and attributes.
|
||||
|
||||
:param title: Title for the report section. This title is used as a header above the table.
|
||||
:param items: List of item objects to include in the table. Each item should have attributes
|
||||
that correspond to the row_attrs and value_functions specified.
|
||||
:param headers: List of strings that will serve as the column headers in the generated table.
|
||||
:param row_attrs: List of attributes to include from each item for the table rows. These
|
||||
should be attributes or keys that exist on the items in the 'items' list.
|
||||
:param value_functions: Optional list of tuples containing additional header and corresponding
|
||||
value function. Each tuple should specify a header (as a string) and
|
||||
a function that takes an item and returns a string. This is used for
|
||||
generating dynamic columns based on item data.
|
||||
|
||||
:return: List with appended HTML sections.
|
||||
"""
|
||||
if not items:
|
||||
return []
|
||||
|
||||
report_sections = [
|
||||
f"""<h2 id="{format_permalink(title)}">{title}<i class="fas fa-link copy-link-icon"
|
||||
onclick="copyPermalink('#{format_permalink(title)}')"></i></h2>""",
|
||||
self._create_table_for_items(
|
||||
items=items, headers=headers, row_attrs=row_attrs, value_functions=value_functions or []
|
||||
),
|
||||
]
|
||||
return report_sections
|
||||
|
||||
@staticmethod
|
||||
def generate_additional_info_section(title: str, count: int, report_url: t.Optional[str] = None) -> str:
|
||||
"""
|
||||
Generate a section for the additional info string.
|
||||
|
||||
:param title: The title of the section.
|
||||
:param count: The count of test cases.
|
||||
:param report_url: The URL of the report. If count = 0, only the count will be included.
|
||||
:return: The formatted additional info section string.
|
||||
"""
|
||||
if count != 0 and report_url:
|
||||
return f'- **{title}:** [{count}]({report_url}/#{format_permalink(title)})\n'
|
||||
else:
|
||||
return f'- **{title}:** {count}\n'
|
||||
|
||||
def _create_table_for_items(
|
||||
self,
|
||||
items: t.Union[t.List[TestCase], t.List[GitlabJob]],
|
||||
headers: t.List[str],
|
||||
row_attrs: t.List[str],
|
||||
value_functions: t.Optional[t.List[t.Tuple[str, t.Callable[[t.Union[TestCase, GitlabJob]], str]]]] = None,
|
||||
) -> str:
|
||||
"""
|
||||
Create a PrettyTable and convert it to an HTML string for the provided test cases.
|
||||
:param items: List of item objects to include in the table.
|
||||
:param headers: List of strings for the table headers.
|
||||
:param row_attrs: List of attributes to include in each row.
|
||||
:param value_functions: List of tuples containing additional header and corresponding value function.
|
||||
:return: HTML table string.
|
||||
"""
|
||||
table = PrettyTable()
|
||||
table.field_names = headers
|
||||
|
||||
# Create a mapping of header names to their corresponding index in the headers list
|
||||
header_index_map = {header: i for i, header in enumerate(headers)}
|
||||
|
||||
for item in items:
|
||||
row = []
|
||||
for attr in row_attrs:
|
||||
value = str(getattr(item, attr, ''))
|
||||
if is_url(value):
|
||||
link = f'<a href="{value}">link</a>'
|
||||
row.append(link)
|
||||
else:
|
||||
row.append(value)
|
||||
|
||||
# Insert values computed by value functions at the correct column position based on their headers
|
||||
if value_functions:
|
||||
for header, func in value_functions:
|
||||
index = header_index_map.get(header)
|
||||
if index is not None:
|
||||
computed_value = func(item)
|
||||
row.insert(index, computed_value)
|
||||
|
||||
table.add_row(row)
|
||||
|
||||
return self.table_to_html_str(table)
|
||||
|
||||
@staticmethod
|
||||
def _filter_items(
|
||||
items: t.Union[t.List[TestCase], t.List[GitlabJob]], condition: t.Callable[[t.Union[TestCase, GitlabJob]], bool]
|
||||
) -> t.List[TestCase]:
|
||||
"""
|
||||
Filter items s based on a given condition.
|
||||
|
||||
:param items: List of items to filter by given condition.
|
||||
:param condition: A function that evaluates to True or False for each items.
|
||||
:return: List of filtered instances.
|
||||
"""
|
||||
return [item for item in items if condition(item)]
|
||||
|
||||
@staticmethod
|
||||
def _sort_items(
|
||||
items: t.List[t.Union[TestCase, GitlabJob]],
|
||||
key: t.Union[str, t.Callable[[t.Union[TestCase, GitlabJob]], t.Any]],
|
||||
order: str = 'asc',
|
||||
) -> t.List[t.Union[TestCase, GitlabJob]]:
|
||||
"""
|
||||
Sort items based on a given key and order.
|
||||
|
||||
:param items: List of items to sort.
|
||||
:param key: A string representing the attribute name or a function to extract the sorting key.
|
||||
:param order: Order of sorting ('asc' for ascending, 'desc' for descending).
|
||||
:return: List of sorted instances.
|
||||
"""
|
||||
key_func = None
|
||||
if isinstance(key, str):
|
||||
|
||||
def key_func(item: t.Any) -> t.Any:
|
||||
return getattr(item, key)
|
||||
|
||||
if key_func is not None:
|
||||
try:
|
||||
items = sorted(items, key=key_func, reverse=(order == 'desc'))
|
||||
except TypeError:
|
||||
print(f'Comparison for the key {key} is not supported')
|
||||
return items
|
||||
|
||||
@abc.abstractmethod
|
||||
def _get_report_str(self) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
def _generate_comment(self, print_report_path: bool) -> str:
|
||||
# Report in HTML format to avoid exceeding length limits
|
||||
comment = f'#### {self.title}\n'
|
||||
report_str = self._get_report_str()
|
||||
|
||||
if self.additional_info:
|
||||
comment += f'{self.additional_info}\n'
|
||||
|
||||
report_url_path = self.write_report_to_file(report_str, self.job_id, self.output_filepath)
|
||||
if print_report_path and report_url_path:
|
||||
comment += dedent(
|
||||
f"""
|
||||
Full {self.title} here: {report_url_path} (with commit {self.commit_id[:8]})
|
||||
|
||||
"""
|
||||
)
|
||||
return comment
|
||||
|
||||
def _update_mr_comment(self, comment: str, print_retry_jobs_message: bool) -> None:
|
||||
retry_job_picture_comment = (f'{RETRY_JOB_TITLE}\n\n' f'{RETRY_JOB_PICTURE_LINK}').format(
|
||||
pic_url=get_repository_file_url(RETRY_JOB_PICTURE_PATH)
|
||||
)
|
||||
del_retry_job_pic_pattern = re.escape(RETRY_JOB_TITLE) + r'.*?' + re.escape(f'{RETRY_JOB_PICTURE_PATH})')
|
||||
|
||||
new_comment = f'{COMMENT_START_MARKER}\n\n{comment}'
|
||||
if print_retry_jobs_message:
|
||||
new_comment += retry_job_picture_comment
|
||||
|
||||
for note in self.mr.notes.list(iterator=True):
|
||||
if note.body.startswith(COMMENT_START_MARKER):
|
||||
updated_str = self._get_updated_comment(note.body, comment)
|
||||
|
||||
# Add retry job message only if any job has failed
|
||||
if print_retry_jobs_message:
|
||||
updated_str = re.sub(del_retry_job_pic_pattern, '', updated_str, flags=re.DOTALL)
|
||||
updated_str += retry_job_picture_comment
|
||||
|
||||
note.body = updated_str
|
||||
try:
|
||||
note.save()
|
||||
except GitlabUpdateError:
|
||||
print('Failed to update MR comment, Creating a new comment')
|
||||
self.mr.notes.create({'body': new_comment})
|
||||
break
|
||||
else:
|
||||
self.mr.notes.create({'body': new_comment})
|
||||
|
||||
def _get_updated_comment(self, existing_comment: str, new_comment: str) -> str:
|
||||
updated_str = re.sub(self.REGEX_PATTERN.format(self.title), new_comment, existing_comment)
|
||||
if updated_str == existing_comment:
|
||||
updated_str = f'{existing_comment.strip()}\n\n{new_comment}'
|
||||
return updated_str
|
||||
|
||||
def post_report(self, print_report_path: bool = True, print_retry_jobs_message: bool = False) -> None:
|
||||
comment = self._generate_comment(print_report_path)
|
||||
|
||||
print(comment)
|
||||
|
||||
if self.mr is None:
|
||||
print('No MR found, skip posting comment')
|
||||
return
|
||||
|
||||
self._update_mr_comment(comment, print_retry_jobs_message=print_retry_jobs_message)
|
||||
|
||||
|
||||
class BuildReportGenerator(ReportGenerator):
|
||||
def __init__(
|
||||
self,
|
||||
project_id: int,
|
||||
mr_iid: int,
|
||||
pipeline_id: int,
|
||||
job_id: int,
|
||||
commit_id: str,
|
||||
*,
|
||||
title: str = 'Build Report',
|
||||
apps: t.List[App],
|
||||
):
|
||||
super().__init__(project_id, mr_iid, pipeline_id, job_id, commit_id, title=title)
|
||||
self.apps = apps
|
||||
|
||||
self.apps_presigned_url_filepath = TEST_RELATED_APPS_DOWNLOAD_URLS_FILENAME
|
||||
|
||||
def _get_report_str(self) -> str:
|
||||
if not self.apps:
|
||||
print('No apps found, skip generating build report')
|
||||
return 'No Apps Built'
|
||||
|
||||
uploader = AppUploader(self.pipeline_id)
|
||||
|
||||
table_str = ''
|
||||
|
||||
failed_apps = [app for app in self.apps if app.build_status == BuildStatus.FAILED]
|
||||
if failed_apps:
|
||||
table_str += '<h2>Failed Apps</h2>'
|
||||
|
||||
failed_apps_table = PrettyTable()
|
||||
failed_apps_table.field_names = [
|
||||
'App Dir',
|
||||
'Build Dir',
|
||||
'Failed Reason',
|
||||
'Build Log',
|
||||
]
|
||||
for app in failed_apps:
|
||||
failed_apps_table.add_row(
|
||||
[
|
||||
app.app_dir,
|
||||
app.build_dir,
|
||||
app.build_comment or '',
|
||||
self.get_download_link_for_url(uploader.get_app_presigned_url(app, ArtifactType.LOGS)),
|
||||
]
|
||||
)
|
||||
|
||||
table_str += self.table_to_html_str(failed_apps_table)
|
||||
|
||||
built_test_related_apps = [app for app in self.apps if app.build_status == BuildStatus.SUCCESS and app.preserve]
|
||||
if built_test_related_apps:
|
||||
table_str += '<h2>Built Apps (Test Related)</h2>'
|
||||
|
||||
built_apps_table = PrettyTable()
|
||||
built_apps_table.field_names = [
|
||||
'App Dir',
|
||||
'Build Dir',
|
||||
'Bin Files with Build Log (without map and elf)',
|
||||
'Map and Elf Files',
|
||||
]
|
||||
app_presigned_urls_dict: t.Dict[str, t.Dict[str, str]] = {}
|
||||
for app in built_test_related_apps:
|
||||
_d = {
|
||||
ArtifactType.BUILD_DIR_WITHOUT_MAP_AND_ELF_FILES.value: uploader.get_app_presigned_url(
|
||||
app, ArtifactType.BUILD_DIR_WITHOUT_MAP_AND_ELF_FILES
|
||||
),
|
||||
ArtifactType.MAP_AND_ELF_FILES.value: uploader.get_app_presigned_url(
|
||||
app, ArtifactType.MAP_AND_ELF_FILES
|
||||
),
|
||||
}
|
||||
|
||||
built_apps_table.add_row(
|
||||
[
|
||||
app.app_dir,
|
||||
app.build_dir,
|
||||
self.get_download_link_for_url(_d[ArtifactType.BUILD_DIR_WITHOUT_MAP_AND_ELF_FILES]),
|
||||
self.get_download_link_for_url(_d[ArtifactType.MAP_AND_ELF_FILES]),
|
||||
]
|
||||
)
|
||||
|
||||
app_presigned_urls_dict[app.build_path] = _d
|
||||
|
||||
# also generate a yaml file that includes the apps and the presigned urls
|
||||
# for helping debugging locally
|
||||
with open(self.apps_presigned_url_filepath, 'w') as fw:
|
||||
yaml.dump(app_presigned_urls_dict, fw)
|
||||
|
||||
table_str += self.table_to_html_str(built_apps_table)
|
||||
|
||||
built_non_test_related_apps = [
|
||||
app for app in self.apps if app.build_status == BuildStatus.SUCCESS and not app.preserve
|
||||
]
|
||||
if built_non_test_related_apps:
|
||||
table_str += '<h2>Built Apps (Non Test Related)</h2>'
|
||||
|
||||
built_apps_table = PrettyTable()
|
||||
built_apps_table.field_names = [
|
||||
'App Dir',
|
||||
'Build Dir',
|
||||
'Build Log',
|
||||
]
|
||||
for app in built_non_test_related_apps:
|
||||
built_apps_table.add_row(
|
||||
[
|
||||
app.app_dir,
|
||||
app.build_dir,
|
||||
self.get_download_link_for_url(uploader.get_app_presigned_url(app, ArtifactType.LOGS)),
|
||||
]
|
||||
)
|
||||
|
||||
table_str += self.table_to_html_str(built_apps_table)
|
||||
|
||||
skipped_apps = [app for app in self.apps if app.build_status == BuildStatus.SKIPPED]
|
||||
if skipped_apps:
|
||||
table_str += '<h2>Skipped Apps</h2>'
|
||||
|
||||
skipped_apps_table = PrettyTable()
|
||||
skipped_apps_table.field_names = ['App Dir', 'Build Dir', 'Skipped Reason', 'Build Log']
|
||||
for app in skipped_apps:
|
||||
skipped_apps_table.add_row(
|
||||
[
|
||||
app.app_dir,
|
||||
app.build_dir,
|
||||
app.build_comment or '',
|
||||
self.get_download_link_for_url(uploader.get_app_presigned_url(app, ArtifactType.LOGS)),
|
||||
]
|
||||
)
|
||||
|
||||
table_str += self.table_to_html_str(skipped_apps_table)
|
||||
|
||||
return self.generate_html_report(table_str)
|
||||
|
||||
|
||||
class TargetTestReportGenerator(ReportGenerator):
|
||||
def __init__(
|
||||
self,
|
||||
project_id: int,
|
||||
mr_iid: int,
|
||||
pipeline_id: int,
|
||||
job_id: int,
|
||||
commit_id: str,
|
||||
*,
|
||||
title: str = 'Target Test Report',
|
||||
test_cases: t.List[TestCase],
|
||||
):
|
||||
super().__init__(project_id, mr_iid, pipeline_id, job_id, commit_id, title=title)
|
||||
|
||||
self.test_cases = test_cases
|
||||
self._known_failure_cases_set = None
|
||||
self.report_titles_map = {
|
||||
'failed_yours': 'Failed Test Cases on Your branch (Excludes Known Failure Cases)',
|
||||
'failed_others': 'Failed Test Cases on Other branches (Excludes Known Failure Cases)',
|
||||
'failed_known': 'Known Failure Cases',
|
||||
'skipped': 'Skipped Test Cases',
|
||||
'succeeded': 'Succeeded Test Cases',
|
||||
}
|
||||
self.skipped_test_cases_report_file = 'skipped_cases.html'
|
||||
self.succeeded_cases_report_file = 'succeeded_cases.html'
|
||||
self.failed_cases_report_file = 'failed_cases.html'
|
||||
|
||||
@property
|
||||
def known_failure_cases_set(self) -> t.Optional[t.Set[str]]:
|
||||
if self._known_failure_cases_set is None:
|
||||
self._known_failure_cases_set = load_known_failure_cases()
|
||||
|
||||
return self._known_failure_cases_set
|
||||
|
||||
def get_known_failure_cases(self) -> t.List[TestCase]:
|
||||
"""
|
||||
Retrieve the known failure test cases.
|
||||
:return: A list of known failure test cases.
|
||||
"""
|
||||
if self.known_failure_cases_set is None:
|
||||
return []
|
||||
matched_cases = [
|
||||
testcase
|
||||
for testcase in self.test_cases
|
||||
if any(fnmatch.fnmatch(testcase.name, pattern) for pattern in self.known_failure_cases_set)
|
||||
and testcase.is_failure
|
||||
]
|
||||
return matched_cases
|
||||
|
||||
@staticmethod
|
||||
def filter_test_cases(
|
||||
cur_branch_failures: t.List[TestCase],
|
||||
other_branch_failures: t.List[TestCase],
|
||||
) -> t.Tuple[t.List[TestCase], t.List[TestCase]]:
|
||||
"""
|
||||
Filter the test cases into current branch failures and other branch failures.
|
||||
|
||||
:param cur_branch_failures: List of failed test cases on the current branch.
|
||||
:param other_branch_failures: List of failed test cases on other branches.
|
||||
:return: A tuple containing two lists:
|
||||
- failed_test_cases_cur_branch_only: Test cases that have failed only on the current branch.
|
||||
- failed_test_cases_other_branch_exclude_cur_branch: Test cases that have failed on other branches
|
||||
excluding the current branch.
|
||||
"""
|
||||
cur_branch_unique_failures = []
|
||||
other_branch_failure_map = {tc.name: tc for tc in other_branch_failures}
|
||||
|
||||
for cur_tc in cur_branch_failures:
|
||||
if cur_tc.latest_failed_count > 0 and (
|
||||
cur_tc.name not in other_branch_failure_map
|
||||
or other_branch_failure_map[cur_tc.name].latest_failed_count == 0
|
||||
):
|
||||
cur_branch_unique_failures.append(cur_tc)
|
||||
uniq_fail_names = {cur_tc.name for cur_tc in cur_branch_unique_failures}
|
||||
other_branch_exclusive_failures = [tc for tc in other_branch_failures if tc.name not in uniq_fail_names]
|
||||
|
||||
return cur_branch_unique_failures, other_branch_exclusive_failures
|
||||
|
||||
def get_failed_cases_report_parts(self) -> t.List[str]:
|
||||
"""
|
||||
Generate the report parts for failed test cases and update the additional info section.
|
||||
:return: A list of strings representing the table sections for the failed test cases.
|
||||
"""
|
||||
known_failures = self.get_known_failure_cases()
|
||||
failed_test_cases = self._filter_items(
|
||||
self.test_cases, lambda tc: tc.is_failure and tc.name not in {case.name for case in known_failures}
|
||||
)
|
||||
failed_test_cases_cur_branch = self._sort_items(
|
||||
fetch_failed_testcases_failure_ratio(
|
||||
copy.deepcopy(failed_test_cases),
|
||||
branches_filter={'include_branches': [os.getenv('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME', '')]},
|
||||
),
|
||||
key='latest_failed_count',
|
||||
)
|
||||
failed_test_cases_other_branch = self._sort_items(
|
||||
fetch_failed_testcases_failure_ratio(
|
||||
copy.deepcopy(failed_test_cases),
|
||||
branches_filter={'exclude_branches': [os.getenv('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME', '')]},
|
||||
),
|
||||
key='latest_failed_count',
|
||||
)
|
||||
failed_test_cases_cur_branch, failed_test_cases_other_branch = self.filter_test_cases(
|
||||
failed_test_cases_cur_branch, failed_test_cases_other_branch
|
||||
)
|
||||
cur_branch_cases_table_section = self.create_table_section(
|
||||
title=self.report_titles_map['failed_yours'],
|
||||
items=failed_test_cases_cur_branch,
|
||||
headers=[
|
||||
'Test Case',
|
||||
'Test Script File Path',
|
||||
'Failure Reason',
|
||||
f'Failures on your branch (40 latest testcases)',
|
||||
'Dut Log URL',
|
||||
'Job URL',
|
||||
'Grafana URL',
|
||||
],
|
||||
row_attrs=['name', 'file', 'failure', 'dut_log_url', 'ci_job_url', 'ci_dashboard_url'],
|
||||
value_functions=[
|
||||
(
|
||||
'Failures on your branch (40 latest testcases)',
|
||||
lambda item: f"{getattr(item, 'latest_failed_count', '')} / {getattr(item, 'latest_total_count', '')}",
|
||||
)
|
||||
],
|
||||
)
|
||||
other_branch_cases_table_section = self.create_table_section(
|
||||
title=self.report_titles_map['failed_others'],
|
||||
items=failed_test_cases_other_branch,
|
||||
headers=[
|
||||
'Test Case',
|
||||
'Test Script File Path',
|
||||
'Failure Reason',
|
||||
'Cases that failed in other branches as well (40 latest testcases)',
|
||||
'Dut Log URL',
|
||||
'Job URL',
|
||||
'Grafana URL',
|
||||
],
|
||||
row_attrs=['name', 'file', 'failure', 'dut_log_url', 'ci_job_url', 'ci_dashboard_url'],
|
||||
value_functions=[
|
||||
(
|
||||
'Cases that failed in other branches as well (40 latest testcases)',
|
||||
lambda item: f"{getattr(item, 'latest_failed_count', '')} / {getattr(item, 'latest_total_count', '')}",
|
||||
)
|
||||
],
|
||||
)
|
||||
known_failures_cases_table_section = self.create_table_section(
|
||||
title=self.report_titles_map['failed_known'],
|
||||
items=known_failures,
|
||||
headers=['Test Case', 'Test Script File Path', 'Failure Reason', 'Job URL', 'Grafana URL'],
|
||||
row_attrs=['name', 'file', 'failure', 'ci_job_url', 'ci_dashboard_url'],
|
||||
)
|
||||
failed_cases_report_url = self.write_report_to_file(
|
||||
self.generate_html_report(
|
||||
''.join(
|
||||
cur_branch_cases_table_section
|
||||
+ other_branch_cases_table_section
|
||||
+ known_failures_cases_table_section
|
||||
)
|
||||
),
|
||||
self.job_id,
|
||||
self.failed_cases_report_file,
|
||||
)
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['failed_yours'], len(failed_test_cases_cur_branch), failed_cases_report_url
|
||||
)
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['failed_others'], len(failed_test_cases_other_branch), failed_cases_report_url
|
||||
)
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['failed_known'], len(known_failures), failed_cases_report_url
|
||||
)
|
||||
return cur_branch_cases_table_section + other_branch_cases_table_section + known_failures_cases_table_section
|
||||
|
||||
def get_skipped_cases_report_parts(self) -> t.List[str]:
|
||||
"""
|
||||
Generate the report parts for skipped test cases and update the additional info section.
|
||||
:return: A list of strings representing the table sections for the skipped test cases.
|
||||
"""
|
||||
skipped_test_cases = self._filter_items(self.test_cases, lambda tc: tc.is_skipped)
|
||||
skipped_cases_table_section = self.create_table_section(
|
||||
title=self.report_titles_map['skipped'],
|
||||
items=skipped_test_cases,
|
||||
headers=['Test Case', 'Test Script File Path', 'Skipped Reason', 'Grafana URL'],
|
||||
row_attrs=['name', 'file', 'skipped', 'ci_dashboard_url'],
|
||||
)
|
||||
skipped_cases_report_url = self.write_report_to_file(
|
||||
self.generate_html_report(''.join(skipped_cases_table_section)),
|
||||
self.job_id,
|
||||
self.skipped_test_cases_report_file,
|
||||
)
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['skipped'], len(skipped_test_cases), skipped_cases_report_url
|
||||
)
|
||||
return skipped_cases_table_section
|
||||
|
||||
def get_succeeded_cases_report_parts(self) -> t.List[str]:
|
||||
"""
|
||||
Generate the report parts for succeeded test cases and update the additional info section.
|
||||
:return: A list of strings representing the table sections for the succeeded test cases.
|
||||
"""
|
||||
succeeded_test_cases = self._filter_items(self.test_cases, lambda tc: tc.is_success)
|
||||
succeeded_cases_table_section = self.create_table_section(
|
||||
title=self.report_titles_map['succeeded'],
|
||||
items=succeeded_test_cases,
|
||||
headers=['Test Case', 'Test Script File Path', 'Job URL', 'Grafana URL'],
|
||||
row_attrs=['name', 'file', 'ci_job_url', 'ci_dashboard_url'],
|
||||
)
|
||||
succeeded_cases_report_url = self.write_report_to_file(
|
||||
self.generate_html_report(''.join(succeeded_cases_table_section)),
|
||||
self.job_id,
|
||||
self.succeeded_cases_report_file,
|
||||
)
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['succeeded'], len(succeeded_test_cases), succeeded_cases_report_url
|
||||
)
|
||||
self.additional_info += '\n'
|
||||
return succeeded_cases_table_section
|
||||
|
||||
def _get_report_str(self) -> str:
|
||||
"""
|
||||
Generate a complete HTML report string by processing test cases.
|
||||
:return: Complete HTML report string.
|
||||
"""
|
||||
self.additional_info = f'**Test Case Summary (with commit {self.commit_id[:8]}):**\n'
|
||||
failed_cases_report_parts = self.get_failed_cases_report_parts()
|
||||
skipped_cases_report_parts = self.get_skipped_cases_report_parts()
|
||||
succeeded_cases_report_parts = self.get_succeeded_cases_report_parts()
|
||||
|
||||
return self.generate_html_report(
|
||||
''.join(failed_cases_report_parts + skipped_cases_report_parts + succeeded_cases_report_parts)
|
||||
)
|
||||
|
||||
|
||||
class JobReportGenerator(ReportGenerator):
|
||||
def __init__(
|
||||
self,
|
||||
project_id: int,
|
||||
mr_iid: int,
|
||||
pipeline_id: int,
|
||||
job_id: int,
|
||||
commit_id: str,
|
||||
*,
|
||||
title: str = 'Job Report',
|
||||
jobs: t.List[GitlabJob],
|
||||
):
|
||||
super().__init__(project_id, mr_iid, pipeline_id, job_id, commit_id, title=title)
|
||||
self.jobs = jobs
|
||||
self.report_titles_map = {
|
||||
'failed_jobs': 'Failed Jobs (Excludes "integration_test" and "target_test" jobs)',
|
||||
'succeeded': 'Succeeded Jobs',
|
||||
}
|
||||
self.failed_jobs_report_file = 'job_report.html'
|
||||
|
||||
def _get_report_str(self) -> str:
|
||||
"""
|
||||
Generate a complete HTML report string by processing jobs.
|
||||
:return: Complete HTML report string.
|
||||
"""
|
||||
report_str: str = ''
|
||||
|
||||
if not self.jobs:
|
||||
print('No jobs found, skip generating job report')
|
||||
return 'No Job Found'
|
||||
|
||||
relevant_failed_jobs = self._sort_items(
|
||||
self._filter_items(
|
||||
self.jobs, lambda job: job.is_failed and job.stage not in ['integration_test', 'target_test']
|
||||
),
|
||||
key='latest_failed_count',
|
||||
)
|
||||
succeeded_jobs = self._filter_items(self.jobs, lambda job: job.is_success)
|
||||
|
||||
self.additional_info = f'**Job Summary (with commit {self.commit_id[:8]}):**\n'
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['succeeded'], len(succeeded_jobs)
|
||||
)
|
||||
|
||||
if not relevant_failed_jobs:
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['failed_jobs'], len(relevant_failed_jobs)
|
||||
)
|
||||
return report_str
|
||||
|
||||
report_sections = self.create_table_section(
|
||||
title='Failed Jobs (Excludes "integration_test" and "target_test" jobs)',
|
||||
items=relevant_failed_jobs,
|
||||
headers=[
|
||||
'Job Name',
|
||||
'Failure Reason',
|
||||
'Failure Log',
|
||||
'Failures across all other branches (10 latest jobs)',
|
||||
'URL',
|
||||
'CI Dashboard URL',
|
||||
],
|
||||
row_attrs=['name', 'failure_reason', 'failure_log', 'url', 'ci_dashboard_url'],
|
||||
value_functions=[
|
||||
(
|
||||
'Failures across all other branches (10 latest jobs)',
|
||||
lambda item: f"{getattr(item, 'latest_failed_count', '')} / {getattr(item, 'latest_total_count', '')}",
|
||||
)
|
||||
],
|
||||
)
|
||||
relevant_failed_jobs_report_url = get_artifacts_url(self.job_id, self.failed_jobs_report_file)
|
||||
self.additional_info += self.generate_additional_info_section(
|
||||
self.report_titles_map['failed_jobs'], len(relevant_failed_jobs), relevant_failed_jobs_report_url
|
||||
)
|
||||
|
||||
report_str = self.generate_html_report(''.join(report_sections))
|
||||
return report_str
|
||||
@@ -1,74 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import __init__ # noqa: F401 # inject the system path
|
||||
from dynamic_pipelines.constants import TEST_RELATED_APPS_FILENAME
|
||||
from idf_build_apps import build_apps
|
||||
from idf_build_apps import setup_logging
|
||||
from idf_build_apps.utils import semicolon_separated_str_to_list
|
||||
from idf_ci_local.app import import_apps_from_txt
|
||||
from idf_pytest.constants import DEFAULT_IGNORE_WARNING_FILEPATH
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Build Apps for Dynamic Pipeline')
|
||||
parser.add_argument('app_list_file', default=TEST_RELATED_APPS_FILENAME, help='List of apps to build')
|
||||
parser.add_argument(
|
||||
'--build-verbose',
|
||||
action='store_true',
|
||||
help='Enable verbose output from build system.',
|
||||
)
|
||||
parser.add_argument('--parallel-count', default=1, type=int, help='Number of parallel build jobs.')
|
||||
parser.add_argument(
|
||||
'--parallel-index',
|
||||
default=1,
|
||||
type=int,
|
||||
help='Index (1-based) of the job, out of the number specified by --parallel-count.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--ignore-warning-file',
|
||||
default=DEFAULT_IGNORE_WARNING_FILEPATH,
|
||||
type=argparse.FileType('r'),
|
||||
help='Ignore the warning strings in the specified file. Each line should be a regex string.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--modified-components',
|
||||
type=semicolon_separated_str_to_list,
|
||||
help='semicolon-separated string which specifies the modified components. '
|
||||
'app with `depends_components` set in the corresponding manifest files would only be built '
|
||||
'if depends on any of the specified components. '
|
||||
'If set to "", the value would be considered as None. '
|
||||
'If set to ";", the value would be considered as an empty list',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--collect-app-info',
|
||||
default='list_job_@p.txt',
|
||||
help='If specified, the test case name and app info json will be written to this file',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--junitxml',
|
||||
default='build_summary_@p.xml',
|
||||
help='Path to the junitxml file. If specified, the junitxml file will be generated',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
setup_logging(verbose=1)
|
||||
|
||||
sys.exit(
|
||||
build_apps(
|
||||
import_apps_from_txt(args.app_list_file),
|
||||
build_verbose=args.build_verbose,
|
||||
keep_going=True,
|
||||
ignore_warning_file=args.ignore_warning_file,
|
||||
modified_components=args.modified_components,
|
||||
check_app_dependencies=True,
|
||||
parallel_count=args.parallel_count,
|
||||
parallel_index=args.parallel_index,
|
||||
collect_size_info='size_info.txt',
|
||||
collect_app_info=args.collect_app_info,
|
||||
junitxml=args.junitxml,
|
||||
copy_sdkconfig=True,
|
||||
)
|
||||
)
|
||||
@@ -1,257 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""This file is used for generating the child pipeline for build jobs."""
|
||||
import argparse
|
||||
import os
|
||||
import typing as t
|
||||
|
||||
import __init__ # noqa: F401 # inject the system path
|
||||
import yaml
|
||||
from dynamic_pipelines.constants import DEFAULT_APPS_BUILD_PER_JOB
|
||||
from dynamic_pipelines.constants import DEFAULT_BUILD_CHILD_PIPELINE_FILEPATH
|
||||
from dynamic_pipelines.constants import DEFAULT_BUILD_CHILD_PIPELINE_NAME
|
||||
from dynamic_pipelines.constants import DEFAULT_TEST_PATHS
|
||||
from dynamic_pipelines.constants import NON_TEST_RELATED_APPS_FILENAME
|
||||
from dynamic_pipelines.constants import NON_TEST_RELATED_BUILD_JOB_NAME
|
||||
from dynamic_pipelines.constants import TEST_RELATED_APPS_FILENAME
|
||||
from dynamic_pipelines.constants import TEST_RELATED_BUILD_JOB_NAME
|
||||
from dynamic_pipelines.models import BuildJob
|
||||
from dynamic_pipelines.models import EmptyJob
|
||||
from dynamic_pipelines.utils import dump_jobs_to_yaml
|
||||
from idf_build_apps.utils import semicolon_separated_str_to_list
|
||||
from idf_ci_local.app import dump_apps_to_txt
|
||||
from idf_ci_utils import IDF_PATH
|
||||
from idf_pytest.constants import CollectMode
|
||||
from idf_pytest.constants import DEFAULT_CONFIG_RULES_STR
|
||||
from idf_pytest.constants import DEFAULT_FULL_BUILD_TEST_COMPONENTS
|
||||
from idf_pytest.constants import DEFAULT_FULL_BUILD_TEST_FILEPATTERNS
|
||||
from idf_pytest.script import get_all_apps
|
||||
|
||||
|
||||
def _separate_str_to_list(s: str) -> t.List[str]:
|
||||
"""
|
||||
Gitlab env file will escape the doublequotes in the env file, so we need to remove them
|
||||
|
||||
For example,
|
||||
|
||||
in pipeline.env file we have
|
||||
|
||||
MR_MODIFIED_COMPONENTS="app1;app2"
|
||||
MR_MODIFIED_FILES="main/app1.c;main/app2.c"
|
||||
|
||||
gitlab will load the doublequotes as well, so we need to remove the doublequotes
|
||||
"""
|
||||
return semicolon_separated_str_to_list(s.strip('"')) # type: ignore
|
||||
|
||||
|
||||
def main(arguments: argparse.Namespace) -> None:
|
||||
# load from default build test rules config file
|
||||
extra_default_build_targets: t.List[str] = []
|
||||
if arguments.default_build_test_rules:
|
||||
with open(arguments.default_build_test_rules) as fr:
|
||||
configs = yaml.safe_load(fr)
|
||||
|
||||
if configs:
|
||||
extra_default_build_targets = configs.get('extra_default_build_targets') or []
|
||||
|
||||
build_jobs = []
|
||||
###########################################
|
||||
# special case with -k, ignore other args #
|
||||
###########################################
|
||||
if arguments.filter_expr:
|
||||
# build only test related apps
|
||||
test_related_apps, _ = get_all_apps(
|
||||
arguments.paths,
|
||||
target=CollectMode.ALL,
|
||||
config_rules_str=DEFAULT_CONFIG_RULES_STR,
|
||||
filter_expr=arguments.filter_expr,
|
||||
marker_expr='not host_test',
|
||||
extra_default_build_targets=extra_default_build_targets,
|
||||
)
|
||||
dump_apps_to_txt(sorted(test_related_apps), TEST_RELATED_APPS_FILENAME)
|
||||
print(f'Generate test related apps file {TEST_RELATED_APPS_FILENAME} with {len(test_related_apps)} apps')
|
||||
|
||||
test_apps_build_job = BuildJob(
|
||||
name=TEST_RELATED_BUILD_JOB_NAME,
|
||||
parallel=len(test_related_apps) // DEFAULT_APPS_BUILD_PER_JOB + 1,
|
||||
variables={
|
||||
'APP_LIST_FILE': TEST_RELATED_APPS_FILENAME,
|
||||
},
|
||||
)
|
||||
|
||||
build_jobs.append(test_apps_build_job)
|
||||
else:
|
||||
#############
|
||||
# all cases #
|
||||
#############
|
||||
test_related_apps, non_test_related_apps = get_all_apps(
|
||||
arguments.paths,
|
||||
CollectMode.ALL,
|
||||
marker_expr='not host_test',
|
||||
config_rules_str=DEFAULT_CONFIG_RULES_STR,
|
||||
extra_default_build_targets=extra_default_build_targets,
|
||||
compare_manifest_sha_filepath=arguments.compare_manifest_sha_filepath,
|
||||
modified_components=arguments.modified_components,
|
||||
modified_files=arguments.modified_files,
|
||||
ignore_app_dependencies_components=arguments.ignore_app_dependencies_components,
|
||||
ignore_app_dependencies_filepatterns=arguments.ignore_app_dependencies_filepatterns,
|
||||
)
|
||||
|
||||
dump_apps_to_txt(sorted(test_related_apps), TEST_RELATED_APPS_FILENAME)
|
||||
print(f'Generate test related apps file {TEST_RELATED_APPS_FILENAME} with {len(test_related_apps)} apps')
|
||||
dump_apps_to_txt(sorted(non_test_related_apps), NON_TEST_RELATED_APPS_FILENAME)
|
||||
print(
|
||||
f'Generate non-test related apps file {NON_TEST_RELATED_APPS_FILENAME} with {len(non_test_related_apps)} apps'
|
||||
)
|
||||
|
||||
if test_related_apps:
|
||||
test_apps_build_job = BuildJob(
|
||||
name=TEST_RELATED_BUILD_JOB_NAME,
|
||||
parallel=len(test_related_apps) // DEFAULT_APPS_BUILD_PER_JOB + 1,
|
||||
variables={
|
||||
'APP_LIST_FILE': TEST_RELATED_APPS_FILENAME,
|
||||
},
|
||||
)
|
||||
build_jobs.append(test_apps_build_job)
|
||||
|
||||
if non_test_related_apps:
|
||||
non_test_apps_build_job = BuildJob(
|
||||
name=NON_TEST_RELATED_BUILD_JOB_NAME,
|
||||
parallel=len(non_test_related_apps) // DEFAULT_APPS_BUILD_PER_JOB + 1,
|
||||
variables={
|
||||
'APP_LIST_FILE': NON_TEST_RELATED_APPS_FILENAME,
|
||||
},
|
||||
)
|
||||
build_jobs.append(non_test_apps_build_job)
|
||||
|
||||
if mr_labels := os.getenv('CI_MERGE_REQUEST_LABELS'):
|
||||
print(f'MR labels: {mr_labels}')
|
||||
|
||||
# check if there's no jobs
|
||||
if not build_jobs:
|
||||
print('No apps need to be built. Create one empty job instead')
|
||||
build_jobs.append(EmptyJob())
|
||||
extra_include_yml = []
|
||||
else:
|
||||
extra_include_yml = ['tools/ci/dynamic_pipelines/templates/test_child_pipeline.yml']
|
||||
|
||||
dump_jobs_to_yaml(build_jobs, arguments.yaml_output, DEFAULT_BUILD_CHILD_PIPELINE_NAME, extra_include_yml)
|
||||
print(f'Generate child pipeline yaml file {arguments.yaml_output} with {sum(j.parallel for j in build_jobs)} jobs')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Generate build child pipeline',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
'-o',
|
||||
'--yaml-output',
|
||||
default=DEFAULT_BUILD_CHILD_PIPELINE_FILEPATH,
|
||||
help='Output YAML path',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p',
|
||||
'--paths',
|
||||
nargs='+',
|
||||
default=DEFAULT_TEST_PATHS,
|
||||
help='Paths to the apps to build.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-k',
|
||||
'--filter-expr',
|
||||
help='only build tests matching given filter expression. For example: -k "test_hello_world". Works only'
|
||||
'for pytest',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--default-build-test-rules',
|
||||
default=os.path.join(IDF_PATH, '.gitlab', 'ci', 'default-build-test-rules.yml'),
|
||||
help='default build test rules config file',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--compare-manifest-sha-filepath',
|
||||
default=os.path.join(IDF_PATH, '.manifest_sha'),
|
||||
help='Path to the recorded manifest sha file generated by `idf-build-apps dump-manifest-sha`'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--modified-components',
|
||||
type=_separate_str_to_list,
|
||||
default=os.getenv('MR_MODIFIED_COMPONENTS'),
|
||||
help='semicolon-separated string which specifies the modified components. '
|
||||
'app with `depends_components` set in the corresponding manifest files would only be built '
|
||||
'if depends on any of the specified components. '
|
||||
'If set to "", the value would be considered as None. '
|
||||
'If set to ";", the value would be considered as an empty list',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--modified-files',
|
||||
type=_separate_str_to_list,
|
||||
default=os.getenv('MR_MODIFIED_FILES'),
|
||||
help='semicolon-separated string which specifies the modified files. '
|
||||
'app with `depends_filepatterns` set in the corresponding manifest files would only be built '
|
||||
'if any of the specified file pattern matches any of the specified modified files. '
|
||||
'If set to "", the value would be considered as None. '
|
||||
'If set to ";", the value would be considered as an empty list',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-ic',
|
||||
'--ignore-app-dependencies-components',
|
||||
type=_separate_str_to_list,
|
||||
help='semicolon-separated string which specifies the modified components used for '
|
||||
'ignoring checking the app dependencies. '
|
||||
'The `depends_components` and `depends_filepatterns` set in the manifest files will be ignored '
|
||||
'when any of the specified components matches any of the modified components. '
|
||||
'Must be used together with --modified-components. '
|
||||
'If set to "", the value would be considered as None. '
|
||||
'If set to ";", the value would be considered as an empty list',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-if',
|
||||
'--ignore-app-dependencies-filepatterns',
|
||||
type=_separate_str_to_list,
|
||||
help='semicolon-separated string which specifies the file patterns used for '
|
||||
'ignoring checking the app dependencies. '
|
||||
'The `depends_components` and `depends_filepatterns` set in the manifest files will be ignored '
|
||||
'when any of the specified file patterns matches any of the modified files. '
|
||||
'Must be used together with --modified-files. '
|
||||
'If set to "", the value would be considered as None. '
|
||||
'If set to ";", the value would be considered as an empty list',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if test_case_filters := os.getenv('TEST_CASE_FILTERS', None):
|
||||
args.filter_expr = test_case_filters
|
||||
|
||||
if os.getenv('IS_MR_PIPELINE') == '0' or os.getenv('BUILD_AND_TEST_ALL_APPS') == '1':
|
||||
print('Build and run all test cases, and compile all cmake apps')
|
||||
args.modified_components = None
|
||||
args.modified_files = None
|
||||
args.ignore_app_dependencies_components = None
|
||||
args.ignore_app_dependencies_filepatterns = None
|
||||
elif args.filter_expr is not None:
|
||||
print('Build and run only test cases matching "%s"' % args.filter_expr)
|
||||
args.modified_components = None
|
||||
args.modified_files = None
|
||||
args.ignore_app_dependencies_components = None
|
||||
args.ignore_app_dependencies_filepatterns = None
|
||||
else:
|
||||
print(
|
||||
f'Build and run only test cases matching:\n'
|
||||
f'- modified components: {args.modified_components}\n'
|
||||
f'- modified files: {args.modified_files}'
|
||||
)
|
||||
|
||||
if args.modified_components is not None and not args.ignore_app_dependencies_components:
|
||||
# setting default values
|
||||
args.ignore_app_dependencies_components = DEFAULT_FULL_BUILD_TEST_COMPONENTS
|
||||
|
||||
if args.modified_files is not None and not args.ignore_app_dependencies_filepatterns:
|
||||
# setting default values
|
||||
args.ignore_app_dependencies_filepatterns = DEFAULT_FULL_BUILD_TEST_FILEPATTERNS
|
||||
|
||||
if not os.path.isfile(args.compare_manifest_sha_filepath):
|
||||
# ignore if the file does not exist
|
||||
args.compare_manifest_sha_filepath = None
|
||||
|
||||
main(args)
|
||||
@@ -1,101 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import argparse
|
||||
import glob
|
||||
import os
|
||||
import typing as t
|
||||
|
||||
import __init__ # noqa: F401 # inject the system path
|
||||
from dynamic_pipelines.report import BuildReportGenerator
|
||||
from dynamic_pipelines.report import JobReportGenerator
|
||||
from dynamic_pipelines.report import TargetTestReportGenerator
|
||||
from dynamic_pipelines.utils import fetch_failed_jobs
|
||||
from dynamic_pipelines.utils import parse_testcases_from_filepattern
|
||||
from idf_ci_local.app import import_apps_from_txt
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser: argparse.ArgumentParser = setup_argument_parser()
|
||||
args: argparse.Namespace = parser.parse_args()
|
||||
|
||||
report_actions: t.Dict[str, t.Callable[[argparse.Namespace], None]] = {
|
||||
'build': generate_build_report,
|
||||
'target_test': generate_target_test_report,
|
||||
'job': generate_jobs_report,
|
||||
}
|
||||
|
||||
report_action = report_actions.get(args.report_type)
|
||||
if report_action is None:
|
||||
raise ValueError('Unknown report type is requested to be generated.')
|
||||
|
||||
report_action(args)
|
||||
|
||||
|
||||
def setup_argument_parser() -> argparse.ArgumentParser:
|
||||
report_type_parser: argparse.ArgumentParser = argparse.ArgumentParser(add_help=False)
|
||||
report_type_parser.add_argument(
|
||||
'--report-type', choices=['build', 'target_test', 'job'], required=True, help='Type of report to generate'
|
||||
)
|
||||
report_type_args: argparse.Namespace
|
||||
remaining_args: t.List[str]
|
||||
report_type_args, remaining_args = report_type_parser.parse_known_args()
|
||||
|
||||
parser: argparse.ArgumentParser = argparse.ArgumentParser(
|
||||
description='Update reports in MR pipelines based on the selected report type',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
parents=[report_type_parser],
|
||||
)
|
||||
|
||||
common_arguments(parser)
|
||||
conditional_arguments(report_type_args, parser)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def common_arguments(parser: argparse.ArgumentParser) -> None:
|
||||
parser.add_argument('--project-id', type=int, default=os.getenv('CI_PROJECT_ID'), help='Project ID')
|
||||
parser.add_argument('--mr-iid', type=int, default=os.getenv('CI_MERGE_REQUEST_IID'), help='Merge Request IID')
|
||||
parser.add_argument('--pipeline-id', type=int, default=os.getenv('PARENT_PIPELINE_ID'), help='Pipeline ID')
|
||||
parser.add_argument('--job-id', type=int, default=os.getenv('CI_JOB_ID'), help='Job ID')
|
||||
parser.add_argument('--commit-id', default=os.getenv('CI_COMMIT_SHA'), help='MR commit ID')
|
||||
|
||||
|
||||
def conditional_arguments(report_type_args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
||||
if report_type_args.report_type == 'build':
|
||||
parser.add_argument('--app-list-filepattern', default='list_job_*.txt', help='Pattern to match app list files')
|
||||
elif report_type_args.report_type == 'target_test':
|
||||
parser.add_argument(
|
||||
'--junit-report-filepattern', default='XUNIT_RESULT*.xml', help='Pattern to match JUnit report files'
|
||||
)
|
||||
|
||||
|
||||
def generate_build_report(args: argparse.Namespace) -> None:
|
||||
apps: t.List[t.Any] = [
|
||||
app for file_name in glob.glob(args.app_list_filepattern) for app in import_apps_from_txt(file_name)
|
||||
]
|
||||
report_generator = BuildReportGenerator(
|
||||
args.project_id, args.mr_iid, args.pipeline_id, args.job_id, args.commit_id, apps=apps
|
||||
)
|
||||
report_generator.post_report()
|
||||
|
||||
|
||||
def generate_target_test_report(args: argparse.Namespace) -> None:
|
||||
test_cases: t.List[t.Any] = parse_testcases_from_filepattern(args.junit_report_filepattern)
|
||||
report_generator = TargetTestReportGenerator(
|
||||
args.project_id, args.mr_iid, args.pipeline_id, args.job_id, args.commit_id, test_cases=test_cases
|
||||
)
|
||||
report_generator.post_report(print_report_path=False)
|
||||
|
||||
|
||||
def generate_jobs_report(args: argparse.Namespace) -> None:
|
||||
jobs: t.List[t.Any] = fetch_failed_jobs(args.commit_id)
|
||||
|
||||
if not jobs:
|
||||
return
|
||||
|
||||
report_generator = JobReportGenerator(args.project_id, args.mr_iid, args.pipeline_id, args.job_id, args.commit_id, jobs=jobs)
|
||||
report_generator.post_report(print_report_path=False, print_retry_jobs_message=any(job.is_failed for job in jobs))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""This file is used for generating the child pipeline for target test jobs.
|
||||
|
||||
@@ -6,121 +6,47 @@
|
||||
2. Post the Build Report if it's running in an MR pipeline.
|
||||
3. Generate the child pipeline for target test jobs.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import glob
|
||||
import os
|
||||
import typing as t
|
||||
from collections import Counter
|
||||
from collections import defaultdict
|
||||
|
||||
import __init__ # noqa: F401 # inject the system path
|
||||
import yaml
|
||||
from dynamic_pipelines.constants import BUILD_ONLY_LABEL
|
||||
from dynamic_pipelines.constants import DEFAULT_CASES_TEST_PER_JOB
|
||||
from dynamic_pipelines.constants import DEFAULT_TARGET_TEST_CHILD_PIPELINE_FILEPATH
|
||||
from dynamic_pipelines.constants import DEFAULT_TARGET_TEST_CHILD_PIPELINE_NAME
|
||||
from dynamic_pipelines.constants import DEFAULT_TEST_PATHS
|
||||
from dynamic_pipelines.constants import (
|
||||
KNOWN_GENERATE_TEST_CHILD_PIPELINE_WARNINGS_FILEPATH,
|
||||
)
|
||||
from dynamic_pipelines.models import EmptyJob
|
||||
from dynamic_pipelines.models import Job
|
||||
from dynamic_pipelines.models import TargetTestJob
|
||||
from dynamic_pipelines.utils import dump_jobs_to_yaml
|
||||
from idf_build_apps import App
|
||||
from idf_ci_local.app import import_apps_from_txt
|
||||
from idf_pytest.script import get_pytest_cases
|
||||
from idf_ci import get_pytest_cases
|
||||
from idf_ci.idf_gitlab import test_child_pipeline
|
||||
from idf_ci.idf_pytest import GroupedPytestCases
|
||||
from idf_ci.idf_pytest.models import GroupKey
|
||||
from idf_ci_utils import IDF_PATH
|
||||
from idf_pytest.constants import TIMEOUT_4H_MARKERS
|
||||
|
||||
from dynamic_pipelines.constants import KNOWN_GENERATE_TEST_CHILD_PIPELINE_WARNINGS_FILEPATH
|
||||
|
||||
BUILD_ONLY_LABEL = 'For Maintainers: Only Build Tests'
|
||||
TIMEOUT_4H_TEMPLATE_NAME = '.timeout_4h_template'
|
||||
TARGET_TEST_CHILD_PIPELINE_FILEPATH = os.path.join(IDF_PATH, 'target_test_child_pipeline.yml')
|
||||
|
||||
|
||||
def get_tags_with_amount(s: str) -> t.List[str]:
|
||||
c: Counter = Counter()
|
||||
for _t in s.split(','):
|
||||
c[_t] += 1
|
||||
|
||||
res = set()
|
||||
for target, amount in c.items():
|
||||
if amount > 1:
|
||||
res.add(f'{target}_{amount}')
|
||||
else:
|
||||
res.add(target)
|
||||
|
||||
return sorted(res)
|
||||
|
||||
|
||||
def get_target_test_jobs(
|
||||
paths: str, apps: t.List[App], exclude_runner_tags: t.Set[str], exclude_runner_tags_matching: t.List[t.Set]
|
||||
) -> t.Tuple[t.List[Job], t.List[str], t.List[str]]:
|
||||
"""
|
||||
Return the target test jobs and the extra yaml files to include
|
||||
"""
|
||||
def main(output_filepath: str) -> None:
|
||||
if mr_labels := os.getenv('CI_MERGE_REQUEST_LABELS'):
|
||||
print(f'MR labels: {mr_labels}')
|
||||
|
||||
if BUILD_ONLY_LABEL in mr_labels.split(','):
|
||||
print('MR has build only label, skip generating target test child pipeline')
|
||||
return [EmptyJob()], [], []
|
||||
test_child_pipeline(
|
||||
output_filepath,
|
||||
cases=GroupedPytestCases([]),
|
||||
)
|
||||
return
|
||||
|
||||
pytest_cases = get_pytest_cases(
|
||||
paths,
|
||||
apps=apps,
|
||||
marker_expr='not host_test', # since it's generating target-test child pipeline
|
||||
)
|
||||
cases = GroupedPytestCases(get_pytest_cases())
|
||||
|
||||
no_env_marker_test_cases: t.List[str] = []
|
||||
res = defaultdict(list)
|
||||
for case in pytest_cases:
|
||||
if not case.env_markers:
|
||||
no_env_marker_test_cases.append(case.item.nodeid)
|
||||
continue
|
||||
|
||||
res[(case.target_selector, tuple(sorted(case.env_markers)))].append(case)
|
||||
|
||||
target_test_jobs: t.List[Job] = []
|
||||
for (target_selector, env_markers), cases in res.items():
|
||||
runner_tags = get_tags_with_amount(target_selector) + list(env_markers)
|
||||
if ','.join(runner_tags) in exclude_runner_tags:
|
||||
print('WARNING: excluding test cases with runner tags:', runner_tags)
|
||||
continue
|
||||
|
||||
if any(set(runner_tags) & group for group in exclude_runner_tags_matching):
|
||||
print(f'WARNING: Excluding test cases with runner tags (wildcard match): {runner_tags}')
|
||||
continue
|
||||
|
||||
target_test_job = TargetTestJob(
|
||||
name=f'{target_selector} - {",".join(env_markers)}',
|
||||
tags=runner_tags,
|
||||
parallel=len(cases) // DEFAULT_CASES_TEST_PER_JOB + 1,
|
||||
)
|
||||
target_test_job.set_variable('TARGET_SELECTOR', f"'{target_selector}'")
|
||||
target_test_job.set_variable('ENV_MARKERS', "'" + ' and '.join(env_markers) + "'")
|
||||
target_test_job.set_variable('PYTEST_NODES', ' '.join([f"'{case.item.nodeid}'" for case in cases]))
|
||||
|
||||
target_test_jobs.append(target_test_job)
|
||||
|
||||
extra_include_yml: t.List[str] = []
|
||||
if not target_test_jobs:
|
||||
print('No target test cases required, create one empty job instead')
|
||||
target_test_jobs.append(EmptyJob())
|
||||
else:
|
||||
extra_include_yml = ['tools/ci/dynamic_pipelines/templates/generate_target_test_report.yml']
|
||||
|
||||
fast_pipeline_flag = int(os.getenv('REPORT_EXIT_CODE', 0)) == 30
|
||||
if fast_pipeline_flag:
|
||||
extra_include_yml = ['tools/ci/dynamic_pipelines/templates/fast_pipeline.yml']
|
||||
|
||||
no_env_marker_test_cases.sort()
|
||||
return target_test_jobs, extra_include_yml, no_env_marker_test_cases
|
||||
|
||||
|
||||
def generate_target_test_child_pipeline(
|
||||
paths: str,
|
||||
apps: t.List[App],
|
||||
output_filepath: str,
|
||||
) -> None:
|
||||
with open(KNOWN_GENERATE_TEST_CHILD_PIPELINE_WARNINGS_FILEPATH) as fr:
|
||||
known_warnings_dict = yaml.safe_load(fr) or dict()
|
||||
|
||||
def _process_match_group(runner_tags: str) -> t.Union[t.Set, None]:
|
||||
def _process_match_group(runner_tags: str) -> set | None:
|
||||
match_group = {_el for _el in runner_tags.split(',') if _el != '*'}
|
||||
if len(match_group) == 0:
|
||||
print('WARNING: wildcard exclusion requires at least one specific tag — skipped')
|
||||
@@ -131,7 +57,7 @@ def generate_target_test_child_pipeline(
|
||||
exclude_runner_tags_matching = []
|
||||
for _tag in known_warnings_dict.get('no_runner_tags', []):
|
||||
if '*' not in _tag:
|
||||
exclude_runner_tags_set.add(_tag)
|
||||
exclude_runner_tags_set.add(frozenset(_tag.split(',')))
|
||||
else:
|
||||
if res := _process_match_group(_tag):
|
||||
exclude_runner_tags_matching.append(res)
|
||||
@@ -142,43 +68,44 @@ def generate_target_test_child_pipeline(
|
||||
if exclude_runner_tags := os.getenv('EXCLUDE_RUNNER_TAGS'):
|
||||
for _tag in exclude_runner_tags.split(';'):
|
||||
if '*' not in _tag:
|
||||
exclude_runner_tags_set.add(_tag)
|
||||
exclude_runner_tags_set.add(frozenset(_tag.split(',')))
|
||||
else:
|
||||
if res := _process_match_group(_tag):
|
||||
exclude_runner_tags_matching.append(res)
|
||||
|
||||
target_test_jobs, extra_include_yml, no_env_marker_test_cases = get_target_test_jobs(
|
||||
paths=paths,
|
||||
apps=apps,
|
||||
exclude_runner_tags=exclude_runner_tags_set,
|
||||
exclude_runner_tags_matching=exclude_runner_tags_matching,
|
||||
)
|
||||
flattened_cases = []
|
||||
additional_dict: dict[GroupKey, dict[str, t.Any]] = {}
|
||||
for key, grouped_cases in cases.grouped_cases.items():
|
||||
# skip test cases with no runner tags
|
||||
if frozenset(key.runner_tags) in exclude_runner_tags_set:
|
||||
print(f'WARNING: excluding test cases with runner tags: {key.runner_tags}')
|
||||
continue
|
||||
|
||||
known_no_env_marker_test_cases = set(known_warnings_dict.get('no_env_marker_test_cases', []))
|
||||
no_env_marker_test_cases_set = set(no_env_marker_test_cases)
|
||||
print(f'INFO: key.runner tags: {key.runner_tags}')
|
||||
if any(set(key.runner_tags) & group for group in exclude_runner_tags_matching):
|
||||
print(f'WARNING: Excluding test cases with runner tags (wildcard match): {key.runner_tags}')
|
||||
continue
|
||||
|
||||
no_env_marker_test_cases_fail = False
|
||||
if no_env_marker_test_cases_set - known_no_env_marker_test_cases:
|
||||
print('ERROR: NEW "no_env_marker_test_cases" detected:')
|
||||
for case in no_env_marker_test_cases_set - known_no_env_marker_test_cases:
|
||||
print(f' - {case}')
|
||||
no_env_marker_test_cases_fail = True
|
||||
flattened_cases.extend(grouped_cases)
|
||||
|
||||
print(
|
||||
'Please add at least one environment markers to the test cases listed above. '
|
||||
'You may check all the env markers here: tools/ci/idf_pytest/constants.py'
|
||||
)
|
||||
for case in grouped_cases:
|
||||
for timeout_4h_marker in TIMEOUT_4H_MARKERS:
|
||||
if timeout_4h_marker in case.env_markers:
|
||||
if key not in additional_dict:
|
||||
additional_dict[key] = {
|
||||
'extra_extends': [],
|
||||
}
|
||||
|
||||
if no_env_marker_test_cases_fail:
|
||||
raise SystemExit('Failed to generate target test child pipeline.')
|
||||
if TIMEOUT_4H_TEMPLATE_NAME not in additional_dict[key]['extra_extends']:
|
||||
additional_dict[key]['extra_extends'].append(TIMEOUT_4H_TEMPLATE_NAME)
|
||||
|
||||
dump_jobs_to_yaml(
|
||||
target_test_jobs,
|
||||
test_child_pipeline(
|
||||
output_filepath,
|
||||
DEFAULT_TARGET_TEST_CHILD_PIPELINE_NAME,
|
||||
extra_include_yml,
|
||||
cases=GroupedPytestCases(
|
||||
cases=flattened_cases,
|
||||
additional_dict=additional_dict,
|
||||
),
|
||||
)
|
||||
print(f'Generate child pipeline yaml file {output_filepath} with {sum(j.parallel for j in target_test_jobs)} jobs')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -186,35 +113,13 @@ if __name__ == '__main__':
|
||||
description='Generate Target Test Child Pipeline. Update Build Report in MR pipelines',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p',
|
||||
'--paths',
|
||||
nargs='+',
|
||||
default=DEFAULT_TEST_PATHS,
|
||||
help='Paths to the apps to build.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-o',
|
||||
'--output',
|
||||
default=DEFAULT_TARGET_TEST_CHILD_PIPELINE_FILEPATH,
|
||||
default=TARGET_TEST_CHILD_PIPELINE_FILEPATH,
|
||||
help='Output child pipeline file path',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--app-info-filepattern',
|
||||
default='list_job_*.txt',
|
||||
help='glob pattern to specify the files that include built app info generated by '
|
||||
'`idf-build-apps --collect-app-info ...`. will not raise ValueError when binary '
|
||||
'paths not exist in local file system if not listed recorded in the app info.',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
apps = []
|
||||
for f in glob.glob(args.app_info_filepattern):
|
||||
apps.extend(import_apps_from_txt(f))
|
||||
|
||||
generate_target_test_child_pipeline(
|
||||
paths=args.paths,
|
||||
apps=apps,
|
||||
output_filepath=args.output,
|
||||
)
|
||||
main(args.output)
|
||||
|
||||
@@ -6,94 +6,87 @@
|
||||
########################
|
||||
.dynamic_build_template:
|
||||
extends:
|
||||
- .before_script:build
|
||||
- .after_script:build:ccache-show-stats:upload-failed-job-logs
|
||||
- .after_script:build
|
||||
image: $ESP_ENV_IMAGE
|
||||
tags: [build, shiny]
|
||||
stage: build
|
||||
timeout: 1 hour
|
||||
timeout: 2 hour
|
||||
variables:
|
||||
# Enable ccache for all build jobs. See configure_ci_environment.sh for more ccache related settings.
|
||||
IDF_CCACHE_ENABLE: "1"
|
||||
# Since the version 3.21 CMake passes source files and include dirs to ninja using absolute paths.
|
||||
# Needed for pytest junit reports.
|
||||
INSTALL_EXTRA_TOOLS: cmake
|
||||
# Suppress Python warning messages during CI builds to keep logs clean and focused on errors.
|
||||
# This prevents non-critical warnings (e.g., deprecation or resource warnings) from cluttering output.
|
||||
PYTHONWARNINGS: "ignore"
|
||||
needs:
|
||||
- pipeline: $PARENT_PIPELINE_ID
|
||||
job: generate_build_child_pipeline
|
||||
- pipeline: $PARENT_PIPELINE_ID
|
||||
job: pipeline_variables
|
||||
artifacts:
|
||||
paths:
|
||||
# The other artifacts patterns are defined under tools/ci/artifacts_handler.py
|
||||
# The other artifacts patterns are defined under .idf_ci.toml
|
||||
# Now we're uploading/downloading the binary files from our internal storage server
|
||||
#
|
||||
|
||||
# keep the log file to help debug
|
||||
- "**/build*/build_log.txt"
|
||||
# build spec files
|
||||
- build_summary_*.xml
|
||||
# list of built apps
|
||||
- list_job_*.txt
|
||||
- app_info_*.txt
|
||||
when: always
|
||||
expire_in: 1 week
|
||||
script:
|
||||
# CI specific options start from "--parallel-count xxx". could ignore when running locally
|
||||
- run_cmd python tools/ci/dynamic_pipelines/scripts/child_pipeline_build_apps.py $APP_LIST_FILE
|
||||
- run_cmd idf-ci build run
|
||||
--parallel-count ${CI_NODE_TOTAL:-1}
|
||||
--parallel-index ${CI_NODE_INDEX:-1}
|
||||
--collect-app-info "list_job_${CI_JOB_NAME_SLUG}.txt"
|
||||
--modified-components ${MR_MODIFIED_COMPONENTS}
|
||||
--junitxml "build_summary_${CI_JOB_NAME_SLUG}.xml"
|
||||
- run_cmd python tools/ci/artifacts_handler.py upload --type size_reports
|
||||
|
||||
.dynamic_target_test_template:
|
||||
extends:
|
||||
- .before_script:fetch:target_test
|
||||
image: $TARGET_TEST_ENV_IMAGE
|
||||
stage: target_test
|
||||
timeout: 1 hour
|
||||
variables:
|
||||
GIT_STRATEGY: "fetch"
|
||||
SUBMODULES_TO_FETCH: "none"
|
||||
# set while generating the pipeline
|
||||
PYTEST_NODES: ""
|
||||
TARGET_SELECTOR: ""
|
||||
ENV_MARKERS: ""
|
||||
nodes: ""
|
||||
INSTALL_EXTRA_TOOLS: "xtensa-esp-elf-gdb riscv32-esp-elf-gdb openocd-esp32 esp-rom-elfs"
|
||||
PYTEST_EXTRA_FLAGS: "--dev-passwd ${ETHERNET_TEST_PASSWORD} --dev-user ${ETHERNET_TEST_USER} --capture=fd --verbosity=0"
|
||||
PYTEST_EXTRA_FLAGS: "--capture=fd --verbosity=0 --unity-test-report-mode merge"
|
||||
needs:
|
||||
- pipeline: $PARENT_PIPELINE_ID
|
||||
job: pipeline_variables
|
||||
cache:
|
||||
# Usually do not need submodule-cache in target_test
|
||||
- key: pip-cache-${LATEST_GIT_TAG}
|
||||
paths:
|
||||
- .cache/pip
|
||||
policy: pull
|
||||
- pipeline: $PARENT_PIPELINE_ID
|
||||
job: snapshot_known_failure_cases
|
||||
artifacts:
|
||||
paths:
|
||||
- XUNIT_RESULT*.xml
|
||||
- pytest-embedded/
|
||||
# Child pipeline reports won't be collected in the main one
|
||||
# https://gitlab.com/groups/gitlab-org/-/epics/8205
|
||||
# reports:
|
||||
# junit: XUNIT_RESULT.xml
|
||||
reports:
|
||||
junit: XUNIT_RESULT*.xml
|
||||
when: always
|
||||
expire_in: 1 week
|
||||
script:
|
||||
# get known failure cases
|
||||
- run_cmd python tools/ci/get_known_failure_cases_file.py
|
||||
# Merge the current known failure cases file with snapshot_known_failure_cases file captured at pipeline start
|
||||
# to avoid retry failures caused by later updates to the known failure cases file.
|
||||
- run_cmd idf-ci gitlab download-known-failure-cases-file ${KNOWN_FAILURE_CASES_FILE_NAME}
|
||||
- printf '\n' >> ${KNOWN_FAILURE_CASES_FILE_NAME}
|
||||
- cat artifacts/${KNOWN_FAILURE_CASES_FILE_NAME}.freeze >> ${KNOWN_FAILURE_CASES_FILE_NAME}
|
||||
# get runner env config file
|
||||
- retry_failed git clone $TEST_ENV_CONFIG_REPO
|
||||
- run_cmd python $CHECKOUT_REF_SCRIPT ci-test-runner-configs ci-test-runner-configs
|
||||
# CI specific options start from "--known-failure-cases-file xxx". could ignore when running locally
|
||||
- run_cmd pytest ${PYTEST_NODES}
|
||||
--target ${TARGET_SELECTOR}
|
||||
-m ${ENV_MARKERS}
|
||||
--pipeline-id $PARENT_PIPELINE_ID
|
||||
--junitxml=XUNIT_RESULT_${CI_JOB_NAME_SLUG}.xml
|
||||
- run_cmd pytest $nodes
|
||||
--junitxml=XUNIT_RESULT_${CI_JOB_ID}.xml
|
||||
--ignore-result-files ${KNOWN_FAILURE_CASES_FILE_NAME}
|
||||
--parallel-count ${CI_NODE_TOTAL:-1}
|
||||
--parallel-index ${CI_NODE_INDEX:-1}
|
||||
${PYTEST_EXTRA_FLAGS}
|
||||
after_script:
|
||||
- source tools/ci/utils.sh
|
||||
- section_start "upload_junit_reports"
|
||||
- run_cmd python tools/ci/artifacts_handler.py upload --type logs junit_reports
|
||||
- section_end "upload_junit_reports"
|
||||
- run_cmd idf-ci gitlab upload-artifacts --type junit
|
||||
|
||||
.timeout_4h_template:
|
||||
timeout: 4 hours
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
.generate_pytest_report_base:
|
||||
stage: .post
|
||||
tags: [build, shiny]
|
||||
image: $ESP_ENV_IMAGE
|
||||
artifacts:
|
||||
paths:
|
||||
- target_test_report.html
|
||||
expire_in: 1 week
|
||||
when: always
|
||||
|
||||
fast_pipeline:pipeline_ended:always_failed:
|
||||
when: on_success
|
||||
extends: .generate_pytest_report_base
|
||||
script:
|
||||
- python tools/ci/dynamic_pipelines/scripts/generate_report.py --report-type target_test
|
||||
- exit 30
|
||||
@@ -1,18 +0,0 @@
|
||||
generate_pytest_report:
|
||||
stage: .post
|
||||
tags: [build, shiny]
|
||||
image: $ESP_ENV_IMAGE
|
||||
when: always
|
||||
artifacts:
|
||||
paths:
|
||||
- target_test_report.html
|
||||
- failed_cases.html
|
||||
- skipped_cases.html
|
||||
- succeeded_cases.html
|
||||
expire_in: 1 week
|
||||
when: always
|
||||
|
||||
script:
|
||||
- python tools/ci/get_known_failure_cases_file.py
|
||||
- python tools/ci/dynamic_pipelines/scripts/generate_report.py --report-type target_test
|
||||
- python tools/ci/previous_stage_job_status.py --stage target_test
|
||||
+14
-10
@@ -2,7 +2,11 @@
|
||||
# no_env_marker_test_cases: List of test cases that do not have environment markers.
|
||||
# each item shall be the test node id, you may check the error message to get the node id.
|
||||
no_env_marker_test_cases:
|
||||
- dummy_test_case
|
||||
- test_examples_security_secure_boot
|
||||
- test_examples_security_secure_boot_corrupt_app_sig
|
||||
- test_examples_security_secure_boot_corrupt_bl_sig
|
||||
- test_examples_security_secure_boot_key_combo
|
||||
- test_examples_security_secure_boot_key_revoke
|
||||
|
||||
# no_runner_tags: List of runner tags that has no test runner set.
|
||||
# each item shall be a comma separated list of runner tags.
|
||||
@@ -27,14 +31,14 @@ no_runner_tags:
|
||||
- esp32c61,generic
|
||||
- esp32c61,jtag
|
||||
- esp32h2,jtag
|
||||
- esp32p4,esp32p4_eco4,flash_encryption
|
||||
- esp32p4,esp32p4_eco4,lp_i2s
|
||||
- esp32p4,esp32p4_eco4,ram_app
|
||||
- esp32p4,esp32p4_eco4,sdcard
|
||||
- esp32p4,esp32p4_eco4,sdcard_spimode
|
||||
- esp32p4,esp32p4_eco4,twai_adapter
|
||||
- esp32p4,esp32p4_eco4,usb_device
|
||||
- esp32p4,esp32p4_eco4,usb_host_flash_disk
|
||||
- esp32p4,esp32p4_rev1,flash_encryption
|
||||
- esp32p4,esp32p4_rev1,lp_i2s
|
||||
- esp32p4,esp32p4_rev1,ram_app
|
||||
- esp32p4,esp32p4_rev1,sdcard
|
||||
- esp32p4,esp32p4_rev1,sdcard_spimode
|
||||
- esp32p4,esp32p4_rev1,twai_adapter
|
||||
- esp32p4,esp32p4_rev1,usb_device
|
||||
- esp32p4,esp32p4_rev1,usb_host_flash_disk
|
||||
- esp32p4,jtag
|
||||
- esp32p4_2,generic_multi_device
|
||||
- esp32p4_2,esp32p4_rev1,generic_multi_device
|
||||
- esp32s2,usb_host_flash_disk
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{{title}}</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
href="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.0/dist/extensions/sticky-header/bootstrap-table-sticky-header.css"
|
||||
/>
|
||||
<link
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<style>
|
||||
.text-toggle,
|
||||
.full-text {
|
||||
cursor: pointer;
|
||||
}
|
||||
th:nth-child(1),
|
||||
td:nth-child(1) {
|
||||
width: 5%;
|
||||
}
|
||||
th:nth-child(2),
|
||||
td:nth-child(2),
|
||||
th:nth-child(3),
|
||||
td:nth-child(3) {
|
||||
width: 30%;
|
||||
}
|
||||
th,
|
||||
td {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
h2 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.copy-link-icon {
|
||||
font-size: 20px;
|
||||
margin-left: 10px;
|
||||
color: #8f8f97;
|
||||
cursor: pointer;
|
||||
}
|
||||
.copy-link-icon:hover {
|
||||
color: #282b2c;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid">{{table}}</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.0/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>
|
||||
<script>
|
||||
$(window).on("load", function () {
|
||||
var hash = window.location.hash;
|
||||
if (hash) {
|
||||
setTimeout(function () {
|
||||
$("html, body").animate(
|
||||
{ scrollTop: $(hash).offset().top },
|
||||
100
|
||||
);
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
scrollToHashLocation();
|
||||
setupTextToggles();
|
||||
setupEventHandlers();
|
||||
});
|
||||
|
||||
function setupEventHandlers() {
|
||||
$(window).on("load", scrollToHashLocation);
|
||||
$("body").on("click", ".toggle-link", toggleText);
|
||||
}
|
||||
|
||||
function scrollToHashLocation() {
|
||||
const hash = window.location.hash;
|
||||
if (hash) {
|
||||
setTimeout(() => {
|
||||
$("html, body").animate(
|
||||
{ scrollTop: $(hash).offset().top },
|
||||
100
|
||||
);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function copyPermalink(anchorId) {
|
||||
const fullUrl = `${window.location.origin}${window.location.pathname}${anchorId}`;
|
||||
history.pushState(null, null, anchorId);
|
||||
navigator.clipboard.writeText(fullUrl);
|
||||
scrollToHashLocation();
|
||||
}
|
||||
|
||||
function toggleText(e) {
|
||||
e.preventDefault();
|
||||
const link = $(this),
|
||||
textSpan = link.siblings(".full-text"),
|
||||
toggleSpan = link.siblings(".text-toggle");
|
||||
const visible = textSpan.is(":visible");
|
||||
link.text(visible ? "Show More" : "Show Less");
|
||||
textSpan.toggle();
|
||||
toggleSpan.toggle();
|
||||
}
|
||||
|
||||
function setupTextToggles() {
|
||||
$("table.table td").each(function () {
|
||||
var cell = $(this);
|
||||
if (cell.text().length > 100) {
|
||||
var originalText = cell.text();
|
||||
var displayText =
|
||||
originalText.substring(0, 100) + "...";
|
||||
cell.html(
|
||||
`<span class="text-toggle">${displayText}</span><span class="full-text" style="display: none;">${originalText}</span><a href="#" class="toggle-link">Show More</a>`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
@@ -1,20 +1,39 @@
|
||||
generate_pytest_build_report:
|
||||
all_build_finished:
|
||||
stage: assign_test
|
||||
tags: [fast_run, shiny]
|
||||
image: $ESP_ENV_IMAGE
|
||||
when: always
|
||||
# this job is used to check if all build jobs are finished
|
||||
# because the `needs` make the later jobs run even if the previous stage are not finished
|
||||
# and there's no `needs: stage` for now in gitlab
|
||||
# https://gitlab.com/gitlab-org/gitlab/-/issues/220758
|
||||
artifacts:
|
||||
untracked: true
|
||||
expire_in: 1 week
|
||||
when: always
|
||||
before_script: []
|
||||
dependencies: []
|
||||
script:
|
||||
- echo "all test jobs finished"
|
||||
|
||||
generate_presigned_json:
|
||||
stage: assign_test
|
||||
image: $ESP_ENV_IMAGE
|
||||
tags:
|
||||
- build
|
||||
- shiny
|
||||
when: always
|
||||
needs:
|
||||
- all_build_finished
|
||||
- pipeline: $PARENT_PIPELINE_ID
|
||||
job: pipeline_variables
|
||||
artifacts:
|
||||
paths:
|
||||
- build_report.html
|
||||
- test_related_apps_download_urls.yml
|
||||
- presigned.json
|
||||
expire_in: 1 week
|
||||
when: always
|
||||
|
||||
script:
|
||||
- python tools/ci/dynamic_pipelines/scripts/generate_report.py --report-type build
|
||||
- python tools/ci/previous_stage_job_status.py --stage build
|
||||
- idf-ci gitlab generate-presigned-json --output presigned.json
|
||||
|
||||
generate_pytest_child_pipeline:
|
||||
# finally, we can get some use out of the default behavior that downloads all artifacts from the previous stage
|
||||
@@ -23,6 +42,13 @@ generate_pytest_child_pipeline:
|
||||
tags:
|
||||
- build
|
||||
- shiny
|
||||
needs:
|
||||
- job: build_test_related_apps
|
||||
optional: true
|
||||
- job: build_non_test_related_apps # make sure all build jobs are passed
|
||||
optional: true
|
||||
- pipeline: $PARENT_PIPELINE_ID
|
||||
job: pipeline_variables
|
||||
artifacts:
|
||||
paths:
|
||||
- target_test_child_pipeline.yml
|
||||
@@ -35,7 +61,6 @@ Pytest Target Test Jobs:
|
||||
- generate_pytest_child_pipeline
|
||||
variables:
|
||||
PARENT_PIPELINE_ID: $PARENT_PIPELINE_ID
|
||||
REPORT_EXIT_CODE: $REPORT_EXIT_CODE
|
||||
# https://gitlab.com/gitlab-org/gitlab/-/issues/214340
|
||||
inherit:
|
||||
variables: false
|
||||
|
||||
-200
@@ -1,200 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<testsuites>
|
||||
<testsuite errors="2" failures="0" hostname="FA002598" name="pytest" skipped="0" tests="2" time="22.981" timestamp="2024-05-17T17:51:26.669364">
|
||||
<testcase classname="components.driver.test_apps.i2c_test_apps.pytest_i2c" file="components/driver/test_apps/i2c_test_apps/pytest_i2c.py" line="21" name="('esp32h2', 'esp32h2').('defaults', 'defaults').test_i2c_multi_device" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/('esp32h2', 'esp32h2').('defaults', 'defaults').test_i2c_multi_device/dut.txt" time="11.910">
|
||||
<error message="failed on setup with "EOFError"">conftest.py:74: in case_tester
|
||||
yield CaseTester(dut, **kwargs)
|
||||
tools/ci/idf_unity_tester.py:202: in __init__
|
||||
self._manager = Manager()
|
||||
/usr/lib/python3.9/multiprocessing/context.py:57: in Manager
|
||||
m.start()
|
||||
/usr/lib/python3.9/multiprocessing/managers.py:557: in start
|
||||
self._address = reader.recv()
|
||||
/usr/lib/python3.9/multiprocessing/connection.py:255: in recv
|
||||
buf = self._recv_bytes()
|
||||
/usr/lib/python3.9/multiprocessing/connection.py:419: in _recv_bytes
|
||||
buf = self._recv(4)
|
||||
/usr/lib/python3.9/multiprocessing/connection.py:388: in _recv
|
||||
raise EOFError
|
||||
E EOFError</error>
|
||||
</testcase>
|
||||
<testcase classname="components.driver.test_apps.i2s_test_apps.i2s_multi_dev.pytest_i2s_multi_dev" file="components/driver/test_apps/i2s_test_apps/i2s_multi_dev/pytest_i2s_multi_dev.py" line="5" name="('esp32h2', 'esp32h2').('default', 'default').test_i2s_multi_dev" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/('esp32h2', 'esp32h2').('default', 'default').test_i2s_multi_dev/dut.txt" time="11.071">
|
||||
<error message="failed on setup with "EOFError"">conftest.py:74: in case_tester
|
||||
yield CaseTester(dut, **kwargs)
|
||||
tools/ci/idf_unity_tester.py:202: in __init__
|
||||
self._manager = Manager()
|
||||
/usr/lib/python3.9/multiprocessing/context.py:57: in Manager
|
||||
m.start()
|
||||
/usr/lib/python3.9/multiprocessing/managers.py:557: in start
|
||||
self._address = reader.recv()
|
||||
/usr/lib/python3.9/multiprocessing/connection.py:255: in recv
|
||||
buf = self._recv_bytes()
|
||||
/usr/lib/python3.9/multiprocessing/connection.py:419: in _recv_bytes
|
||||
buf = self._recv(4)
|
||||
/usr/lib/python3.9/multiprocessing/connection.py:388: in _recv
|
||||
raise EOFError
|
||||
E EOFError</error>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite errors="0" failures="1" hostname="GX64-C2-SH-1-ITS1N4" name="pytest" skipped="0" tests="3" time="101.163" timestamp="2024-05-17T17:52:04.061589">
|
||||
<testcase classname="components.vfs.test_apps.pytest_vfs" file="components/vfs/test_apps/pytest_vfs.py" line="7" name="esp32c2.default.test_vfs_default" dut_log_url="https://https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c2.default.test_vfs_default/dut.txt" time="30.044"/>
|
||||
<testcase classname="components.vfs.test_apps.pytest_vfs" file="components/vfs/test_apps/pytest_vfs.py" line="7" name="esp32c2.iram.test_vfs_default" dut_log_url="https://https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c2.iram.test_vfs_default/dut.txt" time="28.323"/>
|
||||
<testcase classname="components.wpa_supplicant.test_apps.pytest_wpa_supplicant_ut" file="components/wpa_supplicant/test_apps/pytest_wpa_supplicant_ut.py" line="8" name="esp32c2.default.test_wpa_supplicant_ut" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c2.default.test_wpa_supplicant_ut/dut.txt" time="42.796">
|
||||
<failure message="AssertionError: Unity test failed">/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/plugin.py:1272: in pytest_runtest_call
|
||||
self._raise_dut_failed_cases_if_exists(duts) # type: ignore
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/plugin.py:1207: in _raise_dut_failed_cases_if_exists
|
||||
raise AssertionError('Unity test failed')
|
||||
E AssertionError: Unity test failed</failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite errors="0" failures="0" hostname="runner-zmdq2hnf-project-103-concurrent-3" name="pytest" skipped="1" tests="8" time="123.596" timestamp="2024-05-17T03:04:11.412971">
|
||||
<testcase classname="test_common" file="test_common.py" line="114" name="test_python_interpreter_unix" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_python_interpreter_unix/dut.txt" time="7.523"/>
|
||||
<testcase classname="test_common" file="test_common.py" line="133" name="test_python_interpreter_win" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_python_interpreter_win/dut.txt" time="0.000">
|
||||
<skipped message="Linux does not support executing .exe files" type="pytest.skip">/builds/espressif/esp-idf/tools/test_build_system/test_common.py:134: Linux does not support executing .exe files</skipped>
|
||||
</testcase>
|
||||
<testcase classname="test_common" file="test_common.py" line="147" name="test_invoke_confserver" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_invoke_confserver/dut.txt" time="10.179"/>
|
||||
<testcase classname="test_common" file="test_common.py" line="153" name="test_ccache_used_to_build" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_ccache_used_to_build/dut.txt" time="23.713"/>
|
||||
<testcase classname="test_common" file="test_common.py" line="171" name="test_toolchain_prefix_in_description_file" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_toolchain_prefix_in_description_file/dut.txt" time="8.390"/>
|
||||
<testcase classname="test_common" file="test_common.py" line="178" name="test_subcommands_with_options" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_subcommands_with_options/dut.txt" time="28.118"/>
|
||||
<testcase classname="test_common" file="test_common.py" line="194" name="test_fallback_to_build_system_target" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_fallback_to_build_system_target/dut.txt" time="11.687"/>
|
||||
<testcase classname="test_common" file="test_common.py" line="203" name="test_create_component_project" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/test_create_component_project/dut.txt" time="33.986"/>
|
||||
</testsuite>
|
||||
<testsuite errors="0" failures="4" hostname="FA002285" name="pytest" skipped="0" tests="4" time="231.048" timestamp="2024-05-17T17:50:02.291973">
|
||||
<testcase classname="components.esp_timer.test_apps.pytest_esp_timer_ut" file="components/esp_timer/test_apps/pytest_esp_timer_ut.py" line="20" name="esp32c3.release.test_esp_timer" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.release.test_esp_timer/dut.txt" time="39.686">
|
||||
<failure message="pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests"
|
||||
Bytes in current buffer (color code eliminated): ce710,len:0x2afc entry 0x403cc710
|
||||
Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.release.test_esp_timer/dut.txt">/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:76: in wrapper
|
||||
index = func(self, pattern, *args, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:153: in expect_exact
|
||||
return self.pexpect_proc.expect_exact(pattern, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/spawnbase.py:432: in expect_exact
|
||||
return exp.expect_loop(timeout)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:181: in expect_loop
|
||||
return self.timeout(e)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:144: in timeout
|
||||
raise exc
|
||||
E pexpect.exceptions.TIMEOUT: <pytest_embedded.log.PexpectProcess object at 0x7f47b1ab46a0>
|
||||
E searcher: searcher_string:
|
||||
E 0: b'Press ENTER to see the list of tests'
|
||||
E <pytest_embedded.log.PexpectProcess object at 0x7f47b1ab46a0>
|
||||
E searcher: searcher_string:
|
||||
E 0: b'Press ENTER to see the list of tests'
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
components/esp_timer/test_apps/pytest_esp_timer_ut.py:24: in test_esp_timer
|
||||
dut.run_all_single_board_cases(timeout=120)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded_idf/unity_tester.py:435: in run_all_single_board_cases
|
||||
for case in self.test_menu:
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded_idf/unity_tester.py:243: in test_menu
|
||||
self._test_menu = self._parse_test_menu()
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded_idf/unity_tester.py:124: in _parse_test_menu
|
||||
self.expect_exact(ready_line)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:83: in wrapper
|
||||
raise e.__class__(debug_str) from e
|
||||
E pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests"
|
||||
E Bytes in current buffer (color code eliminated): ce710,len:0x2afc entry 0x403cc710
|
||||
E Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.release.test_esp_timer/dut.txt</failure>
|
||||
</testcase>
|
||||
<testcase classname="components.wear_levelling.test_apps.pytest_wear_levelling" file="components/wear_levelling/test_apps/pytest_wear_levelling.py" line="7" name="esp32c3.512safe.test_wear_levelling" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.512safe.test_wear_levelling/dut.txt" time="69.850">
|
||||
<failure message="pexpect.exceptions.TIMEOUT: Not found "re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)', re.MULTILINE)"
|
||||
Bytes in current buffer (color code eliminated): Serial port /dev/ttyUSB16 Connecting.... Connecting.... esptool.py v4.7.0 Found 1 serial ports Chip is ESP32-C3 (QFN32) (revision v0.3) Features: WiFi, BLE, Embedded Flash 4MB... (total 6673 bytes)
|
||||
Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.512safe.test_wear_levelling/dut.txt">/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:76: in wrapper
|
||||
index = func(self, pattern, *args, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:131: in expect
|
||||
return self.pexpect_proc.expect(pattern, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/spawnbase.py:354: in expect
|
||||
return self.expect_list(compiled_pattern_list,
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/spawnbase.py:383: in expect_list
|
||||
return exp.expect_loop(timeout)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:181: in expect_loop
|
||||
return self.timeout(e)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:144: in timeout
|
||||
raise exc
|
||||
E pexpect.exceptions.TIMEOUT: <pytest_embedded.log.PexpectProcess object at 0x7f47af653b80>
|
||||
E searcher: searcher_re:
|
||||
E 0: re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)')
|
||||
E <pytest_embedded.log.PexpectProcess object at 0x7f47af653b80>
|
||||
E searcher: searcher_re:
|
||||
E 0: re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)')
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
components/wear_levelling/test_apps/pytest_wear_levelling.py:18: in test_wear_levelling
|
||||
dut.expect_unity_test_output()
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:180: in expect_unity_test_output
|
||||
self.expect(UNITY_SUMMARY_LINE_REGEX, timeout=timeout)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:83: in wrapper
|
||||
raise e.__class__(debug_str) from e
|
||||
E pexpect.exceptions.TIMEOUT: Not found "re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)', re.MULTILINE)"
|
||||
E Bytes in current buffer (color code eliminated): Serial port /dev/ttyUSB16 Connecting.... Connecting.... esptool.py v4.7.0 Found 1 serial ports Chip is ESP32-C3 (QFN32) (revision v0.3) Features: WiFi, BLE, Embedded Flash 4MB... (total 6673 bytes)
|
||||
E Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.512safe.test_wear_levelling/dut.txt</failure>
|
||||
</testcase>
|
||||
<testcase classname="components.wear_levelling.test_apps.pytest_wear_levelling" file="components/wear_levelling/test_apps/pytest_wear_levelling.py" line="7" name="esp32c3.release.test_wear_levelling" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.release.test_wear_levelling/dut.txt" time="70.304">
|
||||
<failure message="pexpect.exceptions.TIMEOUT: Not found "re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)', re.MULTILINE)"
|
||||
Bytes in current buffer (color code eliminated): Serial port /dev/ttyUSB16 Connecting.... Connecting.... esptool.py v4.7.0 Found 1 serial ports Chip is ESP32-C3 (QFN32) (revision v0.3) Features: WiFi, BLE, Embedded Flash 4MB... (total 24528 bytes)
|
||||
Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.release.test_wear_levelling/dut.txt">/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:76: in wrapper
|
||||
index = func(self, pattern, *args, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:131: in expect
|
||||
return self.pexpect_proc.expect(pattern, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/spawnbase.py:354: in expect
|
||||
return self.expect_list(compiled_pattern_list,
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/spawnbase.py:383: in expect_list
|
||||
return exp.expect_loop(timeout)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:181: in expect_loop
|
||||
return self.timeout(e)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:144: in timeout
|
||||
raise exc
|
||||
E pexpect.exceptions.TIMEOUT: <pytest_embedded.log.PexpectProcess object at 0x7f47afc540d0>
|
||||
E searcher: searcher_re:
|
||||
E 0: re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)')
|
||||
E <pytest_embedded.log.PexpectProcess object at 0x7f47afc540d0>
|
||||
E searcher: searcher_re:
|
||||
E 0: re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)')
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
components/wear_levelling/test_apps/pytest_wear_levelling.py:18: in test_wear_levelling
|
||||
dut.expect_unity_test_output()
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:180: in expect_unity_test_output
|
||||
self.expect(UNITY_SUMMARY_LINE_REGEX, timeout=timeout)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:83: in wrapper
|
||||
raise e.__class__(debug_str) from e
|
||||
E pexpect.exceptions.TIMEOUT: Not found "re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)', re.MULTILINE)"
|
||||
E Bytes in current buffer (color code eliminated): Serial port /dev/ttyUSB16 Connecting.... Connecting.... esptool.py v4.7.0 Found 1 serial ports Chip is ESP32-C3 (QFN32) (revision v0.3) Features: WiFi, BLE, Embedded Flash 4MB... (total 24528 bytes)
|
||||
E Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.release.test_wear_levelling/dut.txt</failure>
|
||||
</testcase>
|
||||
<testcase classname="components.wpa_supplicant.test_apps.pytest_wpa_supplicant_ut" file="components/wpa_supplicant/test_apps/pytest_wpa_supplicant_ut.py" line="8" name="esp32c3.default.test_wpa_supplicant_ut" dut_log_url="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.default.test_wpa_supplicant_ut/dut.txt" time="51.208">
|
||||
<failure message="pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests"
|
||||
Bytes in current buffer (color code eliminated): 0 d4 000 00x0000 x0000x00 000000 0
|
||||
Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.default.test_wpa_supplicant_ut/dut.txt">/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:76: in wrapper
|
||||
index = func(self, pattern, *args, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:153: in expect_exact
|
||||
return self.pexpect_proc.expect_exact(pattern, **kwargs)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/spawnbase.py:432: in expect_exact
|
||||
return exp.expect_loop(timeout)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:181: in expect_loop
|
||||
return self.timeout(e)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pexpect/expect.py:144: in timeout
|
||||
raise exc
|
||||
E pexpect.exceptions.TIMEOUT: <pytest_embedded.log.PexpectProcess object at 0x7f47afc54df0>
|
||||
E searcher: searcher_string:
|
||||
E 0: b'Press ENTER to see the list of tests'
|
||||
E <pytest_embedded.log.PexpectProcess object at 0x7f47afc54df0>
|
||||
E searcher: searcher_string:
|
||||
E 0: b'Press ENTER to see the list of tests'
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
components/wpa_supplicant/test_apps/pytest_wpa_supplicant_ut.py:17: in test_wpa_supplicant_ut
|
||||
dut.run_all_single_board_cases()
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded_idf/unity_tester.py:435: in run_all_single_board_cases
|
||||
for case in self.test_menu:
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded_idf/unity_tester.py:243: in test_menu
|
||||
self._test_menu = self._parse_test_menu()
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded_idf/unity_tester.py:124: in _parse_test_menu
|
||||
self.expect_exact(ready_line)
|
||||
/root/.espressif/python_env/idf5.2_py3.9_env/lib/python3.9/site-packages/pytest_embedded/dut.py:83: in wrapper
|
||||
raise e.__class__(debug_str) from e
|
||||
E pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests"
|
||||
E Bytes in current buffer (color code eliminated): 0 d4 000 00x0000 x0000x00 000000 0
|
||||
E Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.default.test_wpa_supplicant_ut/dut.txt</failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
-170
@@ -1,170 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Job Report</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
href="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.0/dist/extensions/sticky-header/bootstrap-table-sticky-header.css"
|
||||
/>
|
||||
<link
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<style>
|
||||
.text-toggle,
|
||||
.full-text {
|
||||
cursor: pointer;
|
||||
}
|
||||
th:nth-child(1),
|
||||
td:nth-child(1) {
|
||||
width: 5%;
|
||||
}
|
||||
th:nth-child(2),
|
||||
td:nth-child(2),
|
||||
th:nth-child(3),
|
||||
td:nth-child(3) {
|
||||
width: 30%;
|
||||
}
|
||||
th,
|
||||
td {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
h2 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.copy-link-icon {
|
||||
font-size: 20px;
|
||||
margin-left: 10px;
|
||||
color: #8f8f97;
|
||||
cursor: pointer;
|
||||
}
|
||||
.copy-link-icon:hover {
|
||||
color: #282b2c;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid"><h2 id="failed-jobs">Failed Jobs (Excludes "integration_test" and "target_test" jobs)<i class="fas fa-link copy-link-icon"
|
||||
onclick="copyPermalink('#failed-jobs')"></i></h2><table data-toggle="table" data-search-align="left" data-search="true" data-sticky-header="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Job Name</th>
|
||||
<th>Failure Reason</th>
|
||||
<th>Failure Log</th>
|
||||
<th>Failures across all other branches (10 latest jobs)</th>
|
||||
<th>URL</th>
|
||||
<th>CI Dashboard URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>build_clang_test_apps_esp32h2</td>
|
||||
<td>Some Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason</td>
|
||||
<td>Some Failure LogSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason</td>
|
||||
<td>2 / 10</td>
|
||||
<td><a href="https://test.com/-/jobs/48838695">link</a></td>
|
||||
<td><a href="https://test_dashboard_host/d/LoUa-qLWz/job-list?var-job_name=build_clang_test_apps_esp32h2">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>build_template_app</td>
|
||||
<td>Some Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason</td>
|
||||
<td>Some Failure LogSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason</td>
|
||||
<td>3 / 10</td>
|
||||
<td><a href="https://test.com/-/jobs/48838704">link</a></td>
|
||||
<td><a href="https://test_dashboard_host/d/LoUa-qLWz/job-list?var-job_name=build_template_app">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>check_public_headers</td>
|
||||
<td>Some Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason</td>
|
||||
<td>Some Failure Log</td>
|
||||
<td>4 / 10</td>
|
||||
<td><a href="https://test.com/-/jobs/48838705">link</a></td>
|
||||
<td><a href="https://test_dashboard_host/d/LoUa-qLWz/job-list?var-job_name=check_public_headers">link</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.0/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>
|
||||
<script>
|
||||
$(window).on("load", function () {
|
||||
var hash = window.location.hash;
|
||||
if (hash) {
|
||||
setTimeout(function () {
|
||||
$("html, body").animate(
|
||||
{ scrollTop: $(hash).offset().top },
|
||||
100
|
||||
);
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
scrollToHashLocation();
|
||||
setupTextToggles();
|
||||
setupEventHandlers();
|
||||
});
|
||||
|
||||
function setupEventHandlers() {
|
||||
$(window).on("load", scrollToHashLocation);
|
||||
$("body").on("click", ".toggle-link", toggleText);
|
||||
}
|
||||
|
||||
function scrollToHashLocation() {
|
||||
const hash = window.location.hash;
|
||||
if (hash) {
|
||||
setTimeout(() => {
|
||||
$("html, body").animate(
|
||||
{ scrollTop: $(hash).offset().top },
|
||||
100
|
||||
);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function copyPermalink(anchorId) {
|
||||
const fullUrl = `${window.location.origin}${window.location.pathname}${anchorId}`;
|
||||
history.pushState(null, null, anchorId);
|
||||
navigator.clipboard.writeText(fullUrl);
|
||||
scrollToHashLocation();
|
||||
}
|
||||
|
||||
function toggleText(e) {
|
||||
e.preventDefault();
|
||||
const link = $(this),
|
||||
textSpan = link.siblings(".full-text"),
|
||||
toggleSpan = link.siblings(".text-toggle");
|
||||
const visible = textSpan.is(":visible");
|
||||
link.text(visible ? "Show More" : "Show Less");
|
||||
textSpan.toggle();
|
||||
toggleSpan.toggle();
|
||||
}
|
||||
|
||||
function setupTextToggles() {
|
||||
$("table.table td").each(function () {
|
||||
var cell = $(this);
|
||||
if (cell.text().length > 100) {
|
||||
var originalText = cell.text();
|
||||
var displayText =
|
||||
originalText.substring(0, 100) + "...";
|
||||
cell.html(
|
||||
`<span class="text-toggle">${displayText}</span><span class="full-text" style="display: none;">${originalText}</span><a href="#" class="toggle-link">Show More</a>`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
-335
@@ -1,335 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Test Report</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
href="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.0/dist/extensions/sticky-header/bootstrap-table-sticky-header.css"
|
||||
/>
|
||||
<link
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<style>
|
||||
.text-toggle,
|
||||
.full-text {
|
||||
cursor: pointer;
|
||||
}
|
||||
th:nth-child(1),
|
||||
td:nth-child(1) {
|
||||
width: 5%;
|
||||
}
|
||||
th:nth-child(2),
|
||||
td:nth-child(2),
|
||||
th:nth-child(3),
|
||||
td:nth-child(3) {
|
||||
width: 30%;
|
||||
}
|
||||
th,
|
||||
td {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
h2 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.copy-link-icon {
|
||||
font-size: 20px;
|
||||
margin-left: 10px;
|
||||
color: #8f8f97;
|
||||
cursor: pointer;
|
||||
}
|
||||
.copy-link-icon:hover {
|
||||
color: #282b2c;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid"><h2 id="failed-test-cases-on-other-branches">Failed Test Cases on Other branches (Excludes Known Failure Cases)<i class="fas fa-link copy-link-icon"
|
||||
onclick="copyPermalink('#failed-test-cases-on-other-branches')"></i></h2><table data-toggle="table" data-search-align="left" data-search="true" data-sticky-header="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Test Case</th>
|
||||
<th>Test Script File Path</th>
|
||||
<th>Failure Reason</th>
|
||||
<th>Cases that failed in other branches as well (40 latest testcases)</th>
|
||||
<th>Dut Log URL</th>
|
||||
<th>Job URL</th>
|
||||
<th>Grafana URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>('esp32h2', 'esp32h2').('defaults', 'defaults').test_i2c_multi_device</td>
|
||||
<td>components/driver/test_apps/i2c_test_apps/pytest_i2c.py</td>
|
||||
<td>failed on setup with "EOFError"</td>
|
||||
<td>0 / 40</td>
|
||||
<td><a href="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/('esp32h2', 'esp32h2').('defaults', 'defaults').test_i2c_multi_device/dut.txt">link</a></td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=%28%27esp32h2%27%2C%20%27esp32h2%27%29.%28%27defaults%27%2C%20%27defaults%27%29.test_i2c_multi_device">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c3.release.test_esp_timer</td>
|
||||
<td>components/esp_timer/test_apps/pytest_esp_timer_ut.py</td>
|
||||
<td>pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests" Bytes in current buffer (color code eliminated): ce710,len:0x2afc entry 0x403cc710 Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.release.test_esp_timer/dut.txt</td>
|
||||
<td>0 / 40</td>
|
||||
<td><a href="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.release.test_esp_timer/dut.txt">link</a></td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c3.release.test_esp_timer">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c3.default.test_wpa_supplicant_ut</td>
|
||||
<td>components/wpa_supplicant/test_apps/pytest_wpa_supplicant_ut.py</td>
|
||||
<td>pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests" Bytes in current buffer (color code eliminated): 0 d4 000 00x0000 x0000x00 000000 0 Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.default.test_wpa_supplicant_ut/dut.txt</td>
|
||||
<td>0 / 40</td>
|
||||
<td><a href="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.default.test_wpa_supplicant_ut/dut.txt">link</a></td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c3.default.test_wpa_supplicant_ut">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>('esp32h2', 'esp32h2').('default', 'default').test_i2s_multi_dev</td>
|
||||
<td>components/driver/test_apps/i2s_test_apps/i2s_multi_dev/pytest_i2s_multi_dev.py</td>
|
||||
<td>failed on setup with "EOFError"</td>
|
||||
<td>3 / 40</td>
|
||||
<td><a href="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/('esp32h2', 'esp32h2').('default', 'default').test_i2s_multi_dev/dut.txt">link</a></td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=%28%27esp32h2%27%2C%20%27esp32h2%27%29.%28%27default%27%2C%20%27default%27%29.test_i2s_multi_dev">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c2.default.test_wpa_supplicant_ut</td>
|
||||
<td>components/wpa_supplicant/test_apps/pytest_wpa_supplicant_ut.py</td>
|
||||
<td>AssertionError: Unity test failed</td>
|
||||
<td>3 / 40</td>
|
||||
<td><a href="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c2.default.test_wpa_supplicant_ut/dut.txt">link</a></td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c2.default.test_wpa_supplicant_ut">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c3.512safe.test_wear_levelling</td>
|
||||
<td>components/wear_levelling/test_apps/pytest_wear_levelling.py</td>
|
||||
<td>pexpect.exceptions.TIMEOUT: Not found "re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)', re.MULTILINE)" Bytes in current buffer (color code eliminated): Serial port /dev/ttyUSB16 Connecting.... Connecting.... esptool.py v4.7.0 Found 1 serial ports Chip is ESP32-C3 (QFN32) (revision v0.3) Features: WiFi, BLE, Embedded Flash 4MB... (total 6673 bytes) Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.512safe.test_wear_levelling/dut.txt</td>
|
||||
<td>3 / 40</td>
|
||||
<td><a href="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.512safe.test_wear_levelling/dut.txt">link</a></td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c3.512safe.test_wear_levelling">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c3.release.test_wear_levelling</td>
|
||||
<td>components/wear_levelling/test_apps/pytest_wear_levelling.py</td>
|
||||
<td>pexpect.exceptions.TIMEOUT: Not found "re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)', re.MULTILINE)" Bytes in current buffer (color code eliminated): Serial port /dev/ttyUSB16 Connecting.... Connecting.... esptool.py v4.7.0 Found 1 serial ports Chip is ESP32-C3 (QFN32) (revision v0.3) Features: WiFi, BLE, Embedded Flash 4MB... (total 24528 bytes) Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.release.test_wear_levelling/dut.txt</td>
|
||||
<td>3 / 40</td>
|
||||
<td><a href="https://url/esp/esp-idf/pytest-embedded/2024-07-01_10-53-05-207900/esp32c3.release.test_wear_levelling/dut.txt">link</a></td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c3.release.test_wear_levelling">link</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><h2 id="known-failure-cases">Known Failure Cases<i class="fas fa-link copy-link-icon"
|
||||
onclick="copyPermalink('#known-failure-cases')"></i></h2><table data-toggle="table" data-search-align="left" data-search="true" data-sticky-header="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Test Case</th>
|
||||
<th>Test Script File Path</th>
|
||||
<th>Failure Reason</th>
|
||||
<th>Job URL</th>
|
||||
<th>Grafana URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>esp32c2.default.test_wpa_supplicant_ut</td>
|
||||
<td>components/wpa_supplicant/test_apps/pytest_wpa_supplicant_ut.py</td>
|
||||
<td>AssertionError: Unity test failed</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c2.default.test_wpa_supplicant_ut">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c3.release.test_esp_timer</td>
|
||||
<td>components/esp_timer/test_apps/pytest_esp_timer_ut.py</td>
|
||||
<td>pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests" Bytes in current buffer (color code eliminated): ce710,len:0x2afc entry 0x403cc710 Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.release.test_esp_timer/dut.txt</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c3.release.test_esp_timer">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c3.512safe.test_wear_levelling</td>
|
||||
<td>components/wear_levelling/test_apps/pytest_wear_levelling.py</td>
|
||||
<td>pexpect.exceptions.TIMEOUT: Not found "re.compile(b'^[-]+\\s*(\\d+) Tests (\\d+) Failures (\\d+) Ignored\\s*(?P<result>OK|FAIL)', re.MULTILINE)" Bytes in current buffer (color code eliminated): Serial port /dev/ttyUSB16 Connecting.... Connecting.... esptool.py v4.7.0 Found 1 serial ports Chip is ESP32-C3 (QFN32) (revision v0.3) Features: WiFi, BLE, Embedded Flash 4MB... (total 6673 bytes) Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.512safe.test_wear_levelling/dut.txt</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c3.512safe.test_wear_levelling">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c3.default.test_wpa_supplicant_ut</td>
|
||||
<td>components/wpa_supplicant/test_apps/pytest_wpa_supplicant_ut.py</td>
|
||||
<td>pexpect.exceptions.TIMEOUT: Not found "Press ENTER to see the list of tests" Bytes in current buffer (color code eliminated): 0 d4 000 00x0000 x0000x00 000000 0 Please check the full log here: /builds/espressif/esp-idf/pytest_embedded/2024-05-17_17-50-04/esp32c3.default.test_wpa_supplicant_ut/dut.txt</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c3.default.test_wpa_supplicant_ut">link</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><h2 id="skipped-test-cases">Skipped Test Cases<i class="fas fa-link copy-link-icon"
|
||||
onclick="copyPermalink('#skipped-test-cases')"></i></h2><table data-toggle="table" data-search-align="left" data-search="true" data-sticky-header="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Test Case</th>
|
||||
<th>Test Script File Path</th>
|
||||
<th>Skipped Reason</th>
|
||||
<th>Grafana URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>test_python_interpreter_win</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Linux does not support executing .exe files</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_python_interpreter_win">link</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><h2 id="succeeded-test-cases">Succeeded Test Cases<i class="fas fa-link copy-link-icon"
|
||||
onclick="copyPermalink('#succeeded-test-cases')"></i></h2><table data-toggle="table" data-search-align="left" data-search="true" data-sticky-header="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Test Case</th>
|
||||
<th>Test Script File Path</th>
|
||||
<th>Job URL</th>
|
||||
<th>Grafana URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>esp32c2.default.test_vfs_default</td>
|
||||
<td>components/vfs/test_apps/pytest_vfs.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c2.default.test_vfs_default">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>esp32c2.iram.test_vfs_default</td>
|
||||
<td>components/vfs/test_apps/pytest_vfs.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=esp32c2.iram.test_vfs_default">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>test_python_interpreter_unix</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_python_interpreter_unix">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>test_invoke_confserver</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_invoke_confserver">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>test_ccache_used_to_build</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_ccache_used_to_build">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>test_toolchain_prefix_in_description_file</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_toolchain_prefix_in_description_file">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>test_subcommands_with_options</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_subcommands_with_options">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>test_fallback_to_build_system_target</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_fallback_to_build_system_target">link</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>test_create_component_project</td>
|
||||
<td>test_common.py</td>
|
||||
<td>Not found</td>
|
||||
<td><a href="https://test_dashboard_host/d/Ucg477Fnz/case-list?var-case_id=test_create_component_project">link</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.23.0/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>
|
||||
<script>
|
||||
$(window).on("load", function () {
|
||||
var hash = window.location.hash;
|
||||
if (hash) {
|
||||
setTimeout(function () {
|
||||
$("html, body").animate(
|
||||
{ scrollTop: $(hash).offset().top },
|
||||
100
|
||||
);
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
scrollToHashLocation();
|
||||
setupTextToggles();
|
||||
setupEventHandlers();
|
||||
});
|
||||
|
||||
function setupEventHandlers() {
|
||||
$(window).on("load", scrollToHashLocation);
|
||||
$("body").on("click", ".toggle-link", toggleText);
|
||||
}
|
||||
|
||||
function scrollToHashLocation() {
|
||||
const hash = window.location.hash;
|
||||
if (hash) {
|
||||
setTimeout(() => {
|
||||
$("html, body").animate(
|
||||
{ scrollTop: $(hash).offset().top },
|
||||
100
|
||||
);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function copyPermalink(anchorId) {
|
||||
const fullUrl = `${window.location.origin}${window.location.pathname}${anchorId}`;
|
||||
history.pushState(null, null, anchorId);
|
||||
navigator.clipboard.writeText(fullUrl);
|
||||
scrollToHashLocation();
|
||||
}
|
||||
|
||||
function toggleText(e) {
|
||||
e.preventDefault();
|
||||
const link = $(this),
|
||||
textSpan = link.siblings(".full-text"),
|
||||
toggleSpan = link.siblings(".text-toggle");
|
||||
const visible = textSpan.is(":visible");
|
||||
link.text(visible ? "Show More" : "Show Less");
|
||||
textSpan.toggle();
|
||||
toggleSpan.toggle();
|
||||
}
|
||||
|
||||
function setupTextToggles() {
|
||||
$("table.table td").each(function () {
|
||||
var cell = $(this);
|
||||
if (cell.text().length > 100) {
|
||||
var originalText = cell.text();
|
||||
var displayText =
|
||||
originalText.substring(0, 100) + "...";
|
||||
cell.html(
|
||||
`<span class="text-toggle">${displayText}</span><span class="full-text" style="display: none;">${originalText}</span><a href="#" class="toggle-link">Show More</a>`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"jobs": [
|
||||
{"failed_count": 2, "failure_ratio": 0.2, "total_count": 10, "name": "build_clang_test_apps_esp32h2"},
|
||||
{"failed_count": 3, "failure_ratio": 0.3, "total_count": 10, "name": "build_template_app"},
|
||||
{"failed_count": 4, "failure_ratio": 0.4, "total_count": 10, "name": "check_public_headers"}
|
||||
]
|
||||
}
|
||||
-212
@@ -1,212 +0,0 @@
|
||||
{
|
||||
"jobs": [
|
||||
{
|
||||
"duration_sec": 42.158688,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:38:16, 24 May 2024",
|
||||
"id": 48838677,
|
||||
"name": "check_pre_commit",
|
||||
"pending_sec": 1.15148,
|
||||
"runner_name": "FA002598-build",
|
||||
"stage": "pre_check",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838677"
|
||||
},
|
||||
{
|
||||
"duration_sec": 35.438477,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:37:32, 24 May 2024",
|
||||
"id": 48838675,
|
||||
"name": "run-danger-mr-linter",
|
||||
"pending_sec": 0.371668,
|
||||
"runner_name": "BrnoVM0211",
|
||||
"stage": "pre_check",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838675"
|
||||
},
|
||||
{
|
||||
"duration_sec": 30.202475,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:37:28, 24 May 2024",
|
||||
"id": 48838682,
|
||||
"name": "check_esp_system",
|
||||
"pending_sec": 1.148756,
|
||||
"runner_name": "ruby6-cent9 [32]",
|
||||
"stage": "pre_check",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838682"
|
||||
},
|
||||
{
|
||||
"duration_sec": 33.75121,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:37:31, 24 May 2024",
|
||||
"id": 48838679,
|
||||
"name": "check_blobs",
|
||||
"pending_sec": 0.725292,
|
||||
"runner_name": "gem3-cent9 [32]",
|
||||
"stage": "pre_check",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838679"
|
||||
},
|
||||
{
|
||||
"duration_sec": 121.84324,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:41:35, 24 May 2024",
|
||||
"id": 48838687,
|
||||
"name": "code_quality_check",
|
||||
"pending_sec": 0.271973,
|
||||
"runner_name": "ruby15-cent9 [32]",
|
||||
"stage": "build",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838687"
|
||||
},
|
||||
{
|
||||
"duration_sec": 153.68849,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:39:32, 24 May 2024",
|
||||
"id": 48838686,
|
||||
"name": "fast_template_app",
|
||||
"pending_sec": 2.319577,
|
||||
"runner_name": "FA002598-build",
|
||||
"stage": "pre_check",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838686"
|
||||
},
|
||||
{
|
||||
"duration_sec": 25.572954,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:37:23, 24 May 2024",
|
||||
"id": 48838684,
|
||||
"name": "check_configure_ci_environment_parsing",
|
||||
"pending_sec": 1.184287,
|
||||
"runner_name": "gem3-cent9 [32]",
|
||||
"stage": "pre_check",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838684"
|
||||
},
|
||||
{
|
||||
"duration_sec": 120.95287,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:41:34, 24 May 2024",
|
||||
"id": 48838690,
|
||||
"name": "build_clang_test_apps_esp32s3",
|
||||
"pending_sec": 0.671956,
|
||||
"runner_name": "ruby7-cent9 [32]",
|
||||
"stage": "build",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838690"
|
||||
},
|
||||
{
|
||||
"duration_sec": 165.74513,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:42:19, 24 May 2024",
|
||||
"id": 48838692,
|
||||
"name": "build_clang_test_apps_esp32c2",
|
||||
"pending_sec": 0.82007,
|
||||
"runner_name": "PowerfulBuildRunner03 [16]",
|
||||
"stage": "build",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838692"
|
||||
},
|
||||
{
|
||||
"duration_sec": 95.72326,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:41:09, 24 May 2024",
|
||||
"id": 48838696,
|
||||
"name": "build_clang_test_apps_esp32p4",
|
||||
"pending_sec": 0.567116,
|
||||
"runner_name": "gem3-cent9 [32]",
|
||||
"stage": "build",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838696"
|
||||
},
|
||||
{
|
||||
"duration_sec": 122.19848,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:41:36, 24 May 2024",
|
||||
"id": 48838691,
|
||||
"name": "build_clang_test_apps_esp32c3",
|
||||
"pending_sec": 0.709112,
|
||||
"runner_name": "ruby6-cent9 [32]",
|
||||
"stage": "build",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838691"
|
||||
},
|
||||
{
|
||||
"duration_sec": 148.09895,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:42:02, 24 May 2024",
|
||||
"id": 48838694,
|
||||
"name": "build_clang_test_apps_esp32c5",
|
||||
"pending_sec": 0.779584,
|
||||
"runner_name": "PowerfulBuildRunner04 [15]",
|
||||
"stage": "build",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838694"
|
||||
},
|
||||
{
|
||||
"duration_sec": 20.275927,
|
||||
"failure_log": null,
|
||||
"failure_reason": null,
|
||||
"finished_at": "03:39:54, 24 May 2024",
|
||||
"id": 48838699,
|
||||
"name": "gen_integration_pipeline",
|
||||
"pending_sec": 0.868898,
|
||||
"runner_name": "FA002598-build",
|
||||
"stage": "assign_test",
|
||||
"status": "success",
|
||||
"url": "https://test.com/-/jobs/48838699"
|
||||
},
|
||||
{
|
||||
"duration_sec": 103.08849,
|
||||
"failure_log": "Some Failure LogSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason",
|
||||
"failure_reason": "Some Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason",
|
||||
"finished_at": "03:41:17, 24 May 2024",
|
||||
"id": 48838695,
|
||||
"name": "build_clang_test_apps_esp32h2",
|
||||
"pending_sec": 0.765111,
|
||||
"runner_name": "gem2-cent9 [32]",
|
||||
"stage": "build",
|
||||
"status": "failed",
|
||||
"url": "https://test.com/-/jobs/48838695"
|
||||
},
|
||||
{
|
||||
"duration_sec": 634.59467,
|
||||
"failure_log": "Some Failure LogSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason",
|
||||
"failure_reason": "Some Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason",
|
||||
"finished_at": "03:50:09, 24 May 2024",
|
||||
"id": 48838704,
|
||||
"name": "build_template_app",
|
||||
"pending_sec": 0.161796,
|
||||
"runner_name": "ruby6-cent9 [32]",
|
||||
"stage": "host_test",
|
||||
"status": "failed",
|
||||
"url": "https://test.com/-/jobs/48838704"
|
||||
},
|
||||
{
|
||||
"duration_sec": 1060.0835,
|
||||
"failure_log": "Some Failure Log",
|
||||
"failure_reason": "Some Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure ReasonSome Failure Reason",
|
||||
"finished_at": "03:55:14, 24 May 2024",
|
||||
"id": 48838705,
|
||||
"name": "check_public_headers",
|
||||
"pending_sec": 0.449408,
|
||||
"runner_name": "ruby6-cent9 [32]",
|
||||
"stage": "host_test",
|
||||
"status": "failed",
|
||||
"url": "https://test.com/-/jobs/48838705"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import json
|
||||
import os.path
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import patch
|
||||
|
||||
sys.path.insert(0, os.path.join(f'{os.environ.get("IDF_PATH")}', 'tools', 'ci', 'python_packages'))
|
||||
sys.path.insert(0, os.path.join(f'{os.environ.get("IDF_PATH")}', 'tools', 'ci'))
|
||||
|
||||
from dynamic_pipelines.models import GitlabJob # noqa: E402
|
||||
from dynamic_pipelines.report import JobReportGenerator, TargetTestReportGenerator # noqa: E402
|
||||
from dynamic_pipelines.utils import load_file, parse_testcases_from_filepattern # noqa: E402
|
||||
|
||||
|
||||
class TestReportGeneration(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.reports_sample_data_path = os.path.join(
|
||||
os.environ.get('IDF_PATH', ''), 'tools', 'ci', 'dynamic_pipelines', 'tests', 'test_report_generator', 'reports_sample_data'
|
||||
)
|
||||
self.setup_patches()
|
||||
self.load_test_and_job_reports()
|
||||
self.create_report_generators()
|
||||
|
||||
def setup_patches(self) -> None:
|
||||
self.gitlab_patcher = patch('dynamic_pipelines.report.Gitlab')
|
||||
self.failure_rate_patcher = patch('dynamic_pipelines.report.fetch_failed_testcases_failure_ratio')
|
||||
self.env_patcher = patch.dict('os.environ', {
|
||||
'CI_DASHBOARD_HOST': 'https://test_dashboard_host',
|
||||
'CI_PAGES_URL': 'https://artifacts_path',
|
||||
'CI_JOB_ID': '1',
|
||||
})
|
||||
|
||||
self.MockGitlab = self.gitlab_patcher.start()
|
||||
self.test_cases_failure_rate = self.failure_rate_patcher.start()
|
||||
self.env_patcher.start()
|
||||
|
||||
self.mock_project = MagicMock()
|
||||
self.mock_mr = MagicMock()
|
||||
self.MockGitlab.return_value.project = self.mock_project
|
||||
self.mock_project.mergerequests.get.return_value = self.mock_mr
|
||||
|
||||
self.addCleanup(self.gitlab_patcher.stop)
|
||||
self.addCleanup(self.failure_rate_patcher.stop)
|
||||
self.addCleanup(self.env_patcher.stop)
|
||||
self.addCleanup(self.cleanup_files)
|
||||
|
||||
def cleanup_files(self) -> None:
|
||||
files_to_delete = [
|
||||
self.target_test_report_generator.skipped_test_cases_report_file,
|
||||
self.target_test_report_generator.succeeded_cases_report_file,
|
||||
self.target_test_report_generator.failed_cases_report_file,
|
||||
]
|
||||
for file_path in files_to_delete:
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
||||
def load_test_and_job_reports(self) -> None:
|
||||
self.expected_target_test_report_html = load_file(
|
||||
os.path.join(self.reports_sample_data_path, 'expected_target_test_report.html')
|
||||
)
|
||||
self.expected_job_report_html = load_file(
|
||||
os.path.join(self.reports_sample_data_path, 'expected_job_report.html')
|
||||
)
|
||||
|
||||
def create_report_generators(self) -> None:
|
||||
jobs_response_raw = load_file(os.path.join(self.reports_sample_data_path, 'jobs_api_response.json'))
|
||||
failure_rate_jobs_response = load_file(os.path.join(self.reports_sample_data_path, 'failure_rate_jobs_response.json'))
|
||||
failure_rates = {item['name']: item for item in json.loads(failure_rate_jobs_response).get('jobs', [])}
|
||||
jobs = [GitlabJob.from_json_data(job_json, failure_rates.get(job_json['name'], {})) for job_json in json.loads(jobs_response_raw)['jobs']]
|
||||
test_cases = parse_testcases_from_filepattern(os.path.join(self.reports_sample_data_path, 'XUNIT_*.xml'))
|
||||
self.target_test_report_generator = TargetTestReportGenerator(
|
||||
project_id=123,
|
||||
mr_iid=1,
|
||||
pipeline_id=456,
|
||||
job_id=0,
|
||||
commit_id='cccc',
|
||||
title='Test Report',
|
||||
test_cases=test_cases
|
||||
)
|
||||
self.job_report_generator = JobReportGenerator(
|
||||
project_id=123,
|
||||
mr_iid=1,
|
||||
pipeline_id=456,
|
||||
job_id=0,
|
||||
commit_id='cccc',
|
||||
title='Job Report',
|
||||
jobs=jobs
|
||||
)
|
||||
self.target_test_report_generator._known_failure_cases_set = {
|
||||
'*.test_wpa_supplicant_ut',
|
||||
'esp32c3.release.test_esp_timer',
|
||||
'*.512safe.test_wear_levelling',
|
||||
}
|
||||
test_cases_failed = [tc for tc in test_cases if tc.is_failure]
|
||||
for index, tc in enumerate(test_cases_failed):
|
||||
tc.latest_total_count = 40
|
||||
if index % 3 == 0:
|
||||
tc.latest_failed_count = 0
|
||||
else:
|
||||
tc.latest_failed_count = 3
|
||||
self.test_cases_failure_rate.return_value = test_cases_failed
|
||||
|
||||
def test_known_failure_cases(self) -> None:
|
||||
known_failure_cases = self.target_test_report_generator.get_known_failure_cases()
|
||||
self.assertEqual(len(known_failure_cases), 4)
|
||||
|
||||
def test_failed_cases_in_target_test_report(self) -> None:
|
||||
known_failures = self.target_test_report_generator.get_known_failure_cases()
|
||||
known_failure_case_names = {case.name for case in known_failures}
|
||||
failed_testcases = self.target_test_report_generator._filter_items(
|
||||
self.target_test_report_generator.test_cases,
|
||||
lambda tc: tc.is_failure and tc.name not in known_failure_case_names,
|
||||
)
|
||||
self.assertEqual(len(failed_testcases), 3)
|
||||
|
||||
def test_skipped_cases_in_target_test_report(self) -> None:
|
||||
skipped_testcases = self.target_test_report_generator._filter_items(
|
||||
self.target_test_report_generator.test_cases, lambda tc: tc.is_skipped
|
||||
)
|
||||
self.assertEqual(len(skipped_testcases), 1)
|
||||
|
||||
def test_successful_cases_in_target_test_report(self) -> None:
|
||||
succeeded_testcases = self.target_test_report_generator._filter_items(
|
||||
self.target_test_report_generator.test_cases, lambda tc: tc.is_success
|
||||
)
|
||||
self.assertEqual(len(succeeded_testcases), 9)
|
||||
|
||||
def test_target_test_report_html_structure(self) -> None:
|
||||
report = self.target_test_report_generator._get_report_str()
|
||||
self.assertEqual(report, self.expected_target_test_report_html)
|
||||
|
||||
def test_failed_jobs_in_job_report(self) -> None:
|
||||
failed_jobs = self.job_report_generator._filter_items(self.job_report_generator.jobs, lambda job: job.is_failed)
|
||||
self.assertEqual(len(failed_jobs), 3)
|
||||
|
||||
def test_successful_jobs_in_job_report(self) -> None:
|
||||
succeeded_jobs = self.job_report_generator._filter_items(
|
||||
self.job_report_generator.jobs, lambda job: job.is_success
|
||||
)
|
||||
self.assertEqual(len(succeeded_jobs), 13)
|
||||
|
||||
def test_job_report_html_structure(self) -> None:
|
||||
report = self.job_report_generator._get_report_str()
|
||||
self.assertEqual(report, self.expected_job_report_html)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,218 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import typing as t
|
||||
import xml.etree.ElementTree as ET
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
|
||||
from .constants import CI_DASHBOARD_API
|
||||
from .constants import CI_JOB_TOKEN
|
||||
from .constants import CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
|
||||
from .constants import CI_PAGES_URL
|
||||
from .constants import CI_PROJECT_URL
|
||||
from .models import GitlabJob
|
||||
from .models import Job
|
||||
from .models import TestCase
|
||||
|
||||
|
||||
def dump_jobs_to_yaml(
|
||||
jobs: t.List[Job],
|
||||
output_filepath: str,
|
||||
pipeline_name: str,
|
||||
extra_include_yml: t.Optional[t.List[str]] = None,
|
||||
) -> None:
|
||||
yaml_dict = {}
|
||||
for job in jobs:
|
||||
yaml_dict.update(job.to_dict())
|
||||
|
||||
# global stuffs
|
||||
yaml_dict.update(
|
||||
{
|
||||
'include': [
|
||||
'tools/ci/dynamic_pipelines/templates/.dynamic_jobs.yml',
|
||||
'.gitlab/ci/common.yml',
|
||||
],
|
||||
'workflow': {
|
||||
'name': pipeline_name,
|
||||
'rules': [
|
||||
# always run the child pipeline, if they are created
|
||||
{'when': 'always'},
|
||||
],
|
||||
},
|
||||
}
|
||||
)
|
||||
yaml_dict['include'].extend(extra_include_yml or [])
|
||||
|
||||
with open(output_filepath, 'w') as fw:
|
||||
yaml.dump(yaml_dict, fw, indent=2)
|
||||
|
||||
|
||||
def parse_testcases_from_filepattern(junit_report_filepattern: str) -> t.List[TestCase]:
|
||||
"""
|
||||
Parses test cases from XML files matching the provided file pattern.
|
||||
|
||||
>>> test_cases = parse_testcases_from_filepattern("path/to/your/junit/reports/*.xml")
|
||||
|
||||
:param junit_report_filepattern: The file pattern to match XML files containing JUnit test reports.
|
||||
:return: List[TestCase]: A list of TestCase objects parsed from the XML files.
|
||||
"""
|
||||
|
||||
test_cases = []
|
||||
for f in glob.glob(junit_report_filepattern):
|
||||
root = ET.parse(f).getroot()
|
||||
for tc in root.findall('.//testcase'):
|
||||
test_cases.append(TestCase.from_test_case_node(tc))
|
||||
return test_cases
|
||||
|
||||
|
||||
def load_known_failure_cases() -> t.Optional[t.Set[str]]:
|
||||
known_failures_file = os.getenv('KNOWN_FAILURE_CASES_FILE_NAME', '')
|
||||
if not known_failures_file:
|
||||
return None
|
||||
try:
|
||||
with open(known_failures_file, 'r') as f:
|
||||
file_content = f.read()
|
||||
|
||||
pattern = re.compile(r'^(.*?)\s+#\s+([A-Z]+)-\d+', re.MULTILINE)
|
||||
matches = pattern.findall(file_content)
|
||||
|
||||
known_cases_list = [match[0].strip() for match in matches]
|
||||
return set(known_cases_list)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
|
||||
def is_url(string: str) -> bool:
|
||||
"""
|
||||
Check if the string is a valid URL by parsing it and verifying if it contains both a scheme and a network location.
|
||||
|
||||
:param string: The string to check if it is a URL.
|
||||
:return: True if the string is a valid URL, False otherwise.
|
||||
"""
|
||||
parsed = urlparse(string)
|
||||
return bool(parsed.scheme) and bool(parsed.netloc)
|
||||
|
||||
|
||||
def fetch_failed_jobs(commit_id: str) -> t.List[GitlabJob]:
|
||||
"""
|
||||
Fetches a list of jobs from the specified commit_id using an API request to ci-dashboard-api.
|
||||
:param commit_id: The commit ID for which to fetch jobs.
|
||||
:return: A list of jobs if the request is successful, otherwise an empty list.
|
||||
"""
|
||||
response = requests.get(
|
||||
f'{CI_DASHBOARD_API}/commits/{commit_id}/jobs',
|
||||
headers={'CI-Job-Token': CI_JOB_TOKEN},
|
||||
)
|
||||
if response.status_code != 200:
|
||||
print(f'Failed to fetch jobs data: {response.status_code} with error: {response.text}')
|
||||
return []
|
||||
|
||||
data = response.json()
|
||||
jobs = data.get('jobs', [])
|
||||
|
||||
if not jobs:
|
||||
return []
|
||||
|
||||
failed_job_names = [job['name'] for job in jobs if job['status'] == 'failed']
|
||||
response = requests.post(
|
||||
f'{CI_DASHBOARD_API}/jobs/failure_ratio',
|
||||
headers={'CI-Job-Token': CI_JOB_TOKEN},
|
||||
json={'job_names': failed_job_names, 'exclude_branches': [os.getenv('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME', '')]},
|
||||
)
|
||||
if response.status_code != 200:
|
||||
print(f'Failed to fetch jobs failure rate data: {response.status_code} with error: {response.text}')
|
||||
return []
|
||||
|
||||
failure_rate_data = response.json()
|
||||
failure_rates = {item['name']: item for item in failure_rate_data.get('jobs', [])}
|
||||
|
||||
combined_jobs = []
|
||||
for job in jobs:
|
||||
failure_data = failure_rates.get(job['name'], {})
|
||||
combined_jobs.append(GitlabJob.from_json_data(job, failure_data))
|
||||
|
||||
return combined_jobs
|
||||
|
||||
|
||||
def fetch_failed_testcases_failure_ratio(failed_testcases: t.List[TestCase], branches_filter: dict) -> t.List[TestCase]:
|
||||
"""
|
||||
Fetches info about failure rates of testcases using an API request to ci-dashboard-api.
|
||||
:param failed_testcases: The list of failed testcases models.
|
||||
:param branches_filter: The filter to filter testcases by branch names.
|
||||
:return: A list of testcases with enriched with failure rates data.
|
||||
"""
|
||||
req_json = {'testcase_names': list(set([testcase.name for testcase in failed_testcases])), **branches_filter}
|
||||
response = requests.post(
|
||||
f'{CI_DASHBOARD_API}/testcases/failure_ratio',
|
||||
headers={'CI-Job-Token': CI_JOB_TOKEN},
|
||||
json=req_json,
|
||||
)
|
||||
if response.status_code != 200:
|
||||
print(f'Failed to fetch testcases failure rate data: {response.status_code} with error: {response.text}')
|
||||
return []
|
||||
|
||||
failure_rate_data = response.json()
|
||||
failure_rates = {item['name']: item for item in failure_rate_data.get('testcases', [])}
|
||||
|
||||
for testcase in failed_testcases:
|
||||
testcase.latest_total_count = failure_rates.get(testcase.name, {}).get('total_count', 0)
|
||||
testcase.latest_failed_count = failure_rates.get(testcase.name, {}).get('failed_count', 0)
|
||||
|
||||
return failed_testcases
|
||||
|
||||
|
||||
def load_file(file_path: str) -> str:
|
||||
"""
|
||||
Loads the content of a file.
|
||||
|
||||
:param file_path: The path to the file needs to be loaded.
|
||||
:return: The content of the file as a string.
|
||||
"""
|
||||
with open(file_path, 'r') as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def format_permalink(s: str) -> str:
|
||||
"""
|
||||
Formats a given string into a permalink.
|
||||
|
||||
:param s: The string to be formatted into a permalink.
|
||||
:return: The formatted permalink as a string.
|
||||
"""
|
||||
end_index = s.find('(')
|
||||
|
||||
if end_index != -1:
|
||||
trimmed_string = s[:end_index].strip()
|
||||
else:
|
||||
trimmed_string = s.strip()
|
||||
|
||||
formatted_string = trimmed_string.lower().replace(' ', '-')
|
||||
|
||||
return formatted_string
|
||||
|
||||
|
||||
def get_artifacts_url(job_id: int, output_filepath: str) -> str:
|
||||
"""
|
||||
Generates the url of the path where the artifact will be stored in the job's artifacts .
|
||||
|
||||
:param job_id: The job identifier used to construct the URL.
|
||||
:param output_filepath: The path to the output file.
|
||||
:return: The modified URL pointing to the job's artifacts.
|
||||
"""
|
||||
url = CI_PAGES_URL.replace('esp-idf', '-/esp-idf')
|
||||
return f'{url}/-/jobs/{job_id}/artifacts/{output_filepath}'
|
||||
|
||||
|
||||
def get_repository_file_url(file_path: str) -> str:
|
||||
"""
|
||||
Generates the url of the file path inside the repository.
|
||||
|
||||
:param file_path: The file path where the file is stored.
|
||||
:return: The modified URL pointing to the file's path in the repository.
|
||||
"""
|
||||
return f'{CI_PROJECT_URL}/-/raw/{CI_MERGE_REQUEST_SOURCE_BRANCH_SHA}/{file_path}'
|
||||
@@ -4,18 +4,15 @@ tools/ci/check_*.py
|
||||
tools/ci/check_*.txt
|
||||
tools/ci/check_*.sh
|
||||
tools/ci/check_copyright_config.yaml
|
||||
tools/ci/get_all_test_results.py
|
||||
tools/gdb_panic_server.py
|
||||
tools/check_term.py
|
||||
tools/python_version_checker.py
|
||||
tools/ci/astyle-rules.yml
|
||||
tools/ci/checkout_project_ref.py
|
||||
tools/ci/ci_fetch_submodule.py
|
||||
tools/ci/ci_get_mr_info.py
|
||||
tools/ci/ci_process_description.py
|
||||
tools/ci/configure_ci_environment.sh
|
||||
tools/ci/generate_rules.py
|
||||
tools/ci/deploy_docs.py
|
||||
tools/ci/envsubst.py
|
||||
tools/ci/*exclude*.txt
|
||||
tools/ci/executable-list.txt
|
||||
@@ -53,7 +50,6 @@ tools/ci/python_packages/idf_iperf_test_util/**/*
|
||||
tools/esp_prov/**/*
|
||||
tools/ci/sort_yaml.py
|
||||
tools/ci/sg_rules/*
|
||||
tools/ci/previous_stage_job_status.py
|
||||
tools/legacy_exports/export_legacy.fish
|
||||
tools/legacy_exports/export_legacy.sh
|
||||
tools/legacy_exports/export_legacy.ps1
|
||||
|
||||
@@ -67,7 +67,6 @@ tools/ci/check_tools_files_patterns.py
|
||||
tools/ci/check_type_comments.py
|
||||
tools/ci/checkout_project_ref.py
|
||||
tools/ci/cleanup_ignore_lists.py
|
||||
tools/ci/deploy_docs.py
|
||||
tools/ci/envsubst.py
|
||||
tools/ci/fix_empty_prototypes.sh
|
||||
tools/ci/generate_rules.py
|
||||
|
||||
+61
-62
@@ -1,39 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import inspect
|
||||
import os
|
||||
import sys
|
||||
import typing as t
|
||||
from collections import defaultdict
|
||||
from itertools import product
|
||||
|
||||
import yaml
|
||||
from idf_ci_utils import GitlabYmlConfig
|
||||
from idf_ci_utils import IDF_PATH
|
||||
|
||||
try:
|
||||
if t.TYPE_CHECKING:
|
||||
import pygraphviz as pgv
|
||||
except ImportError: # used when pre-commit, skip generating image
|
||||
pass
|
||||
|
||||
try:
|
||||
from typing import Union
|
||||
except ImportError: # used for type hint
|
||||
pass
|
||||
|
||||
|
||||
def _list(str_or_list): # type: (Union[str, list]) -> list
|
||||
def _list(str_or_list: str | list) -> list:
|
||||
if isinstance(str_or_list, str):
|
||||
return [str_or_list]
|
||||
elif isinstance(str_or_list, list):
|
||||
return str_or_list
|
||||
else:
|
||||
raise ValueError('Wrong type: {}. Only supports str or list.'.format(type(str_or_list)))
|
||||
raise ValueError(f'Wrong type: {type(str_or_list)}. Only supports str or list.')
|
||||
|
||||
|
||||
def _format_nested_dict(_dict, f_tuple): # type: (dict[str, dict], tuple[str, ...]) -> dict[str, dict]
|
||||
def _format_nested_dict(_dict: dict[str, dict], f_tuple: tuple[str, ...]) -> dict[str, dict]:
|
||||
res = {}
|
||||
for k, v in _dict.items():
|
||||
k = k.split('__')[0]
|
||||
@@ -47,7 +43,7 @@ def _format_nested_dict(_dict, f_tuple): # type: (dict[str, dict], tuple[str, .
|
||||
return res
|
||||
|
||||
|
||||
def _format_nested_list(_list, f_tuple): # type: (list[str], tuple[str, ...]) -> list[str]
|
||||
def _format_nested_list(_list: list[str], f_tuple: tuple[str, ...]) -> list[str]:
|
||||
res = []
|
||||
for item in _list:
|
||||
if isinstance(item, list):
|
||||
@@ -61,26 +57,23 @@ def _format_nested_list(_list, f_tuple): # type: (list[str], tuple[str, ...]) -
|
||||
|
||||
|
||||
class RulesWriter:
|
||||
AUTO_GENERATE_MARKER = inspect.cleandoc(r'''
|
||||
AUTO_GENERATE_MARKER = inspect.cleandoc(r"""
|
||||
##################
|
||||
# Auto Generated #
|
||||
##################
|
||||
''')
|
||||
""")
|
||||
|
||||
LABEL_TEMPLATE = inspect.cleandoc(r'''
|
||||
LABEL_TEMPLATE = inspect.cleandoc(r"""
|
||||
.if-label-{0}: &if-label-{0}
|
||||
if: '$BOT_LABEL_{1} || $CI_MERGE_REQUEST_LABELS =~ /^(?:[^,\n\r]+,)*{0}(?:,[^,\n\r]+)*$/i'
|
||||
''')
|
||||
""")
|
||||
|
||||
RULE_PROTECTED = ' - <<: *if-protected'
|
||||
RULE_PROTECTED_NO_LABEL = ' - <<: *if-protected-no_label'
|
||||
RULE_BUILD_ONLY = ' - <<: *if-label-build-only\n' \
|
||||
' when: never'
|
||||
RULE_REVERT_BRANCH = ' - <<: *if-revert-branch\n' \
|
||||
' when: never'
|
||||
RULE_PROTECTED_CHECK = ' - <<: *if-protected-check'
|
||||
RULE_PROTECTED_PUSH = ' - <<: *if-protected-push'
|
||||
RULE_BUILD_ONLY = ' - <<: *if-label-build-only\n when: never'
|
||||
RULE_REVERT_BRANCH = ' - <<: *if-revert-branch\n when: never'
|
||||
RULE_LABEL_TEMPLATE = ' - <<: *if-label-{0}'
|
||||
RULE_PATTERN_TEMPLATE = ' - <<: *if-dev-push\n' \
|
||||
' changes: *patterns-{0}'
|
||||
RULE_PATTERN_TEMPLATE = ' - <<: *if-dev-push\n changes: *patterns-{0}'
|
||||
SPECIFIC_RULE_TEMPLATE = ' - <<: *{0}'
|
||||
RULES_TEMPLATE = inspect.cleandoc(r"""
|
||||
.rules:{0}:
|
||||
@@ -99,7 +92,6 @@ class RulesWriter:
|
||||
self.cfg = self.expand_matrices()
|
||||
self.rules = self.expand_rules()
|
||||
|
||||
self.yml_config = GitlabYmlConfig()
|
||||
self.graph = None
|
||||
|
||||
def expand_matrices(self): # type: () -> dict
|
||||
@@ -116,11 +108,11 @@ class RulesWriter:
|
||||
deploy = v.get('deploy')
|
||||
if deploy:
|
||||
for item in _list(deploy):
|
||||
res['{}-{}'.format(k, item)] = v
|
||||
res[f'{k}-{item}'] = v
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def _expand_matrix(name, cfg): # type: (str, dict) -> dict
|
||||
def _expand_matrix(name: str, cfg: dict[str, t.Any]) -> dict[str, t.Any]:
|
||||
"""
|
||||
Expand matrix into multi keys
|
||||
:param cfg: single rule dict
|
||||
@@ -138,7 +130,7 @@ class RulesWriter:
|
||||
res.update(_format_nested_dict(default, comb))
|
||||
return res
|
||||
|
||||
def expand_rules(self): # type: () -> dict[str, dict[str, list]]
|
||||
def expand_rules(self) -> dict[str, dict[str, list[str]]]:
|
||||
res = defaultdict(lambda: defaultdict(set)) # type: dict[str, dict[str, set]]
|
||||
for k, v in self.cfg.items():
|
||||
if not v:
|
||||
@@ -164,18 +156,18 @@ class RulesWriter:
|
||||
if 'patterns' in v:
|
||||
for _pat in _list(v['patterns']):
|
||||
# Patterns must be pre-defined
|
||||
if '.patterns-{}'.format(_pat) not in self.rules_cfg:
|
||||
print('WARNING: pattern {} not exists'.format(_pat))
|
||||
if f'.patterns-{_pat}' not in self.rules_cfg:
|
||||
print(f'WARNING: pattern {_pat} not exists')
|
||||
continue
|
||||
res[item]['patterns'].add(_pat)
|
||||
|
||||
sorted_res = defaultdict(lambda: defaultdict(list)) # type: dict[str, dict[str, list]]
|
||||
sorted_res = defaultdict(lambda: defaultdict(list)) # type: t.Dict[str, t.Dict[str, t.List[str]]]
|
||||
for k, v in res.items():
|
||||
for vk, vv in v.items():
|
||||
sorted_res[k][vk] = sorted(vv)
|
||||
return sorted_res
|
||||
|
||||
def new_labels_str(self): # type: () -> str
|
||||
def new_labels_str(self) -> str:
|
||||
_labels = set([])
|
||||
for k, v in self.cfg.items():
|
||||
if not v:
|
||||
@@ -191,33 +183,29 @@ class RulesWriter:
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def _format_label(cls, label): # type: (str) -> str
|
||||
def _format_label(cls, label: str) -> str:
|
||||
return cls.LABEL_TEMPLATE.format(label, cls.bot_label_str(label))
|
||||
|
||||
@staticmethod
|
||||
def bot_label_str(label): # type: (str) -> str
|
||||
def bot_label_str(label: str) -> str:
|
||||
return label.upper().replace('-', '_')
|
||||
|
||||
def new_rules_str(self): # type: () -> str
|
||||
def new_rules_str(self) -> str:
|
||||
res = []
|
||||
for k, v in sorted(self.rules.items()):
|
||||
if k.startswith('pattern'):
|
||||
continue
|
||||
|
||||
if '.rules:' + k not in self.yml_config.used_templates:
|
||||
print(f'WARNING: unused rule: {k}, skipping...')
|
||||
continue
|
||||
|
||||
res.append(self.RULES_TEMPLATE.format(k, self._format_rule(k, v)))
|
||||
return '\n\n'.join(res)
|
||||
|
||||
def _format_rule(self, name, cfg): # type: (str, dict) -> str
|
||||
def _format_rule(self, name: str, cfg: dict[str, t.Any]) -> str:
|
||||
_rules = [self.RULE_REVERT_BRANCH]
|
||||
if name.endswith('-production'):
|
||||
_rules.append(self.RULE_PROTECTED_NO_LABEL)
|
||||
_rules.append(self.RULE_PROTECTED_PUSH)
|
||||
else:
|
||||
if not (name.endswith('-preview') or name.startswith('labels:')):
|
||||
_rules.append(self.RULE_PROTECTED)
|
||||
_rules.append(self.RULE_PROTECTED_CHECK)
|
||||
if name.startswith('test:'):
|
||||
_rules.append(self.RULE_BUILD_ONLY)
|
||||
|
||||
@@ -225,21 +213,21 @@ class RulesWriter:
|
||||
if f'.{specific_rule}' in self.rules_cfg:
|
||||
_rules.append(self.SPECIFIC_RULE_TEMPLATE.format(specific_rule))
|
||||
else:
|
||||
print('WARNING: specific_rule {} not exists'.format(specific_rule))
|
||||
print(f'WARNING: specific_rule {specific_rule} not exists')
|
||||
for label in cfg['labels']:
|
||||
_rules.append(self.RULE_LABEL_TEMPLATE.format(label))
|
||||
for pattern in cfg['patterns']:
|
||||
if '.patterns-{}'.format(pattern) in self.rules_cfg:
|
||||
if f'.patterns-{pattern}' in self.rules_cfg:
|
||||
_rules.append(self.RULE_PATTERN_TEMPLATE.format(pattern))
|
||||
else:
|
||||
print('WARNING: pattern {} not exists'.format(pattern))
|
||||
print(f'WARNING: pattern {pattern} not exists')
|
||||
return '\n'.join(_rules)
|
||||
|
||||
def update_rules_yml(self): # type: () -> bool
|
||||
def update_rules_yml(self) -> bool:
|
||||
with open(self.rules_yml) as fr:
|
||||
file_str = fr.read()
|
||||
|
||||
auto_generate_str = '\n{}\n\n{}\n'.format(self.new_labels_str(), self.new_rules_str())
|
||||
auto_generate_str = f'\n{self.new_labels_str()}\n\n{self.new_rules_str()}\n'
|
||||
rest, marker, old = file_str.partition(self.AUTO_GENERATE_MARKER)
|
||||
if old == auto_generate_str:
|
||||
return False
|
||||
@@ -255,7 +243,9 @@ PATTERN_COLOR = 'cyan'
|
||||
RULE_COLOR = 'blue'
|
||||
|
||||
|
||||
def build_graph(rules_dict): # type: (dict[str, dict[str, list]]) -> pgv.AGraph
|
||||
def build_graph(rules_dict: dict[str, dict[str, list[str]]]) -> pgv.AGraph:
|
||||
from pygraphviz import pgv
|
||||
|
||||
graph = pgv.AGraph(directed=True, rankdir='LR', concentrate=True)
|
||||
|
||||
for k, v in rules_dict.items():
|
||||
@@ -270,18 +260,18 @@ def build_graph(rules_dict): # type: (dict[str, dict[str, list]]) -> pgv.AGraph
|
||||
labels = v.get('labels')
|
||||
if labels:
|
||||
for _label in labels:
|
||||
graph.add_node('label:{}'.format(_label), color=LABEL_COLOR)
|
||||
graph.add_edge('label:{}'.format(_label), k, color=LABEL_COLOR)
|
||||
graph.add_node(f'label:{_label}', color=LABEL_COLOR)
|
||||
graph.add_edge(f'label:{_label}', k, color=LABEL_COLOR)
|
||||
patterns = v.get('patterns')
|
||||
if patterns:
|
||||
for _pat in patterns:
|
||||
graph.add_node('pattern:{}'.format(_pat), color=PATTERN_COLOR)
|
||||
graph.add_edge('pattern:{}'.format(_pat), k, color=PATTERN_COLOR)
|
||||
graph.add_node(f'pattern:{_pat}', color=PATTERN_COLOR)
|
||||
graph.add_edge(f'pattern:{_pat}', k, color=PATTERN_COLOR)
|
||||
|
||||
return graph
|
||||
|
||||
|
||||
def output_graph(graph, output_path='output.png'): # type: (pgv.AGraph, str) -> None
|
||||
def output_graph(graph: pgv.AGraph, output_path: str = 'output.png') -> None:
|
||||
graph.layout('dot')
|
||||
if output_path.endswith('.png'):
|
||||
img_path = output_path
|
||||
@@ -292,13 +282,22 @@ def output_graph(graph, output_path='output.png'): # type: (pgv.AGraph, str) ->
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('rules_yml', nargs='?', default=os.path.join(IDF_PATH, '.gitlab', 'ci', 'rules.yml'),
|
||||
help='rules.yml file path')
|
||||
parser.add_argument('dependencies_yml', nargs='?', default=os.path.join(IDF_PATH, '.gitlab', 'ci', 'dependencies',
|
||||
'dependencies.yml'),
|
||||
help='dependencies.yml file path')
|
||||
parser.add_argument('--graph',
|
||||
help='Specify PNG image output path. Use this argument to generate dependency graph')
|
||||
parser.add_argument(
|
||||
'rules_yml',
|
||||
nargs='?',
|
||||
default=os.path.join(IDF_PATH, '.gitlab', 'ci', 'rules.yml'),
|
||||
help='rules.yml file path',
|
||||
)
|
||||
parser.add_argument(
|
||||
'dependencies_yml',
|
||||
nargs='?',
|
||||
default=os.path.join(IDF_PATH, '.gitlab', 'ci', 'dependencies', 'dependencies.yml'),
|
||||
help='dependencies.yml file path',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--graph',
|
||||
help='Specify PNG image output path. Use this argument to generate dependency graph',
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
writer = RulesWriter(args.rules_yml, args.dependencies_yml)
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
||||
'''
|
||||
Download artifacts from all test jobs
|
||||
|
||||
CI_PROJECT_DIR
|
||||
└── TEST_RESULTS
|
||||
├── <job_id>
|
||||
│ └── XUNIT_RESULT.xml
|
||||
├── <job_id>
|
||||
│ └── XUNIT_RESULT.xml
|
||||
├── <job_id>
|
||||
│ └── TEST_LOGS
|
||||
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import gitlab_api
|
||||
|
||||
CI_PROJECT_ID = int(os.getenv('CI_PROJECT_ID', ''))
|
||||
CI_PIPELINE_ID = int(os.getenv('CI_PIPELINE_ID', ''))
|
||||
IDF_PATH = os.getenv('IDF_PATH', '.')
|
||||
TEST_RESULT_PATH = os.path.join(IDF_PATH, 'TEST_RESULTS')
|
||||
|
||||
|
||||
def download_all_test_results(result_path: str, include_retried: bool = False) -> None:
|
||||
if os.path.exists(result_path):
|
||||
shutil.rmtree(result_path)
|
||||
os.makedirs(result_path, exist_ok=True)
|
||||
|
||||
gitlab_inst = gitlab_api.Gitlab(CI_PROJECT_ID)
|
||||
pipelines = gitlab_inst.project.pipelines.get(CI_PIPELINE_ID)
|
||||
_include_retried = 'true' if include_retried else 'false'
|
||||
jobs = pipelines.jobs.list(all=True, per_page=100, include_retried=_include_retried)
|
||||
|
||||
job_info_list = []
|
||||
for job in jobs:
|
||||
if job.stage in ['target_test', 'host_test']:
|
||||
log_path = ''
|
||||
if job.status not in ['success', 'failed']:
|
||||
print('Job {}({}) is not finished'.format(job.id, job.name))
|
||||
elif not hasattr(job, 'artifacts_file'):
|
||||
print('Job {}({}) has no artifacts.'.format(job.id, job.name))
|
||||
else:
|
||||
log_path = os.path.join(result_path, 'job_{}'.format(job.id))
|
||||
print('Downloading artifacts from: {}'.format(job.name))
|
||||
os.makedirs(log_path, exist_ok=True)
|
||||
gitlab_inst.download_artifacts(job.id, log_path)
|
||||
|
||||
job_info = {
|
||||
'id': job.id,
|
||||
'name': job.name,
|
||||
'tag_list': job.tag_list,
|
||||
'status': job.status,
|
||||
'stage': job.stage,
|
||||
'web_url': job.web_url,
|
||||
'commit_url': job.commit['web_url'],
|
||||
'log_path': log_path,
|
||||
}
|
||||
job_info_list.append(job_info)
|
||||
|
||||
with open(os.path.join(result_path, 'index.json'), 'w') as f:
|
||||
f.write(json.dumps({'jobs': job_info_list}, indent=1, sort_keys=True))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--path', '-p', default=TEST_RESULT_PATH, help='Path to save result files.')
|
||||
parser.add_argument('--include_retried', action='store_true', help='Including retried jobs.')
|
||||
args = parser.parse_args()
|
||||
|
||||
download_all_test_results(args.path, args.include_retried)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,27 +1,29 @@
|
||||
#!/usr/bin/env python
|
||||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""
|
||||
Check gitlab ci yaml files
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import typing as t
|
||||
from functools import cached_property
|
||||
|
||||
from idf_ci_utils import get_submodule_dirs
|
||||
from idf_ci_utils import GitlabYmlConfig
|
||||
from idf_ci_utils import IDF_PATH
|
||||
from idf_ci_utils import GitlabYmlConfig
|
||||
from idf_ci_utils import get_submodule_dirs
|
||||
|
||||
|
||||
class YmlLinter:
|
||||
def __init__(self, yml_config: GitlabYmlConfig) -> None:
|
||||
self.yml_config = yml_config
|
||||
|
||||
self._errors: t.List[str] = []
|
||||
self._errors: list[str] = []
|
||||
|
||||
@cached_property
|
||||
def lint_functions(self) -> t.List[str]:
|
||||
def lint_functions(self) -> list[str]:
|
||||
funcs = []
|
||||
for func in dir(self):
|
||||
if func.startswith('_lint_'):
|
||||
@@ -43,17 +45,6 @@ class YmlLinter:
|
||||
|
||||
exit(exit_code)
|
||||
|
||||
# name it like _1_ to make it run first
|
||||
def _lint_1_yml_parser(self) -> None:
|
||||
for k, v in self.yml_config.config.items():
|
||||
if (
|
||||
k not in self.yml_config.global_keys
|
||||
and k not in self.yml_config.anchors
|
||||
and k not in self.yml_config.templates
|
||||
and k not in self.yml_config.jobs
|
||||
):
|
||||
raise SystemExit(f'Parser incorrect. Key {k} not in global keys, anchors, templates, or jobs')
|
||||
|
||||
def _lint_default_values_artifacts(self) -> None:
|
||||
defaults_artifacts = self.yml_config.default.get('artifacts', {})
|
||||
|
||||
@@ -79,19 +70,6 @@ class YmlLinter:
|
||||
for item in undefined_patterns:
|
||||
self._errors.append(f'undefined pattern {item}. Please add {item} to .patterns-submodule')
|
||||
|
||||
def _lint_gitlab_yml_templates(self) -> None:
|
||||
unused_templates = self.yml_config.templates.keys() - self.yml_config.used_templates
|
||||
for item in unused_templates:
|
||||
# known unused ones
|
||||
if item not in [
|
||||
'.before_script:fetch:target_test', # used in dynamic pipeline
|
||||
]:
|
||||
self._errors.append(f'Unused template: {item}, please remove it')
|
||||
|
||||
undefined_templates = self.yml_config.used_templates - self.yml_config.templates.keys()
|
||||
for item in undefined_templates:
|
||||
self._errors.append(f'Undefined template: {item}')
|
||||
|
||||
def _lint_dependencies_and_needs(self) -> None:
|
||||
"""
|
||||
Use `dependencies: []` together with `needs: []` could cause missing artifacts issue.
|
||||
@@ -123,7 +101,9 @@ class YmlLinter:
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--root-yml-filepath', help='root yml file path', default=os.path.join(IDF_PATH, '.gitlab-ci.yml')
|
||||
'--root-yml-filepath',
|
||||
help='root yml file path',
|
||||
default=os.path.join(IDF_PATH, '.gitlab-ci.yml'),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import typing as t
|
||||
from typing import Literal
|
||||
|
||||
from idf_build_apps import App
|
||||
from idf_build_apps import CMakeApp
|
||||
from idf_build_apps import json_to_app
|
||||
from idf_ci_local.uploader import AppUploader
|
||||
from idf_ci_local.uploader import get_app_uploader
|
||||
from idf_build_apps.constants import BuildStatus
|
||||
from idf_build_apps.utils import rmdir
|
||||
|
||||
|
||||
class IdfCMakeApp(CMakeApp):
|
||||
uploader: t.ClassVar[t.Optional['AppUploader']] = get_app_uploader()
|
||||
build_system: Literal['idf_cmake'] = 'idf_cmake'
|
||||
build_system: t.Literal['idf_cmake'] = 'idf_cmake'
|
||||
|
||||
def _initialize_hook(self, **kwargs: t.Any) -> None:
|
||||
# ensure this env var exists
|
||||
@@ -25,25 +22,27 @@ class IdfCMakeApp(CMakeApp):
|
||||
def _post_build(self) -> None:
|
||||
super()._post_build()
|
||||
|
||||
if self.uploader:
|
||||
self.uploader.upload_app(self.build_path)
|
||||
# only upload in CI
|
||||
if os.getenv('CI_JOB_ID'):
|
||||
command = [
|
||||
'idf-ci',
|
||||
'gitlab',
|
||||
'upload-artifacts',
|
||||
self.app_dir,
|
||||
'--build-dir',
|
||||
self.build_dir,
|
||||
]
|
||||
|
||||
result = subprocess.run(
|
||||
command,
|
||||
stdout=sys.stdout,
|
||||
stderr=sys.stderr,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
self.build_status = BuildStatus.FAILED
|
||||
self.build_comment = 'Failed to upload artifacts'
|
||||
|
||||
def dump_apps_to_txt(apps: t.List[App], output_filepath: str) -> None:
|
||||
with open(output_filepath, 'w') as fw:
|
||||
for app in apps:
|
||||
fw.write(app.model_dump_json() + '\n')
|
||||
|
||||
|
||||
def import_apps_from_txt(input_filepath: str) -> t.List[App]:
|
||||
apps: t.List[App] = []
|
||||
with open(input_filepath) as fr:
|
||||
for line in fr:
|
||||
if line := line.strip():
|
||||
try:
|
||||
apps.append(json_to_app(line, extra_classes=[IdfCMakeApp]))
|
||||
except Exception: # noqa
|
||||
print('Failed to deserialize app from line: %s' % line)
|
||||
sys.exit(1)
|
||||
|
||||
return apps
|
||||
rmdir(
|
||||
self.build_path,
|
||||
exclude_file_patterns=['build_log.txt', 'size*.json'],
|
||||
)
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import abc
|
||||
import glob
|
||||
import os
|
||||
import typing as t
|
||||
from datetime import timedelta
|
||||
from zipfile import ZIP_DEFLATED
|
||||
from zipfile import ZipFile
|
||||
|
||||
import minio
|
||||
from artifacts_handler import ArtifactType
|
||||
from artifacts_handler import get_minio_client
|
||||
from artifacts_handler import getenv
|
||||
from idf_build_apps import App
|
||||
from idf_build_apps.utils import rmdir
|
||||
from idf_ci_utils import IDF_PATH
|
||||
from idf_pytest.constants import DEFAULT_BUILD_LOG_FILENAME
|
||||
from idf_pytest.constants import DEFAULT_SIZE_JSON_FILENAME
|
||||
|
||||
|
||||
class AppDownloader:
|
||||
ALL_ARTIFACT_TYPES = [ArtifactType.MAP_AND_ELF_FILES, ArtifactType.BUILD_DIR_WITHOUT_MAP_AND_ELF_FILES]
|
||||
|
||||
@abc.abstractmethod
|
||||
def _download_app(self, app_build_path: str, artifact_type: ArtifactType) -> None:
|
||||
pass
|
||||
|
||||
def download_app(self, app_build_path: str, artifact_type: t.Optional[ArtifactType] = None) -> None:
|
||||
"""
|
||||
Download the app
|
||||
:param app_build_path: the path to the build directory
|
||||
:param artifact_type: if not specify, download all types of artifacts
|
||||
:return: None
|
||||
"""
|
||||
if not artifact_type:
|
||||
for _artifact_type in self.ALL_ARTIFACT_TYPES:
|
||||
self._download_app(app_build_path, _artifact_type)
|
||||
else:
|
||||
self._download_app(app_build_path, artifact_type)
|
||||
|
||||
|
||||
class AppUploader(AppDownloader):
|
||||
TYPE_PATTERNS_DICT = {
|
||||
ArtifactType.MAP_AND_ELF_FILES: [
|
||||
'bootloader/*.map',
|
||||
'bootloader/*.elf',
|
||||
'*.map',
|
||||
'*.elf',
|
||||
'gdbinit/*',
|
||||
],
|
||||
ArtifactType.BUILD_DIR_WITHOUT_MAP_AND_ELF_FILES: [
|
||||
'*.bin',
|
||||
'bootloader/*.bin',
|
||||
'partition_table/*.bin',
|
||||
'flasher_args.json',
|
||||
'flash_project_args',
|
||||
'config/sdkconfig.json',
|
||||
'sdkconfig',
|
||||
'project_description.json',
|
||||
],
|
||||
ArtifactType.LOGS: [
|
||||
DEFAULT_BUILD_LOG_FILENAME,
|
||||
],
|
||||
}
|
||||
|
||||
def __init__(self, pipeline_id: t.Union[str, int, None] = None) -> None:
|
||||
self.pipeline_id = str(pipeline_id or '1')
|
||||
|
||||
self._client = get_minio_client()
|
||||
|
||||
def get_app_object_name(self, app_path: str, zip_name: str, artifact_type: ArtifactType) -> str:
|
||||
return f'{self.pipeline_id}/{artifact_type.value}/{app_path}/{zip_name}'
|
||||
|
||||
def _upload_app(self, app_build_path: str, artifact_type: ArtifactType) -> bool:
|
||||
app_path, build_dir = os.path.split(app_build_path)
|
||||
zip_filename = f'{build_dir}.zip'
|
||||
|
||||
has_file = False
|
||||
with ZipFile(
|
||||
zip_filename,
|
||||
'w',
|
||||
compression=ZIP_DEFLATED,
|
||||
# 1 is the fastest compression level
|
||||
# the size differs not much between 1 and 9
|
||||
compresslevel=1,
|
||||
) as zw:
|
||||
for pattern in self.TYPE_PATTERNS_DICT[artifact_type]:
|
||||
for file in glob.glob(os.path.join(app_build_path, pattern), recursive=True):
|
||||
zw.write(file)
|
||||
has_file = True
|
||||
|
||||
uploaded = False
|
||||
try:
|
||||
if has_file:
|
||||
obj_name = self.get_app_object_name(app_path, zip_filename, artifact_type)
|
||||
self._client.fput_object(getenv('IDF_S3_BUCKET'), obj_name, zip_filename)
|
||||
uploaded = True
|
||||
finally:
|
||||
os.remove(zip_filename)
|
||||
return uploaded
|
||||
|
||||
def upload_app(self, app_build_path: str, artifact_type: t.Optional[ArtifactType] = None) -> None:
|
||||
uploaded = False
|
||||
if not artifact_type:
|
||||
upload_types: t.Iterable[ArtifactType] = self.TYPE_PATTERNS_DICT.keys()
|
||||
else:
|
||||
upload_types = [artifact_type]
|
||||
|
||||
# Upload of size.json files is handled by GitLab CI via "artifacts_handler.py" script.
|
||||
print(f'Uploading {app_build_path} {[k.value for k in upload_types]} to minio server')
|
||||
for upload_type in upload_types:
|
||||
uploaded |= self._upload_app(app_build_path, upload_type)
|
||||
|
||||
if uploaded:
|
||||
rmdir(app_build_path, exclude_file_patterns=[DEFAULT_BUILD_LOG_FILENAME, DEFAULT_SIZE_JSON_FILENAME])
|
||||
|
||||
def _download_app(self, app_build_path: str, artifact_type: ArtifactType) -> None:
|
||||
app_path, build_dir = os.path.split(app_build_path)
|
||||
zip_filename = f'{build_dir}.zip'
|
||||
|
||||
# path are relative to IDF_PATH
|
||||
current_dir = os.getcwd()
|
||||
os.chdir(IDF_PATH)
|
||||
try:
|
||||
obj_name = self.get_app_object_name(app_path, zip_filename, artifact_type)
|
||||
print(f'Downloading {obj_name}')
|
||||
try:
|
||||
try:
|
||||
self._client.stat_object(getenv('IDF_S3_BUCKET'), obj_name)
|
||||
except minio.error.S3Error as e:
|
||||
raise RuntimeError(
|
||||
f'No such file on minio server: {obj_name}. '
|
||||
f'Probably the build failed or the artifacts got expired. '
|
||||
f'Full error message: {str(e)}'
|
||||
)
|
||||
else:
|
||||
self._client.fget_object(getenv('IDF_S3_BUCKET'), obj_name, zip_filename)
|
||||
print(f'Downloaded to {zip_filename}')
|
||||
except minio.error.S3Error as e:
|
||||
raise RuntimeError('Shouldn\'t happen, please report this bug in the CI channel' + str(e))
|
||||
|
||||
with ZipFile(zip_filename, 'r') as zr:
|
||||
zr.extractall()
|
||||
|
||||
os.remove(zip_filename)
|
||||
finally:
|
||||
os.chdir(current_dir)
|
||||
|
||||
def get_app_presigned_url(self, app: App, artifact_type: ArtifactType) -> str:
|
||||
obj_name = self.get_app_object_name(app.app_dir, f'{app.build_dir}.zip', artifact_type)
|
||||
try:
|
||||
self._client.stat_object(
|
||||
getenv('IDF_S3_BUCKET'),
|
||||
obj_name,
|
||||
)
|
||||
except minio.error.S3Error:
|
||||
return ''
|
||||
else:
|
||||
return self._client.get_presigned_url( # type: ignore
|
||||
'GET', getenv('IDF_S3_BUCKET'), obj_name, expires=timedelta(days=4)
|
||||
)
|
||||
|
||||
|
||||
def get_app_uploader() -> t.Optional['AppUploader']:
|
||||
if parent_pipeline_id := os.getenv('PARENT_PIPELINE_ID'):
|
||||
return AppUploader(parent_pipeline_id)
|
||||
|
||||
return None
|
||||
+112
-122
@@ -2,9 +2,11 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# internal use only for CI
|
||||
# some CI related util functions
|
||||
|
||||
from __future__ import annotations # Must be the first line of code
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import typing as t
|
||||
@@ -14,7 +16,7 @@ from pathlib import Path
|
||||
IDF_PATH: str = os.path.abspath(os.getenv('IDF_PATH', os.path.join(os.path.dirname(__file__), '..', '..')))
|
||||
|
||||
|
||||
def get_submodule_dirs(full_path: bool = False) -> t.List[str]:
|
||||
def get_submodule_dirs(full_path: bool = False) -> list[str]:
|
||||
"""
|
||||
To avoid issue could be introduced by multi-os or additional dependency,
|
||||
we use python and git to get this output
|
||||
@@ -72,7 +74,7 @@ def is_executable(full_path: str) -> bool:
|
||||
return os.access(full_path, os.X_OK)
|
||||
|
||||
|
||||
def get_git_files(path: str = IDF_PATH, full_path: bool = False) -> t.List[str]:
|
||||
def get_git_files(path: str = IDF_PATH, full_path: bool = False) -> list[str]:
|
||||
"""
|
||||
Get the result of git ls-files
|
||||
:param path: path to run git ls-files
|
||||
@@ -99,7 +101,7 @@ def get_git_files(path: str = IDF_PATH, full_path: bool = False) -> t.List[str]:
|
||||
return [os.path.join(path, f) for f in files] if full_path else files
|
||||
|
||||
|
||||
def to_list(s: t.Any) -> t.List[t.Any]:
|
||||
def to_list(s: t.Any) -> list[t.Any]:
|
||||
if not s:
|
||||
return []
|
||||
|
||||
@@ -114,8 +116,8 @@ def to_list(s: t.Any) -> t.List[t.Any]:
|
||||
|
||||
class GitlabYmlConfig:
|
||||
def __init__(self, root_yml_filepath: str = os.path.join(IDF_PATH, '.gitlab-ci.yml')) -> None:
|
||||
self._config: t.Dict[str, t.Any] = {}
|
||||
self._defaults: t.Dict[str, t.Any] = {}
|
||||
self._config: dict[str, t.Any] = {}
|
||||
self._defaults: dict[str, t.Any] = {}
|
||||
|
||||
self._load(root_yml_filepath)
|
||||
|
||||
@@ -123,125 +125,130 @@ class GitlabYmlConfig:
|
||||
# avoid unused import in other pre-commit hooks
|
||||
import yaml
|
||||
|
||||
all_config = dict()
|
||||
root_yml = yaml.load(open(root_yml_filepath), Loader=yaml.FullLoader)
|
||||
|
||||
# expanding "include"
|
||||
for item in root_yml.pop('include', []) or []:
|
||||
if isinstance(item, dict):
|
||||
if 'project' in item:
|
||||
continue
|
||||
elif 'local' in item:
|
||||
item = item['local']
|
||||
else:
|
||||
continue
|
||||
all_config.update(yaml.load(open(os.path.join(IDF_PATH, item)), Loader=yaml.FullLoader))
|
||||
merged_yaml = self._compile_via_gitlab_api(root_yml_filepath)
|
||||
all_config = yaml.load(merged_yaml, Loader=yaml.FullLoader) or {}
|
||||
|
||||
if 'default' in all_config:
|
||||
self._defaults = all_config.pop('default')
|
||||
|
||||
self._config = all_config
|
||||
|
||||
# anchor is the string that will be reused in templates
|
||||
self._anchor_keys: t.Set[str] = set()
|
||||
# template is a dict that will be extended
|
||||
self._template_keys: t.Set[str] = set()
|
||||
self._used_template_keys: t.Set[str] = set() # tracing the used templates
|
||||
# job is a dict that will be executed
|
||||
self._job_keys: t.Set[str] = set()
|
||||
def _inline_local_includes(self, root_yml_filepath: str) -> str:
|
||||
"""
|
||||
Recursively resolve `include: local` entries straight from disk (so uncommitted local
|
||||
changes are always picked up -- CI runners also work off a disk checkout, so there's no
|
||||
need to fetch a ref remotely via `ci_lint`'s `content_ref`/`ref`/`dry_run_ref` GET
|
||||
params). `include: project` entries (including ones nested inside local files, e.g.
|
||||
`.gitlab/ci/common.yml` including `templates/idf/common-scripts.yml`) are collected and
|
||||
left in the final `include:` list, since those files live in another GitLab project and
|
||||
can only be resolved remotely.
|
||||
|
||||
self.expand_extends()
|
||||
A dedicated Loader/Dumper pair round-trips `!reference` tags as a marker list subclass,
|
||||
since GitLab CI uses `!reference` which plain YAML doesn't know, and we need to parse
|
||||
(to merge dicts, not just string-concat) then re-dump losslessly.
|
||||
|
||||
:param root_yml_filepath: path to the local root yml file to compile
|
||||
:return: yml content with local includes resolved and merged
|
||||
"""
|
||||
import yaml
|
||||
|
||||
class _Loader(yaml.FullLoader):
|
||||
pass
|
||||
|
||||
class _Dumper(yaml.Dumper):
|
||||
pass
|
||||
|
||||
class _Reference(list):
|
||||
pass
|
||||
|
||||
_Loader.add_constructor(
|
||||
'!reference',
|
||||
lambda loader, node: _Reference(loader.construct_sequence(t.cast(yaml.SequenceNode, node))),
|
||||
)
|
||||
_Dumper.add_representer(
|
||||
_Reference,
|
||||
lambda dumper, data: dumper.represent_sequence('!reference', list(data)),
|
||||
)
|
||||
|
||||
def resolve(yml_filepath: str) -> tuple[dict, list]:
|
||||
with open(yml_filepath) as fr:
|
||||
data = yaml.load(fr, Loader=_Loader) or {}
|
||||
|
||||
includes = to_list(data.pop('include', None))
|
||||
|
||||
merged: dict = {}
|
||||
remaining_project_includes: list = []
|
||||
for item in includes:
|
||||
if isinstance(item, dict):
|
||||
if 'project' in item:
|
||||
remaining_project_includes.append(item)
|
||||
continue
|
||||
elif 'local' in item:
|
||||
local_path = item['local']
|
||||
else:
|
||||
continue
|
||||
elif isinstance(item, str):
|
||||
local_path = item
|
||||
else:
|
||||
continue
|
||||
|
||||
sub_merged, sub_remaining = resolve(os.path.join(IDF_PATH, local_path.lstrip('/')))
|
||||
merged.update(sub_merged)
|
||||
remaining_project_includes.extend(sub_remaining)
|
||||
|
||||
# this file's own top-level keys override whatever its includes defined
|
||||
merged.update(data)
|
||||
return merged, remaining_project_includes
|
||||
|
||||
merged_config, project_includes = resolve(root_yml_filepath)
|
||||
if project_includes:
|
||||
merged_config['include'] = project_includes
|
||||
|
||||
return yaml.dump(merged_config, Dumper=_Dumper, sort_keys=False) # type: ignore
|
||||
|
||||
def _compile_via_gitlab_api(self, root_yml_filepath: str) -> str:
|
||||
"""
|
||||
Call the GitLab CI Lint API to get the fully compiled (all `include`s resolved) yml,
|
||||
same as what `glab ci config compile` does. This replaces the old recursive local-only
|
||||
parsing, since the project now includes configs from other projects as well.
|
||||
|
||||
:param root_yml_filepath: path to the local root yml file to compile
|
||||
:return: merged (fully resolved) yml content as a string
|
||||
"""
|
||||
sys.path.insert(0, os.path.join(IDF_PATH, 'tools', 'ci', 'python_packages'))
|
||||
import gitlab_api
|
||||
|
||||
content = self._inline_local_includes(root_yml_filepath)
|
||||
|
||||
gitlab_inst = gitlab_api.Gitlab()
|
||||
project_id = os.getenv('CI_PROJECT_ID') or gitlab_inst.get_project_id('esp-idf', namespace='espressif')
|
||||
project = gitlab_inst.gitlab_inst.projects.get(project_id, lazy=True)
|
||||
|
||||
lint_result = project.ci_lint.create({'content': content})
|
||||
if not lint_result.valid:
|
||||
raise RuntimeError(f'Failed to compile {root_yml_filepath} via GitLab CI Lint API: {lint_result.errors}')
|
||||
|
||||
return lint_result.merged_yaml # type: ignore
|
||||
|
||||
@property
|
||||
def default(self) -> t.Dict[str, t.Any]:
|
||||
def default(self) -> dict[str, t.Any]:
|
||||
return self._defaults
|
||||
|
||||
@property
|
||||
def config(self) -> t.Dict[str, t.Any]:
|
||||
def config(self) -> dict[str, t.Any]:
|
||||
return self._config
|
||||
|
||||
@cached_property
|
||||
def global_keys(self) -> t.List[str]:
|
||||
def global_keys(self) -> list[str]:
|
||||
return ['default', 'include', 'workflow', 'variables', 'stages']
|
||||
|
||||
@cached_property
|
||||
def anchors(self) -> t.Dict[str, t.Any]:
|
||||
return {k: v for k, v in self.config.items() if k in self._anchor_keys}
|
||||
|
||||
@cached_property
|
||||
def jobs(self) -> t.Dict[str, t.Any]:
|
||||
return {k: v for k, v in self.config.items() if k in self._job_keys}
|
||||
|
||||
@cached_property
|
||||
def templates(self) -> t.Dict[str, t.Any]:
|
||||
return {k: v for k, v in self.config.items() if k in self._template_keys}
|
||||
|
||||
@cached_property
|
||||
def used_templates(self) -> t.Set[str]:
|
||||
return self._used_template_keys
|
||||
|
||||
def expand_extends(self) -> None:
|
||||
"""
|
||||
expand the `extends` key in-place.
|
||||
"""
|
||||
for k, v in self.config.items():
|
||||
if k in self.global_keys:
|
||||
continue
|
||||
|
||||
if isinstance(v, (str, list)):
|
||||
self._anchor_keys.add(k)
|
||||
elif k.startswith('.if-'):
|
||||
self._anchor_keys.add(k)
|
||||
elif k.startswith('.'):
|
||||
self._template_keys.add(k)
|
||||
elif isinstance(v, dict):
|
||||
self._job_keys.add(k)
|
||||
else:
|
||||
raise ValueError(f'Unknown type for key {k} with value {v}')
|
||||
|
||||
# no need to expand anchor
|
||||
|
||||
# expand template first
|
||||
for k in self._template_keys:
|
||||
self._expand_extends(k)
|
||||
|
||||
# expand job
|
||||
for k in self._job_keys:
|
||||
self._expand_extends(k)
|
||||
|
||||
def _merge_dict(self, d1: t.Dict[str, t.Any], d2: t.Dict[str, t.Any]) -> t.Any:
|
||||
for k, v in d2.items():
|
||||
if k in d1:
|
||||
if isinstance(v, dict) and isinstance(d1[k], dict):
|
||||
d1[k] = self._merge_dict(d1[k], v)
|
||||
else:
|
||||
d1[k] = v
|
||||
else:
|
||||
d1[k] = v
|
||||
|
||||
return d1
|
||||
|
||||
def _expand_extends(self, name: str) -> t.Dict[str, t.Any]:
|
||||
extends = to_list(self.config[name].pop('extends', None))
|
||||
if not extends:
|
||||
return self.config[name] # type: ignore
|
||||
|
||||
original_d = self.config[name].copy()
|
||||
d = {}
|
||||
while extends:
|
||||
self._used_template_keys.update(extends) # for tracking
|
||||
|
||||
for i in extends:
|
||||
d.update(self._expand_extends(i))
|
||||
|
||||
extends = to_list(self.config[name].pop('extends', None))
|
||||
|
||||
self.config[name] = self._merge_dict(d, original_d)
|
||||
return self.config[name] # type: ignore
|
||||
def jobs(self) -> dict[str, t.Any]:
|
||||
return {k: v for k, v in self.config.items() if not k.startswith('.') and k not in self.global_keys}
|
||||
|
||||
|
||||
def get_all_manifest_files() -> t.List[str]:
|
||||
paths: t.List[str] = []
|
||||
def get_all_manifest_files() -> list[str]:
|
||||
paths: list[str] = []
|
||||
|
||||
for p in Path(IDF_PATH).glob('**/.build-test-rules.yml'):
|
||||
if 'managed_components' in p.parts:
|
||||
@@ -252,23 +259,6 @@ def get_all_manifest_files() -> t.List[str]:
|
||||
return paths
|
||||
|
||||
|
||||
def sanitize_job_name(name: str) -> str:
|
||||
"""
|
||||
Sanitize the job name from CI_JOB_NAME
|
||||
|
||||
- for job with `parallel: int` set, the `CI_JOB_NAME` would be `job_name index/total`, like `foo 1/3`
|
||||
- for job with `parallel: matrix` set, the `CI_JOB_NAME` would be `job_name: [var1, var2]`, like `foo: [a, b]`
|
||||
|
||||
We consider
|
||||
- the jobs generated by `parallel: int` as the same job, i.e., we remove the index/total part.
|
||||
- the jobs generated by `parallel: matrix` as different jobs, so we keep the matrix part.
|
||||
|
||||
:param name: job name
|
||||
:return: sanitized job name
|
||||
"""
|
||||
return re.sub(r' \d+/\d+', '', name)
|
||||
|
||||
|
||||
def idf_relpath(p: str) -> str:
|
||||
"""
|
||||
Turn all paths under IDF_PATH to relative paths
|
||||
|
||||
@@ -1,332 +1,36 @@
|
||||
# SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import typing as t
|
||||
|
||||
"""
|
||||
Pytest Related Constants. Don't import third-party packages here.
|
||||
"""
|
||||
import os
|
||||
import typing as t
|
||||
import warnings
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from functools import cached_property
|
||||
from pathlib import Path
|
||||
|
||||
from _pytest.python import Function
|
||||
from idf_ci_utils import IDF_PATH
|
||||
from idf_ci_utils import idf_relpath
|
||||
from pytest_embedded.utils import to_list
|
||||
|
||||
SUPPORTED_TARGETS = ['esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2', 'esp32c6', 'esp32h2', 'esp32p4', 'esp32c5', 'esp32c61']
|
||||
SUPPORTED_TARGETS = [
|
||||
'esp32',
|
||||
'esp32s2',
|
||||
'esp32c3',
|
||||
'esp32s3',
|
||||
'esp32c2',
|
||||
'esp32c6',
|
||||
'esp32h2',
|
||||
'esp32p4',
|
||||
'esp32c5',
|
||||
'esp32c61',
|
||||
]
|
||||
PREVIEW_TARGETS: t.List[str] = [] # this PREVIEW_TARGETS excludes 'linux' target
|
||||
DEFAULT_SDKCONFIG = 'default'
|
||||
|
||||
DEFAULT_LOGDIR = 'pytest-embedded'
|
||||
|
||||
TARGET_MARKERS = {
|
||||
'esp32': 'support esp32 target',
|
||||
'esp32s2': 'support esp32s2 target',
|
||||
'esp32s3': 'support esp32s3 target',
|
||||
'esp32c3': 'support esp32c3 target',
|
||||
'esp32c2': 'support esp32c2 target',
|
||||
'esp32c5': 'support esp32c5 target',
|
||||
'esp32c6': 'support esp32c6 target',
|
||||
'esp32h2': 'support esp32h2 target',
|
||||
'esp32p4': 'support esp32p4 target',
|
||||
'esp32c61': 'support esp32c61 target',
|
||||
'linux': 'support linux target',
|
||||
}
|
||||
|
||||
SPECIAL_MARKERS = {
|
||||
'supported_targets': 'support all officially announced supported targets, refer to `SUPPORTED_TARGETS`',
|
||||
'preview_targets': "support all preview targets ('none')",
|
||||
'all_targets': 'support all targets, including supported ones and preview ones',
|
||||
'temp_skip_ci': 'temp skip tests for specified targets only in ci',
|
||||
'temp_skip': 'temp skip tests for specified targets both in ci and locally',
|
||||
'nightly_run': 'tests should be executed as part of the nightly trigger pipeline',
|
||||
'host_test': 'tests which should not be built at the build stage, and instead built in host_test stage',
|
||||
}
|
||||
|
||||
ENV_MARKERS = {
|
||||
# special markers
|
||||
'qemu': 'build and test using qemu, not real target',
|
||||
'macos_shell': 'tests should be run on macos hosts',
|
||||
# single-dut markers
|
||||
'generic': 'tests should be run on generic runners',
|
||||
'flash_suspend': 'support flash suspend feature',
|
||||
'eth_ip101': 'connected via IP101 ethernet transceiver',
|
||||
'eth_lan8720': 'connected via LAN8720 ethernet transceiver',
|
||||
'eth_rtl8201': 'connected via RTL8201 ethernet transceiver',
|
||||
'eth_ksz8041': 'connected via KSZ8041 ethernet transceiver',
|
||||
'eth_dp83848': 'connected via DP83848 ethernet transceiver',
|
||||
'eth_w5500': 'SPI Ethernet module with two W5500',
|
||||
'eth_ksz8851snl': 'SPI Ethernet module with two KSZ8851SNL',
|
||||
'eth_dm9051': 'SPI Ethernet module with two DM9051',
|
||||
'quad_psram': 'runners with quad psram',
|
||||
'octal_psram': 'runners with octal psram',
|
||||
'usb_host_flash_disk': 'usb host runners with USB flash disk attached',
|
||||
'usb_device': 'usb device runners',
|
||||
'ethernet_ota': 'ethernet OTA runners',
|
||||
'flash_encryption': 'Flash Encryption runners',
|
||||
'flash_encryption_f4r8': 'Flash Encryption runners with 4-line flash and 8-line psram',
|
||||
'flash_encryption_f8r8': 'Flash Encryption runners with 8-line flash and 8-line psram',
|
||||
'flash_encryption_ota': 'Flash Encryption runners with ethernet OTA support with 4mb flash size',
|
||||
'flash_multi': 'Multiple flash chips tests',
|
||||
'psram': 'Chip has 4-line psram',
|
||||
'ir_transceiver': 'runners with a pair of IR transmitter and receiver',
|
||||
'flash_encryption_wifi_high_traffic': 'Flash Encryption runners with wifi high traffic support',
|
||||
'ethernet': 'ethernet runner',
|
||||
'ethernet_flash_8m': 'ethernet runner with 8mb flash',
|
||||
'ethernet_router': 'both the runner and dut connect to the same router through ethernet NIC',
|
||||
'ethernet_vlan': 'ethernet runner GARM-32-SH-1-R16S5N3',
|
||||
'wifi_ap': 'a wifi AP in the environment',
|
||||
'wifi_router': 'both the runner and dut connect to the same wifi router',
|
||||
'wifi_high_traffic': 'wifi high traffic runners',
|
||||
'wifi_wlan': 'wifi runner with a wireless NIC',
|
||||
'wifi_iperf': 'the AP and ESP dut were placed in a shielded box - for iperf test',
|
||||
'Example_ShieldBox': 'multiple shielded APs connected to shielded ESP DUT via RF cable with programmable attenuator',
|
||||
'xtal_26mhz': 'runner with 26MHz xtal on board',
|
||||
'xtal_40mhz': 'runner with 40MHz xtal on board',
|
||||
'external_flash': 'external flash memory connected via VSPI (FSPI)',
|
||||
'sdcard_sdmode': 'sdcard running in SD mode, to be removed after test migration',
|
||||
'sdcard_spimode': 'sdcard running in SPI mode',
|
||||
'emmc': 'eMMC card',
|
||||
'sdcard': 'sdcard runner',
|
||||
'MSPI_F8R8': 'runner with Octal Flash and Octal PSRAM',
|
||||
'MSPI_F4R8': 'runner with Quad Flash and Octal PSRAM',
|
||||
'MSPI_F4R4': 'runner with Quad Flash and Quad PSRAM',
|
||||
'jtag': 'runner where the chip is accessible through JTAG as well',
|
||||
'usb_serial_jtag': 'runner where the chip is accessible through builtin JTAG as well',
|
||||
'xtal32k': 'Runner with external 32k crystal connected',
|
||||
'no32kXtal': 'Runner with no external 32k crystal connected',
|
||||
'psramv0': 'Runner with PSRAM version 0',
|
||||
'esp32eco3': 'Runner with esp32 eco3 connected',
|
||||
'ecdsa_efuse': 'Runner with test ECDSA private keys programmed in efuse',
|
||||
'ccs811': 'Runner with CCS811 connected',
|
||||
'nvs_encr_hmac': 'Runner with test HMAC key programmed in efuse',
|
||||
'i2c_oled': 'Runner with ssd1306 I2C oled connected',
|
||||
'httpbin': 'runner for tests that need to access the httpbin service',
|
||||
'flash_4mb': 'C2 runners with 4 MB flash',
|
||||
'jtag_re_enable': 'Runner to re-enable jtag which is softly disabled by burning bit SOFT_DIS_JTAG on eFuse',
|
||||
'es8311': 'Development board that carries es8311 codec',
|
||||
# multi-dut markers
|
||||
'multi_dut_modbus_rs485': 'a pair of runners connected by RS485 bus',
|
||||
'ieee802154': 'ieee802154 related tests should run on ieee802154 runners.',
|
||||
'openthread_br': 'openthread BR basic and multicast cases.',
|
||||
'openthread_br_connect': 'openthread BR attach and connectivity cases.',
|
||||
'openthread_br_service': 'openthread BR service discovery cases.',
|
||||
'openthread_br_nat64': 'openthread BR NAT64 cases without internet.',
|
||||
'openthread_bbr': 'openthread BR cases with internet access.',
|
||||
'openthread_sleep': 'tests should be used for openthread sleepy device.',
|
||||
'zigbee_multi_dut': 'zigbee runner which have multiple duts.',
|
||||
'two_duts': 'tests should be run on runners which has two wifi duts connected.',
|
||||
'generic_multi_device': 'generic multiple devices whose corresponding gpio pins are connected to each other.',
|
||||
'twai_network': 'multiple runners form a TWAI network.',
|
||||
'sdio_master_slave': 'Test sdio multi board, esp32+esp32',
|
||||
'sdio_multidev_32_c6': 'Test sdio multi board, esp32+esp32c6',
|
||||
'usj_device': 'Test usb_serial_jtag and usb_serial_jtag is used as serial only (not console)',
|
||||
'twai_adapter': 'runner with multiple twai_std',
|
||||
'lp_i2s': 'lp_i2s runner tested with hp_i2s',
|
||||
'ram_app': 'ram_app runners',
|
||||
'esp32c3eco7': 'esp32c3 major version(v1.1) chips',
|
||||
'esp32c2eco4': 'esp32c2 major version(v2.0) chips',
|
||||
'esp32p4_eco4': 'esp32p4 major version(v1.1) chips',
|
||||
}
|
||||
|
||||
DEFAULT_CONFIG_RULES_STR = ['sdkconfig.ci=default', 'sdkconfig.ci.*=', '=default']
|
||||
DEFAULT_IGNORE_WARNING_FILEPATH = os.path.join(IDF_PATH, 'tools', 'ci', 'ignore_build_warnings.txt')
|
||||
DEFAULT_BUILD_TEST_RULES_FILEPATH = os.path.join(IDF_PATH, '.gitlab', 'ci', 'default-build-test-rules.yml')
|
||||
DEFAULT_FULL_BUILD_TEST_COMPONENTS = [
|
||||
'cxx',
|
||||
'esp_common',
|
||||
'esp_hw_support',
|
||||
'esp_rom',
|
||||
'esp_system',
|
||||
'esp_timer',
|
||||
'freertos',
|
||||
'hal',
|
||||
'heap',
|
||||
'log',
|
||||
'newlib',
|
||||
'riscv',
|
||||
'soc',
|
||||
'xtensa',
|
||||
# by default the timeout is 1h, for some special cases we need to extend it
|
||||
TIMEOUT_4H_MARKERS = [
|
||||
'ethernet_stress',
|
||||
]
|
||||
DEFAULT_FULL_BUILD_TEST_FILEPATTERNS = [
|
||||
# tools
|
||||
'tools/cmake/**/*',
|
||||
'tools/tools.json',
|
||||
# ci
|
||||
'tools/ci/ignore_build_warnings.txt',
|
||||
|
||||
REV_MARKERS = [
|
||||
'esp32_rev3',
|
||||
'esp32c2_rev2',
|
||||
'esp32c3_rev1',
|
||||
'esp32p4_rev1',
|
||||
'esp32c5_rev1',
|
||||
]
|
||||
DEFAULT_BUILD_LOG_FILENAME = 'build_log.txt'
|
||||
DEFAULT_SIZE_JSON_FILENAME = 'size.json'
|
||||
|
||||
|
||||
class CollectMode(str, Enum):
|
||||
SINGLE_SPECIFIC = 'single_specific'
|
||||
MULTI_SPECIFIC = 'multi_specific'
|
||||
MULTI_ALL_WITH_PARAM = 'multi_all_with_param'
|
||||
ALL = 'all'
|
||||
|
||||
|
||||
class PytestApp:
|
||||
"""
|
||||
Pytest App with relative path to IDF_PATH
|
||||
"""
|
||||
def __init__(self, path: str, target: str, config: str) -> None:
|
||||
self.path = idf_relpath(path)
|
||||
self.target = target
|
||||
self.config = config
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash((self.path, self.target, self.config))
|
||||
|
||||
@cached_property
|
||||
def build_dir(self) -> str:
|
||||
return os.path.join(self.path, f'build_{self.target}_{self.config}')
|
||||
|
||||
|
||||
@dataclass
|
||||
class PytestCase:
|
||||
apps: t.List[PytestApp]
|
||||
|
||||
item: Function
|
||||
multi_dut_without_param: bool
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash((self.path, self.name, self.apps, self.all_markers))
|
||||
|
||||
@cached_property
|
||||
def path(self) -> str:
|
||||
return str(self.item.path)
|
||||
|
||||
@cached_property
|
||||
def name(self) -> str:
|
||||
return self.item.originalname # type: ignore
|
||||
|
||||
@cached_property
|
||||
def targets(self) -> t.List[str]:
|
||||
if not self.multi_dut_without_param:
|
||||
return [app.target for app in self.apps]
|
||||
|
||||
# multi-dut test cases without parametrize
|
||||
skip = True
|
||||
for _t in [app.target for app in self.apps]:
|
||||
if _t in self.target_markers:
|
||||
skip = False
|
||||
warnings.warn(f'`pytest.mark.[TARGET]` defined in parametrize for multi-dut test cases is deprecated. ' # noqa: W604
|
||||
f'Please use parametrize instead for test case {self.item.nodeid}')
|
||||
break
|
||||
|
||||
if not skip:
|
||||
return [app.target for app in self.apps]
|
||||
|
||||
return [''] * len(self.apps) # this will help to filter these cases out later
|
||||
|
||||
@cached_property
|
||||
def is_single_dut_test_case(self) -> bool:
|
||||
return True if len(self.apps) == 1 else False
|
||||
|
||||
@cached_property
|
||||
def is_host_test(self) -> bool:
|
||||
return 'host_test' in self.all_markers or 'linux' in self.targets
|
||||
|
||||
# the following markers could be changed dynamically, don't use cached_property
|
||||
@property
|
||||
def all_markers(self) -> t.Set[str]:
|
||||
return {marker.name for marker in self.item.iter_markers()}
|
||||
|
||||
@property
|
||||
def target_markers(self) -> t.Set[str]:
|
||||
def _get_temp_markers_disabled_targets(marker_name: str) -> t.Set[str]:
|
||||
temp_marker = self.item.get_closest_marker(marker_name)
|
||||
|
||||
if not temp_marker:
|
||||
return set()
|
||||
|
||||
# temp markers should always use keyword arguments `targets` and `reason`
|
||||
if not temp_marker.kwargs.get('targets') or not temp_marker.kwargs.get('reason'):
|
||||
raise ValueError(
|
||||
f'`{marker_name}` should always use keyword arguments `targets` and `reason`. ' # noqa: W604
|
||||
f'For example: '
|
||||
f'`@pytest.mark.{marker_name}(targets=["esp32"], reason="IDF-xxxx, will fix it ASAP")`'
|
||||
)
|
||||
|
||||
return set(to_list(temp_marker.kwargs['targets'])) # type: ignore
|
||||
|
||||
temp_skip_ci_targets = _get_temp_markers_disabled_targets('temp_skip_ci')
|
||||
temp_skip_targets = _get_temp_markers_disabled_targets('temp_skip')
|
||||
|
||||
# in CI we skip the union of `temp_skip` and `temp_skip_ci`
|
||||
if os.getenv('CI_JOB_ID'):
|
||||
skip_targets = temp_skip_ci_targets.union(temp_skip_targets)
|
||||
else: # we use `temp_skip` locally
|
||||
skip_targets = temp_skip_targets
|
||||
|
||||
return {marker for marker in self.all_markers if marker in TARGET_MARKERS} - skip_targets
|
||||
|
||||
@property
|
||||
def env_markers(self) -> t.Set[str]:
|
||||
return {marker for marker in self.all_markers if marker in ENV_MARKERS}
|
||||
|
||||
@property
|
||||
def target_selector(self) -> str:
|
||||
return ','.join(app.target for app in self.apps)
|
||||
|
||||
@property
|
||||
def requires_elf_or_map(self) -> bool:
|
||||
"""
|
||||
This property determines whether the test case requires elf or map file. By default, one app in the test case
|
||||
only requires .bin files.
|
||||
|
||||
:return: True if the test case requires elf or map file, False otherwise
|
||||
"""
|
||||
if 'jtag' in self.env_markers or 'usb_serial_jtag' in self.env_markers:
|
||||
return True
|
||||
|
||||
cases_need_elf = [
|
||||
'panic',
|
||||
'gdbstub_runtime'
|
||||
]
|
||||
|
||||
for case in cases_need_elf:
|
||||
if any(case in Path(app.path).parts for app in self.apps):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def all_built_in_app_lists(self, app_lists: t.Optional[t.List[str]] = None) -> t.Optional[str]:
|
||||
"""
|
||||
Check if all binaries of the test case are built in the app lists.
|
||||
|
||||
:param app_lists: app lists to check
|
||||
:return: debug string if not all binaries are built in the app lists, None otherwise
|
||||
"""
|
||||
if app_lists is None:
|
||||
# ignore this feature
|
||||
return None
|
||||
|
||||
bin_found = [0] * len(self.apps)
|
||||
for i, app in enumerate(self.apps):
|
||||
if app.build_dir in app_lists:
|
||||
bin_found[i] = 1
|
||||
|
||||
if sum(bin_found) == 0:
|
||||
msg = f'Skip test case {self.name} because all following binaries are not listed in the app lists: ' # noqa: E713
|
||||
for app in self.apps:
|
||||
msg += f'\n - {app.build_dir}'
|
||||
|
||||
print(msg)
|
||||
return msg
|
||||
|
||||
if sum(bin_found) == len(self.apps):
|
||||
return None
|
||||
|
||||
# some found, some not, looks suspicious
|
||||
msg = f'Found some binaries of test case {self.name} are not listed in the app lists.' # noqa: E713
|
||||
for i, app in enumerate(self.apps):
|
||||
if bin_found[i] == 0:
|
||||
msg += f'\n - {app.build_dir}'
|
||||
|
||||
msg += '\nMight be a issue of .build-test-rules.yml files'
|
||||
print(msg)
|
||||
return msg
|
||||
|
||||
+140
-264
@@ -1,106 +1,109 @@
|
||||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import typing as t
|
||||
from collections import defaultdict
|
||||
from functools import cached_property
|
||||
from unittest.mock import MagicMock
|
||||
from pathlib import Path
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
import pytest
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.main import Session
|
||||
import yaml
|
||||
from _pytest.config import Config
|
||||
from _pytest.python import Function
|
||||
from _pytest.runner import CallInfo
|
||||
from idf_build_apps import App
|
||||
from idf_build_apps.constants import BuildStatus
|
||||
from idf_ci_utils import idf_relpath
|
||||
from dynamic_pipelines.constants import KNOWN_GENERATE_TEST_CHILD_PIPELINE_WARNINGS_FILEPATH
|
||||
from idf_ci import IdfPytestPlugin
|
||||
from idf_ci import PytestCase
|
||||
from idf_ci.idf_pytest.plugin import IDF_CI_PYTEST_DEBUG_INFO_KEY
|
||||
from idf_ci_utils import to_list
|
||||
from pytest_embedded import Dut
|
||||
from pytest_embedded.plugin import parse_multi_dut_args
|
||||
from pytest_embedded.utils import find_by_suffix
|
||||
from pytest_embedded.utils import to_list
|
||||
from pytest_ignore_test_results.ignore_results import ChildCase
|
||||
from pytest_ignore_test_results.ignore_results import ChildCasesStashKey
|
||||
|
||||
from .constants import CollectMode
|
||||
from .constants import DEFAULT_SDKCONFIG
|
||||
from .constants import PREVIEW_TARGETS
|
||||
from .constants import PytestApp
|
||||
from .constants import PytestCase
|
||||
from .constants import SUPPORTED_TARGETS
|
||||
from .utils import comma_sep_str_to_list
|
||||
from .constants import REV_MARKERS
|
||||
from .utils import format_case_id
|
||||
from .utils import merge_junit_files
|
||||
from .utils import normalize_testcase_file_path
|
||||
|
||||
IDF_PYTEST_EMBEDDED_KEY = pytest.StashKey['IdfPytestEmbedded']()
|
||||
ITEM_FAILED_CASES_KEY = pytest.StashKey[list]()
|
||||
ITEM_FAILED_KEY = pytest.StashKey[bool]()
|
||||
ITEM_PYTEST_CASE_KEY = pytest.StashKey[PytestCase]()
|
||||
IDF_LOCAL_PLUGIN_KEY = pytest.StashKey['IdfLocalPlugin']()
|
||||
|
||||
|
||||
class IdfPytestEmbedded:
|
||||
def requires_elf_or_map(case: PytestCase) -> bool:
|
||||
"""
|
||||
Determines whether the test case requires elf or map file. By default, one app in the test case
|
||||
only requires .bin files.
|
||||
|
||||
:return: True if the test case requires elf or map file, False otherwise
|
||||
"""
|
||||
if 'jtag' in case.env_markers or 'usb_serial_jtag' in case.env_markers:
|
||||
return True
|
||||
|
||||
folders_need_elf = ['panic', 'gdbstub_runtime']
|
||||
if 'require_elf' in case.all_markers:
|
||||
return True
|
||||
|
||||
for folder in folders_need_elf:
|
||||
if any(folder in Path(app.path).parts for app in case.apps):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def skipped_targets(item: Function) -> t.Set[str]:
|
||||
def _get_temp_markers_disabled_targets(marker_name: str) -> t.Set[str]:
|
||||
targets = []
|
||||
for _m in item.own_markers:
|
||||
if _m.name == marker_name:
|
||||
if not _m.kwargs.get('targets') or not _m.kwargs.get('reason'):
|
||||
raise ValueError(
|
||||
f'`{marker_name}` should always use keyword arguments `targets` and `reason`. ' # noqa: W604
|
||||
f'For example: '
|
||||
f'`@pytest.mark.{marker_name}(targets=["esp32"], reason="IDF-xxxx, will fix it ASAP")`'
|
||||
)
|
||||
targets.extend(to_list(_m.kwargs['targets']))
|
||||
|
||||
if targets:
|
||||
return set(targets)
|
||||
return set()
|
||||
|
||||
_count = IdfLocalPlugin.get_param(item, 'count', 1)
|
||||
|
||||
def normalize_targets(target: str) -> str:
|
||||
targets = target.split(',')
|
||||
if len(targets) == 1:
|
||||
return ','.join(targets * _count)
|
||||
if len(targets) != _count:
|
||||
raise ValueError(
|
||||
f"Invalid target format: '{target}'. "
|
||||
f'Expected a single target or exactly {_count} values separated by commas.'
|
||||
f'len({targets}) != {_count}'
|
||||
)
|
||||
return target
|
||||
|
||||
temp_skip_ci_targets = set(normalize_targets(_t) for _t in _get_temp_markers_disabled_targets('temp_skip_ci'))
|
||||
temp_skip_targets = set(normalize_targets(_t) for _t in _get_temp_markers_disabled_targets('temp_skip'))
|
||||
|
||||
# in CI we skip the union of `temp_skip` and `temp_skip_ci`
|
||||
if os.getenv('CI_JOB_ID'):
|
||||
_skip_targets = temp_skip_ci_targets.union(temp_skip_targets)
|
||||
else: # we use `temp_skip` locally
|
||||
_skip_targets = temp_skip_targets
|
||||
|
||||
return _skip_targets
|
||||
|
||||
|
||||
class IdfLocalPlugin:
|
||||
UNITY_RESULT_MAPPINGS = {
|
||||
'PASS': 'passed',
|
||||
'FAIL': 'failed',
|
||||
'IGNORE': 'skipped',
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
target: t.Union[t.List[str], str],
|
||||
*,
|
||||
config_name: t.Optional[str] = None,
|
||||
single_target_duplicate_mode: bool = False,
|
||||
apps: t.Optional[t.List[App]] = None,
|
||||
):
|
||||
if isinstance(target, str):
|
||||
# sequence also matters
|
||||
self.target = comma_sep_str_to_list(target)
|
||||
else:
|
||||
self.target = target
|
||||
def __init__(self) -> None:
|
||||
with open(KNOWN_GENERATE_TEST_CHILD_PIPELINE_WARNINGS_FILEPATH) as fr:
|
||||
known_warnings_dict = yaml.safe_load(fr) or dict()
|
||||
|
||||
if not self.target:
|
||||
raise ValueError('`target` should not be empty')
|
||||
|
||||
self.config_name = config_name
|
||||
|
||||
# these are useful while gathering all the multi-dut test cases
|
||||
# when this mode is activated,
|
||||
#
|
||||
# pytest.mark.esp32
|
||||
# pytest.mark.parametrize('count', [2], indirect=True)
|
||||
# def test_foo(dut):
|
||||
# pass
|
||||
#
|
||||
# should be collected when running `pytest --target esp32`
|
||||
#
|
||||
# otherwise, it should be collected when running `pytest --target esp32,esp32`
|
||||
self._single_target_duplicate_mode = single_target_duplicate_mode
|
||||
|
||||
self.apps_list = (
|
||||
[os.path.join(idf_relpath(app.app_dir), app.build_dir) for app in apps if app.build_status == BuildStatus.SUCCESS]
|
||||
if apps is not None
|
||||
else None
|
||||
)
|
||||
|
||||
self.cases: t.List[PytestCase] = []
|
||||
|
||||
# record the additional info
|
||||
# test case id: {key: value}
|
||||
self.additional_info: t.Dict[str, t.Dict[str, t.Any]] = defaultdict(dict)
|
||||
|
||||
@cached_property
|
||||
def collect_mode(self) -> CollectMode:
|
||||
if len(self.target) == 1:
|
||||
if self.target[0] == CollectMode.MULTI_ALL_WITH_PARAM:
|
||||
return CollectMode.MULTI_ALL_WITH_PARAM
|
||||
else:
|
||||
return CollectMode.SINGLE_SPECIFIC
|
||||
else:
|
||||
return CollectMode.MULTI_SPECIFIC
|
||||
self.exclude_no_env_markers_test_cases: set[str] = set(known_warnings_dict['no_env_marker_test_cases'])
|
||||
|
||||
@staticmethod
|
||||
def get_param(item: Function, key: str, default: t.Any = None) -> t.Any:
|
||||
@@ -111,207 +114,82 @@ class IdfPytestEmbedded:
|
||||
|
||||
return item.callspec.params.get(key, default) or default
|
||||
|
||||
def item_to_pytest_case(self, item: Function) -> t.Optional[PytestCase]:
|
||||
"""
|
||||
Turn pytest item to PytestCase
|
||||
"""
|
||||
count = self.get_param(item, 'count', 1)
|
||||
@pytest.hookimpl(wrapper=True)
|
||||
def pytest_collection_modifyitems(self, config: Config, items: t.List[Function]) -> t.Generator[None, None, None]:
|
||||
yield # throw it back to idf-ci
|
||||
|
||||
# default app_path is where the test script locates
|
||||
app_paths = to_list(parse_multi_dut_args(count, self.get_param(item, 'app_path', os.path.dirname(item.path))))
|
||||
configs = to_list(parse_multi_dut_args(count, self.get_param(item, 'config', DEFAULT_SDKCONFIG)))
|
||||
targets = to_list(parse_multi_dut_args(count, self.get_param(item, 'target')))
|
||||
deselected_items = []
|
||||
|
||||
multi_dut_without_param = False
|
||||
if count > 1 and targets == [None] * count:
|
||||
multi_dut_without_param = True
|
||||
try:
|
||||
targets = to_list(parse_multi_dut_args(count, '|'.join(self.target))) # check later while collecting
|
||||
except ValueError: # count doesn't match
|
||||
return None
|
||||
|
||||
elif targets is None:
|
||||
targets = self.target
|
||||
|
||||
return PytestCase(
|
||||
apps=[PytestApp(app_paths[i], targets[i], configs[i]) for i in range(count)],
|
||||
item=item,
|
||||
multi_dut_without_param=multi_dut_without_param
|
||||
)
|
||||
|
||||
def pytest_collectstart(self) -> None:
|
||||
# mock the optional packages while collecting locally
|
||||
if not os.getenv('CI_JOB_ID') or os.getenv('PYTEST_IGNORE_COLLECT_IMPORT_ERROR') == '1':
|
||||
# optional packages required by test scripts
|
||||
for p in [
|
||||
'scapy',
|
||||
'scapy.all',
|
||||
'websocket', # websocket-client
|
||||
'netifaces',
|
||||
'RangeHTTPServer', # rangehttpserver
|
||||
'dbus', # dbus-python
|
||||
'dbus.mainloop',
|
||||
'dbus.mainloop.glib',
|
||||
'google.protobuf', # protobuf
|
||||
'google.protobuf.internal',
|
||||
'bleak',
|
||||
'paho', # paho-mqtt
|
||||
'paho.mqtt',
|
||||
'paho.mqtt.client',
|
||||
'paramiko',
|
||||
'netmiko',
|
||||
'pyecharts',
|
||||
'pyecharts.options',
|
||||
'pyecharts.charts',
|
||||
'can', # python-can
|
||||
]:
|
||||
try:
|
||||
importlib.import_module(p)
|
||||
except ImportError:
|
||||
logging.warning(f'Optional package {p} is not installed, mocking it while collecting...')
|
||||
sys.modules[p] = MagicMock()
|
||||
|
||||
@pytest.hookimpl(tryfirst=True)
|
||||
def pytest_collection_modifyitems(self, items: t.List[Function]) -> None:
|
||||
"""
|
||||
Background info:
|
||||
|
||||
We're using `pytest.mark.[TARGET]` as a syntactic sugar to indicate that they are actually supported by all
|
||||
the listed targets. For example,
|
||||
|
||||
>>> @pytest.mark.esp32
|
||||
>>> @pytest.mark.esp32s2
|
||||
|
||||
should be treated as
|
||||
|
||||
>>> @pytest.mark.parametrize('target', [
|
||||
>>> 'esp32',
|
||||
>>> 'esp32s2',
|
||||
>>> ], indirect=True)
|
||||
|
||||
All single-dut test cases, and some of the multi-dut test cases with the same targets, are using this
|
||||
way to indicate the supported targets.
|
||||
|
||||
To avoid ambiguity,
|
||||
|
||||
- when we're collecting single-dut test cases with esp32, we call
|
||||
|
||||
`pytest --collect-only --target esp32`
|
||||
|
||||
- when we're collecting multi-dut test cases, we list all the targets, even when they're the same
|
||||
|
||||
`pytest --collect-only --target esp32,esp32` for two esp32 connected
|
||||
`pytest --collect-only --target esp32,esp32s2` for esp32 and esp32s2 connected
|
||||
|
||||
therefore, we have two different logic for searching test cases, explained in 2.1 and 2.2
|
||||
"""
|
||||
# 1. Filter according to nighty_run related markers
|
||||
if os.getenv('INCLUDE_NIGHTLY_RUN') == '1':
|
||||
# nightly_run and non-nightly_run cases are both included
|
||||
pass
|
||||
elif os.getenv('NIGHTLY_RUN') == '1':
|
||||
# only nightly_run cases are included
|
||||
items[:] = [_item for _item in items if _item.get_closest_marker('nightly_run') is not None]
|
||||
else:
|
||||
# only non-nightly_run cases are included
|
||||
items[:] = [_item for _item in items if _item.get_closest_marker('nightly_run') is None]
|
||||
|
||||
# 2. Add markers according to special markers
|
||||
item_to_case_dict: t.Dict[Function, PytestCase] = {}
|
||||
# Filter
|
||||
filtered_items = []
|
||||
for item in items:
|
||||
case = self.item_to_pytest_case(item)
|
||||
if case is None:
|
||||
case = IdfPytestPlugin.get_case_by_item(item)
|
||||
if not case:
|
||||
deselected_items.append(item)
|
||||
continue
|
||||
|
||||
item.stash[ITEM_PYTEST_CASE_KEY] = item_to_case_dict[item] = case
|
||||
if 'supported_targets' in item.keywords:
|
||||
for _target in SUPPORTED_TARGETS:
|
||||
item.add_marker(_target)
|
||||
if 'preview_targets' in item.keywords:
|
||||
for _target in PREVIEW_TARGETS:
|
||||
item.add_marker(_target)
|
||||
if 'all_targets' in item.keywords:
|
||||
for _target in [*SUPPORTED_TARGETS, *PREVIEW_TARGETS]:
|
||||
item.add_marker(_target)
|
||||
skipped = False
|
||||
current_targets = case.target_selector.split(',')
|
||||
for st in skipped_targets(item):
|
||||
# Handle wildcard patterns like "esp32p4,*" or "*,esp32p4"
|
||||
if '*' in st:
|
||||
skip_pattern = st.split(',')
|
||||
if len(skip_pattern) != len(current_targets):
|
||||
continue
|
||||
if all(_p == '*' or _p == _t for _p, _t in zip(skip_pattern, current_targets)):
|
||||
skipped = True
|
||||
break
|
||||
# Exact match (no wildcard)
|
||||
elif case.target_selector == st:
|
||||
skipped = True
|
||||
break
|
||||
|
||||
# add single-dut "target" as param
|
||||
_item_target_param = self.get_param(item, 'target', None)
|
||||
if case.is_single_dut_test_case and _item_target_param and _item_target_param not in case.all_markers:
|
||||
item.add_marker(_item_target_param)
|
||||
if skipped:
|
||||
deselected_items.append(item)
|
||||
item.stash[IDF_CI_PYTEST_DEBUG_INFO_KEY] = 'skipped by temp_skip markers'
|
||||
continue
|
||||
|
||||
items[:] = [_item for _item in items if _item in item_to_case_dict]
|
||||
if not case.env_markers and 'host_test' not in case.all_markers:
|
||||
if case.name in self.exclude_no_env_markers_test_cases:
|
||||
deselected_items.append(item)
|
||||
continue
|
||||
|
||||
# 3.1. CollectMode.SINGLE_SPECIFIC, like `pytest --target esp32`
|
||||
if self.collect_mode == CollectMode.SINGLE_SPECIFIC:
|
||||
filtered_items = []
|
||||
for item in items:
|
||||
case = item_to_case_dict[item]
|
||||
raise ValueError(
|
||||
f'Test case {case.name} does not have any env markers. '
|
||||
f'Please add env markers to the test case or add it to the '
|
||||
f'`no_env_markers_test_cases` list in {KNOWN_GENERATE_TEST_CHILD_PIPELINE_WARNINGS_FILEPATH}'
|
||||
)
|
||||
|
||||
# single-dut one
|
||||
if case.is_single_dut_test_case and self.target[0] in case.target_markers:
|
||||
filtered_items.append(item)
|
||||
filtered_items.append(item)
|
||||
|
||||
# multi-dut ones and in single_target_duplicate_mode
|
||||
elif self._single_target_duplicate_mode and not case.is_single_dut_test_case:
|
||||
# ignore those test cases with `target` defined in parametrize, since these will be covered in 3.3
|
||||
if self.get_param(item, 'target', None) is None and self.target[0] in case.target_markers:
|
||||
filtered_items.append(item)
|
||||
items[:] = filtered_items
|
||||
|
||||
items[:] = filtered_items
|
||||
# 3.2. CollectMode.MULTI_SPECIFIC, like `pytest --target esp32,esp32`
|
||||
elif self.collect_mode == CollectMode.MULTI_SPECIFIC:
|
||||
items[:] = [_item for _item in items if item_to_case_dict[_item].targets == self.target]
|
||||
|
||||
# 3.3. CollectMode.MULTI_ALL_WITH_PARAM, intended to be used by `get_pytest_cases`
|
||||
else:
|
||||
items[:] = [
|
||||
_item
|
||||
for _item in items
|
||||
if not item_to_case_dict[_item].is_single_dut_test_case
|
||||
and self.get_param(_item, 'target', None) is not None
|
||||
]
|
||||
|
||||
# 4. filter according to the sdkconfig, if there's param 'config' defined
|
||||
if self.config_name:
|
||||
_items = []
|
||||
for item in items:
|
||||
case = item_to_case_dict[item]
|
||||
if self.config_name not in set(app.config or DEFAULT_SDKCONFIG for app in case.apps):
|
||||
self.additional_info[case.name]['skip_reason'] = f'Only run with sdkconfig {self.config_name}'
|
||||
else:
|
||||
_items.append(item)
|
||||
items[:] = _items
|
||||
|
||||
# 5. filter by `self.apps_list`, skip the test case if not listed
|
||||
# should only be used in CI
|
||||
_items = []
|
||||
for item in items:
|
||||
case = item_to_case_dict[item]
|
||||
if msg := case.all_built_in_app_lists(self.apps_list):
|
||||
self.additional_info[case.name]['skip_reason'] = msg
|
||||
else:
|
||||
_items.append(item)
|
||||
# Deselect
|
||||
config.hook.pytest_deselected(items=deselected_items)
|
||||
|
||||
# OKAY!!! All left ones will be executed, sort it and add more markers
|
||||
items[:] = sorted(
|
||||
_items, key=lambda x: (os.path.dirname(x.path), self.get_param(x, 'config', DEFAULT_SDKCONFIG))
|
||||
)
|
||||
items[:] = sorted(items, key=lambda x: (os.path.dirname(x.path), self.get_param(x, 'config', 'default')))
|
||||
|
||||
for item in items:
|
||||
case = item_to_case_dict[item]
|
||||
case = IdfPytestPlugin.get_case_by_item(item)
|
||||
|
||||
# set default timeout 10 minutes for each case
|
||||
if 'timeout' not in item.keywords:
|
||||
item.add_marker(pytest.mark.timeout(10 * 60))
|
||||
|
||||
# add 'xtal_40mhz' tag as a default tag for esp32c2 target
|
||||
# only add this marker for esp32c2 cases
|
||||
if 'esp32c2' in self.target and 'esp32c2' in case.targets and 'xtal_26mhz' not in case.all_markers:
|
||||
if 'esp32c2' in case.targets and 'xtal_26mhz' not in case.all_markers:
|
||||
item.add_marker('xtal_40mhz')
|
||||
|
||||
if 'esp32p4' in self.target and 'esp32p4' in case.targets:
|
||||
item.add_marker('esp32p4_eco4')
|
||||
for rev_marker in REV_MARKERS:
|
||||
if rev_marker in case.all_markers:
|
||||
break
|
||||
else:
|
||||
# ESP32-P4's default build supports revisions below 3.0.
|
||||
item.add_marker('esp32p4_rev1' if 'esp32p4' in case.targets else 'rev_default')
|
||||
|
||||
def pytest_report_collectionfinish(self, items: t.List[Function]) -> None:
|
||||
self.cases = [item.stash[ITEM_PYTEST_CASE_KEY] for item in items]
|
||||
if 'host_test' in case.all_markers:
|
||||
item.add_marker('skip_app_downloader') # host_test jobs will build the apps itself
|
||||
|
||||
def pytest_custom_test_case_name(self, item: Function) -> str:
|
||||
return item.funcargs.get('test_case_name', item.nodeid) # type: ignore
|
||||
@@ -368,22 +246,20 @@ class IdfPytestEmbedded:
|
||||
is_qemu = item.get_closest_marker('qemu') is not None
|
||||
target = item.funcargs['target']
|
||||
config = item.funcargs['config']
|
||||
app_path = item.funcargs.get('app_path')
|
||||
for junit in junits:
|
||||
xml = ET.parse(junit)
|
||||
testcases = xml.findall('.//testcase')
|
||||
for case in testcases:
|
||||
# modify the junit files
|
||||
# Use from case attrib if available, otherwise fallback to the previously defined
|
||||
app_path = case.attrib.get('app_path') or app_path
|
||||
new_case_name = format_case_id(target, config, case.attrib['name'], is_qemu=is_qemu)
|
||||
case.attrib['name'] = new_case_name
|
||||
if 'file' in case.attrib:
|
||||
case.attrib['file'] = case.attrib['file'].replace('/IDF/', '') # our unity test framework
|
||||
|
||||
# our unity test framework
|
||||
case.attrib['file'] = normalize_testcase_file_path(case.attrib['file'], app_path)
|
||||
if ci_job_url := os.getenv('CI_JOB_URL'):
|
||||
case.attrib['ci_job_url'] = ci_job_url
|
||||
|
||||
xml.write(junit)
|
||||
|
||||
def pytest_sessionfinish(self, session: Session, exitstatus: int) -> None:
|
||||
if exitstatus != 0:
|
||||
if exitstatus == ExitCode.NO_TESTS_COLLECTED:
|
||||
session.exitstatus = 0
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
[pytest]
|
||||
addopts = -p no:idf-ci
|
||||
python_files = test_*.py
|
||||
@@ -1,236 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import fnmatch
|
||||
import io
|
||||
import logging
|
||||
import os.path
|
||||
import typing as t
|
||||
from contextlib import redirect_stdout
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from _pytest.config import ExitCode
|
||||
from idf_build_apps import App
|
||||
from idf_build_apps import find_apps
|
||||
from idf_build_apps.constants import BuildStatus
|
||||
from idf_build_apps.constants import SUPPORTED_TARGETS
|
||||
from idf_ci_local.app import IdfCMakeApp
|
||||
from idf_ci_utils import get_all_manifest_files
|
||||
from idf_ci_utils import IDF_PATH
|
||||
from idf_ci_utils import idf_relpath
|
||||
from idf_ci_utils import to_list
|
||||
from idf_py_actions.constants import PREVIEW_TARGETS as TOOLS_PREVIEW_TARGETS
|
||||
from idf_py_actions.constants import SUPPORTED_TARGETS as TOOLS_SUPPORTED_TARGETS
|
||||
|
||||
from .constants import CollectMode
|
||||
from .constants import DEFAULT_BUILD_LOG_FILENAME
|
||||
from .constants import DEFAULT_CONFIG_RULES_STR
|
||||
from .constants import DEFAULT_SIZE_JSON_FILENAME
|
||||
from .constants import PytestCase
|
||||
from .plugin import IdfPytestEmbedded
|
||||
|
||||
|
||||
def get_pytest_files(paths: t.List[str]) -> t.List[str]:
|
||||
# this is a workaround to solve pytest collector super slow issue
|
||||
# benchmark with
|
||||
# - time pytest -m esp32 --collect-only
|
||||
# user=15.57s system=1.35s cpu=95% total=17.741
|
||||
# - time { find -name 'pytest_*.py'; } | xargs pytest -m esp32 --collect-only
|
||||
# user=0.11s system=0.63s cpu=36% total=2.044
|
||||
# user=1.76s system=0.22s cpu=43% total=4.539
|
||||
# use glob.glob would also save a bunch of time
|
||||
pytest_scripts: t.Set[str] = set()
|
||||
for p in paths:
|
||||
path = Path(p)
|
||||
pytest_scripts.update(str(_p) for _p in path.glob('**/pytest_*.py') if 'managed_components' not in _p.parts)
|
||||
|
||||
return list(pytest_scripts)
|
||||
|
||||
|
||||
def get_pytest_cases(
|
||||
paths: t.Union[str, t.List[str]],
|
||||
target: str = CollectMode.ALL,
|
||||
*,
|
||||
config_name: t.Optional[str] = None,
|
||||
marker_expr: t.Optional[str] = None,
|
||||
filter_expr: t.Optional[str] = None,
|
||||
apps: t.Optional[t.List[App]] = None,
|
||||
) -> t.List[PytestCase]:
|
||||
"""
|
||||
Return the list of test cases
|
||||
|
||||
For single-dut test cases, `target` could be
|
||||
- [TARGET], e.g. `esp32`, to get the test cases for the given target
|
||||
- or `single_all`, to get all single-dut test cases
|
||||
|
||||
For multi-dut test cases, `target` could be
|
||||
- [TARGET,[TARGET...]], e.g. `esp32,esp32s2`, to get the test cases for the given targets
|
||||
- or `multi_all`, to get all multi-dut test cases
|
||||
|
||||
:param paths: paths to search for pytest scripts
|
||||
:param target: target or keywords to get test cases for, detailed above
|
||||
:param config_name: sdkconfig name
|
||||
:param marker_expr: pytest marker expression, `-m`
|
||||
:param filter_expr: pytest filter expression, `-k`
|
||||
:param apps: built app list, skip the tests required by apps not in the list
|
||||
:return: list of test cases
|
||||
"""
|
||||
paths = to_list(paths)
|
||||
|
||||
cases: t.List[PytestCase] = []
|
||||
pytest_scripts = get_pytest_files(paths) # type: ignore
|
||||
if not pytest_scripts:
|
||||
print(f'WARNING: no pytest scripts found for target {target} under paths {", ".join(paths)}')
|
||||
return cases
|
||||
|
||||
def _get_pytest_cases(_target: str, _single_target_duplicate_mode: bool = False) -> t.List[PytestCase]:
|
||||
collector = IdfPytestEmbedded(_target, config_name=config_name, single_target_duplicate_mode=_single_target_duplicate_mode, apps=apps)
|
||||
|
||||
with io.StringIO() as buf:
|
||||
with redirect_stdout(buf):
|
||||
cmd = ['--collect-only', *pytest_scripts, '--target', _target, '-q']
|
||||
if marker_expr:
|
||||
cmd.extend(['-m', marker_expr])
|
||||
if filter_expr:
|
||||
cmd.extend(['-k', filter_expr])
|
||||
res = pytest.main(cmd, plugins=[collector])
|
||||
|
||||
if res.value != ExitCode.OK:
|
||||
if res.value == ExitCode.NO_TESTS_COLLECTED:
|
||||
print(f'WARNING: no pytest app found for target {_target} under paths {", ".join(paths)}')
|
||||
else:
|
||||
print(buf.getvalue())
|
||||
raise RuntimeError(
|
||||
f'pytest collection failed at {", ".join(paths)} with command \"{" ".join(cmd)}\"'
|
||||
)
|
||||
|
||||
return collector.cases # type: ignore
|
||||
|
||||
if target == CollectMode.ALL:
|
||||
targets = TOOLS_SUPPORTED_TARGETS + TOOLS_PREVIEW_TARGETS + [CollectMode.MULTI_ALL_WITH_PARAM]
|
||||
else:
|
||||
targets = [target]
|
||||
|
||||
for _target in targets:
|
||||
if target == CollectMode.ALL:
|
||||
cases.extend(_get_pytest_cases(_target, _single_target_duplicate_mode=True))
|
||||
else:
|
||||
cases.extend(_get_pytest_cases(_target))
|
||||
|
||||
return sorted(cases, key=lambda x: (x.path, x.name, str(x.targets)))
|
||||
|
||||
|
||||
def get_all_apps(
|
||||
paths: t.List[str],
|
||||
target: str = CollectMode.ALL,
|
||||
*,
|
||||
marker_expr: t.Optional[str] = None,
|
||||
filter_expr: t.Optional[str] = None,
|
||||
config_rules_str: t.Optional[t.List[str]] = None,
|
||||
preserve_all: bool = False,
|
||||
extra_default_build_targets: t.Optional[t.List[str]] = None,
|
||||
compare_manifest_sha_filepath: t.Optional[str] = None,
|
||||
modified_components: t.Optional[t.List[str]] = None,
|
||||
modified_files: t.Optional[t.List[str]] = None,
|
||||
ignore_app_dependencies_components: t.Optional[t.List[str]] = None,
|
||||
ignore_app_dependencies_filepatterns: t.Optional[t.List[str]] = None,
|
||||
) -> t.Tuple[t.Set[App], t.Set[App]]:
|
||||
"""
|
||||
Return the tuple of test-required apps and non-test-related apps
|
||||
|
||||
:param paths: paths to search for pytest scripts
|
||||
:param target: target or keywords to get test cases for, explained in `get_pytest_cases`
|
||||
:param marker_expr: pytest marker expression, `-m`
|
||||
:param filter_expr: pytest filter expression, `-k`
|
||||
:param config_rules_str: config rules string
|
||||
:param preserve_all: preserve all apps
|
||||
:param extra_default_build_targets: extra default build targets
|
||||
:param compare_manifest_sha_filepath: check manifest sha filepath
|
||||
:param modified_components: modified components
|
||||
:param modified_files: modified files
|
||||
:param ignore_app_dependencies_components: ignore app dependencies components
|
||||
:param ignore_app_dependencies_filepatterns: ignore app dependencies filepatterns
|
||||
:return: tuple of test-required apps and non-test-related apps
|
||||
"""
|
||||
# target could be comma separated list
|
||||
all_apps: t.List[App] = []
|
||||
for _t in set(target.split(',')):
|
||||
all_apps.extend(find_apps(
|
||||
paths,
|
||||
_t,
|
||||
build_system=IdfCMakeApp,
|
||||
recursive=True,
|
||||
build_dir='build_@t_@w',
|
||||
config_rules_str=config_rules_str or DEFAULT_CONFIG_RULES_STR,
|
||||
build_log_filename=DEFAULT_BUILD_LOG_FILENAME,
|
||||
size_json_filename=DEFAULT_SIZE_JSON_FILENAME,
|
||||
check_warnings=True,
|
||||
manifest_rootpath=IDF_PATH,
|
||||
compare_manifest_sha_filepath=compare_manifest_sha_filepath,
|
||||
manifest_files=get_all_manifest_files(),
|
||||
default_build_targets=SUPPORTED_TARGETS + (extra_default_build_targets or []),
|
||||
modified_components=modified_components,
|
||||
modified_files=modified_files,
|
||||
ignore_app_dependencies_components=ignore_app_dependencies_components,
|
||||
ignore_app_dependencies_filepatterns=ignore_app_dependencies_filepatterns,
|
||||
include_skipped_apps=True,
|
||||
))
|
||||
|
||||
pytest_cases = get_pytest_cases(
|
||||
paths,
|
||||
target,
|
||||
marker_expr=marker_expr,
|
||||
filter_expr=filter_expr,
|
||||
)
|
||||
|
||||
modified_pytest_cases = []
|
||||
if modified_files:
|
||||
modified_pytest_scripts = [
|
||||
os.path.dirname(f) for f in modified_files if fnmatch.fnmatch(os.path.basename(f), 'pytest_*.py')
|
||||
]
|
||||
if modified_pytest_scripts:
|
||||
modified_pytest_cases = get_pytest_cases(
|
||||
modified_pytest_scripts,
|
||||
target,
|
||||
marker_expr=marker_expr,
|
||||
filter_expr=filter_expr,
|
||||
)
|
||||
|
||||
# app_path, target, config
|
||||
pytest_app_path_tuple_dict: t.Dict[t.Tuple[str, str, str], PytestCase] = {}
|
||||
for case in pytest_cases:
|
||||
for app in case.apps:
|
||||
pytest_app_path_tuple_dict[(app.path, app.target, app.config)] = case
|
||||
|
||||
modified_pytest_app_path_tuple_dict: t.Dict[t.Tuple[str, str, str], PytestCase] = {}
|
||||
for case in modified_pytest_cases:
|
||||
for app in case.apps:
|
||||
modified_pytest_app_path_tuple_dict[(app.path, app.target, app.config)] = case
|
||||
|
||||
test_related_apps: t.Set[App] = set()
|
||||
non_test_related_apps: t.Set[App] = set()
|
||||
for app in all_apps:
|
||||
# PytestCase.app.path is idf_relpath
|
||||
app_path = idf_relpath(app.app_dir)
|
||||
|
||||
# override build_status if test script got modified
|
||||
if case := modified_pytest_app_path_tuple_dict.get((app_path, app.target, app.config_name)):
|
||||
test_related_apps.add(app)
|
||||
app.build_status = BuildStatus.SHOULD_BE_BUILT
|
||||
app.preserve = True
|
||||
logging.debug('Found app: %s - required by modified test case %s', app, case.path)
|
||||
elif app.build_status != BuildStatus.SKIPPED:
|
||||
if case := pytest_app_path_tuple_dict.get((app_path, app.target, app.config_name)):
|
||||
test_related_apps.add(app)
|
||||
# build or not should be decided by the build stage
|
||||
app.preserve = True
|
||||
logging.debug('Found test-related app: %s - required by %s', app, case.path)
|
||||
else:
|
||||
non_test_related_apps.add(app)
|
||||
app.preserve = preserve_all
|
||||
logging.debug('Found non-test-related app: %s', app)
|
||||
|
||||
print(f'Found {len(test_related_apps)} test-related apps')
|
||||
print(f'Found {len(non_test_related_apps)} non-test-related apps')
|
||||
|
||||
return test_related_apps, non_test_related_apps
|
||||
@@ -1,6 +1,5 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import logging
|
||||
import os
|
||||
import typing as t
|
||||
@@ -31,8 +30,8 @@ def merge_junit_files(junit_files: t.List[str], target_path: str) -> None:
|
||||
testcases: t.Dict[str, ET.Element] = {}
|
||||
for junit in junit_files:
|
||||
logging.info(f'Merging {junit} to {target_path}')
|
||||
tree: ET.ElementTree = ET.parse(junit)
|
||||
testsuite: ET.Element = tree.getroot()
|
||||
tree: ET.ElementTree = ET.parse(junit) # type: ignore
|
||||
testsuite: ET.Element = tree.getroot() # type: ignore
|
||||
|
||||
for testcase in testsuite.findall('testcase'):
|
||||
name: str = testcase.get('name') if testcase.get('name') else '' # type: ignore
|
||||
@@ -63,5 +62,35 @@ def merge_junit_files(junit_files: t.List[str], target_path: str) -> None:
|
||||
fw.write(ET.tostring(merged_testsuite))
|
||||
|
||||
|
||||
def comma_sep_str_to_list(s: str) -> t.List[str]:
|
||||
return [s.strip() for s in s.split(',') if s.strip()]
|
||||
def normalize_testcase_file_path(file: str, app_path: t.Union[str, tuple]) -> str:
|
||||
"""
|
||||
Normalize file paths to a consistent format, resolving relative paths based on the `app_path`.
|
||||
|
||||
This function ensures that file paths are correctly resolved and normalized:
|
||||
- If `app_path` is a tuple, the function will try each app path in the tuple in order and join the results with ':'.
|
||||
- If `app_path` is a string, the file will be resolved using that base path.
|
||||
|
||||
:param file: The original file path, which can be relative, absolute.
|
||||
:param app_path: The base app path used to resolve relative paths, which can be a string or tuple.
|
||||
:return: A normalized file path with the IDF_PATH prefix removed if applicable.
|
||||
"""
|
||||
|
||||
def normalize_path(file_path: str, app_path: str) -> str:
|
||||
"""Helper function to normalize a single path."""
|
||||
if not os.path.isabs(file_path):
|
||||
# startswith/slice instead of str.removeprefix (3.9+), keep 3.8 compat
|
||||
if file_path.startswith('./'):
|
||||
file_path = file_path[2:]
|
||||
if file_path.startswith('../'):
|
||||
file_path = file_path[3:]
|
||||
resolved_path = os.path.normpath(os.path.join(app_path, file_path))
|
||||
else:
|
||||
resolved_path = os.path.normpath(file_path)
|
||||
|
||||
return resolved_path.replace(f'{os.environ.get("IDF_PATH", "")}', '').replace('/IDF/', '').lstrip('/')
|
||||
|
||||
if isinstance(app_path, tuple):
|
||||
normalized_paths = [normalize_path(file, base_path) for base_path in app_path]
|
||||
return '|'.join(normalized_paths)
|
||||
|
||||
return normalize_path(file, app_path)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
import requests
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--stage', type=str, help='Stage name for check jobs status')
|
||||
args = parser.parse_args()
|
||||
|
||||
GITLAB_TOKEN = os.getenv('ESPCI_TOKEN')
|
||||
GITLAB_HTTP_SERVER = os.getenv('GITLAB_HTTP_SERVER')
|
||||
CI_PROJECT_ID = os.getenv('CI_PROJECT_ID')
|
||||
CI_PIPELINE_ID = os.getenv('CI_PIPELINE_ID')
|
||||
|
||||
api_path = f'projects/{CI_PROJECT_ID}/pipelines/{CI_PIPELINE_ID}/jobs?scope[]=failed&per_page=100'
|
||||
|
||||
page = 0
|
||||
while True:
|
||||
response = requests.get(
|
||||
f'{GITLAB_HTTP_SERVER}/api/v4/{api_path}&page={page}',
|
||||
headers={'PRIVATE-TOKEN': GITLAB_TOKEN}
|
||||
)
|
||||
jobs = response.json()
|
||||
if not jobs:
|
||||
break
|
||||
|
||||
for job in jobs:
|
||||
if job['stage'] == args.stage:
|
||||
print(f'Jobs from the previous stage {args.stage} should pass; otherwise, this job will fail.')
|
||||
sys.exit(1)
|
||||
page += 1
|
||||
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import argparse
|
||||
import logging
|
||||
@@ -36,7 +36,7 @@ def retry(func: TR) -> TR:
|
||||
while True:
|
||||
try:
|
||||
res = func(self, *args, **kwargs)
|
||||
except (IOError, EOFError, gitlab.exceptions.GitlabError) as e:
|
||||
except (OSError, EOFError, gitlab.exceptions.GitlabError) as e:
|
||||
if isinstance(e, gitlab.exceptions.GitlabError):
|
||||
if e.response_code == 500:
|
||||
# retry on this error
|
||||
@@ -52,9 +52,11 @@ def retry(func: TR) -> TR:
|
||||
raise e # get out of the loop
|
||||
else:
|
||||
logging.warning(
|
||||
'Network failure in {}, retrying ({})'.format(getattr(func, '__name__', '(unknown callable)'),
|
||||
retried))
|
||||
time.sleep(2 ** retried) # wait a bit more after each retry
|
||||
'Network failure in {}, retrying ({})'.format(
|
||||
getattr(func, '__name__', '(unknown callable)'), retried
|
||||
)
|
||||
)
|
||||
time.sleep(2**retried) # wait a bit more after each retry
|
||||
continue
|
||||
else:
|
||||
break
|
||||
@@ -63,11 +65,10 @@ def retry(func: TR) -> TR:
|
||||
return wrapper
|
||||
|
||||
|
||||
class Gitlab(object):
|
||||
class Gitlab:
|
||||
JOB_NAME_PATTERN = re.compile(r'(\w+)(\s+(\d+)/(\d+))?')
|
||||
|
||||
DOWNLOAD_ERROR_MAX_RETRIES = 3
|
||||
DEFAULT_BUILD_CHILD_PIPELINE_NAME = 'Build Child Pipeline'
|
||||
|
||||
def __init__(self, project_id: Union[int, str, None] = None):
|
||||
config_data_from_env = os.getenv('PYTHON_GITLAB_CONFIG')
|
||||
@@ -117,7 +118,7 @@ class Gitlab(object):
|
||||
:param namespace: namespace to match when we have multiple project with same name
|
||||
:return: project ID
|
||||
"""
|
||||
projects = self.gitlab_inst.projects.list(search=name)
|
||||
projects = self.gitlab_inst.projects.list(search=name, get_all=True)
|
||||
res = []
|
||||
for project in projects:
|
||||
if namespace is None:
|
||||
@@ -152,7 +153,9 @@ class Gitlab(object):
|
||||
archive_file.extractall(destination)
|
||||
|
||||
@retry
|
||||
def download_artifact(self, job_id: int, artifact_path: List[str], destination: Optional[str] = None) -> List[bytes]:
|
||||
def download_artifact(
|
||||
self, job_id: int, artifact_path: List[str], destination: Optional[str] = None
|
||||
) -> List[bytes]:
|
||||
"""
|
||||
download specific path of job artifacts and extract to destination.
|
||||
|
||||
@@ -169,7 +172,7 @@ class Gitlab(object):
|
||||
try:
|
||||
data = job.artifact(a_path) # type: bytes
|
||||
except gitlab.GitlabGetError as e:
|
||||
logging.error("Failed to download '{}' from job {}".format(a_path, job_id))
|
||||
logging.error(f"Failed to download '{a_path}' from job {job_id}")
|
||||
raise e
|
||||
raw_data_list.append(data)
|
||||
if destination:
|
||||
@@ -208,8 +211,9 @@ class Gitlab(object):
|
||||
return job_id_list
|
||||
|
||||
@retry
|
||||
def download_archive(self, ref: str, destination: str, project_id: Optional[int] = None,
|
||||
cache_dir: Optional[str] = None) -> str:
|
||||
def download_archive(
|
||||
self, ref: str, destination: str, project_id: Optional[int] = None, cache_dir: Optional[str] = None
|
||||
) -> str:
|
||||
"""
|
||||
Download archive of certain commit of a repository and extract to destination path
|
||||
|
||||
@@ -233,10 +237,11 @@ class Gitlab(object):
|
||||
try:
|
||||
project.repository_archive(sha=ref, streamed=True, action=fw.write)
|
||||
except gitlab.GitlabGetError as e:
|
||||
logging.error('Failed to archive from project {}'.format(project_id))
|
||||
logging.error(f'Failed to archive from project {project_id}')
|
||||
raise e
|
||||
logging.info('Downloaded archive size: {:.03f}MB'.format(
|
||||
float(os.path.getsize(local_archive_file)) / (1024 * 1024)))
|
||||
logging.info(
|
||||
f'Downloaded archive size: {float(os.path.getsize(local_archive_file)) / (1024 * 1024):.03f}MB'
|
||||
)
|
||||
|
||||
return self.decompress_archive(local_archive_file, destination)
|
||||
|
||||
@@ -245,10 +250,10 @@ class Gitlab(object):
|
||||
try:
|
||||
project.repository_archive(sha=ref, streamed=True, action=temp_file.write)
|
||||
except gitlab.GitlabGetError as e:
|
||||
logging.error('Failed to archive from project {}'.format(project_id))
|
||||
logging.error(f'Failed to archive from project {project_id}')
|
||||
raise e
|
||||
|
||||
logging.info('Downloaded archive size: {:.03f}MB'.format(float(os.path.getsize(temp_file.name)) / (1024 * 1024)))
|
||||
logging.info(f'Downloaded archive size: {float(os.path.getsize(temp_file.name)) / (1024 * 1024):.03f}MB')
|
||||
|
||||
return self.decompress_archive(temp_file.name, destination)
|
||||
|
||||
@@ -282,36 +287,28 @@ class Gitlab(object):
|
||||
|
||||
def get_downstream_pipeline_ids(self, main_pipeline_id: int) -> List[int]:
|
||||
"""
|
||||
Retrieve the IDs of all downstream child pipelines for a given main pipeline.
|
||||
Retrieve the IDs of all downstream child pipelines for a given main pipeline,
|
||||
recursing through arbitrarily nested child pipelines.
|
||||
|
||||
:param main_pipeline_id: The ID of the main pipeline to start the search.
|
||||
:return: A list of IDs of all downstream child pipelines.
|
||||
:return: A list of IDs of all downstream child pipelines (all levels).
|
||||
"""
|
||||
bridge_pipeline_ids = []
|
||||
child_pipeline_ids = []
|
||||
child_pipeline_ids: List[int] = []
|
||||
|
||||
main_pipeline_bridges = self.project.pipelines.get(main_pipeline_id).bridges.list()
|
||||
for bridge in main_pipeline_bridges:
|
||||
pipeline_bridges = self.project.pipelines.get(main_pipeline_id).bridges.list()
|
||||
for bridge in pipeline_bridges:
|
||||
downstream_pipeline = bridge.attributes.get('downstream_pipeline')
|
||||
if not downstream_pipeline:
|
||||
continue
|
||||
bridge_pipeline_ids.append(downstream_pipeline['id'])
|
||||
|
||||
for bridge_pipeline_id in bridge_pipeline_ids:
|
||||
child_pipeline_ids.append(bridge_pipeline_id)
|
||||
bridge_pipeline = self.project.pipelines.get(bridge_pipeline_id)
|
||||
|
||||
if not bridge_pipeline.name == self.DEFAULT_BUILD_CHILD_PIPELINE_NAME:
|
||||
downstream_pipeline_id = downstream_pipeline.get('id')
|
||||
if downstream_pipeline_id is None:
|
||||
continue
|
||||
|
||||
child_bridges = bridge_pipeline.bridges.list()
|
||||
for child_bridge in child_bridges:
|
||||
downstream_child_pipeline = child_bridge.attributes.get('downstream_pipeline')
|
||||
if not downstream_child_pipeline:
|
||||
continue
|
||||
child_pipeline_ids.append(downstream_child_pipeline.get('id'))
|
||||
child_pipeline_ids.append(downstream_pipeline_id)
|
||||
# recurse to collect further nested (grandchild+) pipelines
|
||||
child_pipeline_ids.extend(self.get_downstream_pipeline_ids(downstream_pipeline_id))
|
||||
|
||||
return [pid for pid in child_pipeline_ids if pid is not None]
|
||||
return child_pipeline_ids
|
||||
|
||||
def retry_failed_jobs(self, pipeline_id: int, retry_allowed_failures: bool = False) -> List[int]:
|
||||
"""
|
||||
@@ -370,10 +367,10 @@ def main() -> None:
|
||||
gitlab_inst.download_archive(args.ref, args.destination)
|
||||
elif args.action == 'get_project_id':
|
||||
ret = gitlab_inst.get_project_id(args.project_name)
|
||||
print('project id: {}'.format(ret))
|
||||
print(f'project id: {ret}')
|
||||
elif args.action == 'retry_failed_jobs':
|
||||
res = gitlab_inst.retry_failed_jobs(args.pipeline_id, args.retry_allowed_failures)
|
||||
print('jobs retried successfully: {}'.format(res))
|
||||
print(f'jobs retried successfully: {res}')
|
||||
elif args.action == 'get_job_tags':
|
||||
ret = gitlab_inst.get_job_tags(args.job_id)
|
||||
print(ret)
|
||||
|
||||
+27
-36
@@ -5,7 +5,14 @@ function add_ssh_keys() {
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo -n "${key_string}" >~/.ssh/id_rsa_base64
|
||||
base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 >~/.ssh/id_rsa
|
||||
# Detect base64 implementation via --help output
|
||||
if base64 --help 2>&1 | grep -q -- '--ignore-garbage'; then
|
||||
# GNU coreutils base64
|
||||
base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 >~/.ssh/id_rsa
|
||||
else
|
||||
# macOS/BSD base64 - requires stdin or -i flag
|
||||
base64 --decode -i ~/.ssh/id_rsa_base64 -o ~/.ssh/id_rsa
|
||||
fi
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
}
|
||||
|
||||
@@ -96,6 +103,25 @@ function run_cmd() {
|
||||
fi
|
||||
}
|
||||
|
||||
function pytest_for_ut() {
|
||||
pytest_args="-c NUL -p no:idf-ci -p no:pytest_embedded"
|
||||
|
||||
if [ -n "${CI_JOB_ID-}" ]; then
|
||||
if [ -z "${KNOWN_FAILURE_CASES_FILE_NAME-}" ]; then
|
||||
echo "Error: KNOWN_FAILURE_CASES_FILE_NAME is not set."
|
||||
return 1
|
||||
fi
|
||||
|
||||
pytest_args="${pytest_args} --junitxml XUNIT_RESULT_${CI_JOB_ID}.xml --ignore-result-files ${KNOWN_FAILURE_CASES_FILE_NAME}"
|
||||
|
||||
if [ ! -e "${KNOWN_FAILURE_CASES_FILE_NAME}" ]; then
|
||||
run_cmd idf-ci gitlab download-known-failure-cases-file "${KNOWN_FAILURE_CASES_FILE_NAME}"
|
||||
fi
|
||||
fi
|
||||
|
||||
run_cmd pytest "$@" "${pytest_args}"
|
||||
}
|
||||
|
||||
# Retries a command RETRY_ATTEMPTS times in case of failure
|
||||
# Inspired by https://stackoverflow.com/a/8351489
|
||||
function retry_failed() {
|
||||
@@ -138,38 +164,3 @@ function join_by {
|
||||
printf %s "$f" "${@/#/$d}"
|
||||
fi
|
||||
}
|
||||
|
||||
function is_based_on_commits() {
|
||||
# This function would accept space-separated args as multiple commits.
|
||||
# The return value would be 0 if current HEAD is based on any of the specified commits.
|
||||
#
|
||||
# In our CI, we use environment variable $REQUIRED_ANCESTOR_COMMITS to declare the ancestor commits.
|
||||
# Please remember to set one commit for each release branch.
|
||||
|
||||
commits=$*
|
||||
if [[ -z $commits ]]; then
|
||||
info "Not specifying commits that branches should be based on, skipping check..."
|
||||
return 0
|
||||
fi
|
||||
|
||||
commits_str="$(join_by " or " $commits)" # no doublequotes here, passing array
|
||||
|
||||
info "Checking if current branch is based on $commits_str..."
|
||||
for i in $commits; do
|
||||
if git merge-base --is-ancestor "$i" HEAD >/dev/null 2>&1; then
|
||||
info "Current branch is based on $i"
|
||||
return 0
|
||||
else
|
||||
info "Current branch is not based on $i"
|
||||
fi
|
||||
done
|
||||
|
||||
error "The base commit of your branch is too old."
|
||||
error "The branch should be more recent than either of the following commits:"
|
||||
error " $commits_str"
|
||||
error "To fix the issue:"
|
||||
error " - If your merge request is 'Draft', or has conflicts with the target branch, rebase it to the latest master or release branch"
|
||||
error " - Otherwise, simply run a new pipeline."
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user