diff options
author | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2019-07-01 13:20:59 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-12 17:39:08 +0000 |
commit | 817e553b69fe4ed33dd6260a2809ca94e1edc843 (patch) | |
tree | cb89cbb321efd43f646734bb4ac3eebc575d696f | |
parent | 8d485588f69365288441978faec046ec89717fcc (diff) | |
download | buildstream-817e553b69fe4ed33dd6260a2809ca94e1edc843.tar.gz |
tests: Add remote execution junction test
Part of #994
7 files changed, 186 insertions, 0 deletions
diff --git a/tests/remoteexecution/junction.py b/tests/remoteexecution/junction.py new file mode 100644 index 000000000..8130e4c7c --- /dev/null +++ b/tests/remoteexecution/junction.py @@ -0,0 +1,116 @@ +# +# Copyright (C) 2019 Bloomberg Finance LP +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. +# + +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os +import pytest +from buildstream.testing import cli_remote_execution as cli # pylint: disable=unused-import +from buildstream.testing import create_repo +from buildstream import _yaml +from tests.testutils import generate_junction + +pytestmark = pytest.mark.remoteexecution + +# Project directory +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "project", +) + + +def configure_project(path, config): + config['name'] = 'test' + config['element-path'] = 'elements' + _yaml.dump(config, os.path.join(path, 'project.conf')) + + +def create_element(repo, name, path, dependencies, ref=None): + element = { + 'kind': 'import', + 'sources': [ + repo.source_config(ref=ref) + ], + 'depends': dependencies + } + _yaml.dump(element, os.path.join(path, name)) + + +@pytest.mark.datafiles(DATA_DIR) +def test_junction_build_remote(cli, tmpdir, datafiles): + project = str(datafiles) + subproject_path = os.path.join(project, 'files', 'sub-project') + subproject_element_path = os.path.join(subproject_path, 'elements') + amhello_files_path = os.path.join(subproject_path, 'files') + element_path = os.path.join(project, 'elements') + junction_path = os.path.join(element_path, 'junction.bst') + + # We need a repo for real trackable elements + repo = create_repo('git', str(tmpdir)) + ref = repo.create(amhello_files_path) + + # ensure that the correct project directory is also listed in the junction + subproject_conf = os.path.join(subproject_path, 'project.conf') + with open(subproject_conf) as f: + config = f.read() + config = config.format(project_dir=subproject_path) + with open(subproject_conf, 'w') as f: + f.write(config) + + # Create a trackable element to depend on the cross junction element, + # this one has it's ref resolved already + create_element(repo, 'sub-target.bst', subproject_element_path, ['autotools/amhello.bst'], ref=ref) + + # Create a trackable element to depend on the cross junction element + create_element(repo, 'target.bst', element_path, [ + { + 'junction': 'junction.bst', + 'filename': 'sub-target.bst' + } + ]) + + # Create a repo to hold the subproject and generate a junction element for it + generate_junction(tmpdir, subproject_path, junction_path, store_ref=False) + + # Now create a compose element at the top level + element = { + 'kind': 'compose', + 'depends': [ + { + 'filename': 'target.bst', + 'type': 'build' + } + ] + } + _yaml.dump(element, os.path.join(element_path, 'composed.bst')) + + # We're doing remote execution so ensure services are available + services = cli.ensure_services() + assert set(services) == set(['action-cache', 'execution', 'storage']) + + # track the junction first to ensure we have refs + result = cli.run(project=project, args=['source', 'track', 'junction.bst']) + result.assert_success() + + # Build it with --track-all + result = cli.run(project=project, silent=True, args=[ + 'build', '--track-all', 'composed.bst']) + result.assert_success() + + # Assert that the main target is cached as a result + assert cli.get_element_state(project, 'composed.bst') == 'cached' diff --git a/tests/remoteexecution/project/files/dev-files/usr/include/pony.h b/tests/remoteexecution/project/files/dev-files/usr/include/pony.h new file mode 100644 index 000000000..40bd0c2e7 --- /dev/null +++ b/tests/remoteexecution/project/files/dev-files/usr/include/pony.h @@ -0,0 +1,12 @@ +#ifndef __PONY_H__ +#define __PONY_H__ + +#define PONY_BEGIN "Once upon a time, there was a pony." +#define PONY_END "And they lived happily ever after, the end." + +#define MAKE_PONY(story) \ + PONY_BEGIN \ + story \ + PONY_END + +#endif /* __PONY_H__ */ diff --git a/tests/remoteexecution/project/files/sub-project/elements/autotools/amhello.bst b/tests/remoteexecution/project/files/sub-project/elements/autotools/amhello.bst new file mode 100644 index 000000000..ee3a029d8 --- /dev/null +++ b/tests/remoteexecution/project/files/sub-project/elements/autotools/amhello.bst @@ -0,0 +1,10 @@ +kind: autotools +description: Autotools test + +depends: +- base.bst + +sources: +- kind: tar + url: project_dir:/files/amhello.tar.gz + ref: 9ba123fa4e660929e9a0aa99f0c487b7eee59c5e7594f3284d015640b90f5590 diff --git a/tests/remoteexecution/project/files/sub-project/elements/base.bst b/tests/remoteexecution/project/files/sub-project/elements/base.bst new file mode 100644 index 000000000..428afa736 --- /dev/null +++ b/tests/remoteexecution/project/files/sub-project/elements/base.bst @@ -0,0 +1,5 @@ +# elements/base.bst + +kind: stack +depends: + - base/base-alpine.bst diff --git a/tests/remoteexecution/project/files/sub-project/elements/base/base-alpine.bst b/tests/remoteexecution/project/files/sub-project/elements/base/base-alpine.bst new file mode 100644 index 000000000..c5833095d --- /dev/null +++ b/tests/remoteexecution/project/files/sub-project/elements/base/base-alpine.bst @@ -0,0 +1,17 @@ +kind: import + +description: | + Alpine Linux base for tests + + Generated using the `tests/integration-tests/base/generate-base.sh` script. + +sources: + - kind: tar + base-dir: '' + (?): + - arch == "x86-64": + ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639 + url: "alpine:integration-tests-base.v1.x86_64.tar.xz" + - arch == "aarch64": + ref: 431fb5362032ede6f172e70a3258354a8fd71fcbdeb1edebc0e20968c792329a + url: "alpine:integration-tests-base.v1.aarch64.tar.xz" diff --git a/tests/remoteexecution/project/files/sub-project/files/amhello.tar.gz b/tests/remoteexecution/project/files/sub-project/files/amhello.tar.gz Binary files differnew file mode 100644 index 000000000..afe189908 --- /dev/null +++ b/tests/remoteexecution/project/files/sub-project/files/amhello.tar.gz diff --git a/tests/remoteexecution/project/files/sub-project/project.conf b/tests/remoteexecution/project/files/sub-project/project.conf new file mode 100644 index 000000000..c4d876cc2 --- /dev/null +++ b/tests/remoteexecution/project/files/sub-project/project.conf @@ -0,0 +1,26 @@ +# Project config for frontend build test +name: subtest + +element-path: elements + +aliases: + alpine: https://bst-integration-test-images.ams3.cdn.digitaloceanspaces.com/ + project_dir: file://{project_dir} + +options: + linux: + type: bool + description: Whether to expect a linux platform + default: True + arch: + type: arch + description: Current architecture + values: + - x86-64 + - aarch64 +split-rules: + test: + - | + /tests + - | + /tests/* |