diff --git a/ci/run_build.sh b/ci/run_build.sh index 74f30f9..4ba0f71 100755 --- a/ci/run_build.sh +++ b/ci/run_build.sh @@ -13,11 +13,18 @@ export SOURCE_DIR="$(readlink -f "${SOURCE_DIR}")" export DIST_DIR="$(readlink -f "${DIST_DIR}")" export BUILD_DIR="$(readlink -f "${BUILD_DIR}")" +# Configuration +: ${FORCE_SUBREAPER:="1"} +export FORCE_SUBREAPER + # Our build platform doesn't have those newer Linux flags, but we want Tini to have subreaper support # We also use those in our tests -export CFLAGS="-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37" - +CFLAGS="-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37" +if [[ "${FORCE_SUBREAPER}" -eq 1 ]]; then + # If FORCE_SUBREAPER is requested, then we set those CFLAGS for the Tini build + export CFLAGS +fi # Ensure Python output is not buffered (to make tests output clearer) export PYTHONUNBUFFERED=1 @@ -69,6 +76,7 @@ virtualenv --system-site-packages "${VENV}" # Don't use activate because it does not play nice with nounset export PATH="${VENV}/bin:${PATH}" +export CFLAGS # We need them to build our test suite, regardless of FORCE_SUBREAPER # Install test dependencies pip install psutil python-prctl diff --git a/ddist.sh b/ddist.sh index d29e2ff..c744779 100755 --- a/ddist.sh +++ b/ddist.sh @@ -14,5 +14,10 @@ rm -f "${HERE}/dist"/* # Create the build image docker build -t "${IMG}" . -# Run the build -docker run --rm --volume="${HERE}:${SRC}" -e BUILD_DIR=/tmp/tini-build -e SOURCE_DIR="${SRC}" "${IMG}" "${SRC}/ci/run_build.sh" +# Run test without subreaper support, don't copy build files here +docker run --rm \ + --volume="${HERE}:${SRC}" \ + -e BUILD_DIR=/tmp/tini-build \ + -e SOURCE_DIR="${SRC}" \ + -e FORCE_SUBREAPER="${FORCE_SUBREAPER}" \ + "${IMG}" "${SRC}/ci/run_build.sh" diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..5d53b74 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -o errexit +set -o nounset + +REL_HERE=$(dirname "${BASH_SOURCE}") +HERE=$(cd "${REL_HERE}"; pwd) + +for i in $(seq 0 1); do + export FORCE_SUBREAPER="${i}" + echo "Testing with FORCE_SUBREAPER=${FORCE_SUBREAPER}" + "${HERE}/ddist.sh" + "${HERE}/dtest.sh" +done diff --git a/test/run_inner_tests.py b/test/run_inner_tests.py index 0828853..7cbef47 100755 --- a/test/run_inner_tests.py +++ b/test/run_inner_tests.py @@ -13,12 +13,17 @@ def main(): proxy = os.path.join(src, "test", "subreaper-proxy.py") tini = os.path.join(build, "tini") - for target, env in [ - ([proxy, tini, "--"], {}), - ([tini, "-s", "--"], {}), - ([tini, "--"], {"TINI_SUBREAPER": ""}), - ]: + subreaper_support = bool(int(os.environ["FORCE_SUBREAPER"])) + tests = [([proxy, tini, "--"], {}),] + + if subreaper_support: + tests.extend([ + ([tini, "-s", "--"], {}), + ([tini, "--"], {"TINI_SUBREAPER": ""}), + ]) + + for target, env in tests: # Run the reaping test print "Running reaping test ({0} with env {1})".format(" ".join(target), env) p = subprocess.Popen(target + [os.path.join(src, "test", "reaping", "stage_1.py")], @@ -26,7 +31,11 @@ def main(): stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - assert "zombie reaping won't work" not in err, "Warning message was output!" + + if subreaper_support: + # If subreaper support sin't available, Tini won't looku p its subreaper bit + # and will output the error message here. + assert "zombie reaping won't work" not in err, "Warning message was output!" ret = p.wait() assert ret == 0, "Reaping test failed!"