2017-10-09 22:44:55 -04:00
|
|
|
# Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http:#www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
""" IDF Test Applications """
|
2019-12-19 19:19:27 -05:00
|
|
|
import hashlib
|
2018-12-04 19:13:33 -05:00
|
|
|
import json
|
2020-04-02 11:50:28 -04:00
|
|
|
import os
|
2020-07-21 04:59:31 -04:00
|
|
|
import re
|
|
|
|
import subprocess
|
2020-04-02 11:50:28 -04:00
|
|
|
import sys
|
2020-07-21 04:59:31 -04:00
|
|
|
from abc import abstractmethod
|
2019-11-26 22:14:29 -05:00
|
|
|
|
2019-11-26 22:21:33 -05:00
|
|
|
from tiny_test_fw import App
|
2020-07-21 04:59:31 -04:00
|
|
|
from .IDFAssignTest import ExampleGroup, TestAppsGroup, UnitTestGroup, IDFCaseGroup
|
2019-11-26 22:14:29 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
import gitlab_api
|
|
|
|
except ImportError:
|
|
|
|
gitlab_api = None
|
|
|
|
|
|
|
|
|
|
|
|
def parse_flash_settings(path):
|
|
|
|
file_name = os.path.basename(path)
|
|
|
|
if file_name == "flasher_args.json":
|
|
|
|
# CMake version using build metadata file
|
|
|
|
with open(path, "r") as f:
|
|
|
|
args = json.load(f)
|
2019-12-06 04:14:15 -05:00
|
|
|
flash_files = [(offs, binary) for (offs, binary) in args["flash_files"].items() if offs != ""]
|
|
|
|
flash_settings = args["flash_settings"]
|
|
|
|
app_name = os.path.splitext(args["app"]["file"])[0]
|
2019-11-26 22:14:29 -05:00
|
|
|
else:
|
|
|
|
# GNU Make version uses download.config arguments file
|
|
|
|
with open(path, "r") as f:
|
|
|
|
args = f.readlines()[-1].split(" ")
|
|
|
|
flash_files = []
|
|
|
|
flash_settings = {}
|
|
|
|
for idx in range(0, len(args), 2): # process arguments in pairs
|
|
|
|
if args[idx].startswith("--"):
|
|
|
|
# strip the -- from the command line argument
|
|
|
|
flash_settings[args[idx][2:]] = args[idx + 1]
|
|
|
|
else:
|
|
|
|
# offs, filename
|
|
|
|
flash_files.append((args[idx], args[idx + 1]))
|
2019-12-06 04:14:15 -05:00
|
|
|
# we can only guess app name in download.config.
|
|
|
|
for p in flash_files:
|
|
|
|
if not os.path.dirname(p[1]) and "partition" not in p[1]:
|
|
|
|
# app bin usually in the same dir with download.config and it's not partition table
|
|
|
|
app_name = os.path.splitext(p[1])[0]
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
app_name = None
|
|
|
|
return flash_files, flash_settings, app_name
|
2019-11-26 22:14:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
class Artifacts(object):
|
2019-12-06 04:14:15 -05:00
|
|
|
def __init__(self, dest_root_path, artifact_index_file, app_path, config_name, target):
|
2019-11-26 22:14:29 -05:00
|
|
|
assert gitlab_api
|
2019-12-06 04:14:15 -05:00
|
|
|
# at least one of app_path or config_name is not None. otherwise we can't match artifact
|
|
|
|
assert app_path or config_name
|
|
|
|
assert os.path.exists(artifact_index_file)
|
2019-11-26 22:14:29 -05:00
|
|
|
self.gitlab_inst = gitlab_api.Gitlab(os.getenv("CI_PROJECT_ID"))
|
|
|
|
self.dest_root_path = dest_root_path
|
2019-12-06 04:14:15 -05:00
|
|
|
with open(artifact_index_file, "r") as f:
|
|
|
|
artifact_index = json.load(f)
|
|
|
|
self.artifact_info = self._find_artifact(artifact_index, app_path, config_name, target)
|
2019-11-26 22:14:29 -05:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _find_artifact(artifact_index, app_path, config_name, target):
|
|
|
|
for artifact_info in artifact_index:
|
|
|
|
match_result = True
|
|
|
|
if app_path:
|
|
|
|
match_result = app_path in artifact_info["app_dir"]
|
|
|
|
if config_name:
|
|
|
|
match_result = match_result and config_name == artifact_info["config"]
|
|
|
|
if target:
|
|
|
|
match_result = match_result and target == artifact_info["target"]
|
|
|
|
if match_result:
|
|
|
|
ret = artifact_info
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
ret = None
|
|
|
|
return ret
|
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def _get_app_base_path(self):
|
2019-12-06 04:14:15 -05:00
|
|
|
if self.artifact_info:
|
2020-07-21 04:59:31 -04:00
|
|
|
return os.path.join(self.artifact_info["work_dir"], self.artifact_info["build_dir"])
|
|
|
|
else:
|
|
|
|
return None
|
2019-11-26 22:14:29 -05:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def _get_flash_arg_file(self, base_path, job_id):
|
|
|
|
if self.artifact_info["build_system"] == "cmake":
|
|
|
|
flash_arg_file = os.path.join(base_path, "flasher_args.json")
|
|
|
|
else:
|
|
|
|
flash_arg_file = os.path.join(base_path, "download.config")
|
2019-11-26 22:14:29 -05:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
self.gitlab_inst.download_artifact(job_id, [flash_arg_file], self.dest_root_path)
|
|
|
|
return flash_arg_file
|
2019-11-26 22:14:29 -05:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def _download_binary_files(self, base_path, job_id, flash_arg_file):
|
|
|
|
flash_files, flash_settings, app_name = parse_flash_settings(os.path.join(self.dest_root_path,
|
|
|
|
flash_arg_file))
|
|
|
|
artifact_files = [os.path.join(base_path, p[1]) for p in flash_files]
|
|
|
|
artifact_files.append(os.path.join(base_path, app_name + ".elf"))
|
2019-11-26 22:14:29 -05:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
self.gitlab_inst.download_artifact(job_id, artifact_files, self.dest_root_path)
|
2019-11-26 22:14:29 -05:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def _download_sdkconfig_file(self, base_path, job_id):
|
|
|
|
self.gitlab_inst.download_artifact(job_id, [os.path.join(os.path.dirname(base_path), "sdkconfig")],
|
|
|
|
self.dest_root_path)
|
|
|
|
|
|
|
|
def download_artifacts(self):
|
|
|
|
if not self.artifact_info:
|
|
|
|
return None
|
|
|
|
base_path = self._get_app_base_path()
|
|
|
|
job_id = self.artifact_info["ci_job_id"]
|
|
|
|
# 1. download flash args file
|
|
|
|
flash_arg_file = self._get_flash_arg_file(base_path, job_id)
|
|
|
|
|
|
|
|
# 2. download all binary files
|
|
|
|
self._download_binary_files(base_path, job_id, flash_arg_file)
|
|
|
|
|
|
|
|
# 3. download sdkconfig file
|
|
|
|
self._download_sdkconfig_file(base_path, job_id)
|
2019-11-26 22:14:29 -05:00
|
|
|
return base_path
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2019-12-06 04:14:15 -05:00
|
|
|
def download_artifact_files(self, file_names):
|
|
|
|
if self.artifact_info:
|
|
|
|
base_path = os.path.join(self.artifact_info["work_dir"], self.artifact_info["build_dir"])
|
|
|
|
job_id = self.artifact_info["ci_job_id"]
|
|
|
|
|
|
|
|
# download all binary files
|
|
|
|
artifact_files = [os.path.join(base_path, fn) for fn in file_names]
|
|
|
|
self.gitlab_inst.download_artifact(job_id, artifact_files, self.dest_root_path)
|
|
|
|
|
|
|
|
# download sdkconfig file
|
|
|
|
self.gitlab_inst.download_artifact(job_id, [os.path.join(os.path.dirname(base_path), "sdkconfig")],
|
|
|
|
self.dest_root_path)
|
|
|
|
else:
|
|
|
|
base_path = None
|
|
|
|
return base_path
|
|
|
|
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
class UnitTestArtifacts(Artifacts):
|
|
|
|
BUILDS_DIR_RE = re.compile(r'^builds/')
|
|
|
|
|
|
|
|
def _get_app_base_path(self):
|
|
|
|
if self.artifact_info:
|
|
|
|
output_dir = self.BUILDS_DIR_RE.sub('output/', self.artifact_info["build_dir"])
|
|
|
|
return os.path.join(self.artifact_info["app_dir"], output_dir)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def _download_sdkconfig_file(self, base_path, job_id):
|
|
|
|
self.gitlab_inst.download_artifact(job_id, [os.path.join(base_path, "sdkconfig")], self.dest_root_path)
|
|
|
|
|
|
|
|
|
2017-10-09 22:44:55 -04:00
|
|
|
class IDFApp(App.BaseApp):
|
|
|
|
"""
|
|
|
|
Implements common esp-idf application behavior.
|
|
|
|
idf applications should inherent from this class and overwrite method get_binary_path.
|
|
|
|
"""
|
|
|
|
|
|
|
|
IDF_DOWNLOAD_CONFIG_FILE = "download.config"
|
2018-12-04 19:13:33 -05:00
|
|
|
IDF_FLASH_ARGS_FILE = "flasher_args.json"
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def __init__(self, app_path, config_name=None, target=None, case_group=IDFCaseGroup, artifact_cls=Artifacts):
|
2017-10-09 22:44:55 -04:00
|
|
|
super(IDFApp, self).__init__(app_path)
|
2020-07-21 04:59:31 -04:00
|
|
|
self.app_path = app_path
|
2019-10-15 08:15:06 -04:00
|
|
|
self.config_name = config_name
|
|
|
|
self.target = target
|
2017-10-09 22:44:55 -04:00
|
|
|
self.idf_path = self.get_sdk_path()
|
2020-07-21 04:59:31 -04:00
|
|
|
self.case_group = case_group
|
|
|
|
self.artifact_cls = artifact_cls
|
|
|
|
self.binary_path = self.get_binary_path()
|
|
|
|
self.elf_file = self._get_elf_file_path()
|
2019-12-19 19:19:27 -05:00
|
|
|
self._elf_file_sha256 = None
|
2017-10-09 22:44:55 -04:00
|
|
|
assert os.path.exists(self.binary_path)
|
2019-12-06 04:14:15 -05:00
|
|
|
if self.IDF_DOWNLOAD_CONFIG_FILE not in os.listdir(self.binary_path):
|
|
|
|
if self.IDF_FLASH_ARGS_FILE not in os.listdir(self.binary_path):
|
|
|
|
msg = ("Neither {} nor {} exists. "
|
|
|
|
"Try to run 'make print_flash_cmd | tail -n 1 > {}/{}' "
|
|
|
|
"or 'idf.py build' "
|
|
|
|
"for resolving the issue."
|
|
|
|
"").format(self.IDF_DOWNLOAD_CONFIG_FILE, self.IDF_FLASH_ARGS_FILE,
|
|
|
|
self.binary_path, self.IDF_DOWNLOAD_CONFIG_FILE)
|
|
|
|
raise AssertionError(msg)
|
|
|
|
|
|
|
|
self.flash_files, self.flash_settings = self._parse_flash_download_config()
|
|
|
|
self.partition_table = self._parse_partition_table()
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def __str__(self):
|
|
|
|
parts = ['app<{}>'.format(self.app_path)]
|
|
|
|
if self.config_name:
|
|
|
|
parts.extend('config<{}>'.format(self.config_name))
|
|
|
|
if self.target:
|
|
|
|
parts.extend('target<{}>'.format(self.target))
|
|
|
|
return ' '.join(parts)
|
|
|
|
|
2017-10-09 22:44:55 -04:00
|
|
|
@classmethod
|
2020-07-21 04:59:31 -04:00
|
|
|
def get_sdk_path(cls): # type: () -> str
|
2017-10-09 22:44:55 -04:00
|
|
|
idf_path = os.getenv("IDF_PATH")
|
|
|
|
assert idf_path
|
|
|
|
assert os.path.exists(idf_path)
|
|
|
|
return idf_path
|
|
|
|
|
2018-12-07 09:15:34 -05:00
|
|
|
def _get_sdkconfig_paths(self):
|
|
|
|
"""
|
|
|
|
returns list of possible paths where sdkconfig could be found
|
|
|
|
|
|
|
|
Note: could be overwritten by a derived class to provide other locations or order
|
|
|
|
"""
|
|
|
|
return [os.path.join(self.binary_path, "sdkconfig"), os.path.join(self.binary_path, "..", "sdkconfig")]
|
|
|
|
|
|
|
|
def get_sdkconfig(self):
|
|
|
|
"""
|
2020-07-21 04:59:31 -04:00
|
|
|
reads sdkconfig and returns a dictionary with all configured variables
|
2018-12-07 09:15:34 -05:00
|
|
|
|
|
|
|
:raise: AssertionError: if sdkconfig file does not exist in defined paths
|
|
|
|
"""
|
|
|
|
d = {}
|
|
|
|
sdkconfig_file = None
|
|
|
|
for i in self._get_sdkconfig_paths():
|
|
|
|
if os.path.exists(i):
|
|
|
|
sdkconfig_file = i
|
|
|
|
break
|
|
|
|
assert sdkconfig_file is not None
|
|
|
|
with open(sdkconfig_file) as f:
|
|
|
|
for line in f:
|
|
|
|
configs = line.split('=')
|
|
|
|
if len(configs) == 2:
|
2019-02-26 10:27:39 -05:00
|
|
|
d[configs[0]] = configs[1].rstrip()
|
2018-12-07 09:15:34 -05:00
|
|
|
return d
|
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
@abstractmethod
|
|
|
|
def _try_get_binary_from_local_fs(self):
|
|
|
|
pass
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def get_binary_path(self):
|
|
|
|
path = self._try_get_binary_from_local_fs()
|
|
|
|
if path:
|
|
|
|
return path
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
artifacts = self.artifact_cls(self.idf_path,
|
|
|
|
self.case_group.get_artifact_index_file(),
|
|
|
|
self.app_path, self.config_name, self.target)
|
|
|
|
if isinstance(self, LoadableElfTestApp):
|
|
|
|
assert self.app_files
|
|
|
|
path = artifacts.download_artifact_files(self.app_files)
|
|
|
|
else:
|
|
|
|
path = artifacts.download_artifacts()
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
if path:
|
|
|
|
return os.path.join(self.idf_path, path)
|
|
|
|
else:
|
|
|
|
raise OSError("Failed to get binary for {}".format(self))
|
|
|
|
|
|
|
|
def _get_elf_file_path(self):
|
2019-03-18 00:16:24 -04:00
|
|
|
ret = ""
|
2020-07-21 04:59:31 -04:00
|
|
|
file_names = os.listdir(self.binary_path)
|
2019-03-18 00:16:24 -04:00
|
|
|
for fn in file_names:
|
|
|
|
if os.path.splitext(fn)[1] == ".elf":
|
2020-07-21 04:59:31 -04:00
|
|
|
ret = os.path.join(self.binary_path, fn)
|
2019-03-18 00:16:24 -04:00
|
|
|
return ret
|
|
|
|
|
2018-12-04 19:13:33 -05:00
|
|
|
def _parse_flash_download_config(self):
|
2017-10-09 22:44:55 -04:00
|
|
|
"""
|
2018-12-04 19:13:33 -05:00
|
|
|
Parse flash download config from build metadata files
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2018-12-04 19:13:33 -05:00
|
|
|
Sets self.flash_files, self.flash_settings
|
|
|
|
|
|
|
|
(Called from constructor)
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2018-12-04 19:13:33 -05:00
|
|
|
Returns (flash_files, flash_settings)
|
2017-10-09 22:44:55 -04:00
|
|
|
"""
|
2018-09-12 07:30:36 -04:00
|
|
|
|
|
|
|
if self.IDF_FLASH_ARGS_FILE in os.listdir(self.binary_path):
|
2018-12-04 19:13:33 -05:00
|
|
|
# CMake version using build metadata file
|
2019-11-26 22:14:29 -05:00
|
|
|
path = os.path.join(self.binary_path, self.IDF_FLASH_ARGS_FILE)
|
2018-09-12 07:30:36 -04:00
|
|
|
else:
|
2018-12-04 19:13:33 -05:00
|
|
|
# GNU Make version uses download.config arguments file
|
2019-11-26 22:14:29 -05:00
|
|
|
path = os.path.join(self.binary_path, self.IDF_DOWNLOAD_CONFIG_FILE)
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2019-12-06 04:14:15 -05:00
|
|
|
flash_files, flash_settings, app_name = parse_flash_settings(path)
|
2019-08-23 00:37:55 -04:00
|
|
|
# The build metadata file does not currently have details, which files should be encrypted and which not.
|
|
|
|
# Assume that all files should be encrypted if flash encryption is enabled in development mode.
|
|
|
|
sdkconfig_dict = self.get_sdkconfig()
|
|
|
|
flash_settings["encrypt"] = "CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT" in sdkconfig_dict
|
|
|
|
|
2018-12-04 19:13:33 -05:00
|
|
|
# make file offsets into integers, make paths absolute
|
2019-12-30 00:24:43 -05:00
|
|
|
flash_files = [(int(offs, 0), os.path.join(self.binary_path, file_path.strip())) for (offs, file_path) in flash_files]
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2019-11-26 22:14:29 -05:00
|
|
|
return flash_files, flash_settings
|
2018-12-04 19:13:33 -05:00
|
|
|
|
|
|
|
def _parse_partition_table(self):
|
|
|
|
"""
|
|
|
|
Parse partition table contents based on app binaries
|
|
|
|
|
|
|
|
Returns partition_table data
|
|
|
|
|
|
|
|
(Called from constructor)
|
|
|
|
"""
|
|
|
|
partition_tool = os.path.join(self.idf_path,
|
|
|
|
"components",
|
|
|
|
"partition_table",
|
|
|
|
"gen_esp32part.py")
|
|
|
|
assert os.path.exists(partition_tool)
|
|
|
|
|
2020-04-02 11:50:28 -04:00
|
|
|
errors = []
|
|
|
|
# self.flash_files is sorted based on offset in order to have a consistent result with different versions of
|
|
|
|
# Python
|
|
|
|
for (_, path) in sorted(self.flash_files, key=lambda elem: elem[0]):
|
|
|
|
if 'partition' in os.path.split(path)[1]:
|
2018-12-04 19:13:33 -05:00
|
|
|
partition_file = os.path.join(self.binary_path, path)
|
2020-04-02 11:50:28 -04:00
|
|
|
|
|
|
|
process = subprocess.Popen([sys.executable, partition_tool, partition_file],
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
(raw_data, raw_error) = process.communicate()
|
|
|
|
if isinstance(raw_error, bytes):
|
|
|
|
raw_error = raw_error.decode()
|
|
|
|
if 'Traceback' in raw_error:
|
2020-07-21 04:59:31 -04:00
|
|
|
# Some exception occurred. It is possible that we've tried the wrong binary file.
|
2020-04-02 11:50:28 -04:00
|
|
|
errors.append((path, raw_error))
|
|
|
|
continue
|
|
|
|
|
|
|
|
if isinstance(raw_data, bytes):
|
|
|
|
raw_data = raw_data.decode()
|
2017-10-09 22:44:55 -04:00
|
|
|
break
|
|
|
|
else:
|
2020-04-02 11:50:28 -04:00
|
|
|
traceback_msg = os.linesep.join(['{} {}:{}{}'.format(partition_tool,
|
|
|
|
p,
|
|
|
|
os.linesep,
|
|
|
|
msg) for p, msg in errors])
|
|
|
|
raise ValueError("No partition table found for IDF binary path: {}{}{}".format(self.binary_path,
|
|
|
|
os.linesep,
|
|
|
|
traceback_msg))
|
2017-10-09 22:44:55 -04:00
|
|
|
|
|
|
|
partition_table = dict()
|
|
|
|
for line in raw_data.splitlines():
|
|
|
|
if line[0] != "#":
|
|
|
|
try:
|
|
|
|
_name, _type, _subtype, _offset, _size, _flags = line.split(",")
|
|
|
|
if _size[-1] == "K":
|
|
|
|
_size = int(_size[:-1]) * 1024
|
|
|
|
elif _size[-1] == "M":
|
|
|
|
_size = int(_size[:-1]) * 1024 * 1024
|
|
|
|
else:
|
|
|
|
_size = int(_size)
|
2019-12-19 21:00:12 -05:00
|
|
|
_offset = int(_offset, 0)
|
2017-10-09 22:44:55 -04:00
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
partition_table[_name] = {
|
|
|
|
"type": _type,
|
|
|
|
"subtype": _subtype,
|
|
|
|
"offset": _offset,
|
|
|
|
"size": _size,
|
|
|
|
"flags": _flags
|
|
|
|
}
|
2018-12-04 19:13:33 -05:00
|
|
|
|
|
|
|
return partition_table
|
2017-10-09 22:44:55 -04:00
|
|
|
|
2019-12-19 19:19:27 -05:00
|
|
|
def get_elf_sha256(self):
|
|
|
|
if self._elf_file_sha256:
|
|
|
|
return self._elf_file_sha256
|
|
|
|
|
|
|
|
sha256 = hashlib.sha256()
|
|
|
|
with open(self.elf_file, 'rb') as f:
|
|
|
|
sha256.update(f.read())
|
|
|
|
self._elf_file_sha256 = sha256.hexdigest()
|
|
|
|
return self._elf_file_sha256
|
|
|
|
|
2017-10-09 22:44:55 -04:00
|
|
|
|
|
|
|
class Example(IDFApp):
|
2020-07-21 04:59:31 -04:00
|
|
|
def __init__(self, app_path, config_name='default', target='esp32', case_group=ExampleGroup, artifacts_cls=Artifacts):
|
|
|
|
if not config_name:
|
|
|
|
config_name = 'default'
|
|
|
|
if not target:
|
|
|
|
target = 'esp32'
|
|
|
|
super(Example, self).__init__(app_path, config_name, target, case_group, artifacts_cls)
|
|
|
|
|
2018-12-07 09:15:34 -05:00
|
|
|
def _get_sdkconfig_paths(self):
|
|
|
|
"""
|
|
|
|
overrides the parent method to provide exact path of sdkconfig for example tests
|
|
|
|
"""
|
|
|
|
return [os.path.join(self.binary_path, "..", "sdkconfig")]
|
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def _try_get_binary_from_local_fs(self):
|
2017-10-09 22:44:55 -04:00
|
|
|
# build folder of example path
|
2020-07-21 04:59:31 -04:00
|
|
|
path = os.path.join(self.idf_path, self.app_path, "build")
|
2019-10-15 08:15:06 -04:00
|
|
|
if os.path.exists(path):
|
|
|
|
return path
|
|
|
|
|
|
|
|
# Search for CI build folders.
|
|
|
|
# Path format: $IDF_PATH/build_examples/app_path_with_underscores/config/target
|
2020-07-21 04:59:31 -04:00
|
|
|
# (see tools/ci/build_examples.sh)
|
2019-10-15 08:15:06 -04:00
|
|
|
# For example: $IDF_PATH/build_examples/examples_get-started_blink/default/esp32
|
2020-07-21 04:59:31 -04:00
|
|
|
app_path_underscored = self.app_path.replace(os.path.sep, "_")
|
|
|
|
example_path = os.path.join(self.idf_path, self.case_group.LOCAL_BUILD_DIR)
|
2019-10-15 08:15:06 -04:00
|
|
|
for dirpath in os.listdir(example_path):
|
|
|
|
if os.path.basename(dirpath) == app_path_underscored:
|
2020-07-21 04:59:31 -04:00
|
|
|
path = os.path.join(example_path, dirpath, self.config_name, self.target, "build")
|
2019-11-26 22:14:29 -05:00
|
|
|
if os.path.exists(path):
|
|
|
|
return path
|
|
|
|
else:
|
2019-12-06 04:14:15 -05:00
|
|
|
return None
|
2019-11-26 22:14:29 -05:00
|
|
|
|
2019-12-06 04:14:15 -05:00
|
|
|
|
2017-10-09 22:44:55 -04:00
|
|
|
class UT(IDFApp):
|
2020-07-21 04:59:31 -04:00
|
|
|
def __init__(self, app_path, config_name='default', target='esp32', case_group=UnitTestGroup, artifacts_cls=UnitTestArtifacts):
|
2019-10-15 08:15:06 -04:00
|
|
|
if not config_name:
|
2020-07-21 04:59:31 -04:00
|
|
|
config_name = 'default'
|
|
|
|
if not target:
|
|
|
|
target = 'esp32'
|
|
|
|
super(UT, self).__init__(app_path, config_name, target, case_group, artifacts_cls)
|
2018-01-31 05:59:10 -05:00
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
def _try_get_binary_from_local_fs(self):
|
|
|
|
path = os.path.join(self.idf_path, self.app_path, "build")
|
|
|
|
if os.path.exists(path):
|
|
|
|
return path
|
2019-10-15 08:15:06 -04:00
|
|
|
|
|
|
|
# first try to get from build folder of unit-test-app
|
|
|
|
path = os.path.join(self.idf_path, "tools", "unit-test-app", "build")
|
|
|
|
if os.path.exists(path):
|
|
|
|
# found, use bin in build path
|
|
|
|
return path
|
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
# ``build_unit_test.sh`` will copy binary to output folder
|
|
|
|
path = os.path.join(self.idf_path, "tools", "unit-test-app", "output", self.target, self.config_name)
|
2019-10-15 08:15:06 -04:00
|
|
|
if os.path.exists(path):
|
|
|
|
return path
|
|
|
|
|
2020-07-21 04:59:31 -04:00
|
|
|
return None
|
2017-10-09 22:44:55 -04:00
|
|
|
|
|
|
|
|
2020-01-27 06:12:49 -05:00
|
|
|
class TestApp(Example):
|
2020-07-21 04:59:31 -04:00
|
|
|
def __init__(self, app_path, config_name='default', target='esp32', case_group=TestAppsGroup, artifacts_cls=Artifacts):
|
|
|
|
super(TestApp, self).__init__(app_path, config_name, target, case_group, artifacts_cls)
|
2019-10-20 14:55:11 -04:00
|
|
|
|
|
|
|
|
2020-04-16 08:42:33 -04:00
|
|
|
class LoadableElfTestApp(TestApp):
|
2020-07-21 04:59:31 -04:00
|
|
|
def __init__(self, app_path, app_files, config_name='default', target='esp32', case_group=TestAppsGroup, artifacts_cls=Artifacts):
|
2020-04-16 08:42:33 -04:00
|
|
|
# add arg `app_files` for loadable elf test_app.
|
|
|
|
# Such examples only build elf files, so it doesn't generate flasher_args.json.
|
|
|
|
# So we can't get app files from config file. Test case should pass it to application.
|
|
|
|
super(IDFApp, self).__init__(app_path)
|
2020-07-21 04:59:31 -04:00
|
|
|
self.app_path = app_path
|
2020-04-16 08:42:33 -04:00
|
|
|
self.app_files = app_files
|
2020-07-21 04:59:31 -04:00
|
|
|
self.config_name = config_name or 'default'
|
|
|
|
self.target = target or 'esp32'
|
2020-04-16 08:42:33 -04:00
|
|
|
self.idf_path = self.get_sdk_path()
|
2020-07-21 04:59:31 -04:00
|
|
|
self.case_group = case_group
|
|
|
|
self.artifact_cls = artifacts_cls
|
|
|
|
self.binary_path = self.get_binary_path()
|
|
|
|
self.elf_file = self._get_elf_file_path()
|
2020-04-16 08:42:33 -04:00
|
|
|
assert os.path.exists(self.binary_path)
|
|
|
|
|
|
|
|
|
2017-10-09 22:44:55 -04:00
|
|
|
class SSC(IDFApp):
|
2020-07-21 04:59:31 -04:00
|
|
|
def get_binary_path(self):
|
2017-10-09 22:44:55 -04:00
|
|
|
# TODO: to implement SSC get binary path
|
2020-07-21 04:59:31 -04:00
|
|
|
return self.app_path
|
2017-10-09 22:44:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
class AT(IDFApp):
|
2020-07-21 04:59:31 -04:00
|
|
|
def get_binary_path(self):
|
2017-10-09 22:44:55 -04:00
|
|
|
# TODO: to implement AT get binary path
|
2020-07-21 04:59:31 -04:00
|
|
|
return self.app_path
|