-
Notifications
You must be signed in to change notification settings - Fork 8
83 lines (71 loc) · 2.22 KB
/
test-go-packages.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Test Go Packages
on:
push:
branches: [ main ]
paths:
- 'pkg/**/*.go'
- 'go.mod'
- 'go.sum'
- '.github/workflows/test-go-packages.yaml'
pull_request:
branches: [ main ]
paths:
- 'pkg/**/*.go'
- 'go.mod'
- 'go.sum'
workflow_dispatch:
jobs:
test:
name: Run Go Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
check-latest: true
cache: true
- name: Install dependencies
run: go mod download
- name: Install libcap
run: sudo apt-get update && sudo apt-get install -y libcap2-bin
- name: Run perf-related package tests
run: |
# Compile the test binaries for perf and perf_ebpf packages
go test -c ./pkg/perf ./pkg/perf_ebpf -race -o .
# Add CAP_PERFMON capability to the test binary
sudo setcap cap_perfmon+ep perf.test
sudo setcap cap_perfmon,cap_bpf+ep perf_ebpf.test
# Verify capability
getcap perf.test
getcap perf_ebpf.test
# Check if perf_event_paranoid is restricting access
cat /proc/sys/kernel/perf_event_paranoid
# Set perf_event_paranoid to 1
echo 1 | sudo tee /proc/sys/kernel/perf_event_paranoid
# Verify perf_event_paranoid
cat /proc/sys/kernel/perf_event_paranoid
# Run the perf tests with the permissioned binary
./perf.test -test.v
./perf_ebpf.test -test.v
- name: Run other package tests
run: |
# Run tests for all packages except perf and perf_ebpf
if [ -n "$(go list ./pkg/... | grep -v 'pkg/perf\|pkg/perf_ebpf')" ]; then
go test -v -race $(go list ./pkg/... | grep -v 'pkg/perf\|pkg/perf_ebpf')
fi
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m
working-directory: pkg/
- name: Check formatting
run: |
# Check if any .go files are not properly formatted
if [ -n "$(gofmt -l ./pkg)" ]; then
echo "The following files are not properly formatted:"
gofmt -l ./pkg
exit 1
fi