From 1decfa84c4a339b561eb2515bb74d1f5ca7824a2 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:13:24 +0000 Subject: [PATCH 01/10] make: add testing flags for `make unit` target --- make/testing_flags.mk | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 make/testing_flags.mk diff --git a/make/testing_flags.mk b/make/testing_flags.mk new file mode 100644 index 0000000000..7078705c37 --- /dev/null +++ b/make/testing_flags.mk @@ -0,0 +1,46 @@ +TEST_FLAGS = + +# If specific package is being unit tested, construct the full name of the +# subpackage. +ifneq ($(pkg),) +UNITPKG := $(PKG)/$(pkg) +UNIT_TARGETED = yes +endif + +# If a specific unit test case is being target, construct test.run filter. +ifneq ($(case),) +TEST_FLAGS += -test.run=$(case) +UNIT_TARGETED = yes +endif + +# If a timeout was requested, construct initialize the proper flag for the go +# test command. If not, we set 20m (btcwallet default). +ifneq ($(timeout),) +TEST_FLAGS += -test.timeout=$(timeout) +else +TEST_FLAGS += -test.timeout=20m +endif + +ifneq ($(verbose),) +TEST_FLAGS += -test.v +endif + +ifneq ($(nocache),) +TEST_FLAGS += -test.count=1 +endif + +GOLIST := $(GOCC) list -deps $(PKG)/... | grep '$(PKG)' + +# UNIT_TARGETED is undefined iff a specific package and/or unit test case is +# not being targeted. +UNIT_TARGETED ?= no + +# If a specific package/test case was requested, run the unit test for the +# targeted case. Otherwise, default to running all tests. +ifeq ($(UNIT_TARGETED), yes) +UNIT := $(GOTEST) $(TEST_FLAGS) $(UNITPKG) +endif + +ifeq ($(UNIT_TARGETED), no) +UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS) +endif From 7c58f1f2305190dd31ac547253744d350e8632b5 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:16:34 +0000 Subject: [PATCH 02/10] Makefile: utilize `UNIT` flag in `make unit` target --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 20e34a84e7..235a528931 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,8 @@ CP := cp MAKE := make XARGS := xargs -L 1 +include make/testing_flags.mk + # Linting uses a lot of memory, so keep it under control by limiting the number # of workers if requested. ifneq ($(workers),) @@ -98,7 +100,7 @@ check: unit #? unit: Run unit tests unit: @$(call print, "Running unit tests.") - $(GOLIST) | $(XARGS) env $(GOTEST) -test.timeout=20m + $(UNIT) #? unit-cover: Run unit coverage tests unit-cover: $(GOACC_BIN) From f2a641eee158b3ed4c1a0e02898f9c06afe94d1a Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:24:03 +0000 Subject: [PATCH 03/10] make: add testing flags for `make unit-cover` target --- make/testing_flags.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 7078705c37..ed584ce1d6 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -1,10 +1,13 @@ TEST_FLAGS = +COVER_PKG = $$($(GOCC) list -deps ./... | grep '$(PKG)') +COVER_FLAGS = -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(PKG)/... # If specific package is being unit tested, construct the full name of the # subpackage. ifneq ($(pkg),) UNITPKG := $(PKG)/$(pkg) UNIT_TARGETED = yes +COVER_PKG = $(PKG)/$(pkg) endif # If a specific unit test case is being target, construct test.run filter. @@ -44,3 +47,5 @@ endif ifeq ($(UNIT_TARGETED), no) UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS) endif + +UNIT_COVER := $(GOTEST) $(COVER_FLAGS) $(TEST_FLAGS) $(COVER_PKG) From 82803420d48860c7bb50403a35c41b2614782e33 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:27:41 +0000 Subject: [PATCH 04/10] Makefile: utilize `UNIT_COVER` flag in `make unit-cover` target --- Makefile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 235a528931..c99a4acd17 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ TOOLS_DIR := tools GOCC ?= go LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint -GOACC_PKG := github.com/ory/go-acc GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports GO_BIN := $(shell go env GOBIN) @@ -16,7 +15,6 @@ endif GOIMPORTS_BIN := $(GO_BIN)/gosimports LINT_BIN := $(GO_BIN)/golangci-lint -GOACC_BIN := $(GO_BIN)/go-acc LINT_VERSION := v1.60.1 GOACC_VERSION := v0.2.8 @@ -70,10 +68,6 @@ $(LINT_BIN): @$(call print, "Fetching linter") $(GOINSTALL) $(LINT_PKG)@$(LINT_VERSION) -$(GOACC_BIN): - @$(call print, "Fetching go-acc") - $(GOINSTALL) $(GOACC_PKG)@$(GOACC_VERSION) - # ============ # INSTALLATION # ============ @@ -103,9 +97,9 @@ unit: $(UNIT) #? unit-cover: Run unit coverage tests -unit-cover: $(GOACC_BIN) +unit-cover: @$(call print, "Running unit coverage tests.") - $(GOACC_BIN) $(GOLIST_COVER) + $(UNIT_COVER) #? unit-race: Run unit race tests unit-race: From 029805fdde3c5b1ebaf2cc16614cc0df32b53812 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:31:47 +0000 Subject: [PATCH 05/10] make: make: add testing flags for `make unit-race` target --- make/testing_flags.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/make/testing_flags.mk b/make/testing_flags.mk index ed584ce1d6..4c84867207 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -42,10 +42,12 @@ UNIT_TARGETED ?= no # targeted case. Otherwise, default to running all tests. ifeq ($(UNIT_TARGETED), yes) UNIT := $(GOTEST) $(TEST_FLAGS) $(UNITPKG) +UNIT_RACE := $(GOTEST) $(TEST_FLAGS) -race $(UNITPKG) endif ifeq ($(UNIT_TARGETED), no) UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS) +UNIT_RACE := $(UNIT) -race endif UNIT_COVER := $(GOTEST) $(COVER_FLAGS) $(TEST_FLAGS) $(COVER_PKG) From 9567dfcebea396b76e05c4262d535c396595b75e Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:36:56 +0000 Subject: [PATCH 06/10] Makefile: utilize `UNIT_RACE` flag in `make unit-race` target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c99a4acd17..99563929a3 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ unit-cover: #? unit-race: Run unit race tests unit-race: @$(call print, "Running unit race tests.") - env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOLIST) | $(XARGS) env $(GOTEST) -race -test.timeout=20m + env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE) # ========= # UTILITIES From 5860ef7cb5ae23c7806e9957738e3960265d0373 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:43:51 +0000 Subject: [PATCH 07/10] make: add testing flags for `make unit-debug` target --- make/testing_flags.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 4c84867207..503a7eec53 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -42,11 +42,13 @@ UNIT_TARGETED ?= no # targeted case. Otherwise, default to running all tests. ifeq ($(UNIT_TARGETED), yes) UNIT := $(GOTEST) $(TEST_FLAGS) $(UNITPKG) +UNIT_DEBUG := $(GOTEST) -v $(TEST_FLAGS) $(UNITPKG) UNIT_RACE := $(GOTEST) $(TEST_FLAGS) -race $(UNITPKG) endif ifeq ($(UNIT_TARGETED), no) UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS) +UNIT_DEBUG := $(GOLIST) | $(XARGS) env $(GOTEST) -v $(TEST_FLAGS) UNIT_RACE := $(UNIT) -race endif From 23205bf6fb280659cdbf9349f9c6f6af5fd77db0 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:45:20 +0000 Subject: [PATCH 08/10] Makefile: utilize `UNIT_DEBUG` flag in `make unit-debug` target --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 99563929a3..830785a995 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,11 @@ unit-race: @$(call print, "Running unit race tests.") env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE) +#? unit-debug: Run unit tests with verbose debug output enabled +unit-debug: + @$(call print, "Running debug unit tests.") + $(UNIT_DEBUG) + # ========= # UTILITIES # ========= @@ -148,6 +153,7 @@ tidy-module-check: tidy-module unit \ unit-cover \ unit-race \ + unit-debug \ fmt \ fmt-check \ lint \ From c8004f2192f3dac3efa553b5df855d3840d8db89 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:47:41 +0000 Subject: [PATCH 09/10] make: add testing flags for `make unit-bench` target --- make/testing_flags.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 503a7eec53..cb0f6ebfa7 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -44,12 +44,18 @@ ifeq ($(UNIT_TARGETED), yes) UNIT := $(GOTEST) $(TEST_FLAGS) $(UNITPKG) UNIT_DEBUG := $(GOTEST) -v $(TEST_FLAGS) $(UNITPKG) UNIT_RACE := $(GOTEST) $(TEST_FLAGS) -race $(UNITPKG) +# NONE is a special value which selects no other tests but only executes the +# benchmark tests here. +UNIT_BENCH := $(GOTEST) -test.bench=. -test.run=NONE $(UNITPKG) endif ifeq ($(UNIT_TARGETED), no) UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS) UNIT_DEBUG := $(GOLIST) | $(XARGS) env $(GOTEST) -v $(TEST_FLAGS) UNIT_RACE := $(UNIT) -race +# NONE is a special value which selects no other tests but only executes the +# benchmark tests here. +UNIT_BENCH := $(GOLIST) | $(XARGS) env $(GOTEST) -test.bench=. -test.run=NONE endif UNIT_COVER := $(GOTEST) $(COVER_FLAGS) $(TEST_FLAGS) $(COVER_PKG) From 046c335a64a0597eb6551faf5edac35ddad77997 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 20 Aug 2025 23:48:26 +0000 Subject: [PATCH 10/10] Makefile: utilize `UNIT_BENCH` flag in `make unit-bench` target --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 830785a995..637f070978 100644 --- a/Makefile +++ b/Makefile @@ -111,6 +111,11 @@ unit-debug: @$(call print, "Running debug unit tests.") $(UNIT_DEBUG) +#? unit-bench: Run benchmark tests +unit-bench: + @$(call print, "Running benchmark tests.") + $(UNIT_BENCH) + # ========= # UTILITIES # ========= @@ -154,6 +159,7 @@ tidy-module-check: tidy-module unit-cover \ unit-race \ unit-debug \ + unit-bench \ fmt \ fmt-check \ lint \