summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-10-09 14:32:05 +0100
committerJonathan Maw <jonathan.maw@codethink.co.uk>2018-10-30 15:42:05 +0000
commit9b89564f0ac8e8278207358ec3aa95c61ed19d96 (patch)
tree1606d17d6f9bbc21dd639cbb2de7031c978c9ed7
parent4bc717730d54c00c4242b0e5b1e7e8ca65b4f832 (diff)
downloadbuildstream-9b89564f0ac8e8278207358ec3aa95c61ed19d96.tar.gz
tests: Add test that cached build trees are staged in build shells
This is related to #539
-rw-r--r--tests/integration/build-tree.py81
-rw-r--r--tests/integration/project/elements/build-shell/buildtree-fail.bst13
-rw-r--r--tests/integration/project/elements/build-shell/buildtree.bst11
3 files changed, 105 insertions, 0 deletions
diff --git a/tests/integration/build-tree.py b/tests/integration/build-tree.py
new file mode 100644
index 000000000..df9006a27
--- /dev/null
+++ b/tests/integration/build-tree.py
@@ -0,0 +1,81 @@
+import os
+import pytest
+import shutil
+
+from tests.testutils import cli, cli_integration, create_artifact_share
+from buildstream._exceptions import ErrorDomain
+
+
+pytestmark = pytest.mark.integration
+
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project"
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_buildtree_staged(cli_integration, tmpdir, datafiles):
+ # i.e. tests that cached build trees are staged by `bst shell --build`
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ element_name = 'build-shell/buildtree.bst'
+
+ res = cli_integration.run(project=project, args=['build', element_name])
+ res.assert_success()
+
+ res = cli_integration.run(project=project, args=[
+ 'shell', '--build', element_name, '--', 'grep', '-q', 'Hi', 'test'
+ ])
+ res.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_buildtree_from_failure(cli_integration, tmpdir, datafiles):
+ # i.e. test that on a build failure, we can still shell into it
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ element_name = 'build-shell/buildtree-fail.bst'
+
+ res = cli_integration.run(project=project, args=['build', element_name])
+ res.assert_main_error(ErrorDomain.STREAM, None)
+
+ # Assert that file has expected contents
+ res = cli_integration.run(project=project, args=[
+ 'shell', '--build', element_name, '--', 'cat', 'test'
+ ])
+ res.assert_success()
+ assert 'Hi' in res.output
+
+
+# Check that build shells work when pulled from a remote cache
+# This is to roughly simulate remote execution
+@pytest.mark.datafiles(DATA_DIR)
+def test_buildtree_pulled(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ element_name = 'build-shell/buildtree.bst'
+
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
+ # Build the element to push it to cache
+ cli.configure({
+ 'artifacts': {'url': share.repo, 'push': True}
+ })
+ result = cli.run(project=project, args=['build', element_name])
+ result.assert_success()
+ assert cli.get_element_state(project, element_name) == 'cached'
+
+ # Discard the cache
+ cli.configure({
+ 'artifacts': {'url': share.repo, 'push': True},
+ 'artifactdir': os.path.join(cli.directory, 'artifacts2')
+ })
+ assert cli.get_element_state(project, element_name) != 'cached'
+
+ # Pull from cache
+ result = cli.run(project=project, args=['pull', '--deps', 'all', element_name])
+ result.assert_success()
+
+ # Check it's using the cached build tree
+ res = cli.run(project=project, args=[
+ 'shell', '--build', element_name, '--', 'grep', '-q', 'Hi', 'test'
+ ])
+ res.assert_success()
diff --git a/tests/integration/project/elements/build-shell/buildtree-fail.bst b/tests/integration/project/elements/build-shell/buildtree-fail.bst
new file mode 100644
index 000000000..a3b515a9a
--- /dev/null
+++ b/tests/integration/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/integration/project/elements/build-shell/buildtree.bst b/tests/integration/project/elements/build-shell/buildtree.bst
new file mode 100644
index 000000000..d5cf256be
--- /dev/null
+++ b/tests/integration/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"