diff options
author | Jürg Billeter <j@bitron.ch> | 2020-01-29 09:33:32 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-02-11 21:08:59 +0100 |
commit | ec7fb6e04dfc8f0d4c3e067ae8e39f19076cdc72 (patch) | |
tree | c08dde0ebc1827a90aeb8f1bfff0eea03bf9db7d | |
parent | e85ecc801b9da2cd43866d0779b7e89da0a1a690 (diff) | |
download | buildstream-ec7fb6e04dfc8f0d4c3e067ae8e39f19076cdc72.tar.gz |
tests/integration/workspace.py: Add incremental build test
Verify basic incremental build and proper mtime handling.
-rw-r--r-- | tests/integration/project/files/workspace-incremental/Makefile | 7 | ||||
-rw-r--r-- | tests/integration/project/files/workspace-incremental/source | 1 | ||||
-rw-r--r-- | tests/integration/workspace.py | 76 |
3 files changed, 84 insertions, 0 deletions
diff --git a/tests/integration/project/files/workspace-incremental/Makefile b/tests/integration/project/files/workspace-incremental/Makefile new file mode 100644 index 000000000..18333fd46 --- /dev/null +++ b/tests/integration/project/files/workspace-incremental/Makefile @@ -0,0 +1,7 @@ +all: random copy + +random: + dd if=/dev/urandom count=8 | sha256sum > random + +copy: source + cp source copy diff --git a/tests/integration/project/files/workspace-incremental/source b/tests/integration/project/files/workspace-incremental/source new file mode 100644 index 000000000..56a6051ca --- /dev/null +++ b/tests/integration/project/files/workspace-incremental/source @@ -0,0 +1 @@ +1
\ No newline at end of file diff --git a/tests/integration/workspace.py b/tests/integration/workspace.py index d0608f450..b94b87f1c 100644 --- a/tests/integration/workspace.py +++ b/tests/integration/workspace.py @@ -8,6 +8,9 @@ from buildstream import _yaml from buildstream.testing import cli_integration as cli # pylint: disable=unused-import from buildstream.testing._utils.site import HAVE_SANDBOX from buildstream.exceptions import ErrorDomain +from buildstream.utils import BST_ARBITRARY_TIMESTAMP + +from tests.testutils import wait_for_cache_granularity pytestmark = pytest.mark.integration @@ -376,3 +379,76 @@ def test_workspace_failed_logs(cli, datafiles): fail_str = "FAILURE {}: Running build-commands".format(element_name) batch_fail_str = "FAILURE {}: Running commands".format(element_name) assert fail_str in log or batch_fail_str in log + + +def get_buildtree_file_contents(cli, project, element_name, filename): + res = cli.run( + project=project, args=["shell", "--build", element_name, "--use-buildtree", "always", "--", "cat", filename,], + ) + res.assert_success() + return res.output + + +@pytest.mark.datafiles(DATA_DIR) +@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox") +def test_incremental(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-incremental"}], + "config": {"build-commands": ["make"]}, + } + _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 file of the initial build + assert get_buildtree_file_contents(cli, project, element_name, "copy") == "1" + + wait_for_cache_granularity() + + # Replace source file contents with '2' + with open(os.path.join(workspace, "source"), "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 the output file matches the new source file + assert get_buildtree_file_contents(cli, project, element_name, "copy") == "2" + + wait_for_cache_granularity() + + # Replace source file contents with '3', however, set an old mtime such + # that `make` will not pick up the change + with open(os.path.join(workspace, "source"), "w") as f: + f.write("3") + os.utime(os.path.join(workspace, "source"), (BST_ARBITRARY_TIMESTAMP, BST_ARBITRARY_TIMESTAMP)) + + # 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 the output file still matches the previous content '2' + assert get_buildtree_file_contents(cli, project, element_name, "copy") == "2" |