Skip to content

Commit

Permalink
chore(Makefile): Fix test run control
Browse files Browse the repository at this point in the history
Remove the verbose test targets. You can enable this
with make VERBOSE=1 test.

Ensure e2e tests aren't run in the normal test target
as they will fail.

Skip bpfassets tests as they need sudo.

Compile bpfassets tests to a tmpdir and then run them.

Fix assertions in the bpfassets test to skip cpuFreq
given that this isn't populated, and to add more
assertions in the data that comes from `processes`.

Split test run into unit-test, bpf-test and bench
targets.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
  • Loading branch information
dave-tucker committed May 15, 2024
1 parent cd70136 commit 1630918
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 60 deletions.
82 changes: 41 additions & 41 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ jobs:
unit_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.1
with:
persist-credentials: false
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Get ginkgo
run: make ginkgo-set
env:
- uses: actions/checkout@v4.1.1
with:
persist-credentials: false
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Get ginkgo
run: make ginkgo-set
env:
GOPATH: /home/runner/go
GOBIN: /home/runner/go/bin
- name: Prepare environment
run: |
- name: Prepare environment
run: |
sudo apt-get install -y cpuid clang
cd doc/ && sudo ./dev/prepare_dev_env.sh && cd -
git config --global --add safe.directory /kepler
- name: install libbpf
uses: sustainable-computing-io/kepler-action@v0.0.6
with:
ebpfprovider: libbpf
- name: Run
run: |
- name: install libbpf
uses: sustainable-computing-io/kepler-action@v0.0.6
with:
ebpfprovider: libbpf
- name: Run
run: |
sudo apt remove libbpf-dev
mkdir temp-libbpf
cd temp-libbpf
Expand All @@ -47,30 +47,30 @@ jobs:
sudo make install_uapi_headers
sudo prefix=/usr BUILD_STATIC_ONLY=y make install
cd ../../../
ATTACHER_TAG=libbpf make test-verbose
make VERBOSE=1 test
go tool cover -func=coverage.out -o=coverage.out
- name: Go Coverage Badge # Pass the `coverage.out` output to this action
uses: tj-actions/coverage-badge-go@v2
with:
filename: coverage.out
- name: Go Coverage Badge # Pass the `coverage.out` output to this action
uses: tj-actions/coverage-badge-go@v2
with:
filename: coverage.out

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v19
id: verify-changed-files
with:
files: README.md
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v19
id: verify-changed-files
with:
files: README.md

