summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.com>2017-09-05 04:22:13 -0500
committerTristan Maat <tristan.maat@codethink.co.uk>2017-09-28 14:46:33 +0100
commit206fc51a6cf57697f03e27508819eafaaee58317 (patch)
treee019ce1bf25ceb1ca90964450908ae2965e75eef /tests
parent37ece921d0cd4a69174ae8591127113973f53d46 (diff)
downloadbuildstream-206fc51a6cf57697f03e27508819eafaaee58317.tar.gz
Fix tests for other platforms
Diffstat (limited to 'tests')
-rw-r--r--tests/cachekey/cachekey.py4
-rw-r--r--tests/context/context.py4
-rw-r--r--tests/frontend/buildcheckout.py1
-rw-r--r--tests/frontend/pull.py3
-rw-r--r--tests/frontend/push.py3
-rw-r--r--tests/frontend/track.py1
-rw-r--r--tests/pipeline/load.py8
-rw-r--r--tests/plugins/pipeline.py8
-rw-r--r--tests/project/plugins.py3
-rw-r--r--tests/testutils/artifactshare.py1
-rw-r--r--tests/testutils/repo/__init__.py2
-rw-r--r--tests/testutils/repo/ostree.py6
-rw-r--r--tests/testutils/runcli.py13
-rw-r--r--tests/testutils/site.py19
-rw-r--r--tests/variables/variables.py4
15 files changed, 77 insertions, 3 deletions
diff --git a/tests/cachekey/cachekey.py b/tests/cachekey/cachekey.py
index b1a2ff282..444da90e8 100644
--- a/tests/cachekey/cachekey.py
+++ b/tests/cachekey/cachekey.py
@@ -36,7 +36,7 @@
# the result.
#
from tests.testutils.runcli import cli
-from tests.testutils.site import HAVE_BZR, HAVE_GIT
+from tests.testutils.site import HAVE_BZR, HAVE_GIT, HAVE_OSTREE, IS_LINUX
import os
from collections import OrderedDict
@@ -149,8 +149,10 @@ DATA_DIR = os.path.join(
# The cache key test uses a project which exercises all plugins,
# so we cant run it at all if we dont have them installed.
#
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
@pytest.mark.skipif(HAVE_BZR is False, reason="bzr is not available")
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.skipif(HAVE_OSTREE is False, reason="ostree is not available")
@pytest.mark.datafiles(DATA_DIR)
def test_cache_key(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
diff --git a/tests/context/context.py b/tests/context/context.py
index 65f6f51fd..80853295b 100644
--- a/tests/context/context.py
+++ b/tests/context/context.py
@@ -4,6 +4,8 @@ import pytest
from buildstream import Context
from buildstream import LoadError, LoadErrorReason
+from tests.testutils.site import HAVE_ROOT
+
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'data',
@@ -36,6 +38,7 @@ def test_context_create(context_fixture):
#######################################
# Test configuration loading #
#######################################
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
def test_context_load(context_fixture):
context = context_fixture['context']
cache_home = context_fixture['xdg-cache']
@@ -50,6 +53,7 @@ def test_context_load(context_fixture):
# Test that values in a user specified config file
# override the defaults
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR))
def test_context_load_user_config(context_fixture, datafiles):
context = context_fixture['context']
diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py
index 7f594ff51..819897928 100644
--- a/tests/frontend/buildcheckout.py
+++ b/tests/frontend/buildcheckout.py
@@ -1,6 +1,7 @@
import os
import pytest
from tests.testutils import cli, create_repo, ALL_REPO_KINDS
+from tests.testutils.site import HAVE_OSTREE
from buildstream import _yaml
diff --git a/tests/frontend/pull.py b/tests/frontend/pull.py
index 114cf9950..07d664c5f 100644
--- a/tests/frontend/pull.py
+++ b/tests/frontend/pull.py
@@ -2,6 +2,7 @@ import os
import shutil
import pytest
from tests.testutils import cli, create_artifact_share
+from tests.testutils.site import IS_LINUX
from buildstream import _yaml
@@ -24,6 +25,7 @@ def assert_shared(cli, share, project, element_name):
.format(share.repo, element_name))
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
@pytest.mark.parametrize(
'user_url, project_url, override_url',
[
@@ -107,6 +109,7 @@ def test_push_pull(cli, tmpdir, datafiles, user_url, project_url, override_url):
assert state == 'cached'
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
@pytest.mark.datafiles(DATA_DIR)
def test_push_pull_all(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index c1131f901..89a864d16 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -1,6 +1,7 @@
import os
import pytest
from tests.testutils import cli, create_artifact_share
+from tests.testutils.site import IS_LINUX
from buildstream import _yaml
@@ -23,6 +24,7 @@ def assert_shared(cli, share, project, element_name):
.format(share.repo, element_name))
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
@pytest.mark.parametrize(
'user_url, project_url, override_url',
[
@@ -82,6 +84,7 @@ def test_push(cli, tmpdir, datafiles, user_url, project_url, override_url):
assert_shared(cli, share, project, 'target.bst')
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
@pytest.mark.datafiles(DATA_DIR)
def test_push_all(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
diff --git a/tests/frontend/track.py b/tests/frontend/track.py
index af899bd04..0ed0b239e 100644
--- a/tests/frontend/track.py
+++ b/tests/frontend/track.py
@@ -1,6 +1,7 @@
import os
import pytest
from tests.testutils import cli, create_repo, ALL_REPO_KINDS
+from tests.testutils.site import HAVE_OSTREE
from buildstream import _yaml
diff --git a/tests/pipeline/load.py b/tests/pipeline/load.py
index 2071bff4e..a1db764dc 100644
--- a/tests/pipeline/load.py
+++ b/tests/pipeline/load.py
@@ -5,6 +5,8 @@ from buildstream import Context, Project, Scope
from buildstream._pipeline import Pipeline
from buildstream._platform import Platform
+from tests.testutils.site import HAVE_ROOT
+
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'load',
@@ -22,6 +24,7 @@ def create_pipeline(tmpdir, basedir, target, variant):
return Pipeline(context, project, target, variant)
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'simple'))
def test_load_simple(datafiles, tmpdir):
@@ -39,6 +42,7 @@ def test_load_simple(datafiles, tmpdir):
###############################################################
# Testing Element.dependencies() iteration #
###############################################################
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_all(datafiles, tmpdir):
@@ -65,6 +69,7 @@ def test_iterate_scope_all(datafiles, tmpdir):
assert(element_list[6].name == "target.bst")
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_run(datafiles, tmpdir):
@@ -88,6 +93,7 @@ def test_iterate_scope_run(datafiles, tmpdir):
assert(element_list[3].name == "target.bst")
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_build(datafiles, tmpdir):
@@ -111,6 +117,7 @@ def test_iterate_scope_build(datafiles, tmpdir):
assert(element_list[2].name == "dep-two.bst")
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'iterate'))
def test_iterate_scope_build_of_child(datafiles, tmpdir):
@@ -142,6 +149,7 @@ def test_iterate_scope_build_of_child(datafiles, tmpdir):
###############################################################
# Testing element removal #
###############################################################
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'remove'))
def test_remove_elements(datafiles, tmpdir):
diff --git a/tests/plugins/pipeline.py b/tests/plugins/pipeline.py
index 868145a11..e44af789c 100644
--- a/tests/plugins/pipeline.py
+++ b/tests/plugins/pipeline.py
@@ -3,6 +3,9 @@ import pytest
from buildstream import Context, Project, Scope, PluginError
from buildstream._pipeline import Pipeline
+from buildstream._platform import Platform
+
+from tests.testutils.site import HAVE_ROOT
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
@@ -16,10 +19,12 @@ def create_pipeline(tmpdir, basedir, target, variant):
context.deploydir = os.path.join(str(tmpdir), 'deploy')
context.artifactdir = os.path.join(str(tmpdir), 'artifact')
+ context._platform = Platform.get_platform(context, project)
return Pipeline(context, project, target, variant)
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customsource'))
def test_customsource(datafiles, tmpdir):
@@ -28,6 +33,7 @@ def test_customsource(datafiles, tmpdir):
assert(pipeline.target.get_kind() == "autotools")
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'customelement'))
def test_customelement(datafiles, tmpdir):
@@ -36,6 +42,7 @@ def test_customelement(datafiles, tmpdir):
assert(pipeline.target.get_kind() == "foo")
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionsource'))
def test_badversionsource(datafiles, tmpdir):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
@@ -44,6 +51,7 @@ def test_badversionsource(datafiles, tmpdir):
pipeline = create_pipeline(tmpdir, basedir, 'simple.bst', None)
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionelement'))
def test_badversionelement(datafiles, tmpdir):
basedir = os.path.join(datafiles.dirname, datafiles.basename)
diff --git a/tests/project/plugins.py b/tests/project/plugins.py
index e414fa479..4aeb3fc09 100644
--- a/tests/project/plugins.py
+++ b/tests/project/plugins.py
@@ -5,6 +5,8 @@ from buildstream import Context, Project, Scope
from buildstream._pipeline import Pipeline
from buildstream._platform import Platform
+from tests.testutils.site import HAVE_ROOT
+
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'data',
@@ -26,6 +28,7 @@ def create_pipeline(tmpdir, basedir, target, variant):
# also test that the project's configuration of plugin
# paths is actually working.
#
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'plugins'))
def test_custom_element(datafiles, tmpdir):
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index 314de7f21..2ddd8c566 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -1,4 +1,5 @@
import string
+import pytest
import subprocess
import os
diff --git a/tests/testutils/repo/__init__.py b/tests/testutils/repo/__init__.py
index c3b54a739..3516679aa 100644
--- a/tests/testutils/repo/__init__.py
+++ b/tests/testutils/repo/__init__.py
@@ -1,5 +1,7 @@
from collections import OrderedDict
import pytest
+from ..site import HAVE_OSTREE
+
from .git import Git
from .bzr import Bzr
from .ostree import OSTree
diff --git a/tests/testutils/repo/ostree.py b/tests/testutils/repo/ostree.py
index f92f40fcb..f49659ca2 100644
--- a/tests/testutils/repo/ostree.py
+++ b/tests/testutils/repo/ostree.py
@@ -1,14 +1,16 @@
+import pytest
import subprocess
from .repo import Repo
-from ..site import HAVE_OSTREE_CLI
+from ..site import HAVE_OSTREE_CLI, HAVE_OSTREE
class OSTree(Repo):
def __init__(self, directory):
- if not HAVE_OSTREE_CLI:
+ if not HAVE_OSTREE_CLI or not HAVE_OSTREE:
pytest.skip("ostree cli is not available")
+
super(OSTree, self).__init__(directory)
def create(self, directory):
diff --git a/tests/testutils/runcli.py b/tests/testutils/runcli.py
index a7508dc72..86cc8f71c 100644
--- a/tests/testutils/runcli.py
+++ b/tests/testutils/runcli.py
@@ -1,4 +1,6 @@
import os
+import sys
+import traceback
from contextlib import contextmanager, ExitStack
from click.testing import CliRunner
import pytest
@@ -66,6 +68,14 @@ class Cli():
if env is not None:
stack.enter_context(environment(env))
+ # Ensure we have a working stdout - required to work
+ # around a bug that appears to cause AIX to close
+ # sys.__stdout__ after setup.py
+ try:
+ sys.__stdout__.fileno()
+ except ValueError:
+ sys.__stdout__ = open('/dev/stdout', 'w')
+
result = self.cli_runner.invoke(bst_cli, bst_args)
# Some informative stdout we can observe when anything fails
@@ -74,6 +84,9 @@ class Cli():
.format(result.exit_code, command))
print("Program output was:\n{}".format(result.output))
+ if result.exc_info and result.exc_info[0] != SystemExit:
+ traceback.print_exception(*result.exc_info)
+
return result
# Fetch an element state by name by
diff --git a/tests/testutils/site.py b/tests/testutils/site.py
index 048af0596..86a300da0 100644
--- a/tests/testutils/site.py
+++ b/tests/testutils/site.py
@@ -1,6 +1,9 @@
# Some things resolved about the execution site,
# so we dont have to repeat this everywhere
#
+import os
+import sys
+
from buildstream import exceptions, utils
try:
@@ -20,3 +23,19 @@ try:
HAVE_OSTREE_CLI = True
except exceptions.ProgramNotFoundError:
HAVE_OSTREE_CLI = False
+
+try:
+ from buildstream import _ostree
+ HAVE_OSTREE = True
+except (ImportError, ValueError):
+ HAVE_OSTREE = False
+
+try:
+ utils.get_host_tool('bwrap')
+ HAVE_BWRAP = True
+except exceptions.ProgramNotFoundError:
+ HAVE_BWRAP = False
+
+IS_LINUX = os.getenv('BST_FORCE_BACKEND', sys.platform).startswith('linux')
+
+HAVE_ROOT = HAVE_BWRAP or os.geteuid() == 0
diff --git a/tests/variables/variables.py b/tests/variables/variables.py
index 156081f8f..55a44b322 100644
--- a/tests/variables/variables.py
+++ b/tests/variables/variables.py
@@ -5,6 +5,8 @@ from buildstream import Context, Project, BuildElement
from buildstream._pipeline import Pipeline
from buildstream._platform import Platform
+from tests.testutils.site import HAVE_ROOT
+
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
)
@@ -37,6 +39,7 @@ def assert_command(datafiles, tmpdir, target, command, expected):
###############################################################
# Test proper loading of some default commands from plugins #
###############################################################
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.parametrize("target,command,expected", [
('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/buildstream/install\" install"),
('cmake.bst', 'configure-commands',
@@ -57,6 +60,7 @@ def test_defaults(datafiles, tmpdir, target, command, expected):
################################################################
# Test overriding of variables to produce different commands #
################################################################
+@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
@pytest.mark.parametrize("target,command,expected", [
('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/custom/install/root\" install"),
('cmake.bst', 'configure-commands',