From 54217d096d02a6206343325862852fd5c8b57ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20C=2E=20Morency?= <1102868+fmorency@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:23:37 -0400 Subject: [PATCH] feat(cov): add simulator tests to coverage (#204) * feat(cov): add simulator tests to coverage * fix: coverage ignore file [skip_ci] * chore: fix ci comment [skip_ci] * fix: import/export test to coverage --- .coverageignore | 1 - Makefile | 43 ++++++++++++++++++++++++++++++-------- scripts/filter-coverage.sh | 4 ++-- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/.coverageignore b/.coverageignore index f3ce024..8df0dfc 100644 --- a/.coverageignore +++ b/.coverageignore @@ -1,4 +1,3 @@ *.pb.go *.pb.gw.go *.pulsar.go -*_simulation.go diff --git a/Makefile b/Makefile index 4af4471..a6d3049 100644 --- a/Makefile +++ b/Makefile @@ -40,18 +40,43 @@ ictest-gov: .PHONY: test ictest-poa ictest-jail ictest-val-add ictest-val-remove +COV_ROOT="/tmp/poa-coverage" +COV_UNIT_E2E="${COV_ROOT}/unit-e2e" +COV_SIMULATION="${COV_ROOT}/simulation" +COV_PKG="github.com/strangelove-ventures/poa/..." +COV_SIM_CMD=${COV_SIMULATION}/simulation.test +COV_SIM_COMMON=-Enabled=True -NumBlocks=100 -Commit=true -Period=5 -Params=$(shell pwd)/simulation/sim_params.json -Verbose=false -test.v -test.gocoverdir=${COV_SIMULATION} + coverage: ## Run coverage report - @echo "--> Running coverage" - @go test -race -cpu=$$(nproc) -covermode=atomic -coverprofile=coverage.out $$(go list ./...) ./e2e/... ./simapp/... -coverpkg=github.com/strangelove-ventures/poa/... > /dev/null 2>&1 - @echo "--> Running coverage filter" - @./scripts/filter-coverage.sh - @echo "--> Running coverage report" - @go tool cover -func=coverage-filtered.out - @echo "--> Running coverage html" - @go tool cover -html=coverage-filtered.out -o coverage.html + @echo "--> Creating GOCOVERDIR" + @mkdir -p ${COV_UNIT_E2E} ${COV_SIMULATION} + @echo "--> Cleaning up coverage files, if any" + @rm -rf ${COV_UNIT_E2E}/* ${COV_SIMULATION}/* + @echo "--> Building instrumented simulation test binary" + @go test -c ./simapp -mod=readonly -covermode=atomic -coverpkg=${COV_PKG} -cover -o ${COV_SIM_CMD} + @echo " --> Running Full App Simulation" + @${COV_SIM_CMD} -test.run TestFullAppSimulation ${COV_SIM_COMMON} > /dev/null 2>&1 + @echo " --> Running App Simulation After Import" + @${COV_SIM_CMD} -test.run TestAppSimulationAfterImport ${COV_SIM_COMMON} > /dev/null 2>&1 + @echo " --> Running App Import/Export Simulation" + @${COV_SIM_CMD} -test.run TestAppImportExport ${COV_SIM_COMMON} > /dev/null 2>&1 + @echo " --> Running App State Determinism Simulation" + @${COV_SIM_CMD} -test.run TestAppStateDeterminism ${COV_SIM_COMMON} > /dev/null 2>&1 + @echo "--> Running unit & e2e tests coverage" + @go test -race -covermode=atomic -v -cpu=$$(nproc) -cover $$(go list ./...) ./e2e/... ./simapp/... -coverpkg=${COV_PKG} -args -test.gocoverdir="${COV_UNIT_E2E}" > /dev/null 2>&1 + @echo "--> Merging coverage reports" + @go tool covdata merge -i=${COV_UNIT_E2E},${COV_SIMULATION} -o ${COV_ROOT} + @echo "--> Converting binary coverage report to text format" + @go tool covdata textfmt -i=${COV_ROOT} -o ${COV_ROOT}/coverage-merged.out + @echo "--> Filtering coverage reports" + @./scripts/filter-coverage.sh ${COV_ROOT}/coverage-merged.out ${COV_ROOT}/coverage-merged-filtered.out + @echo "--> Generating coverage report" + @go tool cover -func=${COV_ROOT}/coverage-merged-filtered.out + @echo "--> Generating HTML coverage report" + @go tool cover -html=${COV_ROOT}/coverage-merged-filtered.out -o coverage.html @echo "--> Coverage report available at coverage.html" @echo "--> Cleaning up coverage files" - @rm coverage.out + @rm -rf ${COV_UNIT_E2E}/* ${COV_SIMULATION}/* @echo "--> Running coverage complete" .PHONY: coverage diff --git a/scripts/filter-coverage.sh b/scripts/filter-coverage.sh index 1a316a1..0f9bd05 100755 --- a/scripts/filter-coverage.sh +++ b/scripts/filter-coverage.sh @@ -1,7 +1,7 @@ #!/bin/bash -coverage_profile="coverage.out" -filtered_coverage_profile="coverage-filtered.out" +coverage_profile="$1" +filtered_coverage_profile="$2" exclusion_file=".coverageignore" cp "$coverage_profile" "$filtered_coverage_profile"