- name: Commit changes
if: github.event_name != 'pull_request' && steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "bot@sustainable-computing.io"
git config --local user.name "sustainable-computing-bot"
git add README.md
git commit -m "bot: Updated coverage badge." -s
- name: Commit changes
if: github.event_name != 'pull_request' && steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "bot@sustainable-computing.io"
git config --local user.name "sustainable-computing-bot"
git add README.md
git commit -m "bot: Updated coverage badge." -s
- name: Push changes
if: github.event_name != 'pull_request' && steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_BOT_SECRET }}
branch: ${{ github.head_ref }}
- name: Push changes
if: github.event_name != 'pull_request' && steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_BOT_SECRET }}
branch: ${{ github.head_ref }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ local-dev-cluster

# object files
*.o

# test coverage
coverage.out
62 changes: 43 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ clean-cross-build:
build: clean_build_local _build_local copy_build_local ## Build binary and copy to $(OUTPUT_DIR)/bin
.PHONY: build

_build_local: ## Build Kepler binary locally.
_build_ebpf_local:
@make -C bpfassets/libbpf

_build_local: _build_ebpf_local ## Build Kepler binary locally.
@echo TAGS=$(GO_BUILD_TAGS)
@mkdir -p "$(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)"
+@$(GOENV) go build -v -tags ${GO_BUILD_TAGS} -o $(CROSS_BUILD_BINDIR)/$(GOOS)_$(GOARCH)/kepler -ldflags $(LDFLAGS) ./cmd/exporter/exporter.go
Expand Down Expand Up @@ -229,17 +231,20 @@ cross-build: clean_build_local cross-build-linux-amd64 cross-build-linux-arm64 c
.PHONY: cross-build

## toolkit ###
.PHONY: tidy-vendor
tidy-vendor:
go mod tidy -v
go mod vendor

.PHONY: ginkgo-set
ginkgo-set:
mkdir -p $(GOBIN)
mkdir -p $(ENVTEST_ASSETS_DIR)
@test -f $(ENVTEST_ASSETS_DIR)/ginkgo || \
(go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo@v2.4.0 && \
cp $(GOBIN)/ginkgo $(ENVTEST_ASSETS_DIR)/ginkgo)

.PHONY: container_test
container_test:
$(CTR_CMD) run --rm \
-v $(base_dir):/kepler:Z\
Expand All @@ -254,32 +259,51 @@ container_test:
cd doc/ && \
./dev/prepare_dev_env.sh && \
cd - && git config --global --add safe.directory /kepler && \
make test-container-verbose'
make VERBOSE=1 unit-test bench'

test: ginkgo-set tidy-vendor
@echo TAGS=$(GO_TEST_TAGS)
@$(GOENV) go test -tags $(GO_TEST_TAGS) ./... --race --bench=. -cover --count=1 --vet=all -v
VERBOSE ?= 0
TMPDIR := $(shell mktemp -d)
TEST_PKGS := $(shell go list ./... | grep -v bpfassets | grep -v e2e)
SUDO?=sudo
SUDO_TEST_PKGS := $(shell go list ./... | grep bpfassets)

test-verbose: ginkgo-set tidy-vendor
@echo TAGS=$(GO_TEST_TAGS)
@echo GOENV=$(GOENV)
@$(GOENV) go test -tags $(GO_TEST_TAGS) \
-timeout=30m \
-covermode=atomic -coverprofile=coverage.out \
-v $$(go list ./... | grep pkg | grep -v bpfassets) \
--race --bench=. -cover --count=1 --vet=all
.PHONY: test
test: unit-test bpf-test bench ## Run all tests.

test-container-verbose: ginkgo-set tidy-vendor
.PHONY: unit-test
unit-test: ginkgo-set tidy-vendor ## Run unit tests.
@echo TAGS=$(GO_TEST_TAGS)
@echo GOENV=$(GOENV)
$(if $(VERBOSE),@echo GOENV=$(GOENV))
@$(GOENV) go test -tags $(GO_TEST_TAGS) \
-covermode=atomic -coverprofile=coverage.out \
-v $$(go list ./... | grep pkg | grep -v bpfassets) \
--race -cover --count=1 --vet=all
$(if $(VERBOSE),-v) \
-cover -covermode=atomic -coverprofile=coverage.out \
--race --count=1 \
$(TEST_PKGS)

.PHONY: bench
bench: ## Run benchmarks.
@echo TAGS=$(GO_TEST_TAGS)
$(GOENV) go test -tags $(GO_TEST_TAGS) \
$(if $(VERBOSE),-v) \
-test.run=dontrunanytests \
-bench=. --count=1 $(TEST_PKGS)

.PHONY: bpf-test
bpf-test: _build_ebpf_local ## Run BPF tests.
for pkg in $(SUDO_TEST_PKGS); do \
$(GOENV) go test -c $$pkg -tags $(GO_TEST_TAGS) -cover \
-covermode=atomic -coverprofile=coverage.bpf.out \
-o $(TMPDIR)/$$(basename $$pkg).test && \
$(SUDO) $(TMPDIR)/$$(basename $$pkg).test; \
done

.PHONY: test-mac-verbose
test-mac-verbose: ginkgo-set
@echo TAGS=$(GO_TEST_TAGS)
@go test $$(go list ./... | grep pkg | grep -v bpfassets) --race --bench=. -cover --count=1 --vet=all
@go test \
-covermode=atomic -coverprofile=coverage.out \
--race --count=1 \
$(TEST_PKGS)

escapes_detect: tidy-vendor
@$(GOENV) go build -tags $(GO_BUILD_TAGS) -gcflags="-m -l" ./... 2>&1 | grep "escapes to heap" || true
Expand Down

0 comments on commit 1630918

Please sign in to comment.