scripts: tests: --package-artifacts fix, blackbox tests
Requirements added for bz2. Blackbox test for --package-artifacts added. package.py no longer includes twister-out no matter the outdir. Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
This commit is contained in:
parent
4300f042bb
commit
36c12482c6
3 changed files with 57 additions and 1 deletions
|
@ -15,7 +15,7 @@ class Artifacts:
|
||||||
def make_tarfile(self, output_filename, source_dirs):
|
def make_tarfile(self, output_filename, source_dirs):
|
||||||
root = os.path.basename(self.options.outdir)
|
root = os.path.basename(self.options.outdir)
|
||||||
with tarfile.open(output_filename, "w:bz2") as tar:
|
with tarfile.open(output_filename, "w:bz2") as tar:
|
||||||
tar.add("twister-out", recursive=False)
|
tar.add(self.options.outdir, recursive=False)
|
||||||
for d in source_dirs:
|
for d in source_dirs:
|
||||||
f = os.path.relpath(d, self.options.outdir)
|
f = os.path.relpath(d, self.options.outdir)
|
||||||
tar.add(d, arcname=os.path.join(root, f))
|
tar.add(d, arcname=os.path.join(root, f))
|
||||||
|
|
|
@ -14,3 +14,6 @@ cbor>=1.0.0
|
||||||
|
|
||||||
# use for twister
|
# use for twister
|
||||||
psutil
|
psutil
|
||||||
|
|
||||||
|
# Artifacts package creation
|
||||||
|
bz
|
||||||
|
|
|
@ -13,6 +13,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
|
import tarfile
|
||||||
|
|
||||||
from conftest import ZEPHYR_BASE, TEST_DATA, sample_filename_mock, testsuite_filename_mock
|
from conftest import ZEPHYR_BASE, TEST_DATA, sample_filename_mock, testsuite_filename_mock
|
||||||
from twisterlib.testplan import TestPlan
|
from twisterlib.testplan import TestPlan
|
||||||
|
@ -199,3 +200,55 @@ class TestOutfile:
|
||||||
# However, the cost of testing that this leaves less seems to outweigh the benefits.
|
# However, the cost of testing that this leaves less seems to outweigh the benefits.
|
||||||
# So we'll only check for the most important artifact.
|
# So we'll only check for the most important artifact.
|
||||||
assert 'zephyr.elf' in zephyr_artifact_list
|
assert 'zephyr.elf' in zephyr_artifact_list
|
||||||
|
|
||||||
|
def test_package_artifacts(self, out_path):
|
||||||
|
test_platforms = ['qemu_x86']
|
||||||
|
path = os.path.join(TEST_DATA, 'samples', 'hello_world')
|
||||||
|
package_name = 'PACKAGE'
|
||||||
|
package_path = os.path.join(out_path, package_name)
|
||||||
|
args = ['-i', '--outdir', out_path, '-T', path] + \
|
||||||
|
['--package-artifacts', package_path] + \
|
||||||
|
[val for pair in zip(
|
||||||
|
['-p'] * len(test_platforms), test_platforms
|
||||||
|
) for val in pair]
|
||||||
|
|
||||||
|
with mock.patch.object(sys, 'argv', [sys.argv[0]] + args), \
|
||||||
|
pytest.raises(SystemExit) as sys_exit:
|
||||||
|
self.loader.exec_module(self.twister_module)
|
||||||
|
|
||||||
|
assert str(sys_exit.value) == '0'
|
||||||
|
|
||||||
|
# Check whether we have something as basic as zephyr.elf file
|
||||||
|
with tarfile.open(package_path, "r") as tar:
|
||||||
|
assert any([path.endswith('zephyr.elf') for path in tar.getnames()])
|
||||||
|
|
||||||
|
# Delete everything but for the package
|
||||||
|
for clean_up in os.listdir(os.path.join(out_path)):
|
||||||
|
if not clean_up.endswith(package_name):
|
||||||
|
clean_up_path = os.path.join(out_path, clean_up)
|
||||||
|
if os.path.isfile(clean_up_path):
|
||||||
|
os.remove(clean_up_path)
|
||||||
|
else:
|
||||||
|
shutil.rmtree(os.path.join(out_path, clean_up))
|
||||||
|
|
||||||
|
# Unpack the package
|
||||||
|
with tarfile.open(package_path, "r") as tar:
|
||||||
|
tar.extractall(path=out_path)
|
||||||
|
|
||||||
|
# Why does package.py put files inside the out_path folder?
|
||||||
|
# It forces us to move files up one directory after extraction.
|
||||||
|
file_names = os.listdir(os.path.join(out_path, os.path.basename(out_path)))
|
||||||
|
for file_name in file_names:
|
||||||
|
shutil.move(os.path.join(out_path, os.path.basename(out_path), file_name), out_path)
|
||||||
|
|
||||||
|
args = ['-i', '--outdir', out_path, '-T', path] + \
|
||||||
|
['--test-only'] + \
|
||||||
|
[val for pair in zip(
|
||||||
|
['-p'] * len(test_platforms), test_platforms
|
||||||
|
) for val in pair]
|
||||||
|
|
||||||
|
with mock.patch.object(sys, 'argv', [sys.argv[0]] + args), \
|
||||||
|
pytest.raises(SystemExit) as sys_exit:
|
||||||
|
self.loader.exec_module(self.twister_module)
|
||||||
|
|
||||||
|
assert str(sys_exit.value) == '0'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue