Skip to content

Commit

Permalink
Allow to run e2e tests with and without coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rewenset committed Sep 27, 2019
1 parent 052637c commit 18e08e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ e2e-tests: ## Run end-to-end tests
@echo "=> running end-to-end tests"
VPP_IMG=$(VPP_IMG) ./tests/e2e/run_e2e.sh

e2e-tests-cover: ## Run end-to-end tests with coverage
@echo "=> running end-to-end tests with coverage"
VPP_IMG=$(VPP_IMG) COVER_DIR=$(COVER_DIR) ./tests/e2e/run_e2e.sh
@echo "=> coverage report generated into ${COVER_DIR}/e2e-cov.out"

# -------------------------------
# Code generation
# -------------------------------
Expand Down
12 changes: 10 additions & 2 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
vppPath = flag.String("vpp-path", "/usr/bin/vpp", "VPP program path")
vppConfig = flag.String("vpp-config", "", "VPP config file")
vppSockAddr = flag.String("vpp-sock-addr", "", "VPP binapi socket address")
covPath = flag.String("cov", "", "Path to collect coverage data")
agentHTTPPort = flag.Int("agent-http-port", 9191, "VPP-Agent HTTP port")
agentGrpcPort = flag.Int("agent-grpc-port", 9111, "VPP-Agent GRPC port")

Expand Down Expand Up @@ -139,8 +140,15 @@ func setupE2E(t *testing.T) *testCtx {

// start the agent
assertProcessNotRunning(t, "vpp_agent")
e2eCovPath := fmt.Sprintf("/tmp/e2e-coverage/%d.out", time.Now().Unix())
agentCmd := startProcess(t, "VPP-Agent", "/vpp-agent", "-test.coverprofile="+e2eCovPath)

var agentArgs []string

if *covPath != "" {
e2eCovPath := fmt.Sprintf("%s/%d.out", *covPath, time.Now().Unix())
agentArgs = []string{"-test.coverprofile", e2eCovPath}
}

agentCmd := startProcess(t, "VPP-Agent", "/vpp-agent", agentArgs...)

// prepare HTTP client for access to REST API of the agent
httpAddr := fmt.Sprintf(":%d", *agentHTTPPort)
Expand Down
30 changes: 21 additions & 9 deletions tests/e2e/run_e2e.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/bin/bash
set -eu

if [ ! -d /tmp/e2e-coverage ]; then
mkdir /tmp/e2e-coverage
elif [ "$(ls -A /tmp/e2e-coverage)" ]; then
rm -f /tmp/e2e-coverage/*
args=($*)

# prepare vpp-agent executable
if [ -z "${COVER_DIR-}" ]; then
go build -v -o ./tests/e2e/vpp-agent ./cmd/vpp-agent
else
if [ ! -d ${COVER_DIR}/e2e-coverage ]; then
mkdir ${COVER_DIR}/e2e-coverage
elif [ "$(ls -A ${COVER_DIR}/e2e-coverage)" ]; then
rm -f ${COVER_DIR}/e2e-coverage/*
fi
go test -covermode=count -coverpkg="github.com/ligato/vpp-agent/..." -c ./cmd/vpp-agent -o ./tests/e2e/vpp-agent
DOCKER_ARGS="${DOCKER_ARGS-} -v ${COVER_DIR}/e2e-coverage:${COVER_DIR}/e2e-coverage"
args+=("-cov=${COVER_DIR}/e2e-coverage")
fi

# compile test
go test -c ./tests/e2e -o ./tests/e2e/e2e.test
go test -covermode=count -coverpkg="github.com/ligato/vpp-agent/..." -c ./cmd/vpp-agent -o ./tests/e2e/vpp-agent

# start vpp image
cid=$(docker run -d -it \
-v $(pwd)/tests/e2e/e2e.test:/e2e.test:ro \
-v $(pwd)/tests/e2e/vpp-agent:/vpp-agent:ro \
-v /tmp/e2e-coverage:/tmp/e2e-coverage \
-v $(pwd)/tests/e2e/grpc.conf:/etc/grpc.conf:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
--label e2e.test="$*" \
Expand All @@ -29,10 +37,14 @@ cid=$(docker run -d -it \


on_exit() {
go get github.com/wadey/gocovmerge
find /tmp/e2e-coverage -type f | xargs gocovmerge > /tmp/e2e-all.out
docker stop -t 2 "$cid" >/dev/null
docker rm "$cid" >/dev/null

# merge coverage
if [ ! -z "${COVER_DIR-}" ]; then
go get github.com/wadey/gocovmerge
find ${COVER_DIR}/e2e-coverage -type f | xargs gocovmerge > ${COVER_DIR}/e2e-cov.out
fi
}

vppver=$(docker exec -i "$cid" dpkg-query -f '${Version}' -W vpp)
Expand All @@ -44,7 +56,7 @@ echo -e " E2E Test - \e[1;33m${vppver}\e[0m"
echo "============================================================="

# run e2e test
if docker exec -i "$cid" /e2e.test -test.v $*; then
if docker exec -i "$cid" /e2e.test -test.v ${args[@]}; then
echo >&2 "-------------------------------------------------------------"
echo >&2 -e " \e[32mPASSED\e[0m (took: ${SECONDS}s)"
echo >&2 "-------------------------------------------------------------"
Expand Down

0 comments on commit 18e08e9

Please sign in to comment.