Skip to content

Commit

Permalink
test: enable coverage of crit unit tests
Browse files Browse the repository at this point in the history
This moves the unit tests in the crit package and enables code coverage.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
  • Loading branch information
rst0git committed Apr 15, 2023
1 parent 83fc137 commit adb3bef
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
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/
20 changes: 18 additions & 2 deletions crit/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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
# Path to .proto source files
Expand Down Expand Up @@ -39,7 +41,21 @@ gen-proto:
bin/crit: cmd/cli.go
$(GO) build -o $@ $^

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

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
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
3 changes: 3 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ 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/ 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
cat .coverage/coverprofile* | \
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
7 changes: 2 additions & 5 deletions test/crit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,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 Down Expand Up @@ -34,4 +31,4 @@ crit-test: main.go
clean:
@rm -rf test-imgs

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

0 comments on commit adb3bef

Please sign in to comment.