summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan@codethink.co.uk>2020-09-12 17:50:50 +0900
committerTristan van Berkom <tristan@codethink.co.uk>2020-09-18 12:38:49 +0900
commit172c7404b00016cf7358af77b45b9d2a946af301 (patch)
treeb254b9b904ca6520d8b8c5cd42368eafcdb17837
parent0d724a09dea8eff25e5f085d041fab377592a9a9 (diff)
downloadbuildstream-172c7404b00016cf7358af77b45b9d2a946af301.tar.gz
tests/frontend/overlaps.py: Test multiple calls to Element.stage_dependency_artifacts()
This patch adds a new test plugin which implements Element.configure_dependencies() in order to offer better flexibility for testing overlaps. Newly added tests: * Test overlap warnings and errors when staging elsewhere than in the sandbox root. * Test unstaged files failure modes when staging elsewhere than in the sandbox root. * Test various overlap behaviors of OverlapAction, when different calls to Element.stage_dependency_artifacts() cause overlaps to occur after staging files into separate directories.
-rw-r--r--tests/frontend/overlaps.py71
-rw-r--r--tests/frontend/overlaps/multistage-overlap-error.bst12
-rw-r--r--tests/frontend/overlaps/multistage-overlap-ignore.bst12
-rw-r--r--tests/frontend/overlaps/multistage-overlap.bst12
-rw-r--r--tests/frontend/overlaps/plugins/overlap.py56
-rw-r--r--tests/frontend/overlaps/relocated-unstaged.bst9
-rw-r--r--tests/frontend/overlaps/relocated.bst15
-rw-r--r--tests/frontend/overlaps/subdir-a.bst7
8 files changed, 192 insertions, 2 deletions
diff --git a/tests/frontend/overlaps.py b/tests/frontend/overlaps.py
index 77e9a82c9..7a9925e48 100644
--- a/tests/frontend/overlaps.py
+++ b/tests/frontend/overlaps.py
@@ -6,16 +6,18 @@ import pytest
from buildstream.testing.runcli import cli # pylint: disable=unused-import
from buildstream.exceptions import ErrorDomain, LoadErrorReason
from buildstream import _yaml
-from buildstream.plugin import CoreWarnings
+from buildstream import CoreWarnings, OverlapAction
from tests.testutils import generate_junction
# Project directory
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "overlaps")
-def gen_project(project_dir, fatal_warnings, *, project_name="test"):
+def gen_project(project_dir, fatal_warnings, *, project_name="test", use_plugin=False):
template = {"name": project_name, "min-version": "2.0"}
template["fatal-warnings"] = [CoreWarnings.OVERLAPS, CoreWarnings.UNSTAGED_FILES] if fatal_warnings else []
+ if use_plugin:
+ template["plugins"] = [{"origin": "local", "path": "plugins", "elements": ["overlap"]}]
projectfile = os.path.join(project_dir, "project.conf")
_yaml.roundtrip_dump(template, projectfile)
@@ -128,3 +130,68 @@ def test_overlap_subproject(cli, tmpdir, datafiles, project_policy, subproject_p
else:
result.assert_success()
assert "WARNING [overlaps]" in result.stderr
+
+
+# Test unstaged-files warnings when staging to an alternative location than "/"
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("error", [False, True], ids=["warning", "error"])
+def test_unstaged_files_relocated(cli, datafiles, error):
+ project_dir = str(datafiles)
+ gen_project(project_dir, error, use_plugin=True)
+ result = cli.run(project=project_dir, silent=True, args=["build", "relocated-unstaged.bst"])
+ if error:
+ result.assert_main_error(ErrorDomain.STREAM, None)
+ result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.UNSTAGED_FILES)
+ else:
+ result.assert_success()
+ assert "WARNING [unstaged-files]" in result.stderr
+
+
+# Test overlap warnings when staging to an alternative location than "/"
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("error", [False, True], ids=["warning", "error"])
+def test_overlaps_relocated(cli, datafiles, error):
+ project_dir = str(datafiles)
+ gen_project(project_dir, error, use_plugin=True)
+ result = cli.run(project=project_dir, silent=True, args=["build", "relocated.bst"])
+ if error:
+ result.assert_main_error(ErrorDomain.STREAM, None)
+ result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.OVERLAPS)
+ else:
+ result.assert_success()
+ assert "WARNING [overlaps]" in result.stderr
+
+
+# Test overlap warnings as a result of multiple calls to Element.stage_dependency_artifacts()
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize(
+ "target,action,error",
+ [
+ ("multistage-overlap-ignore.bst", OverlapAction.IGNORE, False),
+ ("multistage-overlap.bst", OverlapAction.WARNING, False),
+ ("multistage-overlap.bst", OverlapAction.WARNING, True),
+ ("multistage-overlap-error.bst", OverlapAction.ERROR, True),
+ ],
+ ids=["ignore", "warn-warning", "warn-error", "error"],
+)
+def test_overlaps_multistage(cli, datafiles, target, action, error):
+ project_dir = str(datafiles)
+ gen_project(project_dir, error, use_plugin=True)
+ result = cli.run(project=project_dir, silent=True, args=["build", target])
+
+ if action == OverlapAction.WARNING:
+ if error:
+ result.assert_main_error(ErrorDomain.STREAM, None)
+ result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.OVERLAPS)
+ else:
+ result.assert_success()
+ assert "WARNING [overlaps]" in result.stderr
+ elif action == OverlapAction.IGNORE:
+ result.assert_success()
+ assert "WARNING [overlaps]" not in result.stderr
+ elif action == OverlapAction.ERROR:
+ result.assert_main_error(ErrorDomain.STREAM, None)
+ result.assert_task_error(ErrorDomain.ELEMENT, "overlaps")
diff --git a/tests/frontend/overlaps/multistage-overlap-error.bst b/tests/frontend/overlaps/multistage-overlap-error.bst
new file mode 100644
index 000000000..5b06c671b
--- /dev/null
+++ b/tests/frontend/overlaps/multistage-overlap-error.bst
@@ -0,0 +1,12 @@
+kind: overlap
+
+build-depends:
+- filename: subdir-a.bst
+ config:
+ location: /
+- filename: c.bst
+ config:
+ location: /opt
+
+config:
+ action: error
diff --git a/tests/frontend/overlaps/multistage-overlap-ignore.bst b/tests/frontend/overlaps/multistage-overlap-ignore.bst
new file mode 100644
index 000000000..d40ae9a8f
--- /dev/null
+++ b/tests/frontend/overlaps/multistage-overlap-ignore.bst
@@ -0,0 +1,12 @@
+kind: overlap
+
+build-depends:
+- filename: subdir-a.bst
+ config:
+ location: /
+- filename: c.bst
+ config:
+ location: /opt
+
+config:
+ action: ignore
diff --git a/tests/frontend/overlaps/multistage-overlap.bst b/tests/frontend/overlaps/multistage-overlap.bst
new file mode 100644
index 000000000..bf8984d5a
--- /dev/null
+++ b/tests/frontend/overlaps/multistage-overlap.bst
@@ -0,0 +1,12 @@
+kind: overlap
+
+build-depends:
+- filename: subdir-a.bst
+ config:
+ location: /
+- filename: c.bst
+ config:
+ location: /opt
+
+config:
+ action: warning
diff --git a/tests/frontend/overlaps/plugins/overlap.py b/tests/frontend/overlaps/plugins/overlap.py
new file mode 100644
index 000000000..b1d8642a2
--- /dev/null
+++ b/tests/frontend/overlaps/plugins/overlap.py
@@ -0,0 +1,56 @@
+from buildstream import Element, OverlapAction
+
+
+# A testing element to test the behavior of staging overlapping files
+#
+class OverlapElement(Element):
+
+ BST_MIN_VERSION = "2.0"
+
+ def configure(self, node):
+ node.validate_keys(["action"])
+ self.overlap_action = node.get_enum("action", OverlapAction)
+
+ def configure_dependencies(self, dependencies):
+ self.layout = {}
+
+ for dep in dependencies:
+ location = "/"
+ if dep.config:
+ dep.config.validate_keys(["location"])
+ location = dep.config.get_str("location")
+ try:
+ element_list = self.layout[location]
+ except KeyError:
+ element_list = []
+ self.layout[location] = element_list
+
+ element_list.append((dep.element, dep.path))
+
+ def preflight(self):
+ pass
+
+ def get_unique_key(self):
+ sorted_locations = sorted(self.layout)
+ layout_key = {
+ location: [dependency_path for _, dependency_path in self.layout[location]]
+ for location in sorted_locations
+ }
+ return {"action": str(self.overlap_action), "layout": layout_key}
+
+ def configure_sandbox(self, sandbox):
+ for location in self.layout:
+ sandbox.mark_directory(location, artifact=True)
+
+ def stage(self, sandbox):
+ sorted_locations = sorted(self.layout)
+ for location in sorted_locations:
+ element_list = [element for element, _ in self.layout[location]]
+ self.stage_dependency_artifacts(sandbox, element_list, path=location, action=self.overlap_action)
+
+ def assemble(self, sandbox):
+ return "/"
+
+
+def setup():
+ return OverlapElement
diff --git a/tests/frontend/overlaps/relocated-unstaged.bst b/tests/frontend/overlaps/relocated-unstaged.bst
new file mode 100644
index 000000000..65592a3dc
--- /dev/null
+++ b/tests/frontend/overlaps/relocated-unstaged.bst
@@ -0,0 +1,9 @@
+kind: overlap
+
+build-depends:
+- filename: directory-file.bst
+ config:
+ location: /opt
+
+config:
+ action: warning
diff --git a/tests/frontend/overlaps/relocated.bst b/tests/frontend/overlaps/relocated.bst
new file mode 100644
index 000000000..a7aea4f1f
--- /dev/null
+++ b/tests/frontend/overlaps/relocated.bst
@@ -0,0 +1,15 @@
+kind: overlap
+
+build-depends:
+- filename: a.bst
+ config:
+ location: /opt
+- filename: b.bst
+ config:
+ location: /opt
+- filename: c.bst
+ config:
+ location: /opt
+
+config:
+ action: warning
diff --git a/tests/frontend/overlaps/subdir-a.bst b/tests/frontend/overlaps/subdir-a.bst
new file mode 100644
index 000000000..b4da5b851
--- /dev/null
+++ b/tests/frontend/overlaps/subdir-a.bst
@@ -0,0 +1,7 @@
+kind: import
+config:
+ source: /
+ target: /opt
+sources:
+- kind: local
+ path: "a"