2017-06-05 16:02:39 +03:00
|
|
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
2015-11-18 17:16:17 +02:00
|
|
|
#
|
|
|
|
# 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.
|
2015-02-13 18:35:09 +02:00
|
|
|
|
2020-10-29 23:42:15 +02:00
|
|
|
import os
|
2018-02-03 22:59:41 +02:00
|
|
|
import random
|
2015-04-03 17:42:00 +03:00
|
|
|
from glob import glob
|
2015-02-13 18:35:09 +02:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2020-08-22 17:48:49 +03:00
|
|
|
from platformio import fs, proc
|
2020-08-17 12:56:57 +03:00
|
|
|
from platformio.package.manager.platform import PlatformPackageManager
|
|
|
|
from platformio.platform.factory import PlatformFactory
|
2019-05-27 22:25:22 +03:00
|
|
|
from platformio.project.config import ProjectConfig
|
2023-03-27 18:59:06 -06:00
|
|
|
from platformio.project.exception import ProjectError
|
2015-02-13 18:35:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if "pioproject_dir" not in metafunc.fixturenames:
|
|
|
|
return
|
2018-02-03 22:59:41 +02:00
|
|
|
examples_dirs = []
|
|
|
|
|
|
|
|
# repo examples
|
2020-10-29 23:42:15 +02:00
|
|
|
examples_dirs.append(
|
|
|
|
os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "examples"))
|
|
|
|
)
|
2018-02-03 22:59:41 +02:00
|
|
|
|
|
|
|
# dev/platforms
|
2020-08-17 12:56:57 +03:00
|
|
|
for pkg in PlatformPackageManager().get_installed():
|
|
|
|
p = PlatformFactory.new(pkg)
|
2020-10-29 23:42:15 +02:00
|
|
|
examples_dir = os.path.join(p.get_dir(), "examples")
|
|
|
|
if os.path.isdir(examples_dir):
|
|
|
|
examples_dirs.append(examples_dir)
|
2018-02-03 22:59:41 +02:00
|
|
|
|
|
|
|
project_dirs = []
|
|
|
|
for examples_dir in examples_dirs:
|
2019-06-15 21:09:52 +03:00
|
|
|
candidates = {}
|
2020-10-29 23:42:15 +02:00
|
|
|
for root, _, files in os.walk(examples_dir):
|
2018-02-03 22:59:41 +02:00
|
|
|
if "platformio.ini" not in files or ".skiptest" in files:
|
|
|
|
continue
|
2023-04-27 15:12:01 +03:00
|
|
|
if "mbed-legacy-examples" in root:
|
|
|
|
continue
|
2020-10-29 23:42:15 +02:00
|
|
|
group = os.path.basename(root)
|
2019-06-15 21:09:52 +03:00
|
|
|
if "-" in group:
|
|
|
|
group = group.split("-", 1)[0]
|
|
|
|
if group not in candidates:
|
|
|
|
candidates[group] = []
|
|
|
|
candidates[group].append(root)
|
|
|
|
|
2019-09-23 23:13:48 +03:00
|
|
|
project_dirs.extend(
|
|
|
|
[random.choice(examples) for examples in candidates.values() if examples]
|
|
|
|
)
|
2019-05-27 18:17:57 +03:00
|
|
|
|
|
|
|
metafunc.parametrize("pioproject_dir", sorted(project_dirs))
|
2015-02-13 18:35:09 +02:00
|
|
|
|
|
|
|
|
2016-08-31 12:49:10 +03:00
|
|
|
def test_run(pioproject_dir):
|
2020-08-22 17:48:49 +03:00
|
|
|
with fs.cd(pioproject_dir):
|
2019-09-27 14:13:53 +03:00
|
|
|
config = ProjectConfig()
|
2023-03-27 18:59:06 -06:00
|
|
|
|
|
|
|
# temporary fix for unreleased dev-platforms with broken env name
|
|
|
|
try:
|
|
|
|
config.validate()
|
|
|
|
except ProjectError as exc:
|
|
|
|
pytest.skip(str(exc))
|
|
|
|
|
2021-10-24 18:19:40 +03:00
|
|
|
build_dir = config.get("platformio", "build_dir")
|
2020-10-29 23:42:15 +02:00
|
|
|
if os.path.isdir(build_dir):
|
2020-08-22 17:48:49 +03:00
|
|
|
fs.rmtree(build_dir)
|
2018-01-03 15:47:02 +02:00
|
|
|
|
2019-09-27 14:13:53 +03:00
|
|
|
env_names = config.envs()
|
2020-08-22 17:48:49 +03:00
|
|
|
result = proc.exec_command(
|
2019-09-23 23:13:48 +03:00
|
|
|
["platformio", "run", "-e", random.choice(env_names)]
|
|
|
|
)
|
|
|
|
if result["returncode"] != 0:
|
2018-12-26 20:54:29 +02:00
|
|
|
pytest.fail(str(result))
|
2018-01-03 15:47:02 +02:00
|
|
|
|
2020-10-29 23:42:15 +02:00
|
|
|
assert os.path.isdir(build_dir)
|
2018-01-03 15:47:02 +02:00
|
|
|
|
|
|
|
# check .elf file
|
2020-10-29 23:42:15 +02:00
|
|
|
for item in os.listdir(build_dir):
|
|
|
|
if not os.path.isdir(item):
|
2018-01-03 15:47:02 +02:00
|
|
|
continue
|
2020-10-29 23:42:15 +02:00
|
|
|
assert os.path.isfile(os.path.join(build_dir, item, "firmware.elf"))
|
2018-01-03 15:47:02 +02:00
|
|
|
# check .hex or .bin files
|
|
|
|
firmwares = []
|
|
|
|
for ext in ("bin", "hex"):
|
2020-10-29 23:42:15 +02:00
|
|
|
firmwares += glob(os.path.join(build_dir, item, "firmware*.%s" % ext))
|
2018-01-03 15:47:02 +02:00
|
|
|
if not firmwares:
|
|
|
|
pytest.fail("Missed firmware file")
|
|
|
|
for firmware in firmwares:
|
2020-10-29 23:42:15 +02:00
|
|
|
assert os.path.getsize(firmware) > 0
|