summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2018-10-09 16:36:08 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2018-11-08 17:35:00 +0000
commit06cfa0c665149f9cbc8a956026e7a8fcd052a9ad (patch)
tree9b3f3e601af34087ea3f2f83f3e166d5acd09993
parentfea2f55c412de9bccdfd93fcba1ea9dbd4b270da (diff)
downloadbuildstream-richardmaw/distinguish-sandboxing-build-fail.tar.gz
tests/integration/sandbox-bwrap.py: Test distinguishing sandbox exit code from commandrichardmaw/distinguish-sandboxing-build-fail
-rw-r--r--tests/integration/project/elements/sandbox-bwrap/break-shell.bst9
-rw-r--r--tests/integration/project/elements/sandbox-bwrap/command-exit-42.bst8
-rw-r--r--tests/integration/project/elements/sandbox-bwrap/non-executable-shell.bst9
-rw-r--r--tests/integration/sandbox-bwrap.py33
4 files changed, 58 insertions, 1 deletions
diff --git a/tests/integration/project/elements/sandbox-bwrap/break-shell.bst b/tests/integration/project/elements/sandbox-bwrap/break-shell.bst
new file mode 100644
index 000000000..c93a92350
--- /dev/null
+++ b/tests/integration/project/elements/sandbox-bwrap/break-shell.bst
@@ -0,0 +1,9 @@
+kind: manual
+depends:
+ - base/base-alpine.bst
+
+public:
+ bst:
+ integration-commands:
+ - |
+ chmod a-x /bin/sh
diff --git a/tests/integration/project/elements/sandbox-bwrap/command-exit-42.bst b/tests/integration/project/elements/sandbox-bwrap/command-exit-42.bst
new file mode 100644
index 000000000..c633334ae
--- /dev/null
+++ b/tests/integration/project/elements/sandbox-bwrap/command-exit-42.bst
@@ -0,0 +1,8 @@
+kind: manual
+depends:
+ - base/base-alpine.bst
+
+config:
+ build-commands:
+ - |
+ exit 42
diff --git a/tests/integration/project/elements/sandbox-bwrap/non-executable-shell.bst b/tests/integration/project/elements/sandbox-bwrap/non-executable-shell.bst
new file mode 100644
index 000000000..a57177bb3
--- /dev/null
+++ b/tests/integration/project/elements/sandbox-bwrap/non-executable-shell.bst
@@ -0,0 +1,9 @@
+kind: manual
+
+depends:
+ - sandbox-bwrap/break-shell.bst
+
+config:
+ build-commands:
+ - |
+ exit 42
diff --git a/tests/integration/sandbox-bwrap.py b/tests/integration/sandbox-bwrap.py
index 7d2a18498..d2484bc17 100644
--- a/tests/integration/sandbox-bwrap.py
+++ b/tests/integration/sandbox-bwrap.py
@@ -1,9 +1,11 @@
import os
import pytest
+from buildstream._exceptions import ErrorDomain
+
from tests.testutils import cli_integration as cli
from tests.testutils.integration import assert_contains
-from tests.testutils.site import HAVE_BWRAP
+from tests.testutils.site import HAVE_BWRAP, HAVE_BWRAP_JSON_STATUS
pytestmark = pytest.mark.integration
@@ -29,3 +31,32 @@ def test_sandbox_bwrap_cleanup_build(cli, tmpdir, datafiles):
# Here, BuildStream should not attempt any rmdir etc.
result = cli.run(project=project, args=['build', element_name])
assert result.exit_code == 0
+
+
+@pytest.mark.skipif(not HAVE_BWRAP, reason='Only available with bubblewrap')
+@pytest.mark.skipif(not HAVE_BWRAP_JSON_STATUS, reason='Only available with bubblewrap supporting --json-status-fd')
+@pytest.mark.datafiles(DATA_DIR)
+def test_sandbox_bwrap_distinguish_setup_error(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ element_name = 'sandbox-bwrap/non-executable-shell.bst'
+
+ result = cli.run(project=project, args=['build', element_name])
+ result.assert_task_error(error_domain=ErrorDomain.SANDBOX, error_reason="bwrap-sandbox-fail")
+
+
+@pytest.mark.integration
+@pytest.mark.skipif(not HAVE_BWRAP, reason='Only available with bubblewrap')
+@pytest.mark.datafiles(DATA_DIR)
+def test_sandbox_bwrap_return_subprocess(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ element_name = 'sandbox-bwrap/command-exit-42.bst'
+
+ cli.configure({
+ "logging": {
+ "message-format": "%{element}|%{message}",
+ },
+ })
+
+ result = cli.run(project=project, args=['build', element_name])
+ result.assert_task_error(error_domain=ErrorDomain.ELEMENT, error_reason=None)
+ assert "sandbox-bwrap/command-exit-42.bst|Command 'exit 42' failed with exitcode 42" in result.stderr