From 416b16e1e200420644072b354b9595ffa9474682 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Sun, 8 Dec 2013 12:57:11 -0700 Subject: [PATCH 1/7] Simplify and resync hack/make/test and hack/make/dyntest output handling --- hack/make/dyntest | 18 ++++++++++++++++-- hack/make/test | 11 +++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/hack/make/dyntest b/hack/make/dyntest index 61f03ada1d..ae157dff55 100644 --- a/hack/make/dyntest +++ b/hack/make/dyntest @@ -10,6 +10,10 @@ if [ ! -x "$INIT" ]; then false fi +TEXTRESET=$'\033[0m' # reset the foreground colour +RED=$'\033[31m' +GREEN=$'\033[32m' + # Run Docker's test suite, including sub-packages, and store their output as a bundle # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. # You can use this to select certain tests to run, eg. @@ -37,16 +41,26 @@ bundle_test() { go test -ldflags "$LDFLAGS -X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" $BUILDFLAGS $TESTFLAGS ); then TESTS_FAILED+=("$test_dir") + echo + echo "${RED}Tests failed: $test_dir${TEXTRESET}" sleep 1 # give it a second, so observers watching can take note fi done - + + echo + echo + echo + # if some tests fail, we want the bundlescript to fail, but we want to # try running ALL the tests first, hence TESTS_FAILED if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then + echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}" echo - echo "Test failures in: ${TESTS_FAILED[@]}" false + else + echo "${GREEN}Test success${TEXTRESET}" + echo + true fi } 2>&1 | tee $DEST/test.log } diff --git a/hack/make/test b/hack/make/test index c8fae70535..ad93e91cf8 100644 --- a/hack/make/test +++ b/hack/make/test @@ -35,21 +35,24 @@ bundle_test() { ); then TESTS_FAILED+=("$test_dir") echo - echo "${RED}Test Failed: $test_dir${TEXTRESET}" - echo + echo "${RED}Tests failed: $test_dir${TEXTRESET}" sleep 1 # give it a second, so observers watching can take note fi done + echo + echo + echo + # if some tests fail, we want the bundlescript to fail, but we want to # try running ALL the tests first, hence TESTS_FAILED if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then - echo echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}" + echo false else - echo echo "${GREEN}Test success${TEXTRESET}" + echo true fi } 2>&1 | tee $DEST/test.log From dcfc4ada4dcc8b1f878370976f29ca0485e690f8 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Sun, 8 Dec 2013 13:49:57 -0700 Subject: [PATCH 2/7] Clean output and simplify hack/make/*test by adding go_test_dir function in make.sh --- hack/make.sh | 18 ++++++++++++++++++ hack/make/dyntest | 23 +++++++---------------- hack/make/test | 14 ++------------ 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/hack/make.sh b/hack/make.sh index 6139c93bb5..23b77509b6 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -62,6 +62,24 @@ LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w' LDFLAGS_STATIC='-X github.com/dotcloud/docker/utils.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"' BUILDFLAGS='-tags netgo' +# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. +# You can use this to select certain tests to run, eg. +# +# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test +# +go_test_dir() { + dir=$1 + ( # we run "go test -i" ouside the "set -x" to provde cleaner output + cd "$dir" + go test -i -ldflags "$LDFLAGS" $BUILDFLAGS + ) + ( + set -x + cd "$dir" + go test -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS + ) +} + bundle() { bundlescript=$1 bundle=$(basename $bundlescript) diff --git a/hack/make/dyntest b/hack/make/dyntest index ae157dff55..e6e1dbb5b2 100644 --- a/hack/make/dyntest +++ b/hack/make/dyntest @@ -17,29 +17,20 @@ GREEN=$'\033[32m' # Run Docker's test suite, including sub-packages, and store their output as a bundle # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. # You can use this to select certain tests to run, eg. -# -# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test +# +# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test # bundle_test() { { date - + + export TEST_DOCKERINIT_PATH=$DEST/../dynbinary/dockerinit-$VERSION + TESTS_FAILED=() for test_dir in $(find_test_dirs); do echo - - if ! ( - set -x - cd $test_dir - - # Install packages that are dependencies of the tests. - # Note: Does not run the tests. - go test -i -ldflags "$LDFLAGS" $BUILDFLAGS - - # Run the tests with the optional $TESTFLAGS. - export TEST_DOCKERINIT_PATH=$DEST/../dynbinary/dockerinit-$VERSION - go test -ldflags "$LDFLAGS -X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" $BUILDFLAGS $TESTFLAGS - ); then + + if ! LDFLAGS="$LDFLAGS -X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" go_test_dir "$test_dir"; then TESTS_FAILED+=("$test_dir") echo echo "${RED}Tests failed: $test_dir${TEXTRESET}" diff --git a/hack/make/test b/hack/make/test index ad93e91cf8..9ec86f0780 100644 --- a/hack/make/test +++ b/hack/make/test @@ -12,7 +12,7 @@ GREEN=$'\033[32m' # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. # You can use this to select certain tests to run, eg. # -# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test +# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test # bundle_test() { { @@ -22,17 +22,7 @@ bundle_test() { for test_dir in $(find_test_dirs); do echo - if ! ( - set -x - cd $test_dir - - # Install packages that are dependencies of the tests. - # Note: Does not run the tests. - go test -i -ldflags "$LDFLAGS $LDFLAGS_STATIC" $BUILDFLAGS - - # Run the tests with the optional $TESTFLAGS. - go test -ldflags "$LDFLAGS $LDFLAGS_STATIC" $BUILDFLAGS $TESTFLAGS - ); then + if ! LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir "$test_dir"; then TESTS_FAILED+=("$test_dir") echo echo "${RED}Tests failed: $test_dir${TEXTRESET}" From bac3a8e6f5eca31108787b98d5659523eefa6a30 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Sun, 8 Dec 2013 13:50:48 -0700 Subject: [PATCH 3/7] Add much better pruning of non-tested directories, including pruning the integration tests directory (doing more with "find" and nothing with "grep") --- hack/make/dyntest | 7 ++++--- hack/make/test | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hack/make/dyntest b/hack/make/dyntest index e6e1dbb5b2..f7290c9557 100644 --- a/hack/make/dyntest +++ b/hack/make/dyntest @@ -61,9 +61,10 @@ bundle_test() { # holding Go test files, and prints their paths on standard output, one per # line. find_test_dirs() { - find . -name '*_test.go' | grep -v '^./vendor' | - { while read f; do dirname $f; done; } | - sort -u + find -not \( \ + \( -wholename './vendor' -o -wholename './integration' \) \ + -prune \ + \) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u } bundle_test diff --git a/hack/make/test b/hack/make/test index 9ec86f0780..760c5a5fc6 100644 --- a/hack/make/test +++ b/hack/make/test @@ -53,9 +53,10 @@ bundle_test() { # holding Go test files, and prints their paths on standard output, one per # line. find_test_dirs() { - find . -name '*_test.go' | grep -v '^./vendor' | - { while read f; do dirname $f; done; } | - sort -u + find -not \( \ + \( -wholename './vendor' -o -wholename './integration' \) \ + -prune \ + \) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u } bundle_test From 45cea94a827bfcb77ef53e2e5046df51dc7c113c Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Sun, 8 Dec 2013 15:32:17 -0700 Subject: [PATCH 4/7] Unify hack/make/*test further by invoking hack/make/test directly from dyntest --- hack/make/dyntest | 60 +++-------------------------------------------- 1 file changed, 3 insertions(+), 57 deletions(-) diff --git a/hack/make/dyntest b/hack/make/dyntest index f7290c9557..cea3ba4e06 100644 --- a/hack/make/dyntest +++ b/hack/make/dyntest @@ -10,61 +10,7 @@ if [ ! -x "$INIT" ]; then false fi -TEXTRESET=$'\033[0m' # reset the foreground colour -RED=$'\033[31m' -GREEN=$'\033[32m' +export TEST_DOCKERINIT_PATH="$INIT" -# Run Docker's test suite, including sub-packages, and store their output as a bundle -# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. -# You can use this to select certain tests to run, eg. -# -# TESTFLAGS='-run ^TestBuild$' ./hack/make.sh test -# -bundle_test() { - { - date - - export TEST_DOCKERINIT_PATH=$DEST/../dynbinary/dockerinit-$VERSION - - TESTS_FAILED=() - for test_dir in $(find_test_dirs); do - echo - - if ! LDFLAGS="$LDFLAGS -X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" go_test_dir "$test_dir"; then - TESTS_FAILED+=("$test_dir") - echo - echo "${RED}Tests failed: $test_dir${TEXTRESET}" - sleep 1 # give it a second, so observers watching can take note - fi - done - - echo - echo - echo - - # if some tests fail, we want the bundlescript to fail, but we want to - # try running ALL the tests first, hence TESTS_FAILED - if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then - echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}" - echo - false - else - echo "${GREEN}Test success${TEXTRESET}" - echo - true - fi - } 2>&1 | tee $DEST/test.log -} - - -# This helper function walks the current directory looking for directories -# holding Go test files, and prints their paths on standard output, one per -# line. -find_test_dirs() { - find -not \( \ - \( -wholename './vendor' -o -wholename './integration' \) \ - -prune \ - \) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u -} - -bundle_test +LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" \ + source "$(dirname "$BASH_SOURCE")/test" From ca405786f468a18859684dc13d43a293d47b89bd Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Sun, 8 Dec 2013 18:40:05 -0700 Subject: [PATCH 5/7] Unify dyntest/test and dynbinary/binary hack bundlescripts further by cross-invocation and keeping all the logic in one place, taking advantage of LDFLAGS_STATIC that is the only bit that gets replaced for dyntest/dynbinary --- hack/make/dynbinary | 6 ++++-- hack/make/dyntest | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hack/make/dynbinary b/hack/make/dynbinary index 96ce482674..100c00eed5 100644 --- a/hack/make/dynbinary +++ b/hack/make/dynbinary @@ -11,5 +11,7 @@ ln -sf dockerinit-$VERSION $DEST/dockerinit export DOCKER_INITSHA1="$(sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)" # exported so that "dyntest" can easily access it later without recalculating it -go build -o $DEST/docker-$VERSION -ldflags "$LDFLAGS -X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" $BUILDFLAGS ./docker -echo "Created binary: $DEST/docker-$VERSION" +( + export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" + source "$(dirname "$BASH_SOURCE")/binary" +) diff --git a/hack/make/dyntest b/hack/make/dyntest index cea3ba4e06..eb5c2b73ed 100644 --- a/hack/make/dyntest +++ b/hack/make/dyntest @@ -10,7 +10,8 @@ if [ ! -x "$INIT" ]; then false fi -export TEST_DOCKERINIT_PATH="$INIT" - -LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" \ +( + export TEST_DOCKERINIT_PATH="$INIT" + export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" source "$(dirname "$BASH_SOURCE")/test" +) From f0879a1e145f31569e9e4e61f429de858bb636ab Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Sun, 8 Dec 2013 18:41:50 -0700 Subject: [PATCH 6/7] Add separate "test-integration" bundlescript (and corresponding dyntest-integration bundlescript) --- Makefile | 2 +- hack/make.sh | 2 ++ hack/make/dyntest-integration | 17 +++++++++++++++++ hack/make/test-integration | 11 +++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 hack/make/dyntest-integration create mode 100644 hack/make/test-integration diff --git a/Makefile b/Makefile index 1518fb1331..02a121dc50 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ doc: docker build -t docker-docs docs && docker run -p 8000:8000 docker-docs test: build - $(DOCKER_RUN_DOCKER) hack/make.sh test + $(DOCKER_RUN_DOCKER) hack/make.sh test test-integration shell: build $(DOCKER_RUN_DOCKER) bash diff --git a/hack/make.sh b/hack/make.sh index 23b77509b6..7b39f3161c 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -35,8 +35,10 @@ grep -q "$RESOLVCONF" /proc/mounts || { DEFAULT_BUNDLES=( binary test + test-integration dynbinary dyntest + dyntest-integration tgz ubuntu ) diff --git a/hack/make/dyntest-integration b/hack/make/dyntest-integration new file mode 100644 index 0000000000..0887c45be0 --- /dev/null +++ b/hack/make/dyntest-integration @@ -0,0 +1,17 @@ +#!/bin/bash + +DEST=$1 +INIT=$DEST/../dynbinary/dockerinit-$VERSION + +set -e + +if [ ! -x "$INIT" ]; then + echo >&2 'error: dynbinary must be run before dyntest-integration' + false +fi + +( + export TEST_DOCKERINIT_PATH="$INIT" + export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\"" + source "$(dirname "$BASH_SOURCE")/test-integration" +) diff --git a/hack/make/test-integration b/hack/make/test-integration new file mode 100644 index 0000000000..f1ab0b99c3 --- /dev/null +++ b/hack/make/test-integration @@ -0,0 +1,11 @@ +#!/bin/bash + +DEST=$1 + +set -e + +bundle_test_integration() { + LDFLAGS="$LDFLAGS $LDFLAGS_STATIC" go_test_dir ./integration +} + +bundle_test_integration 2>&1 | tee $DEST/test.log From 0db1c60542d3570558bad09eddd3b2b605e55e4e Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 12 Dec 2013 11:24:00 -0700 Subject: [PATCH 7/7] Make Tianon the hack maintainer --- hack/MAINTAINERS | 1 - 1 file changed, 1 deletion(-) diff --git a/hack/MAINTAINERS b/hack/MAINTAINERS index afd13f8e50..18e05a3070 100644 --- a/hack/MAINTAINERS +++ b/hack/MAINTAINERS @@ -1,2 +1 @@ -Solomon Hykes (@shykes) Tianon Gravi (@tianon)