Skip to content

Commit

Permalink
test: add tests for capture command
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <ale_grey_91@hotmail.it>
  • Loading branch information
alegrey91 committed Dec 20, 2024
1 parent 15ed84e commit 4be81b6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ jobs:
make build-bpf
make build-go-cover && sudo make -B install
- name: Build test application
run: |
make build -C tests/testcases/example-app/
- name: Run integration test
run: |
mkdir -p /tmp/integration
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/alegrey91/harpoon

go 1.21
go 1.22

toolchain go1.21.7
toolchain go1.23.2

require (
github.com/aquasecurity/libbpfgo v0.6.0-libbpf-1.3.0.20240111220235-90dbffffbdab
Expand All @@ -14,12 +14,12 @@ require (
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/tools v0.22.0 // indirect
)

require (
github.com/rogpeppe/go-internal v1.12.0
github.com/rogpeppe/go-internal v1.13.1
github.com/spf13/cobra v1.8.0
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/yaml.v2 v2.4.0
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/seccomp/libseccomp-golang v0.10.0 h1:aA4bp+/Zzi0BnWZ2F1wgNBs5gTpm+na2rWM6M9YjLpY=
github.com/seccomp/libseccomp-golang v0.10.0/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
Expand All @@ -24,8 +26,12 @@ golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Expand Down
48 changes: 48 additions & 0 deletions tests/integration.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,54 @@ exec harpoon build -D harpoon/ -S --name profile.json
exists profile.json
cmp profile.json expected-profile.json

# test harpoon capture command
exec harpoon capture -h
stdout 'Usage:'

# setting up test application
exists bin/example-app
# this must be done within the testscript environment
exec chmod +x bin/example-app
exec ls -la bin/example-app
exec bin/example-app coin

exec harpoon capture -f main.main -c -- ./bin/example-app coin
stdout 'stdout: \[flip coin\]'

exec harpoon capture -f main.main -- ./bin/example-app coin
stdout 'write'

exec harpoon capture -f main.main -l -- ./bin/example-app coin
stderr 'libbpf: license of ebpf.o is GPL'

exec harpoon capture -f main.main -i 2 -- ./bin/example-app ten
stdout 'write'
stdout 'nanosleep'

exec harpoon capture -f main.main -i 2 -c -- ./bin/example-app ten
stdout 'write'
stdout 'nanosleep'
stdout 'stdout: hello!'

exec harpoon capture -f main.main -i 2 -S -D /tmp/test-ten -- ./bin/example-app ten
exists /tmp/test-ten/main_main
grep 'write' /tmp/test-ten/main_main
grep 'nanosleep' /tmp/test-ten/main_main

exec harpoon capture -f main.main -c -i 2 -S -D /tmp/test-ten -- ./bin/example-app ten
stdout -count=10 'stdout: hello!'
exists /tmp/test-ten/main_main
grep 'write' /tmp/test-ten/main_main
grep 'nanosleep' /tmp/test-ten/main_main

exec harpoon capture -f main.main -c -i 2 -S -D /tmp/test-infinite -- ./bin/example-app infinite &infinite&
exec sleep 5
kill -KILL infinite
# wait infinite
exists /tmp/test-infinite/main_main
grep 'write' /tmp/test-infinite/main_main
grep 'nanosleep' /tmp/test-infinite/main_main

-- testcases/example-app/harpoon-expected-report.yml --
---
symbolsOrigins:
Expand Down

0 comments on commit 4be81b6

Please sign in to comment.