-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increase testing coverage (and some related refactors) #86
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dd07353
Testing RingBufForwarder (44% -> 53% cov)
mariomac e03cb7d
ringbuf forwarder: don't create ticker if there is no batch timeout
mariomac f86c747
Reduced cyclomatic complexity of ringbufForwarder
mariomac e720caf
Merging integration tests coverage data
mariomac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,5 @@ linters-settings: | |
- indexAlloc | ||
- deprecatedComment | ||
cyclop: | ||
max-complexity: 20 | ||
max-complexity: 10 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ MAIN_GO_FILE ?= cmd/$(CMD)/main.go | |
GOOS ?= linux | ||
GOARCH ?= amd64 | ||
|
||
TEST_OUTPUT ?= ./testoutput | ||
|
||
IMG_REGISTRY ?= docker.io | ||
# Set your registry username. CI will set 'grafana' but you mustn't use it for manual pushing. | ||
IMG_ORG ?= | ||
|
@@ -27,7 +29,7 @@ CLANG ?= clang | |
CFLAGS := -O2 -g -Wall -Werror $(CFLAGS) | ||
|
||
# regular expressions for excluded file patterns | ||
EXCLUDE_COVERAGE_FILES="(/cmd/)|(bpf_bpfe)|(/pingserver/)|(/test/collector/)" | ||
EXCLUDE_COVERAGE_FILES="(bpf_)|(/pingserver/)|(/test/collector/)" | ||
|
||
.DEFAULT_GOAL := all | ||
|
||
|
@@ -71,6 +73,7 @@ GO_OFFSETS_TRACKER = $(TOOLS_DIR)/go-offsets-tracker | |
.PHONY: prereqs | ||
prereqs: | ||
@echo "### Check if prerequisites are met, and installing missing dependencies" | ||
mkdir -p $(TEST_OUTPUT) | ||
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/[email protected]) | ||
$(call go-install-tool,$(BPF2GO),github.com/cilium/ebpf/cmd/[email protected]) | ||
$(call go-install-tool,$(GO_OFFSETS_TRACKER),github.com/grafana/go-offsets-tracker/cmd/[email protected]) | ||
|
@@ -114,24 +117,30 @@ compile: | |
@echo "### Compiling project" | ||
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod vendor -ldflags -a -o bin/$(CMD) $(MAIN_GO_FILE) | ||
|
||
# Generated binary can provide coverage stats according to https://go.dev/blog/integration-test-coverage | ||
.PHONY: compile-for-coverage | ||
compile-for-coverage: | ||
@echo "### Compiling project to generate coverage profiles" | ||
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -mod vendor -cover -a -o bin/$(CMD) $(MAIN_GO_FILE) | ||
|
||
.PHONY: test | ||
test: | ||
@echo "### Testing code" | ||
go test -mod vendor -a ./... -coverpkg=./... -coverprofile cover.all.out | ||
go test -mod vendor -a ./... -coverpkg=./... -coverprofile $(TEST_OUTPUT)/cover.all.txt | ||
|
||
.PHONY: cov-exclude-generated | ||
cov-exclude-generated: | ||
grep -vE $(EXCLUDE_COVERAGE_FILES) cover.all.out > cover.out | ||
grep -vE $(EXCLUDE_COVERAGE_FILES) $(TEST_OUTPUT)/cover.all.txt > $(TEST_OUTPUT)/cover.txt | ||
|
||
.PHONY: coverage-report | ||
coverage-report: cov-exclude-generated | ||
@echo "### Generating coverage report" | ||
go tool cover --func=./cover.out | ||
go tool cover --func=$(TEST_OUTPUT)/cover.txt | ||
|
||
.PHONY: coverage-report-html | ||
coverage-report-html: cov-exclude-generated | ||
@echo "### Generating HTML coverage report" | ||
go tool cover --html=./cover.out | ||
go tool cover --html=$(TEST_OUTPUT)/cover.txt | ||
|
||
.PHONY: image-build-push | ||
image-build-push: | ||
|
@@ -158,18 +167,29 @@ cleanup-integration-test: | |
$(OCI_BIN) compose $(COMPOSE_ARGS) rm -f | ||
$(OCI_BIN) rmi -f $(shell $(OCI_BIN) images --format '{{.Repository}}:{{.Tag}}' | grep 'hatest-') || true | ||
|
||
# TODO: provide coverage info for integration testing https://go.dev/blog/integration-test-coverage | ||
.PHONY: run-integration-test | ||
run-integration-test: | ||
@echo "### Running integration tests" | ||
go clean -testcache | ||
go test -mod vendor -a ./test/integration/... --tags=integration | ||
|
||
.PHONY: integration-test | ||
integration-test: prepare-integration-test | ||
integration-test: prereqs prepare-integration-test | ||
$(MAKE) run-integration-test || (ret=$$?; $(MAKE) cleanup-integration-test && exit $$ret) | ||
$(MAKE) itest-coverage-data | ||
$(MAKE) cleanup-integration-test | ||
|
||
.PHONY: itest-coverage-data | ||
itest-coverage-data: | ||
# merge coverage data from all the integration tests | ||
mkdir -p $(TEST_OUTPUT)/merge | ||
go tool covdata merge -i=$(TEST_OUTPUT) -o $(TEST_OUTPUT)/merge | ||
go tool covdata textfmt -i=$(TEST_OUTPUT)/merge -o $(TEST_OUTPUT)/itest-covdata.raw.txt | ||
# replace the unexpected /src/cmd/otelauto/main.go file by the module path | ||
sed 's/^\/src\/cmd\//github.com\/grafana\/ebpf-autoinstrument\/cmd\//' $(TEST_OUTPUT)/itest-covdata.raw.txt > $(TEST_OUTPUT)/itest-covdata.all.txt | ||
# exclude generated files from coverage data | ||
grep -vE $(EXCLUDE_COVERAGE_FILES) $(TEST_OUTPUT)/itest-covdata.all.txt > $(TEST_OUTPUT)/itest-covdata.txt | ||
|
||
.PHONY: drone | ||
drone: | ||
@echo "### Regenerating and signing .drone/drone.yml" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grcevski this will conflict with your ongoing work, but I had to do it here because the runtime coverage generator requires a graceful stop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's fine, not a problem. I'll merge.