summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-02-06 09:57:19 +0100
committerJürg Billeter <j@bitron.ch>2020-02-11 21:08:59 +0100
commit6cd3add40c3e081af0b066542eac316af11184b0 (patch)
tree22110135c1d71a57834da1a6dda6ffc126c19e74
parentec7fb6e04dfc8f0d4c3e067ae8e39f19076cdc72 (diff)
downloadbuildstream-6cd3add40c3e081af0b066542eac316af11184b0.tar.gz
tests/integration/workspace.py: Test incremental build after failure
-rw-r--r--tests/integration/project/files/workspace-partial/Makefile10
-rw-r--r--tests/integration/project/files/workspace-partial/source11
-rw-r--r--tests/integration/project/files/workspace-partial/source21
-rw-r--r--tests/integration/workspace.py62
4 files changed, 74 insertions, 0 deletions
diff --git a/tests/integration/project/files/workspace-partial/Makefile b/tests/integration/project/files/workspace-partial/Makefile
new file mode 100644
index 000000000..1b3683b0d
--- /dev/null
+++ b/tests/integration/project/files/workspace-partial/Makefile
@@ -0,0 +1,10 @@
+all: copy1 copy2
+
+random:
+ dd if=/dev/urandom count=8 | sha256sum > random
+
+copy1: source1
+ cp source1 copy1
+
+copy2: source2
+ cp source2 copy2
diff --git a/tests/integration/project/files/workspace-partial/source1 b/tests/integration/project/files/workspace-partial/source1
new file mode 100644
index 000000000..56a6051ca
--- /dev/null
+++ b/tests/integration/project/files/workspace-partial/source1
@@ -0,0 +1 @@
+1 \ No newline at end of file
diff --git a/tests/integration/project/files/workspace-partial/source2 b/tests/integration/project/files/workspace-partial/source2
new file mode 100644
index 000000000..56a6051ca
--- /dev/null
+++ b/tests/integration/project/files/workspace-partial/source2
@@ -0,0 +1 @@
+1 \ No newline at end of file
diff --git a/tests/integration/workspace.py b/tests/integration/workspace.py
index b94b87f1c..a2ea4841a 100644
--- a/tests/integration/workspace.py
+++ b/tests/integration/workspace.py
@@ -452,3 +452,65 @@ def test_incremental(cli, datafiles):
# Verify that the output file still matches the previous content '2'
assert get_buildtree_file_contents(cli, project, element_name, "copy") == "2"
+
+
+# Test incremental build after partial build / build failure
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
+def test_incremental_partial(cli, datafiles):
+ project = str(datafiles)
+ workspace = os.path.join(cli.directory, "workspace")
+ element_path = os.path.join(project, "elements")
+ element_name = "workspace/incremental.bst"
+
+ element = {
+ "kind": "manual",
+ "depends": [{"filename": "base.bst", "type": "build"}],
+ "sources": [{"kind": "local", "path": "files/workspace-partial"}],
+ "config": {"build-commands": ["make random", "make copy1", "make copy2"]},
+ }
+ _yaml.roundtrip_dump(element, os.path.join(element_path, element_name))
+
+ # We open a workspace on the above element
+ res = cli.run(project=project, args=["workspace", "open", "--directory", workspace, element_name])
+ res.assert_success()
+
+ # Initial (non-incremental) build of the workspace
+ res = cli.run(project=project, args=["build", element_name])
+ res.assert_success()
+
+ # Save the random hash
+ random_hash = get_buildtree_file_contents(cli, project, element_name, "random")
+
+ # Verify the expected output files of the initial build
+ assert get_buildtree_file_contents(cli, project, element_name, "copy1") == "1"
+ assert get_buildtree_file_contents(cli, project, element_name, "copy2") == "1"
+
+ wait_for_cache_granularity()
+
+ # Delete source1 and replace source2 file contents with '2'
+ os.unlink(os.path.join(workspace, "source1"))
+ with open(os.path.join(workspace, "source2"), "w") as f:
+ f.write("2")
+
+ # Perform incremental build of the workspace
+ # This should fail because of the missing source1 file.
+ res = cli.run(project=project, args=["build", element_name])
+ res.assert_main_error(ErrorDomain.STREAM, None)
+
+ wait_for_cache_granularity()
+
+ # Recreate source1 file
+ with open(os.path.join(workspace, "source1"), "w") as f:
+ f.write("2")
+
+ # Perform incremental build of the workspace
+ res = cli.run(project=project, args=["build", element_name])
+ res.assert_success()
+
+ # Verify that this was an incremental build by comparing the random hash
+ assert get_buildtree_file_contents(cli, project, element_name, "random") == random_hash
+
+ # Verify that both files got rebuilt
+ assert get_buildtree_file_contents(cli, project, element_name, "copy1") == "2"
+ assert get_buildtree_file_contents(cli, project, element_name, "copy2") == "2"