Skip to content

Commit

Permalink
feat(cov): add simulator tests to coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Jul 23, 2024
1 parent 3595e3d commit 98cb836
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
44 changes: 35 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,44 @@ 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
# Enable when https://github.com/strangelove-ventures/poa/pull/202 is merged
# @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
Expand Down
4 changes: 2 additions & 2 deletions scripts/filter-coverage.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 98cb836

Please sign in to comment.