summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-07-12 18:06:27 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-12 18:06:27 +0000
commitc6886c251fa3f65aa1cddb533c6121c2eb7c4ed6 (patch)
tree2fc1b7254cc48c17738a23b1d255633d5fe84ebf
parent8d485588f69365288441978faec046ec89717fcc (diff)
parentecfdfd419323fa1be080459ff81e613b9da82978 (diff)
downloadbuildstream-c6886c251fa3f65aa1cddb533c6121c2eb7c4ed6.tar.gz
Merge branch 'raoul/994-further-re-testing' into 'master'
Further RE testing Closes #994 See merge request BuildStream/buildstream!1452
-rw-r--r--src/buildstream/scriptelement.py3
-rw-r--r--tests/remoteexecution/buildfail.py75
-rw-r--r--tests/remoteexecution/buildtree.py81
-rw-r--r--tests/remoteexecution/junction.py116
-rw-r--r--tests/remoteexecution/project/elements/build-shell/buildtree-fail.bst13
-rw-r--r--tests/remoteexecution/project/elements/build-shell/buildtree.bst11
-rw-r--r--tests/remoteexecution/project/files/dev-files/usr/include/pony.h12
-rw-r--r--tests/remoteexecution/project/files/sub-project/elements/autotools/amhello.bst10
-rw-r--r--tests/remoteexecution/project/files/sub-project/elements/base.bst5
-rw-r--r--tests/remoteexecution/project/files/sub-project/elements/base/base-alpine.bst17
-rw-r--r--tests/remoteexecution/project/files/sub-project/files/amhello.tar.gzbin0 -> 30555 bytes
-rw-r--r--tests/remoteexecution/project/files/sub-project/project.conf26
12 files changed, 369 insertions, 0 deletions
diff --git a/src/buildstream/scriptelement.py b/src/buildstream/scriptelement.py
index dfdbb45c0..8023e64d2 100644
--- a/src/buildstream/scriptelement.py
+++ b/src/buildstream/scriptelement.py
@@ -206,6 +206,9 @@ class ScriptElement(Element):
# Tell the sandbox to mount the install root
directories = {self.__install_root: False}
+ # set the output directory
+ sandbox.set_output_directory(self.__install_root)
+
# Mark the artifact directories in the layout
for item in self.__layout:
destination = item['destination']
diff --git a/tests/remoteexecution/buildfail.py b/tests/remoteexecution/buildfail.py
new file mode 100644
index 000000000..031e5829e
--- /dev/null
+++ b/tests/remoteexecution/buildfail.py
@@ -0,0 +1,75 @@
+#
+# Copyright (C) 2018 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._exceptions import ErrorDomain
+from buildstream import _yaml
+from buildstream.testing import cli_remote_execution as cli # pylint: disable=unused-import
+
+pytestmark = pytest.mark.remoteexecution
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_remote_failure(cli, datafiles):
+ project = str(datafiles)
+ element_path = os.path.join(project, 'elements', 'element.bst')
+ checkout_path = os.path.join(cli.directory, 'checkout')
+
+ # Write out our test target
+ element = {
+ 'kind': 'script',
+ 'depends': [
+ {
+ 'filename': 'base.bst',
+ 'type': 'build',
+ },
+ ],
+ 'config': {
+ 'commands': [
+ 'touch %{install-root}/foo',
+ 'false',
+ ],
+ },
+ }
+ _yaml.dump(element, element_path)
+
+ services = cli.ensure_services()
+ assert set(services) == set(['action-cache', 'execution', 'storage'])
+
+ # Try to build it, this should result in a failure that contains the content
+ result = cli.run(project=project, args=['build', 'element.bst'])
+ result.assert_main_error(ErrorDomain.STREAM, None)
+
+ result = cli.run(project=project, args=[
+ 'artifact', 'checkout', 'element.bst', '--directory', checkout_path
+ ])
+ result.assert_success()
+
+ # check that the file created before the failure exists
+ filename = os.path.join(checkout_path, 'foo')
+ assert os.path.isfile(filename)
diff --git a/tests/remoteexecution/buildtree.py b/tests/remoteexecution/buildtree.py
new file mode 100644
index 000000000..a64b8716c
--- /dev/null
+++ b/tests/remoteexecution/buildtree.py
@@ -0,0 +1,81 @@
+# 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 shutil
+import pytest
+
+from buildstream.testing import cli_remote_execution as cli # pylint: disable=unused-import
+
+from tests.testutils import create_artifact_share
+
+pytestmark = pytest.mark.remoteexecution
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_buildtree_remote(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element_name = 'build-shell/buildtree.bst'
+ share_path = os.path.join(str(tmpdir), 'share')
+
+ services = cli.ensure_services()
+ assert set(services) == set(['action-cache', 'execution', 'storage'])
+
+ with create_artifact_share(share_path) as share:
+ cli.configure({
+ 'artifacts': {'url': share.repo, 'push': True},
+ 'cache': {'pull-buildtrees': False}
+ })
+
+ res = cli.run(project=project, args=[
+ '--cache-buildtrees', 'always', 'build', element_name])
+ res.assert_success()
+
+ # remove local cache
+ shutil.rmtree(os.path.join(str(tmpdir), 'cache', 'cas'))
+ shutil.rmtree(os.path.join(str(tmpdir), 'cache', 'artifacts'))
+
+ # pull without buildtree
+ res = cli.run(project=project, args=[
+ 'artifact', 'pull', '--deps', 'all', element_name])
+ res.assert_success()
+
+ # check shell doesn't work
+ res = cli.run(project=project, args=[
+ 'shell', '--build', element_name, '--', 'cat', 'test'
+ ])
+ res.assert_shell_error()
+
+ # pull with buildtree
+ res = cli.run(project=project, args=[
+ '--pull-buildtrees', 'artifact', 'pull', '--deps', 'all', element_name])
+ res.assert_success()
+
+ # check it works this time
+ res = cli.run(project=project, args=[
+ 'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
+ ])
+ res.assert_success()
+ assert "Hi" in res.output
diff --git a/tests/remoteexecution/junction.py b/tests/remoteexecution/junction.py
new file mode 100644
index 000000000..8130e4c7c
--- /dev/null
+++ b/tests/remoteexecution/junction.py
@@ -0,0 +1,116 @@
+#
+# 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.testing import cli_remote_execution as cli # pylint: disable=unused-import
+from buildstream.testing import create_repo
+from buildstream import _yaml
+from tests.testutils import generate_junction
+
+pytestmark = pytest.mark.remoteexecution
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+
+def configure_project(path, config):
+ config['name'] = 'test'
+ config['element-path'] = 'elements'
+ _yaml.dump(config, os.path.join(path, 'project.conf'))
+
+
+def create_element(repo, name, path, dependencies, ref=None):
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref)
+ ],
+ 'depends': dependencies
+ }
+ _yaml.dump(element, os.path.join(path, name))
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_junction_build_remote(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ subproject_path = os.path.join(project, 'files', 'sub-project')
+ subproject_element_path = os.path.join(subproject_path, 'elements')
+ amhello_files_path = os.path.join(subproject_path, 'files')
+ element_path = os.path.join(project, 'elements')
+ junction_path = os.path.join(element_path, 'junction.bst')
+
+ # We need a repo for real trackable elements
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(amhello_files_path)
+
+ # ensure that the correct project directory is also listed in the junction
+ subproject_conf = os.path.join(subproject_path, 'project.conf')
+ with open(subproject_conf) as f:
+ config = f.read()
+ config = config.format(project_dir=subproject_path)
+ with open(subproject_conf, 'w') as f:
+ f.write(config)
+
+ # Create a trackable element to depend on the cross junction element,
+ # this one has it's ref resolved already
+ create_element(repo, 'sub-target.bst', subproject_element_path, ['autotools/amhello.bst'], ref=ref)
+
+ # Create a trackable element to depend on the cross junction element
+ create_element(repo, 'target.bst', element_path, [
+ {
+ 'junction': 'junction.bst',
+ 'filename': 'sub-target.bst'
+ }
+ ])
+
+ # Create a repo to hold the subproject and generate a junction element for it
+ generate_junction(tmpdir, subproject_path, junction_path, store_ref=False)
+
+ # Now create a compose element at the top level
+ element = {
+ 'kind': 'compose',
+ 'depends': [
+ {
+ 'filename': 'target.bst',
+ 'type': 'build'
+ }
+ ]
+ }
+ _yaml.dump(element, os.path.join(element_path, 'composed.bst'))
+
+ # We're doing remote execution so ensure services are available
+ services = cli.ensure_services()
+ assert set(services) == set(['action-cache', 'execution', 'storage'])
+
+ # track the junction first to ensure we have refs
+ result = cli.run(project=project, args=['source', 'track', 'junction.bst'])
+ result.assert_success()
+
+ # Build it with --track-all
+ result = cli.run(project=project, silent=True, args=[
+ 'build', '--track-all', 'composed.bst'])
+ result.assert_success()
+
+ # Assert that the main target is cached as a result
+ assert cli.get_element_state(project, 'composed.bst') == 'cached'
diff --git a/tests/remoteexecution/project/elements/build-shell/buildtree-fail.bst b/tests/remoteexecution/project/elements/build-shell/buildtree-fail.bst
new file mode 100644
index 000000000..a3b515a9a
--- /dev/null
+++ b/tests/remoteexecution/project/elements/build-shell/buildtree-fail.bst
@@ -0,0 +1,13 @@
+kind: manual
+description: |
+ Puts a file in the build tree so that build tree caching and staging can be tested,
+ then deliberately failing to build so we can check the output.
+
+depends:
+ - filename: base.bst
+ type: build
+
+config:
+ build-commands:
+ - "echo 'Hi' > %{build-root}/test"
+ - "false"
diff --git a/tests/remoteexecution/project/elements/build-shell/buildtree.bst b/tests/remoteexecution/project/elements/build-shell/buildtree.bst
new file mode 100644
index 000000000..d5cf256be
--- /dev/null
+++ b/tests/remoteexecution/project/elements/build-shell/buildtree.bst
@@ -0,0 +1,11 @@
+kind: manual
+description: |
+ Puts a file in the build tree so that build tree caching and staging can be tested.
+
+depends:
+ - filename: base.bst
+ type: build
+
+config:
+ build-commands:
+ - "echo 'Hi' > %{build-root}/test"
diff --git a/tests/remoteexecution/project/files/dev-files/usr/include/pony.h b/tests/remoteexecution/project/files/dev-files/usr/include/pony.h
new file mode 100644
index 000000000..40bd0c2e7
--- /dev/null
+++ b/tests/remoteexecution/project/files/dev-files/usr/include/pony.h
@@ -0,0 +1,12 @@
+#ifndef __PONY_H__
+#define __PONY_H__
+
+#define PONY_BEGIN "Once upon a time, there was a pony."
+#define PONY_END "And they lived happily ever after, the end."
+
+#define MAKE_PONY(story) \
+ PONY_BEGIN \
+ story \
+ PONY_END
+
+#endif /* __PONY_H__ */
diff --git a/tests/remoteexecution/project/files/sub-project/elements/autotools/amhello.bst b/tests/remoteexecution/project/files/sub-project/elements/autotools/amhello.bst
new file mode 100644
index 000000000..ee3a029d8
--- /dev/null
+++ b/tests/remoteexecution/project/files/sub-project/elements/autotools/amhello.bst
@@ -0,0 +1,10 @@
+kind: autotools
+description: Autotools test
+
+depends:
+- base.bst
+
+sources:
+- kind: tar
+ url: project_dir:/files/amhello.tar.gz
+ ref: 9ba123fa4e660929e9a0aa99f0c487b7eee59c5e7594f3284d015640b90f5590
diff --git a/tests/remoteexecution/project/files/sub-project/elements/base.bst b/tests/remoteexecution/project/files/sub-project/elements/base.bst
new file mode 100644
index 000000000..428afa736
--- /dev/null
+++ b/tests/remoteexecution/project/files/sub-project/elements/base.bst
@@ -0,0 +1,5 @@
+# elements/base.bst
+
+kind: stack
+depends:
+ - base/base-alpine.bst
diff --git a/tests/remoteexecution/project/files/sub-project/elements/base/base-alpine.bst b/tests/remoteexecution/project/files/sub-project/elements/base/base-alpine.bst
new file mode 100644
index 000000000..c5833095d
--- /dev/null
+++ b/tests/remoteexecution/project/files/sub-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/remoteexecution/project/files/sub-project/files/amhello.tar.gz b/tests/remoteexecution/project/files/sub-project/files/amhello.tar.gz
new file mode 100644
index 000000000..afe189908
--- /dev/null
+++ b/tests/remoteexecution/project/files/sub-project/files/amhello.tar.gz
Binary files differ
diff --git a/tests/remoteexecution/project/files/sub-project/project.conf b/tests/remoteexecution/project/files/sub-project/project.conf
new file mode 100644
index 000000000..c4d876cc2
--- /dev/null
+++ b/tests/remoteexecution/project/files/sub-project/project.conf
@@ -0,0 +1,26 @@
+# Project config for frontend build test
+name: subtest
+
+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/*