Merge 1286-tool (PR #1470): Use test script from build-tools.git
This commit is contained in:
commit
f8e06f9dbc
10 files changed
+20
-255
No files matched your search
@@ -43,8 +43,6 @@ prog/netcheck/netcheck
|
||||
prog/docker_tls_args/docker_tls_args
|
||||
testing/cover/cover
|
||||
testing/runner/runner
|
||||
tools/bin
|
||||
tools/build
|
||||
releases
|
||||
.weaver.uptodate
|
||||
.weavedns.uptodate
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "tools"]
|
||||
path = tools
|
||||
url = https://github.com/weaveworks/build-tools
|
||||
@@ -21,7 +21,6 @@ install:
|
||||
- go get ./...
|
||||
|
||||
script:
|
||||
- bin/lint .
|
||||
- make tests
|
||||
|
||||
after_success:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
PUBLISH=publish_weave publish_weaveexec
|
||||
|
||||
.DEFAULT: all
|
||||
.PHONY: all update tests publish $(PUBLISH) clean clean-bin prerequisites build travis run-smoketests
|
||||
.PHONY: all update tests lint publish $(PUBLISH) clean clean-bin prerequisites build travis run-smoketests
|
||||
|
||||
# If you can use docker without being root, you can do "make SUDO="
|
||||
SUDO=sudo
|
||||
@@ -16,10 +16,9 @@ WEAVEWAIT_EXE=prog/weavewait/weavewait
|
||||
WEAVEHOSTS_EXE=prog/weavehosts/weavehosts
|
||||
NETCHECK_EXE=prog/netcheck/netcheck
|
||||
DOCKERTLSARGS_EXE=prog/docker_tls_args/docker_tls_args
|
||||
COVER_EXE=testing/cover/cover
|
||||
RUNNER_EXE=testing/runner/runner
|
||||
|
||||
EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEHOSTS_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) $(COVER_EXE) $(RUNNER_EXE)
|
||||
EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEHOSTS_EXE) $(NETCHECK_EXE) $(DOCKERTLSARGS_EXE) $(RUNNER_EXE)
|
||||
|
||||
WEAVER_UPTODATE=.weaver.uptodate
|
||||
WEAVEEXEC_UPTODATE=.weaveexec.uptodate
|
||||
@@ -46,7 +45,7 @@ NETGO_CHECK=@strings $@ | grep cgo_stub\\\.go >/dev/null || { \
|
||||
}
|
||||
BUILD_FLAGS=-ldflags "-extldflags \"-static\" -X main.version $(WEAVE_VERSION)" -tags netgo
|
||||
|
||||
all: $(WEAVE_EXPORT) $(COVER_EXE) $(RUNNER_EXE)
|
||||
all: $(WEAVE_EXPORT) $(RUNNER_EXE)
|
||||
|
||||
travis: $(EXES)
|
||||
|
||||
@@ -78,11 +77,10 @@ $(NETCHECK_EXE): prog/netcheck/netcheck.go
|
||||
$(SIGPROXY_EXE): prog/sigproxy/main.go
|
||||
$(WEAVEWAIT_EXE): prog/weavewait/main.go net/*.go
|
||||
$(WEAVEHOSTS_EXE): prog/weavehosts/weavehosts.go
|
||||
$(COVER_EXE): testing/cover/cover.go
|
||||
$(RUNNER_EXE): testing/runner/runner.go
|
||||
$(DOCKERTLSARGS_EXE): prog/docker_tls_args/*.go
|
||||
|
||||
$(WEAVEWAIT_EXE) $(SIGPROXY_EXE) $(WEAVEHOSTS_EXE) $(COVER_EXE) $(RUNNER_EXE) $(DOCKERTLSARGS_EXE):
|
||||
$(WEAVEWAIT_EXE) $(SIGPROXY_EXE) $(WEAVEHOSTS_EXE) $(RUNNER_EXE) $(DOCKERTLSARGS_EXE):
|
||||
go get -tags netgo ./$(@D)
|
||||
go build $(BUILD_FLAGS) -o $@ ./$(@D)
|
||||
|
||||
@@ -108,8 +106,14 @@ $(WEAVE_EXPORT): $(IMAGES_UPTODATE)
|
||||
$(DOCKER_DISTRIB):
|
||||
curl -o $(DOCKER_DISTRIB) $(DOCKER_DISTRIB_URL)
|
||||
|
||||
tests: $(COVER_EXE)
|
||||
@test/units.sh
|
||||
tests: tools/.git
|
||||
tools/test
|
||||
|
||||
lint: tools/.git
|
||||
tools/lint -nocomment -notestpackage .
|
||||
|
||||
tools/.git:
|
||||
git submodule update --init
|
||||
|
||||
$(PUBLISH): publish_%: $(IMAGES_UPTODATE)
|
||||
$(SUDO) docker tag -f $(DOCKERHUB_USER)/$* $(DOCKERHUB_USER)/$*:$(WEAVE_VERSION)
|
||||
@@ -122,7 +126,7 @@ publish: $(PUBLISH)
|
||||
|
||||
clean-bin:
|
||||
-$(SUDO) docker rmi $(IMAGES)
|
||||
go clean -r ./...
|
||||
go clean -r $(addprefix ./,$(dir $(EXES)))
|
||||
rm -f $(EXES) $(IMAGES_UPTODATE) $(WEAVE_EXPORT)
|
||||
|
||||
clean: clean-bin
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
#!/bin/bash
|
||||
# This scipt lints go files for common errors.
|
||||
#
|
||||
# Its runs gofmt and go vet, and optionally golint and
|
||||
# gocyclo, if they are installed.
|
||||
#
|
||||
# With no arguments, it lints the current files staged
|
||||
# for git commit. Or you can pass it explicit filenames
|
||||
# (or directories) and it will lint them.
|
||||
#
|
||||
# To use this script automatically, run:
|
||||
# ln -s ../../bin/lint .git/hooks/pre-commit
|
||||
|
||||
set -eu
|
||||
|
||||
function lint_go {
|
||||
filename="$1"
|
||||
result=0
|
||||
|
||||
if [ -n "$(gofmt -l "${filename}")" ]; then
|
||||
result=1
|
||||
echo "${filename}: run gofmt -w ${filename}!"
|
||||
fi
|
||||
|
||||
go tool vet "${filename}" || result=$?
|
||||
|
||||
# golint is completely optional. If you don't like it
|
||||
# don't have it installed.
|
||||
if type golint >/dev/null 2>&1; then
|
||||
# golint doesn't set an exit code it seems
|
||||
lintoutput=$(golint "${filename}" | grep -vE 'comment|dot imports')
|
||||
if [ "$lintoutput" != "" ]; then
|
||||
result=1
|
||||
echo "$lintoutput"
|
||||
fi
|
||||
fi
|
||||
|
||||
# gocyclo is completely optional. If you don't like it
|
||||
# don't have it installed. Also never blocks a commit,
|
||||
# it just warns.
|
||||
if type gocyclo >/dev/null 2>&1; then
|
||||
gocyclo -over 25 "${filename}" | while read line; do
|
||||
echo "${filename}": higher than 25 cyclomatic complexity - "${line}"
|
||||
done
|
||||
fi
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
function lint {
|
||||
filename="$1"
|
||||
ext="${filename##*\.}"
|
||||
|
||||
# Don't lint this script
|
||||
if [ "${filename}" = "bin/lint" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# Don't lint files that don't exist
|
||||
if ! [ -a "${filename}" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
case "$ext" in
|
||||
go) lint_go "${filename}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function lint_files {
|
||||
lint_result=0
|
||||
while read filename; do
|
||||
lint "${filename}" || lint_result=1
|
||||
done
|
||||
exit $lint_result
|
||||
}
|
||||
|
||||
function list_files {
|
||||
if [ $# -gt 0 ]; then
|
||||
find "$@" -type f
|
||||
else
|
||||
git diff --cached --name-only
|
||||
fi
|
||||
}
|
||||
|
||||
list_files "$@" | lint_files
|
||||
@@ -37,6 +37,8 @@ dependencies:
|
||||
|
||||
test:
|
||||
override:
|
||||
- cd $SRCDIR; make lint:
|
||||
parallel: true
|
||||
- docker run -v /home/ubuntu:/home/go -e COVERDIR=test/coverage -e SLOW=true -e CIRCLECI -e CIRCLE_BUILD_NUM -e CIRCLE_NODE_TOTAL -e CIRCLE_NODE_INDEX weaveworks/weave-test:
|
||||
parallel: true
|
||||
- docker run -v /var/run/docker.sock:/run/docker.sock -v /home/ubuntu:/home/go -e COVERAGE=true weaveworks/weave-build:
|
||||
|
||||
@@ -9,7 +9,7 @@ if [ -n "$CIRCLECI" ]; then
|
||||
done
|
||||
fi
|
||||
|
||||
$DIR/../testing/cover/cover
|
||||
go get github.com/weaveworks/build-tools/cover
|
||||
cover ./coverage/* >profile.cov
|
||||
go tool cover -html=profile.cov -o coverage.html
|
||||
go tool cover -func=profile.cov -o coverage.txt
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SLOW=${SLOW-}
|
||||
GO_TEST_ARGS="-tags netgo -cpu 4 -timeout 8m"
|
||||
if [ -n "$SLOW" -o "$1" = "-slow" ]; then
|
||||
GO_TEST_ARGS="$GO_TEST_ARGS -race -covermode=atomic"
|
||||
|
||||
if [ -n "$COVERDIR" ] ; then
|
||||
coverdir="$COVERDIR"
|
||||
else
|
||||
coverdir=$(mktemp -d coverage.XXXXXXXXXX)
|
||||
fi
|
||||
|
||||
mkdir -p $coverdir
|
||||
fi
|
||||
|
||||
fail=0
|
||||
|
||||
TESTDIRS=$(find . -type f -name '*_test.go' | xargs -n1 dirname | grep -v prog | sort -u)
|
||||
|
||||
# If running on circle, use the scheduler to work out what tests to run on what shard
|
||||
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
|
||||
TESTDIRS=$(echo $TESTDIRS | "$DIR/sched" sched units-$CIRCLE_BUILD_NUM $CIRCLE_NODE_TOTAL $CIRCLE_NODE_INDEX)
|
||||
echo $TESTDIRS
|
||||
fi
|
||||
|
||||
for dir in $TESTDIRS; do
|
||||
go get -t -tags netgo $dir
|
||||
|
||||
GO_TEST_ARGS_RUN="$GO_TEST_ARGS"
|
||||
if [ -n "$SLOW" ]; then
|
||||
COVERPKGS=$((go list $dir; go list -f '{{join .Deps "\n"}}' $dir | grep "weaveworks") | paste -s -d,)
|
||||
output=$(mktemp $coverdir/unit.XXXXXXXXXX)
|
||||
GO_TEST_ARGS_RUN="$GO_TEST_ARGS -coverprofile=$output -coverpkg=$COVERPKGS"
|
||||
fi
|
||||
|
||||
START=$(date +%s)
|
||||
if ! go test $GO_TEST_ARGS_RUN $dir ; then
|
||||
fail=1
|
||||
fi
|
||||
RUNTIME=$(( $(date +%s) - $START ))
|
||||
|
||||
# Report test runtime when running on circle, to help scheduler
|
||||
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
|
||||
"$DIR/sched" time $dir $RUNTIME
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$SLOW" -a -z "$COVERDIR" ] ; then
|
||||
$DIR/../testing/cover/cover $coverdir/* >profile.cov
|
||||
rm -rf $coverdir
|
||||
go tool cover -html=profile.cov -o=coverage.html
|
||||
go tool cover -func=profile.cov | tail -n1
|
||||
fi
|
||||
|
||||
exit $fail
|
||||
@@ -1,97 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"golang.org/x/tools/cover"
|
||||
)
|
||||
|
||||
func merge(p1, p2 *cover.Profile) *cover.Profile {
|
||||
output := cover.Profile{
|
||||
FileName: p1.FileName,
|
||||
Mode: p1.Mode,
|
||||
}
|
||||
|
||||
i, j := 0, 0
|
||||
for i < len(p1.Blocks) && j < len(p2.Blocks) {
|
||||
bi, bj := p1.Blocks[i], p2.Blocks[j]
|
||||
if bi.StartLine == bj.StartLine && bi.StartCol == bj.StartCol {
|
||||
|
||||
if bi.EndLine != bj.EndLine ||
|
||||
bi.EndCol != bj.EndCol ||
|
||||
bi.NumStmt != bj.NumStmt {
|
||||
panic("Not run on same source!")
|
||||
}
|
||||
|
||||
output.Blocks = append(output.Blocks, cover.ProfileBlock{
|
||||
StartLine: bi.StartLine,
|
||||
StartCol: bi.StartCol,
|
||||
EndLine: bi.EndLine,
|
||||
EndCol: bi.EndCol,
|
||||
NumStmt: bi.NumStmt,
|
||||
Count: bi.Count + bj.Count,
|
||||
})
|
||||
i++
|
||||
j++
|
||||
} else if bi.StartLine < bj.StartLine || bi.StartLine == bj.StartLine && bi.StartCol < bj.StartCol {
|
||||
output.Blocks = append(output.Blocks, bi)
|
||||
i++
|
||||
} else {
|
||||
output.Blocks = append(output.Blocks, bj)
|
||||
j++
|
||||
}
|
||||
}
|
||||
|
||||
for ; i < len(p1.Blocks); i++ {
|
||||
output.Blocks = append(output.Blocks, p1.Blocks[i])
|
||||
}
|
||||
|
||||
for ; j < len(p2.Blocks); j++ {
|
||||
output.Blocks = append(output.Blocks, p2.Blocks[j])
|
||||
}
|
||||
|
||||
return &output
|
||||
}
|
||||
|
||||
func print(profiles []*cover.Profile) {
|
||||
fmt.Println("mode: atomic")
|
||||
for _, profile := range profiles {
|
||||
for _, block := range profile.Blocks {
|
||||
fmt.Printf("%s:%d.%d,%d.%d %d %d\n", profile.FileName, block.StartLine, block.StartCol,
|
||||
block.EndLine, block.EndCol, block.NumStmt, block.Count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from https://github.com/golang/tools/blob/master/cover/profile.go
|
||||
type byFileName []*cover.Profile
|
||||
|
||||
func (p byFileName) Len() int { return len(p) }
|
||||
func (p byFileName) Less(i, j int) bool { return p[i].FileName < p[j].FileName }
|
||||
func (p byFileName) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||
|
||||
func main() {
|
||||
outputProfiles := map[string]*cover.Profile{}
|
||||
for _, input := range os.Args[1:] {
|
||||
inputProfiles, err := cover.ParseProfiles(input)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Error parsing %s: %v", input, err))
|
||||
}
|
||||
for _, ip := range inputProfiles {
|
||||
op := outputProfiles[ip.FileName]
|
||||
if op == nil {
|
||||
outputProfiles[ip.FileName] = ip
|
||||
} else {
|
||||
outputProfiles[ip.FileName] = merge(op, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
profiles := make([]*cover.Profile, 0, len(outputProfiles))
|
||||
for _, profile := range outputProfiles {
|
||||
profiles = append(profiles, profile)
|
||||
}
|
||||
sort.Sort(byFileName(profiles))
|
||||
print(profiles)
|
||||
}
|
||||
Submodule
+1
Submodule tools added at caecc98fa8.
Reference in new issue
Block a user