summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Salmon <will.salmon@codethink.co.uk>2020-07-23 17:30:32 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2020-08-11 08:11:09 +0000
commit46e92ead4ca2878c289fb72a62865d16d916f82a (patch)
treeec703501b098140fae265ce2ee21fba517b9b5cb
parent333644244f8d5779d01dfcfbf357afdc95d37265 (diff)
downloadbuildstream-46e92ead4ca2878c289fb72a62865d16d916f82a.tar.gz
Add tests for checking the working of a remote cache
These basic tests are ment to be run with a remote cache and can be used to check bst conpatiblity with a remote cache server.
-rw-r--r--setup.cfg1
-rwxr-xr-xtests/conftest.py11
-rw-r--r--tests/remotecache/project/elements/autotools/amhello.bst26
-rw-r--r--tests/remotecache/project/elements/base.bst5
-rw-r--r--tests/remotecache/project/elements/base/base-alpine.bst17
-rw-r--r--tests/remotecache/project/elements/build-shell/buildtree-fail.bst13
-rw-r--r--tests/remotecache/project/elements/build-shell/buildtree.bst11
-rw-r--r--tests/remotecache/project/elements/no-runtime-deps.bst9
-rw-r--r--tests/remotecache/project/files/amhello.tar.gzbin0 -> 30555 bytes
-rw-r--r--tests/remotecache/project/files/dev-files/usr/include/pony.h12
-rw-r--r--tests/remotecache/project/project.conf25
-rw-r--r--tests/remotecache/simple.py65
12 files changed, 195 insertions, 0 deletions
diff --git a/setup.cfg b/setup.cfg
index 5a3a75d67..e8ba5ac35 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -18,6 +18,7 @@ markers =
datafiles: data files for tests
integration: run test only if --integration option is specified
remoteexecution: run test only if --remote-execution option is specified
+ remotecache: run tests only if --remote-cache option is specified
xfail_strict=True
[mypy]
diff --git a/tests/conftest.py b/tests/conftest.py
index bb4611a11..28e120d5e 100755
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -49,6 +49,7 @@ def pytest_addoption(parser):
parser.addoption("--integration", action="store_true", default=False, help="Run integration tests")
parser.addoption("--plugins", action="store_true", default=False, help="Run only plugins tests")
parser.addoption("--remote-execution", action="store_true", default=False, help="Run remote-execution tests only")
+ parser.addoption("--remote-cache", action="store_true", default=False, help="Run remote-cache tests only")
def pytest_runtest_setup(item):
@@ -67,6 +68,16 @@ def pytest_runtest_setup(item):
if item.get_closest_marker("remoteexecution"):
pytest.skip("skipping remote-execution test")
+ # With --remote-cache: only run tests marked with 'remotecache'
+ if item.config.getvalue("remote_cache"):
+ if not item.get_closest_marker("remotecache"):
+ pytest.skip("skipping non remote-cache test")
+
+ # Without --remote-cache: skip tests marked with 'remotecache'
+ else:
+ if item.get_closest_marker("remotecache"):
+ pytest.skip("skipping remote-cache test")
+
# With --plugins only run plugins tests
if item.config.getvalue("plugins"):
if not item.get_closest_marker("generic_source_test"):
diff --git a/tests/remotecache/project/elements/autotools/amhello.bst b/tests/remotecache/project/elements/autotools/amhello.bst
new file mode 100644
index 000000000..3af67ef3c
--- /dev/null
+++ b/tests/remotecache/project/elements/autotools/amhello.bst
@@ -0,0 +1,26 @@
+kind: autotools
+description: Autotools test
+
+depends:
+- base.bst
+
+sources:
+- kind: tar
+ url: project_dir:/files/amhello.tar.gz
+ ref: 9ba123fa4e660929e9a0aa99f0c487b7eee59c5e7594f3284d015640b90f5590
+
+config:
+
+ configure-commands:
+ - |
+ %{autogen}
+ - |
+ %{configure}
+ - |
+ date +%s > config-time
+
+ build-commands:
+ - |
+ %{make}
+ - |
+ date +%s > build-time
diff --git a/tests/remotecache/project/elements/base.bst b/tests/remotecache/project/elements/base.bst
new file mode 100644
index 000000000..428afa736
--- /dev/null
+++ b/tests/remotecache/project/elements/base.bst
@@ -0,0 +1,5 @@
+# elements/base.bst
+
+kind: stack
+depends:
+ - base/base-alpine.bst
diff --git a/tests/remotecache/project/elements/base/base-alpine.bst b/tests/remotecache/project/elements/base/base-alpine.bst
new file mode 100644
index 000000000..c5833095d
--- /dev/null
+++ b/tests/remotecache/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/remotecache/project/elements/build-shell/buildtree-fail.bst b/tests/remotecache/project/elements/build-shell/buildtree-fail.bst
new file mode 100644
index 000000000..a3b515a9a
--- /dev/null
+++ b/tests/remotecache/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/remotecache/project/elements/build-shell/buildtree.bst b/tests/remotecache/project/elements/build-shell/buildtree.bst
new file mode 100644
index 000000000..d5cf256be
--- /dev/null
+++ b/tests/remotecache/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/remotecache/project/elements/no-runtime-deps.bst b/tests/remotecache/project/elements/no-runtime-deps.bst
new file mode 100644
index 000000000..ca76aaf9f
--- /dev/null
+++ b/tests/remotecache/project/elements/no-runtime-deps.bst
@@ -0,0 +1,9 @@
+kind: manual
+description: Test element without runtime dependencies
+
+build-depends:
+- autotools/amhello.bst
+
+config:
+ install-commands:
+ - echo Test > %{install-root}/test
diff --git a/tests/remotecache/project/files/amhello.tar.gz b/tests/remotecache/project/files/amhello.tar.gz
new file mode 100644
index 000000000..afe189908
--- /dev/null
+++ b/tests/remotecache/project/files/amhello.tar.gz
Binary files differ
diff --git a/tests/remotecache/project/files/dev-files/usr/include/pony.h b/tests/remotecache/project/files/dev-files/usr/include/pony.h
new file mode 100644
index 000000000..40bd0c2e7
--- /dev/null
+++ b/tests/remotecache/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/remotecache/project/project.conf b/tests/remotecache/project/project.conf
new file mode 100644
index 000000000..27b5f5e34
--- /dev/null
+++ b/tests/remotecache/project/project.conf
@@ -0,0 +1,25 @@
+# Project config for frontend build test
+name: test
+min-version: 2.0
+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/remotecache/simple.py b/tests/remotecache/simple.py
new file mode 100644
index 000000000..74c44ae1e
--- /dev/null
+++ b/tests/remotecache/simple.py
@@ -0,0 +1,65 @@
+# 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.integration import assert_contains
+
+
+pytestmark = pytest.mark.remotecache
+
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project")
+
+# Test building an executable with a remote cache:
+@pytest.mark.datafiles(DATA_DIR)
+def test_remote_autotools_build(cli, datafiles):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, "checkout")
+ element_name = "autotools/amhello.bst"
+
+ result = cli.run(project=project, args=["build", element_name])
+ result.assert_success()
+ assert element_name in result.get_pushed_elements()
+
+ result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkout])
+ result.assert_success()
+
+ assert_contains(
+ checkout,
+ [
+ "/usr",
+ "/usr/lib",
+ "/usr/bin",
+ "/usr/share",
+ "/usr/bin/hello",
+ "/usr/share/doc",
+ "/usr/share/doc/amhello",
+ "/usr/share/doc/amhello/README",
+ ],
+ )
+
+ # then remove it locally
+ result = cli.run(project=project, args=["artifact", "delete", element_name])
+ result.assert_success()
+
+ result = cli.run(project=project, args=["build", element_name])
+ result.assert_success()
+ assert element_name in result.get_pulled_elements()
+
+
+# Test building an executable with a remote cache:
+@pytest.mark.datafiles(DATA_DIR)
+def test_remote_autotools_build_no_cache(cli, datafiles):
+ project = str(datafiles)
+ checkout = os.path.join(cli.directory, "checkout")
+ element_name = "autotools/amhello.bst"
+
+ cli.configure({"artifacts": {"url": "http://fake.url.service", "push": True}})
+ result = cli.run(project=project, args=["build", element_name])
+ result.assert_success()
+
+ assert """WARNING Failed to initialize remote""" in result.stderr
+ assert """Remote initialisation failed with status UNAVAILABLE: DNS resolution failed""" in result.stderr