Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: enable coverage of crit unit/e2e tests #121

Merged
merged 5 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
make -C crit gen-proto
sudo -E make -C crit all
fi
sudo -E make -C crit unit-test
sudo -E make -C test crit-test

- name: Check code coverage
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ scripts/*.h
scripts/expected.go
scripts/output.go
crit/bin
crit/test-imgs/
22 changes: 19 additions & 3 deletions crit/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GO ?= go
CRIU ?= criu

# The import path that protoc will use if a proto file imports another one
import_path := github.com/checkpoint-restore/go-criu/crit/images
Expand Down Expand Up @@ -37,9 +38,24 @@ gen-proto:
$(proto_files)

bin/crit: cmd/cli.go
$(GO) build -o $@ $^
$(GO) build ${GOFLAGS} -o $@ $^

../test/loop/loop:
rst0git marked this conversation as resolved.
Show resolved Hide resolved
$(MAKE) -C ../test/loop

test-imgs: ../test/loop/loop
$(eval PID := $(shell ../test/loop/loop))
mkdir -p $@
$(CRIU) dump -v4 -o dump.log -D $@ -t $(PID)
$(CRIU) restore -v4 -o restore.log -D $@ -d
pkill -9 loop

unit-test: test-imgs
$(eval GOFLAGS ?= -cover)
adrianreber marked this conversation as resolved.
Show resolved Hide resolved
go test ${GOFLAGS} -v ./...

clean:
rm -f bin/crit
@rm -f bin/crit
@rm -rf test-imgs

.PHONY: all gen-proto update-proto clean
.PHONY: all gen-proto update-proto unit-test clean
12 changes: 4 additions & 8 deletions test/crit/stats_test.go → crit/stats_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package main
package crit

import (
"testing"

"github.com/checkpoint-restore/go-criu/v6/crit"
)
import "testing"

func TestGetDumpStats(t *testing.T) {
dumpStats, err := crit.GetDumpStats("test-imgs")
dumpStats, err := GetDumpStats("test-imgs")
if err != nil {
t.Error("Failed to get stats")
}
Expand All @@ -17,7 +13,7 @@ func TestGetDumpStats(t *testing.T) {
}

func TestGetRestoreStats(t *testing.T) {
restoreStats, err := crit.GetRestoreStats("test-imgs")
restoreStats, err := GetRestoreStats("test-imgs")
if err != nil {
t.Error("Failed to get stats")
}
Expand Down
12 changes: 11 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ phaul/phaul.coverage: check-go-version phaul/*.go
-o $@ phaul/main.go

crit/crit-test.coverage: check-go-version crit/*.go
$(MAKE) -C ../crit bin/crit
# Re-build the crit binary, so that test coverage
# works even if we run `make test` before that.
$(MAKE) -C ../crit clean
$(MAKE) -C ../crit bin/crit GOFLAGS="-cover"
$(MAKE) -C crit/ test-imgs
$(GO) build \
-cover \
Expand All @@ -88,10 +91,17 @@ coverage: check-go-version $(COVERAGE_BINARIES) $(TEST_PAYLOAD)
pkill -9 piggie; \
}
cd crit/ && GOCOVERDIR=${COVERAGE_PATH} ./crit-test.coverage
$(MAKE) -C ../crit/ unit-test GOFLAGS="-coverprofile=${COVERAGE_PATH}/coverprofile-crit-unit-test"
$(MAKE) -C crit/ e2e-test GOCOVERDIR=${COVERAGE_PATH}
$(MAKE) -C crit/ clean
# Print coverage from this run
$(GO) tool covdata percent -i=${COVERAGE_PATH}
$(GO) tool covdata textfmt -i=${COVERAGE_PATH} -o ${COVERAGE_PATH}/coverage.out
# The coverage from 'go test' is stored in coverprofile-*,
# but we upload only 'coverage.out' with codecov. Here we
# combine the coverage results to show up in GitHub.
cat .coverage/coverprofile* | \
rst0git marked this conversation as resolved.
Show resolved Hide resolved
grep -v mode: | sort -r | awk '{if($$1 != last) {print $$0;last=$$1}}' >> ${COVERAGE_PATH}/coverage.out

codecov:
curl -Os https://uploader.codecov.io/latest/linux/codecov
Expand Down
14 changes: 5 additions & 9 deletions test/crit/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
CC ?= gcc
GO ?= go
CRIU ?= criu

all: unit-test integration-test e2e-test clean

unit-test: test-imgs
go test -v ./...
all: integration-test e2e-test clean

integration-test: test-imgs crit-test
@echo "Running integration test"
Expand All @@ -23,15 +19,15 @@ test-imgs: ../loop/loop
pkill -9 loop

../../crit/bin/crit:
$(MAKE) -C ../../crit bin/crit
$(MAKE) -C ../../crit bin/crit GOFLAGS="${GOFLAGS}"

../loop/loop: ../loop/loop.c
$(CC) $^ -o $@
../loop/loop:
$(MAKE) -C ../loop

crit-test: main.go
$(GO) build -v -o $@ $^

clean:
@rm -rf test-imgs

.PHONY: all test unit-test integration-test e2e-test clean
.PHONY: all test integration-test e2e-test clean
4 changes: 4 additions & 0 deletions test/loop/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CC ?= gcc

loop: loop.c
$(CC) $^ -o $@