Skip to content

Commit 6574d88

Browse files
ci: add test coverage to e2e (#1684)
* ci: add test coverage to e2e Signed-off-by: David Son <davbson@amazon.com> * ci: complete e2e coverage with instrumented binary Signed-off-by: ayush-panta <ayushkp@amazon.com> --------- Signed-off-by: David Son <davbson@amazon.com> Signed-off-by: ayush-panta <ayushkp@amazon.com> Co-authored-by: David Son <davbson@amazon.com>
1 parent b8fefdb commit 6574d88

File tree

8 files changed

+47
-15
lines changed

8 files changed

+47
-15
lines changed

.github/workflows/e2e-linux.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
steps:
4747
- name: Clean macOS runner workspace
4848
run: |
49-
rm -rf ${{ github.workspace }}/*
49+
sudo rm -rf ${{ github.workspace }}/*
5050
- name: Allow Node16 on AL2
5151
if: ${{ (startsWith(inputs.os, 'amazon') && inputs.version == '2' ) }}
5252
run: |
@@ -90,10 +90,11 @@ jobs:
9090
sudo rm -rf /var/lib/containerd
9191
sudo rm -rf /var/soci-snapshotter
9292
sudo rm -rf ./_output
93+
sudo rm -rf ./cov
9394
sudo rm -rf /run/containerd || true
9495
- name: Build project
9596
run: |
96-
./contrib/packaging/rpm/build.sh --local
97+
E2E_COVERAGE=1 ./contrib/packaging/rpm/build.sh --local
9798
- name: Install Dependencies
9899
run: |
99100
sudo yum install iptables -y
@@ -133,6 +134,8 @@ jobs:
133134
sudo -E env "PATH=$PATH" INSTALLED=true REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} make test-e2e-container
134135
sudo -E env "PATH=$PATH" INSTALLED=true REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} make test-e2e-vm
135136
sudo -E env "PATH=/usr/libexec/finch:/usr/libexec/finch/cni/bin/:/usr/local/bin:$PATH" NERDCTL_TOML=/etc/finch/nerdctl/nerdctl.toml BUILDKIT_HOST=unix:///var/lib/finch/buildkit/buildkitd.sock make test-e2e-daemon-linux
137+
- name: Show test coverage
138+
run: make test-e2e-cov
136139
- name: Change ownership of reports
137140
if: always()
138141
run: |

.github/workflows/e2e-macos.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,17 @@ jobs:
8585
- name: Build project
8686
run: |
8787
export PATH="/opt/homebrew/opt/libtool/libexec/gnubin:$PATH"
88-
make
88+
E2E_COVERAGE=1 make
8989
shell: zsh {0}
9090
- name: Run e2e tests
9191
run: |
9292
git status
9393
git clean -f -d
9494
REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} make ${{ inputs.test-command }}
9595
shell: zsh {0}
96+
- name: Show test coverage
97+
if: ${{ inputs.test-command != 'test-e2e-daemon' }}
98+
run: make test-e2e-cov
9699
- name: Set artifacts name outputs
97100
if: always()
98101
id: set-multiple-vars

.github/workflows/e2e-ubuntu-finch.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
steps:
8080
- name: Clean Ubuntu workspace
8181
run: |
82-
rm -rf ${{ github.workspace }}/*
82+
sudo rm -rf ${{ github.workspace }}/*
8383
- name: Clean existing Finch environment
8484
run: |
8585
# Stop services
@@ -115,6 +115,7 @@ jobs:
115115
116116
# Clean up root cache
117117
sudo rm -rf /root/.cache || true
118+
sudo rm -rf ${{ github.workspace }}/cov || true
118119
119120
# Reload systemd after cleanup
120121
sudo systemctl daemon-reload
@@ -150,7 +151,7 @@ jobs:
150151
sudo apt install iptables -y
151152
- name: Build for Ubuntu ${{ inputs.output-arch }}
152153
run: |
153-
make
154+
E2E_COVERAGE=1 make
154155
- name: Generate deb
155156
run: |
156157
./contrib/packaging/deb/package.sh --${{ inputs.output-arch }} --version ${{ needs.get-tag-and-version.outputs.version }}
@@ -173,8 +174,10 @@ jobs:
173174
git status
174175
git clean -f -d
175176
eval $(ssh-agent)
176-
sudo -E env "PATH=$PATH" INSTALLED=true make test-e2e-container
177-
sudo -E env "PATH=$PATH" INSTALLED=true make test-e2e-vm
177+
sudo -E env "PATH=$PATH" INSTALLED=false make test-e2e-container
178+
sudo -E env "PATH=$PATH" INSTALLED=false make test-e2e-vm
179+
- name: Show test coverage
180+
run: make test-e2e-cov
178181
- name: Change ownership of reports
179182
if: always()
180183
run: |

.github/workflows/e2e-windows.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ jobs:
7575
run: |
7676
Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore
7777
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse -ErrorAction Ignore
78+
Remove-Item ${{ github.workspace }}\cov -Recurse -ErrorAction Ignore
7879
make clean
7980
cd deps/finch-core && make clean
8081
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
@@ -84,6 +85,7 @@ jobs:
8485
- name: Build project
8586
run: |
8687
git status
88+
$env:E2E_COVERAGE="1"
8789
make
8890
- name: Run e2e tests
8991
run: |
@@ -98,6 +100,8 @@ jobs:
98100
git clean -f -d
99101
100102
make ${{ inputs.test-command }}
103+
- name: Show test coverage
104+
run: make test-e2e-cov
101105
- name: Set artifacts name outputs
102106
if: always()
103107
id: set-multiple-vars

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ _vde_output/
77
**/*.tar.gz
88
**/*.lz4
99
**/*.img
10+
cov/
1011
tmp/
1112
.vscode/
1213
tools_bin/

Makefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DEST := $(shell echo "$(DESTDIR)/$(PREFIX)" | sed 's:///*:/:g; s://*$$::')
88
BINDIR ?= /usr/local/bin
99
OUTDIR ?= $(CURDIR)/_output
1010
OS_OUTDIR ?= $(OUTDIR)/os
11+
COVERAGE_DIR ?= $(CURDIR)/cov
1112
REPORT_DIR ?= $(CURDIR)/reports
1213
RUN_ID ?= $(GITHUB_RUN_ID)
1314
RUN_ATTEMPT ?= $(GITHUB_RUN_ATTEMPT)
@@ -174,8 +175,9 @@ finch-unix: finch-all
174175
finch-native: GO_BUILD_TAGS += native
175176
finch-native: finch-all
176177

178+
E2E_COVERAGE ?=
177179
finch-all:
178-
$(GO) build -ldflags $(LDFLAGS) -tags "$(GO_BUILD_TAGS)" -o $(OUTDIR)/bin/$(BINARYNAME) $(PACKAGE)/cmd/finch
180+
$(GO) build $(if $(E2E_COVERAGE),-cover) -ldflags $(LDFLAGS) -tags "$(GO_BUILD_TAGS)" -o $(OUTDIR)/bin/$(BINARYNAME) $(PACKAGE)/cmd/finch
179181

180182
.PHONY: release
181183
release: check-licenses all download-licenses
@@ -185,7 +187,7 @@ $(OUTDIR)/finch-daemon/finch@.service:
185187

186188
.PHONY: coverage
187189
coverage:
188-
go test $(shell go list ./... | grep -v e2e | grep -v benchmark | grep -v mocks) -coverprofile=test-coverage.out
190+
go test $(shell go list ./... | grep -v e2e | grep -v benchmark | grep -v mocks)
189191
go tool cover -html=test-coverage.out
190192

191193
.PHONY: download-licenses
@@ -299,6 +301,10 @@ test-unit:
299301
# Container tests and VM tests can be run in any order, but they must be run sequentially.
300302
# For more details, see the package-level comment of the e2e package.
301303

304+
.PHONY: create-coverage-dir
305+
create-coverage-dir:
306+
mkdir -p $(COVERAGE_DIR)
307+
302308
.PHONY: create-report-dir
303309
create-report-dir:
304310
mkdir -p $(REPORT_DIR)
@@ -307,16 +313,20 @@ create-report-dir:
307313
test-e2e: test-e2e-vm-serial test-e2e-container
308314

309315
.PHONY: test-e2e-vm-serial
310-
test-e2e-vm-serial: create-report-dir
311-
go test -ldflags $(LDFLAGS) -timeout 2h ./e2e/vm -test.v -ginkgo.v -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-vm-serial-report.json --installed="$(INSTALLED)"
316+
test-e2e-vm-serial: create-report-dir create-coverage-dir
317+
FINCH_GOCOVERDIR=$(COVERAGE_DIR) go test -coverpkg=./... -ldflags $(LDFLAGS) -timeout 2h ./e2e/vm -test.v -test.gocoverdir=$(COVERAGE_DIR) -ginkgo.v -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-vm-serial-report.json --installed="$(INSTALLED)"
312318

313319
.PHONY: test-e2e-container
314-
test-e2e-container: create-report-dir
315-
go test -ldflags $(LDFLAGS) -timeout 2h ./e2e/container -test.v -ginkgo.v -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-container-report.json --installed="$(INSTALLED)"
320+
test-e2e-container: create-report-dir create-coverage-dir
321+
FINCH_GOCOVERDIR=$(COVERAGE_DIR) go test -coverpkg=./... -ldflags $(LDFLAGS) -timeout 2h ./e2e/container -test.v -test.gocoverdir=$(COVERAGE_DIR) -ginkgo.v -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-container-report.json --installed="$(INSTALLED)"
316322

317323
.PHONY: test-e2e-vm
318-
test-e2e-vm: create-report-dir
319-
go test -ldflags $(LDFLAGS) -timeout 2h ./e2e/vm -test.v -ginkgo.v -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-vm-report.json --installed="$(INSTALLED)" --registry="$(REGISTRY)"
324+
test-e2e-vm: create-report-dir create-coverage-dir
325+
FINCH_GOCOVERDIR=$(COVERAGE_DIR) go test -coverpkg=./... -ldflags $(LDFLAGS) -timeout 2h ./e2e/vm -test.v -test.gocoverdir=$(COVERAGE_DIR) -ginkgo.v -ginkgo.timeout=2h -ginkgo.focus "updates init-only config values when values are changed after init" -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-vm-report.json --installed="$(INSTALLED)" --registry="$(REGISTRY)"
326+
327+
.PHONY: test-e2e-cov
328+
test-e2e-cov:
329+
go tool covdata percent -i=$(COVERAGE_DIR) -pkg=$(shell go list ./... | grep -v e2e | grep -v benchmark | grep -v version | tr '\n' ',')
320330

321331
GINKGO = go run github.com/onsi/ginkgo/v2/ginkgo
322332
# Common ginkgo options: -v for verbose mode, --focus="test name" for running single tests

coverage/coverage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func main() {
2626
}
2727

2828
cmd := exec.Command("go", "tool", "cover", "-func=coverage.out")
29+
2930
output, err := cmd.Output()
3031
if err != nil {
3132
fmt.Fprintln(os.Stderr, "Error executing coverage command:", err)

e2e/e2e.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ func CreateOption() (*option.Option, error) {
7979
if err != nil {
8080
return nil, fmt.Errorf("failed to initialize a testing option: %w", err)
8181
}
82+
83+
// Explicitly pass GOCOVERDIR for coverage collection
84+
// Use FINCH_GOCOVERDIR to avoid conflict with test process's GOCOVERDIR
85+
if gocoverdir := os.Getenv("FINCH_GOCOVERDIR"); gocoverdir != "" {
86+
o.UpdateEnv("GOCOVERDIR", gocoverdir)
87+
}
88+
8289
return o, nil
8390
}
8491

0 commit comments

Comments
 (0)