diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 429b09171..720d2a27e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -274,7 +274,13 @@ jobs: run: ./scripts/install_bitcoind.sh $BITCOIN_VERSION - name: run ${{ matrix.name }} - run: make itest-parallel ${{ matrix.args }} + run: make itest-parallel ${{ matrix.args }} cover=1 + + - name: Send coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.txt + parallel: true - name: Zip log files on failure if: ${{ failure() }} diff --git a/.gitignore b/.gitignore index 16d33c142..a44a7b8f5 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ itest/.minerlogs itest/lnd-itest itest/btcd-itest itest/.logs-* +itest/cover cmd/cmd *.key diff --git a/Makefile b/Makefile index 41fabbfcc..3c42cd6cf 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ build: build-itest: @$(call print, "Building itest btcd and lnd.") CGO_ENABLED=0 $(GOBUILD) -tags="integration" -o itest/btcd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(BTCD_PKG) - CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o itest/lnd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(PKG)/cmd/lnd + CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" $(ITEST_COVERAGE) -o itest/lnd-itest$(EXEC_SUFFIX) $(DEV_LDFLAGS) $(PKG)/cmd/lnd @$(call print, "Building itest binary for ${backend} backend.") CGO_ENABLED=0 $(GOTEST) -v ./itest -tags="$(DEV_TAGS) $(RPC_TAGS) integration $(backend)" -c -o itest/itest.test$(EXEC_SUFFIX) @@ -197,6 +197,7 @@ itest-only: db-instance @$(call print, "Running integration tests with ${backend} backend.") rm -rf itest/*.log itest/.logs-*; date EXEC_SUFFIX=$(EXEC_SUFFIX) scripts/itest_part.sh 0 1 $(TEST_FLAGS) $(ITEST_FLAGS) + $(COLLECT_ITEST_COVERAGE) #? itest: Build and run integration tests itest: build-itest itest-only @@ -209,6 +210,7 @@ itest-parallel: build-itest db-instance @$(call print, "Running tests") rm -rf itest/*.log itest/.logs-*; date EXEC_SUFFIX=$(EXEC_SUFFIX) scripts/itest_parallel.sh $(ITEST_PARALLELISM) $(NUM_ITEST_TRANCHES) $(TEST_FLAGS) $(ITEST_FLAGS) + $(COLLECT_ITEST_COVERAGE) #? itest-clean: Kill all running itest processes itest-clean: diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 3fecb073a..b2db6861c 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -2,7 +2,9 @@ DEV_TAGS = dev RPC_TAGS = autopilotrpc chainrpc invoicesrpc neutrinorpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc LOG_TAGS = TEST_FLAGS = -ITEST_FLAGS = +ITEST_FLAGS = +ITEST_COVERAGE = +COLLECT_ITEST_COVERAGE = EXEC_SUFFIX = COVER_PKG = $$(go list -deps -tags="$(DEV_TAGS)" ./... | grep '$(PKG)' | grep -v lnrpc) NUM_ITEST_TRANCHES = 4 @@ -77,6 +79,12 @@ ifneq ($(tags),) DEV_TAGS += ${tags} endif +# Enable integration test coverage (requires Go >= 1.20.0). +ifneq ($(cover),) +ITEST_COVERAGE = -cover +COLLECT_ITEST_COVERAGE = go tool covdata textfmt -i=itest/cover -o coverage.txt +endif + # Define the log tags that will be applied only when running unit tests. If none # are provided, we default to "nolog" which will be silent. ifneq ($(log),) diff --git a/scripts/itest_part.sh b/scripts/itest_part.sh index 312e13a01..bdf4ecdf5 100755 --- a/scripts/itest_part.sh +++ b/scripts/itest_part.sh @@ -16,6 +16,8 @@ shift EXEC="$WORKDIR"/itest.test"$EXEC_SUFFIX" LND_EXEC="$WORKDIR"/lnd-itest"$EXEC_SUFFIX" BTCD_EXEC="$WORKDIR"/btcd-itest"$EXEC_SUFFIX" +export GOCOVERDIR="$WORKDIR/cover" +mkdir -p "$GOCOVERDIR" echo $EXEC -test.v "$@" -logoutput -logdir=.logs-tranche$TRANCHE -lndexec=$LND_EXEC -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE # Exit code 255 causes the parallel jobs to abort, so if one part fails the