summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2018-01-17 17:54:26 +0000
committerJürg Billeter <j@bitron.ch>2018-02-13 06:40:44 +0100
commitfc682d8c2539937d41f5e63acfc210319c77a328 (patch)
tree0549c8fabea49f4e56dd12975135469ff19e069f
parent27287513156120b56ec1d56b8a455f411fe2d84b (diff)
downloadbuildstream-sam/integration-tests-alpine.tar.gz
tests/integration: Use a minimal custom base sysrootsam/integration-tests-alpine
We have been using the Freedesktop SDK binaries to provide a base system to run the integration tests. This works OK but it weighs in at 985MB of content, and there is no simple way to customize it so that we only download the bits we actually need. This commit changes the tests to use a custom sysroot based on the Alpine Linux distribution. The sysroot is 155MB unpacked, and packs down to a 27MB .tar.xz. This speeds up the integration tests significantly as we greatly reduce the amount of network traffic required and the amount of data that gets copied around when creating the staging area.
-rwxr-xr-xtests/integration/base/generate-base.sh67
-rw-r--r--tests/integration/pip.py2
-rw-r--r--tests/integration/project/elements/base.bst3
-rw-r--r--tests/integration/project/elements/base/base-alpine.bst12
-rw-r--r--tests/integration/project/elements/base/base-sdk.bst18
-rw-r--r--tests/integration/project/elements/base/usermerge.bst6
-rw-r--r--tests/integration/project/files/usrmerge.tar.xzbin232 -> 0 bytes
-rw-r--r--tests/integration/script.py2
-rw-r--r--tests/integration/shell.py2
9 files changed, 83 insertions, 29 deletions
diff --git a/tests/integration/base/generate-base.sh b/tests/integration/base/generate-base.sh
new file mode 100755
index 000000000..433f36ea5
--- /dev/null
+++ b/tests/integration/base/generate-base.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+# Generate a base sysroot for running the BuildStream integration tests.
+#
+# The sysroot is based off the Alpine Linux distribution. The script downloads
+# a release of Alpine, sets up a cheap consider using `bwrap` and installs the
+# packages that are needed by the integration tests, then outputs a .tar.xz
+# file.
+
+set -eux
+
+ALPINE_ARCH=${ARCH:-x86_64}
+ALPINE_BASE=http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/${ALPINE_ARCH}/alpine-minirootfs-3.7.0-${ALPINE_ARCH}.tar.gz
+
+mkdir root
+
+wget ${ALPINE_BASE} -O alpine-base.tar.gz
+
+tar -x -f ./alpine-base.tar.gz -C ./root --exclude dev/\*
+
+run() {
+ # This turns the unpacked rootfs into a container using Bubblewrap.
+ # The Alpine package manager (apk) calls `chroot` when running package
+ # triggers so we need to enable CAP_SYS_CHROOT. We also have to fake
+ # UID 0 (root) inside the container to avoid permissions errors.
+ bwrap --bind ./root / --dev /dev --proc /proc --tmpfs /tmp \
+ --ro-bind /etc/resolv.conf /etc/resolv.conf \
+ --setenv PATH "/usr/bin:/usr/sbin:/bin:/sbin" \
+ --unshare-user --uid 0 --gid 0 \
+ --cap-add CAP_SYS_CHROOT \
+ /bin/sh -c "$@"
+}
+
+# Enable testing repo for Tiny C Compiler package
+run "echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories"
+
+# Fetch the list of Alpine packages.
+run "apk update"
+
+# There are various random errors from `apk add` to do with ownership, probably
+# because of our hacked up `bwrap` container. The errors seem harmless so I am
+# just ignoring them.
+set +e
+
+# Install stuff needed by all integration tests that compile C code.
+#
+# Note that we use Tiny C Compiler in preference to GCC. There is a huge
+# size difference -- 600KB for TinyCC vs. 50MB to 100MB for GCC. TinyCC
+# supports most of the ISO C99 standard, but has no C++ support at all.
+run "apk add binutils libc-dev make tcc"
+run "ln -s /usr/bin/tcc /usr/bin/cc"
+
+# Install stuff for tests/integration/autotools
+run "apk add autoconf automake"
+
+# Install stuff for tests/integration/cmake
+run "apk add cmake"
+
+# Install stuff for tests/integration/pip
+run "apk add python3"
+
+set -e
+
+# Cleanup the package cache
+run "rm -R /var/cache/apk"
+
+tar -c -v -J -f integration-tests-base.tar.xz -C root .
diff --git a/tests/integration/pip.py b/tests/integration/pip.py
index 6471bd242..6c6de8bf8 100644
--- a/tests/integration/pip.py
+++ b/tests/integration/pip.py
@@ -49,7 +49,7 @@ def test_pip_build(cli, tmpdir, datafiles):
assert result.exit_code == 0
assert_contains(checkout, ['/usr', '/usr/lib', '/usr/bin',
- '/usr/bin/hello', '/usr/lib/python3.5'])
+ '/usr/bin/hello', '/usr/lib/python3.6'])
# Test running an executable built with pip
diff --git a/tests/integration/project/elements/base.bst b/tests/integration/project/elements/base.bst
index 6f2c56fa9..428afa736 100644
--- a/tests/integration/project/elements/base.bst
+++ b/tests/integration/project/elements/base.bst
@@ -2,5 +2,4 @@
kind: stack
depends:
- - base/base-sdk.bst
- - base/usermerge.bst
+ - base/base-alpine.bst
diff --git a/tests/integration/project/elements/base/base-alpine.bst b/tests/integration/project/elements/base/base-alpine.bst
new file mode 100644
index 000000000..91327bc73
--- /dev/null
+++ b/tests/integration/project/elements/base/base-alpine.bst
@@ -0,0 +1,12 @@
+kind: import
+
+description: |
+ Alpine Linux base for tests
+
+ Generated using the `tests/integration-tests/base/generate-base.sh` script.
+
+sources:
+ - kind: tar
+ url: https://gnome7.codethink.co.uk/tarballs/integration-tests-base.v1.x86_64.tar.xz
+ base-dir: ''
+ ref: 3eb559250ba82b64a68d86d0636a6b127aa5f6d25d3601a79f79214dc9703639
diff --git a/tests/integration/project/elements/base/base-sdk.bst b/tests/integration/project/elements/base/base-sdk.bst
deleted file mode 100644
index 6b7418e99..000000000
--- a/tests/integration/project/elements/base/base-sdk.bst
+++ /dev/null
@@ -1,18 +0,0 @@
-kind: import
-description: Import the base freedesktop SDK
-(?):
- - linux == True:
- sources:
- - kind: ostree
- url: gnomesdk:repo/
- gpg-key: keys/gnome-sdk.gpg
- track: runtime/org.freedesktop.BaseSdk/x86_64/1.6
- ref: 48b8c907522d3edeb0fb9f36c6515ce1ef5fb80a6e4e5dd54033b3fd6ad784d0
- - linux == False:
- sources:
- - kind: tar
- url: gnome7:tarballs/gnome-sdk.tar.xz
- ref: 96d5062a19fa9ac3439f8a502664f8d46860bad7efd28e7909b03ddbcdbe66e6
-config:
- source: files
- target: usr
diff --git a/tests/integration/project/elements/base/usermerge.bst b/tests/integration/project/elements/base/usermerge.bst
deleted file mode 100644
index fb9cffba9..000000000
--- a/tests/integration/project/elements/base/usermerge.bst
+++ /dev/null
@@ -1,6 +0,0 @@
-kind: import
-description: Some symlinks for the flatpak runtime environment
-sources:
- - kind: tar
- url: project_dir:/files/usrmerge.tar.xz
- ref: 96e4458fafb85c10fe6271ad8839754b6eabeceac8523f8f602dea6470db5961
diff --git a/tests/integration/project/files/usrmerge.tar.xz b/tests/integration/project/files/usrmerge.tar.xz
deleted file mode 100644
index e54fbbb43..000000000
--- a/tests/integration/project/files/usrmerge.tar.xz
+++ /dev/null
Binary files differ
diff --git a/tests/integration/script.py b/tests/integration/script.py
index d7448c4d5..af5ff67a8 100644
--- a/tests/integration/script.py
+++ b/tests/integration/script.py
@@ -107,7 +107,7 @@ def test_script_no_root(cli, tmpdir, datafiles):
res = cli.run(project=project, args=['build', element_name])
assert res.exit_code != 0
- assert "sh: /test: Read-only file system" in res.stderr
+ assert "/test: Read-only file system" in res.stderr
@pytest.mark.datafiles(DATA_DIR)
diff --git a/tests/integration/shell.py b/tests/integration/shell.py
index 1e14f736c..6a66b7e4d 100644
--- a/tests/integration/shell.py
+++ b/tests/integration/shell.py
@@ -76,6 +76,6 @@ def test_no_shell(cli, tmpdir, datafiles):
result = cli.run(project=project, args=['build', element_name])
assert result.exit_code == 0
- result = execute_shell(cli, project, '/usr/bin/echo Pegasissies!', element=element_name)
+ result = execute_shell(cli, project, '/bin/echo Pegasissies!', element=element_name)
assert result.exit_code == 0
assert result.output == "Pegasissies!\n"