Browse code

Run unit tests as single command

For me it increased speed of unit-tests tremendously, however this disabled
coverage profiles generation, which I think is pretty good tradeoff.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2015/10/29 08:58:05
Showing 2 changed files
1 1
deleted file mode 100755
... ...
@@ -1,39 +0,0 @@
1
-#!/bin/bash
2
-set -e
3
-
4
-# Compile phase run by parallel in test-unit. No support for coverpkg
5
-
6
-dir=$1
7
-in_file="$dir/$(basename "$dir").test"
8
-out_file="$DEST/precompiled/$dir.test"
9
-# we want to use binary_extension() here, but we can't because it's in main.sh and this file gets re-execed
10
-if [ "$(go env GOOS)" = 'windows' ]; then
11
-	in_file+='.exe'
12
-	out_file+='.exe'
13
-fi
14
-testcover=()
15
-if [ "$HAVE_GO_TEST_COVER" ]; then
16
-	# if our current go install has -cover, we want to use it :)
17
-	mkdir -p "$DEST/coverprofiles"
18
-	coverprofile="docker${dir#.}"
19
-	coverprofile="$DEST/coverprofiles/${coverprofile//\//-}"
20
-	testcover=( -cover -coverprofile "$coverprofile" ) # missing $coverpkg
21
-fi
22
-if [ "$BUILDFLAGS_FILE" ]; then
23
-	readarray -t BUILDFLAGS < "$BUILDFLAGS_FILE"
24
-fi
25
-
26
-if [[ "$(go version)" =~ "gccgo" ]]; then
27
-	GCCGOFLAGS="-gccgoflags= -lpthread -ldl "
28
-fi
29
-
30
-if ! (
31
-	cd "$dir"
32
-	go test "${testcover[@]}" "$GCCGOFLAGS" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS -c 
33
-); then
34
-	exit 1
35
-fi
36
-
37
-mkdir -p "$(dirname "$out_file")"
38
-mv "$in_file" "$out_file"
39
-echo "Precompiled: ${DOCKER_PKG}${dir#.}"
... ...
@@ -1,12 +1,6 @@
1 1
 #!/bin/bash
2 2
 set -e
3 3
 
4
-: ${PARALLEL_JOBS:=$(nproc 2>/dev/null || echo 1)} # if nproc fails (usually because we don't have it), let's not parallelize by default
5
-
6
-RED=$'\033[31m'
7
-GREEN=$'\033[32m'
8
-TEXTRESET=$'\033[0m' # reset the foreground colour
9
-
10 4
 # Run Docker's test suite, including sub-packages, and store their output as a bundle
11 5
 # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
12 6
 # You can use this to select certain tests to run, eg.
... ...
@@ -14,73 +8,15 @@ TEXTRESET=$'\033[0m' # reset the foreground colour
14 14
 #   TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
15 15
 #
16 16
 bundle_test_unit() {
17
-	{
18
-		date
19
-
20
-		# Run all the tests if no TESTDIRS were specified.
21
-		if [ -z "$TESTDIRS" ]; then
22
-			TESTDIRS=$(find_dirs '*_test.go')
23
-		fi
24
-		(
25
-			export LDFLAGS
26
-			export TESTFLAGS
27
-			export HAVE_GO_TEST_COVER
28
-
29
-			# some hack to export array variables
30
-			export BUILDFLAGS_FILE="$DEST/buildflags-file"
31
-			( IFS=$'\n'; echo "${BUILDFLAGS[*]}" ) > "$BUILDFLAGS_FILE"
32
-
33
-			if command -v parallel &> /dev/null; then
34
-				# accommodate parallel to be able to access variables
35
-				export SHELL="$BASH"
36
-				export HOME="$(mktemp -d)"
37
-				mkdir -p "$HOME/.parallel"
38
-				touch "$HOME/.parallel/ignored_vars"
39
-
40
-				echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --env _ "${MAKEDIR}/.go-compile-test-dir"
41
-				rm -rf "$HOME"
42
-			else
43
-				# aww, no "parallel" available - fall back to boring
44
-				for test_dir in $TESTDIRS; do
45
-					"${MAKEDIR}/.go-compile-test-dir" "$test_dir" || true
46
-					# don't let one directory that fails to build tank _all_ our tests!
47
-				done
48
-			fi
49
-			rm -f "$BUILDFLAGS_FILE"
50
-		)
51
-		echo "$TESTDIRS" | go_run_test_dir
52
-	}
53
-}
54
-
55
-go_run_test_dir() {
56
-	TESTS_FAILED=()
57
-	while read dir; do
58
-		echo
59
-		echo '+ go test' $TESTFLAGS "${DOCKER_PKG}/${dir#./}"
60
-		precompiled="$ABS_DEST/precompiled/$dir.test$(binary_extension)"
61
-		if ! ( cd "$dir" && test_env "$precompiled" $TESTFLAGS ); then
62
-			TESTS_FAILED+=("$dir")
63
-			echo
64
-			echo "${RED}Tests failed: $dir${TEXTRESET}"
65
-			sleep 1 # give it a second, so observers watching can take note
66
-		fi
67
-	done
68
-
69
-	echo
70
-	echo
71
-	echo
72
-
73
-	# if some tests fail, we want the bundlescript to fail, but we want to
74
-	# try running ALL the tests first, hence TESTS_FAILED
75
-	if [ "${#TESTS_FAILED[@]}" -gt 0 ]; then
76
-		echo "${RED}Test failures in: ${TESTS_FAILED[@]}${TEXTRESET}"
77
-		echo
78
-		false
79
-	else
80
-		echo "${GREEN}Test success${TEXTRESET}"
81
-		echo
82
-		true
83
-	fi
17
+	date
18
+	pkg_list=$(go list -e \
19
+		-f '{{if ne .Name "github.com/docker/docker"}}
20
+				{{.ImportPath}}
21
+			{{end}}' \
22
+		"${BUILDFLAGS[@]}" ./... \
23
+		| grep -v github.com/docker/docker/vendor \
24
+		| grep -v github.com/docker/docker/integration-cli)
25
+	go test -cover $GCCGOFLAGS -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list
84 26
 }
85 27
 
86 28
 bundle_test_unit 2>&1 | tee -a "$DEST/test.log"