This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/buildstream-plugins.git
commit 9de643f3b6887519ec893c38aa675c56eecd0d22 Author: Tristan van Berkom <[email protected]> AuthorDate: Mon Mar 21 15:54:00 2022 +0900 tests/elements/cmake.py: Adding cmake element test --- tests/elements/cmake.py | 67 +++++++++++++++++++++ tests/elements/cmake/elements/base.bst | 6 ++ .../elements/cmake/elements/base/alpine-image.bst | 6 ++ .../cmake/elements/base/base-configure.bst | 28 +++++++++ .../elements/cmake/elements/base/install-dpkg.bst | 15 +++++ tests/elements/cmake/elements/base/ninja.bst | 15 +++++ .../elements/cmake/elements/cmakeconfroothello.bst | 15 +++++ tests/elements/cmake/elements/cmakehello.bst | 10 +++ tests/elements/cmake/files/cmakehello.tar.gz | Bin 0 -> 10240 bytes tests/elements/cmake/project.conf | 15 +++++ 10 files changed, 177 insertions(+) diff --git a/tests/elements/cmake.py b/tests/elements/cmake.py new file mode 100644 index 0000000..a409ac1 --- /dev/null +++ b/tests/elements/cmake.py @@ -0,0 +1,67 @@ +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os +import pytest + +from buildstream._testing.runcli import cli_integration as cli # pylint: disable=unused-import +from buildstream._testing.integration import integration_cache # pylint: disable=unused-import +from buildstream._testing.integration import assert_contains +from buildstream._testing._utils.site import HAVE_SANDBOX + +pytestmark = pytest.mark.integration + + +DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "cmake") + + [email protected](DATA_DIR) [email protected](not HAVE_SANDBOX, reason="Only available with a functioning sandbox") +def test_cmake_build(cli, datafiles): + project = str(datafiles) + checkout = os.path.join(cli.directory, "checkout") + element_name = "cmakehello.bst" + + result = cli.run(project=project, args=["build", element_name]) + assert result.exit_code == 0 + + result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkout],) + assert result.exit_code == 0 + + assert_contains(checkout, ["/usr", "/usr/bin", "/usr/bin/hello"]) + + [email protected](DATA_DIR) [email protected](not HAVE_SANDBOX, reason="Only available with a functioning sandbox") +def test_cmake_confroot_build(cli, datafiles): + project = str(datafiles) + checkout = os.path.join(cli.directory, "checkout") + element_name = "cmakeconfroothello.bst" + + result = cli.run(project=project, args=["build", element_name]) + assert result.exit_code == 0 + + result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkout],) + assert result.exit_code == 0 + + assert_contains(checkout, ["/usr", "/usr/bin", "/usr/bin/hello"]) + + [email protected](DATA_DIR) [email protected](not HAVE_SANDBOX, reason="Only available with a functioning sandbox") +def test_cmake_run(cli, datafiles): + project = str(datafiles) + element_name = "cmakehello.bst" + + result = cli.run(project=project, args=["build", element_name]) + assert result.exit_code == 0 + + result = cli.run(project=project, args=["shell", element_name, "/usr/bin/hello"]) + assert result.exit_code == 0 + + assert ( + result.output + == """Hello World! +This is hello. +""" + ) diff --git a/tests/elements/cmake/elements/base.bst b/tests/elements/cmake/elements/base.bst new file mode 100644 index 0000000..5907dd5 --- /dev/null +++ b/tests/elements/cmake/elements/base.bst @@ -0,0 +1,6 @@ +kind: stack +depends: +- base/install-dpkg.bst +- base/base-configure.bst +- base/alpine-image.bst +- base/ninja.bst diff --git a/tests/elements/cmake/elements/base/alpine-image.bst b/tests/elements/cmake/elements/base/alpine-image.bst new file mode 100644 index 0000000..f8e00ba --- /dev/null +++ b/tests/elements/cmake/elements/base/alpine-image.bst @@ -0,0 +1,6 @@ +kind: import +description: Import an alpine image as the platform +sources: +- kind: tar + url: alpine:integration-tests-base.v1.x86_64.tar.xz + ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639 diff --git a/tests/elements/cmake/elements/base/base-configure.bst b/tests/elements/cmake/elements/base/base-configure.bst new file mode 100644 index 0000000..5323004 --- /dev/null +++ b/tests/elements/cmake/elements/base/base-configure.bst @@ -0,0 +1,28 @@ +kind: script +depends: +- filename: base/install-dpkg.bst + type: build + +variables: + install-root: / + +config: + + commands: + - | + # Avoid some chowns which fail at dpkg configure time + # + mv /bin/chown /bin/chown.real + ln -s true /bin/chown + + - | + # This is expected to fail, but will configure everything we need + # at least for the purpose of building, other dpkg scripts which + # require real root privileges will always fail here. + DEBIAN_FRONTEND=noninteractive dpkg --configure -a --abort-after=100000 || exit 0 + + - | + # Restore chown + # + rm -f /bin/chown + mv /bin/chown.real /bin/chown diff --git a/tests/elements/cmake/elements/base/install-dpkg.bst b/tests/elements/cmake/elements/base/install-dpkg.bst new file mode 100644 index 0000000..858044a --- /dev/null +++ b/tests/elements/cmake/elements/base/install-dpkg.bst @@ -0,0 +1,15 @@ +kind: manual +depends: +- filename: base/alpine-image.bst + type: build +sources: +- kind: git + url: https://gitlab.com/BuildStream/buildstream-sysroots.git + track: dpkg-build + ref: ecf14954e4298ce5495f701464339162fad73f30 +config: + install-commands: + - tar xf dpkg-build-sysroot.tar.xz -C %{install-root} --no-same-owner + strip-commands: + # For some reason, the strip commands were hanging... + - echo "none" diff --git a/tests/elements/cmake/elements/base/ninja.bst b/tests/elements/cmake/elements/base/ninja.bst new file mode 100644 index 0000000..74afb16 --- /dev/null +++ b/tests/elements/cmake/elements/base/ninja.bst @@ -0,0 +1,15 @@ +kind: manual + +depends: +- filename: base/alpine-image.bst + +config: + install-commands: + - | + install -D -m 0755 ninja %{install-root}%{bindir}/ninja + +sources: +- kind: zip + url: https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip + ref: 1b1235f2b0b4df55ac6d80bbe681ea3639c9d2c505c7ff2159a3daf63d196305 + base-dir: '' diff --git a/tests/elements/cmake/elements/cmakeconfroothello.bst b/tests/elements/cmake/elements/cmakeconfroothello.bst new file mode 100644 index 0000000..cd33dee --- /dev/null +++ b/tests/elements/cmake/elements/cmakeconfroothello.bst @@ -0,0 +1,15 @@ +kind: cmake +description: Cmake test + +depends: + - base.bst + +sources: + - kind: tar + directory: Source + url: project_dir:/files/cmakehello.tar.gz + ref: 508266f40dbc5875293bd24c4e50a9eb6b88cbacab742033f7b92f8c087b64e5 + +variables: + conf-root: "%{build-root}/Source" + command-subdir: build diff --git a/tests/elements/cmake/elements/cmakehello.bst b/tests/elements/cmake/elements/cmakehello.bst new file mode 100644 index 0000000..c5fe496 --- /dev/null +++ b/tests/elements/cmake/elements/cmakehello.bst @@ -0,0 +1,10 @@ +kind: cmake +description: Cmake test + +depends: + - base.bst + +sources: + - kind: tar + url: project_dir:/files/cmakehello.tar.gz + ref: 508266f40dbc5875293bd24c4e50a9eb6b88cbacab742033f7b92f8c087b64e5 diff --git a/tests/elements/cmake/files/cmakehello.tar.gz b/tests/elements/cmake/files/cmakehello.tar.gz new file mode 100644 index 0000000..54d9505 Binary files /dev/null and b/tests/elements/cmake/files/cmakehello.tar.gz differ diff --git a/tests/elements/cmake/project.conf b/tests/elements/cmake/project.conf new file mode 100644 index 0000000..bdcf99b --- /dev/null +++ b/tests/elements/cmake/project.conf @@ -0,0 +1,15 @@ +# test project config +name: test +min-version: 2.0 + +element-path: elements + +plugins: +- origin: pip + package-name: buildstream-plugins + elements: + - cmake + +aliases: + alpine: https://bst-integration-test-images.ams3.cdn.digitaloceanspaces.com/ + project_dir: file://{project_dir}
