diff options
author | William Salmon <will.salmon@codethink.co.uk> | 2019-06-10 11:50:20 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-12 06:57:52 +0000 |
commit | f8da4743c5d5b4785d646d06f8c6d271776794ae (patch) | |
tree | b98a40036259a54ea8efa4971c9d0b82c45dbdac /tests | |
parent | 33272aa7764c03f7d0b3a7b36f08636f883c3e69 (diff) | |
download | buildstream-f8da4743c5d5b4785d646d06f8c6d271776794ae.tar.gz |
test for BST_FORCE_SANDBOX and BST_FORCE_BACKENDwillsalmon/platformRefactor
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sandboxes/fallback.py | 80 | ||||
-rw-r--r-- | tests/sandboxes/project/elements/base.bst | 5 | ||||
-rw-r--r-- | tests/sandboxes/project/elements/base/base-alpine.bst | 17 | ||||
-rw-r--r-- | tests/sandboxes/project/elements/import-file1.bst | 5 | ||||
-rw-r--r-- | tests/sandboxes/project/files/file1.txt | 0 | ||||
-rw-r--r-- | tests/sandboxes/project/project.conf | 23 | ||||
-rw-r--r-- | tests/sandboxes/selection.py | 101 |
7 files changed, 231 insertions, 0 deletions
diff --git a/tests/sandboxes/fallback.py b/tests/sandboxes/fallback.py new file mode 100644 index 000000000..eebe7ddb2 --- /dev/null +++ b/tests/sandboxes/fallback.py @@ -0,0 +1,80 @@ +# +# Copyright (C) 2019 Bloomberg Finance LP +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os +import pytest + +from buildstream import _yaml +from buildstream._exceptions import ErrorDomain +from buildstream.testing import cli # pylint: disable=unused-import + +from tests.conftest import clean_platform_cache + +pytestmark = pytest.mark.integration + + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "project" +) + + +@pytest.mark.datafiles(DATA_DIR) +def test_fallback_platform_fails(cli, datafiles): + project = str(datafiles) + element_path = os.path.join(project, 'elements', 'element.bst') + + # Write out our test target + element = { + 'kind': 'script', + 'depends': [ + { + 'filename': 'base.bst', + 'type': 'build', + }, + ], + 'config': { + 'commands': [ + 'true', + ], + }, + } + _yaml.dump(element, element_path) + + clean_platform_cache() + + result = cli.run(project=project, args=['build', 'element.bst'], + env={'BST_FORCE_BACKEND': 'fallback', + 'BST_FORCE_SANDBOX': None}) + result.assert_main_error(ErrorDomain.STREAM, None) + assert "FallBack platform only implements dummy sandbox" in result.stderr + # The dummy sandbox can not build the element but it can get the element read + # There for the element should be `buildable` rather than `waiting` + assert cli.get_element_state(project, 'element.bst') == 'buildable' + + +@pytest.mark.datafiles(DATA_DIR) +def test_fallback_platform_can_use_dummy(cli, datafiles): + project = str(datafiles) + + result = cli.run(project=project, args=['build', 'import-file1.bst'], + env={'BST_FORCE_BACKEND': 'fallback', + 'BST_FORCE_SANDBOX': None}) + result.assert_success() + # The fallback platform can still provide a dummy sandbox that alows simple elemnts that do not need + # a full sandbox to still be built on new platforms. diff --git a/tests/sandboxes/project/elements/base.bst b/tests/sandboxes/project/elements/base.bst new file mode 100644 index 000000000..428afa736 --- /dev/null +++ b/tests/sandboxes/project/elements/base.bst @@ -0,0 +1,5 @@ +# elements/base.bst + +kind: stack +depends: + - base/base-alpine.bst diff --git a/tests/sandboxes/project/elements/base/base-alpine.bst b/tests/sandboxes/project/elements/base/base-alpine.bst new file mode 100644 index 000000000..c5833095d --- /dev/null +++ b/tests/sandboxes/project/elements/base/base-alpine.bst @@ -0,0 +1,17 @@ +kind: import + +description: | + Alpine Linux base for tests + + Generated using the `tests/integration-tests/base/generate-base.sh` script. + +sources: + - kind: tar + base-dir: '' + (?): + - arch == "x86-64": + ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639 + url: "alpine:integration-tests-base.v1.x86_64.tar.xz" + - arch == "aarch64": + ref: 431fb5362032ede6f172e70a3258354a8fd71fcbdeb1edebc0e20968c792329a + url: "alpine:integration-tests-base.v1.aarch64.tar.xz" diff --git a/tests/sandboxes/project/elements/import-file1.bst b/tests/sandboxes/project/elements/import-file1.bst new file mode 100644 index 000000000..a729ba03d --- /dev/null +++ b/tests/sandboxes/project/elements/import-file1.bst @@ -0,0 +1,5 @@ +kind: import +description: This is the test element +sources: +- kind: local + path: files/file1.txt diff --git a/tests/sandboxes/project/files/file1.txt b/tests/sandboxes/project/files/file1.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/sandboxes/project/files/file1.txt diff --git a/tests/sandboxes/project/project.conf b/tests/sandboxes/project/project.conf new file mode 100644 index 000000000..ddfe47b6d --- /dev/null +++ b/tests/sandboxes/project/project.conf @@ -0,0 +1,23 @@ +# Project config for frontend build test +name: test +element-path: elements +aliases: + alpine: https://bst-integration-test-images.ams3.cdn.digitaloceanspaces.com/ + project_dir: file://{project_dir} +options: + linux: + type: bool + description: Whether to expect a linux platform + default: True + arch: + type: arch + description: Current architecture + values: + - x86-64 + - aarch64 +split-rules: + test: + - | + /tests + - | + /tests/* diff --git a/tests/sandboxes/selection.py b/tests/sandboxes/selection.py new file mode 100644 index 000000000..c20ce3d3a --- /dev/null +++ b/tests/sandboxes/selection.py @@ -0,0 +1,101 @@ +# +# Copyright (C) 2019 Bloomberg Finance LP +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os +import pytest + +from buildstream import _yaml +from buildstream._exceptions import ErrorDomain +from buildstream.testing import cli # pylint: disable=unused-import + +from tests.conftest import clean_platform_cache + +pytestmark = pytest.mark.integration + + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "project" +) + + +@pytest.mark.datafiles(DATA_DIR) +def test_force_sandbox(cli, datafiles): + project = str(datafiles) + element_path = os.path.join(project, 'elements', 'element.bst') + + # Write out our test target + element = { + 'kind': 'script', + 'depends': [ + { + 'filename': 'base.bst', + 'type': 'build', + }, + ], + 'config': { + 'commands': [ + 'true', + ], + }, + } + _yaml.dump(element, element_path) + + clean_platform_cache() + + # Build without access to host tools, this will fail + result = cli.run(project=project, args=['build', 'element.bst'], env={'PATH': '', 'BST_FORCE_SANDBOX': 'bwrap'}) + result.assert_main_error(ErrorDomain.PLATFORM, None) + assert "Bubblewrap not found" in result.stderr + # we have asked for a spesific sand box, but it is not avalble so + # bst should fail early and the element should be waiting + assert cli.get_element_state(project, 'element.bst') == 'waiting' + + +@pytest.mark.datafiles(DATA_DIR) +def test_dummy_sandbox_fallback(cli, datafiles): + project = str(datafiles) + element_path = os.path.join(project, 'elements', 'element.bst') + + # Write out our test target + element = { + 'kind': 'script', + 'depends': [ + { + 'filename': 'base.bst', + 'type': 'build', + }, + ], + 'config': { + 'commands': [ + 'true', + ], + }, + } + _yaml.dump(element, element_path) + + clean_platform_cache() + + # Build without access to host tools, this will fail + result = cli.run(project=project, args=['build', 'element.bst'], env={'PATH': '', 'BST_FORCE_SANDBOX': None}) + # But if we dont spesify a sandbox then we fall back to dummy, we still + # fail early but only once we know we need a facny sandbox and that + # dumy is not enough, there for element gets fetched and so is buildable + + result.assert_task_error(ErrorDomain.SANDBOX, 'unavailable-local-sandbox') + assert cli.get_element_state(project, 'element.bst') == 'buildable' |