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
|
|
|
|
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
|
|
|
from os import listdir, walk
|
|
|
|
from os.path import dirname, getsize, isdir, isfile, join, normpath
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2016-08-05 18:43:20 +03:00
|
|
|
from platformio import util
|
2018-02-03 22:59:41 +02:00
|
|
|
from platformio.managers.platform import PlatformFactory, PlatformManager
|
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
|
|
|
|
examples_dirs.append(normpath(join(dirname(__file__), "..", "examples")))
|
|
|
|
|
|
|
|
# dev/platforms
|
|
|
|
for manifest in PlatformManager().get_installed():
|
|
|
|
p = PlatformFactory.newPlatform(manifest['__pkg_dir'])
|
|
|
|
if not p.is_embedded():
|
2015-02-13 18:35:09 +02:00
|
|
|
continue
|
2018-08-20 20:54:07 +03:00
|
|
|
# issue with "version `CXXABI_1.3.9' not found (required by sdcc)"
|
|
|
|
if "linux" in util.get_systype() and p.name == "intel_mcs51":
|
|
|
|
continue
|
2018-02-03 22:59:41 +02:00
|
|
|
examples_dir = join(p.get_dir(), "examples")
|
|
|
|
assert isdir(examples_dir)
|
|
|
|
examples_dirs.append(examples_dir)
|
|
|
|
|
|
|
|
project_dirs = []
|
|
|
|
for examples_dir in examples_dirs:
|
2018-07-27 15:45:51 +03:00
|
|
|
platform_examples = []
|
2018-02-03 22:59:41 +02:00
|
|
|
for root, _, files in walk(examples_dir):
|
|
|
|
if "platformio.ini" not in files or ".skiptest" in files:
|
|
|
|
continue
|
2018-07-27 15:45:51 +03:00
|
|
|
platform_examples.append(root)
|
|
|
|
|
|
|
|
# test random 3 examples
|
|
|
|
random.shuffle(platform_examples)
|
|
|
|
project_dirs.extend(platform_examples[:3])
|
2015-02-21 15:15:00 +02:00
|
|
|
project_dirs.sort()
|
2015-02-13 18:35:09 +02:00
|
|
|
metafunc.parametrize("pioproject_dir", project_dirs)
|
|
|
|
|
|
|
|
|
2016-08-31 12:49:10 +03:00
|
|
|
@pytest.mark.examples
|
|
|
|
def test_run(pioproject_dir):
|
2018-01-03 15:47:02 +02:00
|
|
|
with util.cd(pioproject_dir):
|
|
|
|
build_dir = util.get_projectbuild_dir()
|
|
|
|
if isdir(build_dir):
|
|
|
|
util.rmtree_(build_dir)
|
|
|
|
|
2018-02-03 22:59:41 +02:00
|
|
|
env_names = []
|
|
|
|
for section in util.load_project_config().sections():
|
|
|
|
if section.startswith("env:"):
|
|
|
|
env_names.append(section[4:])
|
|
|
|
|
|
|
|
result = util.exec_command(
|
|
|
|
["platformio", "run", "-e",
|
|
|
|
random.choice(env_names)])
|
2018-01-03 15:47:02 +02:00
|
|
|
if result['returncode'] != 0:
|
|
|
|
pytest.fail(result)
|
|
|
|
|
|
|
|
assert isdir(build_dir)
|
|
|
|
|
|
|
|
# check .elf file
|
|
|
|
for item in listdir(build_dir):
|
|
|
|
if not isdir(item):
|
|
|
|
continue
|
|
|
|
assert isfile(join(build_dir, item, "firmware.elf"))
|
|
|
|
# check .hex or .bin files
|
|
|
|
firmwares = []
|
|
|
|
for ext in ("bin", "hex"):
|
|
|
|
firmwares += glob(join(build_dir, item, "firmware*.%s" % ext))
|
|
|
|
if not firmwares:
|
|
|
|
pytest.fail("Missed firmware file")
|
|
|
|
for firmware in firmwares:
|
|
|
|
assert getsize(firmware) > 0
|