2016-08-03 22:18:51 +03:00
|
|
|
# Copyright 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
|
|
|
|
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
|
|
|
|
from shutil import rmtree
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from platformio.util import exec_command
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if "pioproject_dir" not in metafunc.fixturenames:
|
|
|
|
return
|
|
|
|
example_dirs = normpath(join(dirname(__file__), "..", "examples"))
|
|
|
|
project_dirs = []
|
|
|
|
for root, _, files in walk(example_dirs):
|
2015-12-14 19:50:50 +02:00
|
|
|
if "platformio.ini" not in files or ".skiptest" in files:
|
2015-02-13 18:35:09 +02:00
|
|
|
continue
|
|
|
|
project_dirs.append(root)
|
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)
|
|
|
|
|
|
|
|
|
2015-02-21 15:15:00 +02:00
|
|
|
@pytest.mark.examples
|
2015-02-13 18:35:09 +02:00
|
|
|
def test_run(platformio_setup, pioproject_dir):
|
|
|
|
if isdir(join(pioproject_dir, ".pioenvs")):
|
|
|
|
rmtree(join(pioproject_dir, ".pioenvs"))
|
|
|
|
|
|
|
|
result = exec_command(
|
2015-05-26 16:41:45 +03:00
|
|
|
["platformio", "--force", "run", "--project-dir", pioproject_dir]
|
2015-02-13 18:35:09 +02:00
|
|
|
)
|
2015-02-19 22:02:50 +02:00
|
|
|
if result['returncode'] != 0:
|
|
|
|
pytest.fail(result)
|
2015-02-13 18:35:09 +02:00
|
|
|
|
|
|
|
# check .elf file
|
|
|
|
pioenvs_dir = join(pioproject_dir, ".pioenvs")
|
|
|
|
for item in listdir(pioenvs_dir):
|
2015-06-04 23:17:18 +03:00
|
|
|
if not isdir(item):
|
|
|
|
continue
|
2015-02-13 18:35:09 +02:00
|
|
|
assert isfile(join(pioenvs_dir, item, "firmware.elf"))
|
2015-04-03 17:42:00 +03:00
|
|
|
# check .hex or .bin files
|
|
|
|
firmwares = []
|
|
|
|
for ext in ("bin", "hex"):
|
|
|
|
firmwares += glob(join(pioenvs_dir, item, "firmware*.%s" % ext))
|
|
|
|
if not firmwares:
|
|
|
|
pytest.fail("Missed firmware file")
|
|
|
|
for firmware in firmwares:
|
|
|
|
assert getsize(firmware) > 0
|