diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2018-03-12 13:12:30 +0100 |
---|---|---|
committer | Tristan Maat <tristan.maat@codethink.co.uk> | 2018-03-27 14:32:55 +0100 |
commit | a7ae93ce305c581d4129b91108c48b3624866d01 (patch) | |
tree | 5d2ad493d4ea487a1e5cee89f994a1e5ee530163 | |
parent | 989bb3fe000dc8c843b7a8293f9cf0a3293b8d39 (diff) | |
download | buildstream-a7ae93ce305c581d4129b91108c48b3624866d01.tar.gz |
integration/workspace.py: Add updated dependency tests
7 files changed, 265 insertions, 0 deletions
diff --git a/tests/integration/project/elements/workspace/workspace-updated-dependency-failed.bst b/tests/integration/project/elements/workspace/workspace-updated-dependency-failed.bst new file mode 100644 index 000000000..f05907cf5 --- /dev/null +++ b/tests/integration/project/elements/workspace/workspace-updated-dependency-failed.bst @@ -0,0 +1,17 @@ +kind: manual + +depends: + - base.bst + - workspace/dependency.bst + +sources: + - kind: local + path: files/workspace-updated-dependency-failed/ + +config: + build-commands: + - make + - chmod +x test.sh + - mkdir -p %{install-root}/usr/bin/ + - cp test.sh %{install-root}/usr/bin/ + - ls %{install-root} diff --git a/tests/integration/project/elements/workspace/workspace-updated-dependency-nested.bst b/tests/integration/project/elements/workspace/workspace-updated-dependency-nested.bst new file mode 100644 index 000000000..6ee770830 --- /dev/null +++ b/tests/integration/project/elements/workspace/workspace-updated-dependency-nested.bst @@ -0,0 +1,17 @@ +kind: manual + +depends: + - base.bst + - workspace/dependency.bst + +sources: + - kind: local + path: files/workspace-updated-dependency-nested/ + +config: + build-commands: + - make + - chmod +x test.sh + - mkdir -p %{install-root}/usr/bin/ + - cp test.sh %{install-root}/usr/bin/ + - ls %{install-root} diff --git a/tests/integration/project/elements/workspace/workspace-updated-dependency.bst b/tests/integration/project/elements/workspace/workspace-updated-dependency.bst new file mode 100644 index 000000000..0dcaacfbe --- /dev/null +++ b/tests/integration/project/elements/workspace/workspace-updated-dependency.bst @@ -0,0 +1,17 @@ +kind: manual + +depends: + - base.bst + - workspace/dependency.bst + +sources: + - kind: local + path: files/workspace-updated-dependency/ + +config: + build-commands: + - make + - chmod +x test.sh + - mkdir -p %{install-root}/usr/bin/ + - cp test.sh %{install-root}/usr/bin/ + - ls %{install-root} diff --git a/tests/integration/project/files/workspace-updated-dependency-failed/Makefile b/tests/integration/project/files/workspace-updated-dependency-failed/Makefile new file mode 100644 index 000000000..c7229d2d6 --- /dev/null +++ b/tests/integration/project/files/workspace-updated-dependency-failed/Makefile @@ -0,0 +1,13 @@ +all: test.sh + +hello: /etc/test/hello.txt + cp $^ $@ + +brazil: /etc/test/brazil.txt + cp $^ $@ + +test.sh: hello brazil + echo "#!/usr/bin/env sh" > $@ + echo -n "echo '" >> $@ + cat $^ >> $@ + echo -n "'" >> $@ diff --git a/tests/integration/project/files/workspace-updated-dependency-nested/Makefile b/tests/integration/project/files/workspace-updated-dependency-nested/Makefile new file mode 100644 index 000000000..5248a7043 --- /dev/null +++ b/tests/integration/project/files/workspace-updated-dependency-nested/Makefile @@ -0,0 +1,13 @@ +all: test.sh + +hello: /etc/test/hello.txt + cp $^ $@ + +tests: /etc/test/tests/*.txt + cp $^ $@ + +test.sh: hello tests + echo "#!/usr/bin/env sh" > $@ + echo -n "echo '" >> $@ + cat $^ >> $@ + echo -n "'" >> $@ diff --git a/tests/integration/project/files/workspace-updated-dependency/Makefile b/tests/integration/project/files/workspace-updated-dependency/Makefile new file mode 100644 index 000000000..935ef1854 --- /dev/null +++ b/tests/integration/project/files/workspace-updated-dependency/Makefile @@ -0,0 +1,5 @@ +test.sh: /etc/test/hello.txt + echo "#!/usr/bin/env sh" > $@ + echo -n "echo '" >> $@ + cat $^ >> $@ + echo -n "'" >> $@ diff --git a/tests/integration/workspace.py b/tests/integration/workspace.py index 26168341d..fcff58f08 100644 --- a/tests/integration/workspace.py +++ b/tests/integration/workspace.py @@ -1,6 +1,7 @@ import os import pytest +from buildstream import _yaml from tests.testutils import cli_integration as cli @@ -27,3 +28,185 @@ def test_workspace_mount(cli, tmpdir, datafiles): assert res.exit_code == 0 assert os.path.exists(os.path.join(cli.directory, 'workspace')) + + +@pytest.mark.integration +@pytest.mark.datafiles(DATA_DIR) +def test_workspace_updated_dependency(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + workspace = os.path.join(cli.directory, 'workspace') + element_path = os.path.join(project, 'elements') + element_name = 'workspace/workspace-updated-dependency.bst' + dep_name = 'workspace/dependency.bst' + + dependency = { + 'kind': 'manual', + 'depends': [{ + 'filename': 'base.bst', + 'type': 'build' + }], + 'config': { + 'build-commands': [ + 'mkdir -p %{install-root}/etc/test/', + 'echo "Hello world!" > %{install-root}/etc/test/hello.txt' + ] + } + } + os.makedirs(os.path.dirname(os.path.join(element_path, dep_name)), exist_ok=True) + _yaml.dump(dependency, os.path.join(element_path, dep_name)) + + # First open the workspace + res = cli.run(project=project, args=['workspace', 'open', element_name, workspace]) + assert res.exit_code == 0 + + # We build the workspaced element, so that we have an artifact + # with specific built dependencies + res = cli.run(project=project, args=['build', element_name]) + assert res.exit_code == 0 + + # Now we update a dependency of our element. + dependency['config']['build-commands'] = [ + 'mkdir -p %{install-root}/etc/test/', + 'echo "Hello china!" > %{install-root}/etc/test/hello.txt' + ] + _yaml.dump(dependency, os.path.join(element_path, dep_name)) + + # `Make` would look at timestamps and normally not realize that + # our dependency's header files changed. BuildStream must + # therefore ensure that we change the mtimes of any files touched + # since the last successful build of this element, otherwise this + # build will fail. + res = cli.run(project=project, args=['build', element_name]) + assert res.exit_code == 0 + + res = cli.run(project=project, args=['shell', element_name, '/usr/bin/test.sh']) + assert res.exit_code == 0 + assert res.output == 'Hello china!\n\n' + + +@pytest.mark.integration +@pytest.mark.datafiles(DATA_DIR) +def test_workspace_update_dependency_failed(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + workspace = os.path.join(cli.directory, 'workspace') + element_path = os.path.join(project, 'elements') + element_name = 'workspace/workspace-updated-dependency-failed.bst' + dep_name = 'workspace/dependency.bst' + + dependency = { + 'kind': 'manual', + 'depends': [{ + 'filename': 'base.bst', + 'type': 'build' + }], + 'config': { + 'build-commands': [ + 'mkdir -p %{install-root}/etc/test/', + 'echo "Hello world!" > %{install-root}/etc/test/hello.txt', + 'echo "Hello brazil!" > %{install-root}/etc/test/brazil.txt' + ] + } + } + os.makedirs(os.path.dirname(os.path.join(element_path, dep_name)), exist_ok=True) + _yaml.dump(dependency, os.path.join(element_path, dep_name)) + + # First open the workspace + res = cli.run(project=project, args=['workspace', 'open', element_name, workspace]) + assert res.exit_code == 0 + + # We build the workspaced element, so that we have an artifact + # with specific built dependencies + res = cli.run(project=project, args=['build', element_name]) + assert res.exit_code == 0 + + # Now we update a dependency of our element. + dependency['config']['build-commands'] = [ + 'mkdir -p %{install-root}/etc/test/', + 'echo "Hello china!" > %{install-root}/etc/test/hello.txt', + 'echo "Hello brazil!" > %{install-root}/etc/test/brazil.txt' + ] + _yaml.dump(dependency, os.path.join(element_path, dep_name)) + + # And our build fails! + with open(os.path.join(workspace, 'Makefile'), 'a') as f: + f.write("\texit 1") + + res = cli.run(project=project, args=['build', element_name]) + assert res.exit_code != 0 + + # We update our dependency again... + dependency['config']['build-commands'] = [ + 'mkdir -p %{install-root}/etc/test/', + 'echo "Hello world!" > %{install-root}/etc/test/hello.txt', + 'echo "Hello spain!" > %{install-root}/etc/test/brazil.txt' + ] + _yaml.dump(dependency, os.path.join(element_path, dep_name)) + + # And fix the source + with open(os.path.join(workspace, 'Makefile'), 'r') as f: + makefile = f.readlines() + with open(os.path.join(workspace, 'Makefile'), 'w') as f: + f.write("\n".join(makefile[:-1])) + + # Since buildstream thinks hello.txt did not change, we could end + # up not rebuilding a file! We need to make sure that a case like + # this can't blind-side us. + res = cli.run(project=project, args=['build', element_name]) + assert res.exit_code == 0 + + res = cli.run(project=project, args=['shell', element_name, '/usr/bin/test.sh']) + assert res.exit_code == 0 + assert res.output == 'Hello world!\nHello spain!\n\n' + + +@pytest.mark.integration +@pytest.mark.datafiles(DATA_DIR) +def test_updated_dependency_nested(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + workspace = os.path.join(cli.directory, 'workspace') + element_path = os.path.join(project, 'elements') + element_name = 'workspace/workspace-updated-dependency-nested.bst' + dep_name = 'workspace/dependency.bst' + + dependency = { + 'kind': 'manual', + 'depends': [{ + 'filename': 'base.bst', + 'type': 'build' + }], + 'config': { + 'build-commands': [ + 'mkdir -p %{install-root}/etc/test/tests/', + 'echo "Hello world!" > %{install-root}/etc/test/hello.txt', + 'echo "Hello brazil!" > %{install-root}/etc/test/tests/brazil.txt' + ] + } + } + os.makedirs(os.path.dirname(os.path.join(element_path, dep_name)), exist_ok=True) + _yaml.dump(dependency, os.path.join(element_path, dep_name)) + + # First open the workspace + res = cli.run(project=project, args=['workspace', 'open', element_name, workspace]) + assert res.exit_code == 0 + + # We build the workspaced element, so that we have an artifact + # with specific built dependencies + res = cli.run(project=project, args=['build', element_name]) + assert res.exit_code == 0 + + # Now we update a dependency of our element. + dependency['config']['build-commands'] = [ + 'mkdir -p %{install-root}/etc/test/tests/', + 'echo "Hello world!" > %{install-root}/etc/test/hello.txt', + 'echo "Hello test!" > %{install-root}/etc/test/tests/tests.txt' + ] + _yaml.dump(dependency, os.path.join(element_path, dep_name)) + + res = cli.run(project=project, args=['build', element_name]) + assert res.exit_code == 0 + + # Buildstream should pick up the newly added element, and pick up + # the lack of the newly removed element + res = cli.run(project=project, args=['shell', element_name, '/usr/bin/test.sh']) + assert res.exit_code == 0 + assert res.output == 'Hello world!\nHello test!\n\n' |