Skip to content

Commit

Permalink
Add make target to enable debugger during test run
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed Jan 14, 2025
1 parent 479f0c3 commit 40cadec
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
46 changes: 46 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
### Debugging test

#### MacOS

You could debug test with [Delve](https://github.com/go-delve/delve) debugger.
Run:
```shell
make test-mac-debug
```
This command will run build `gvisor` binary with debugger enabled.

>Note: By default it would use `--continue` `dlv` option to not pause `gvisor` execution on start, if debugger is not connected.
> To pause `gvisor` execution until debugger is connected just remove `"--continue"` parameter from this [line](./test-vfkit/vfkit_suite_test.go#L93)
And debug server with `2345` port, you could use any `delve` client to interact with debugger

##### CLI Example

Connect to debugger server with:
```shell
dlv connect :2345
```
Example of usage:
```shell
Type 'help' for list of commands.
(dlv) break main.main
Breakpoint 1 set at 0xe735776 for main.main() ./work/redhat/gvisor-tap-vsock/cmd/gvproxy/main.go:59
(dlv) continue
> [Breakpoint 1] main.main() ./work/redhat/gvisor-tap-vsock/cmd/gvproxy/main.go:59 (hits goroutine(1):1 total:1) (PC: 0xe735776)
54: hostIP = "192.168.127.254"
55: host = "host"
56: gateway = "gateway"
57: )
58:
=> 59: func main() {
60: version := types.NewVersion("gvproxy")
61: version.AddFlag()
62: flag.Var(&endpoints, "listen", "control endpoint")
63: flag.BoolVar(&debug, "debug", false, "Print debug info")
64: flag.IntVar(&mtu, "mtu", 1500, "Set the MTU")
```
More info about CLI client [here](https://github.com/go-delve/delve/blob/master/Documentation/cli/README.md)
#### Editor integration
For available editor integration look [there](https://github.com/go-delve/delve/blob/master/Documentation/EditorIntegration.md)
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ test-qemu: gvproxy test-companion
.PHONY: test-mac
test-mac: gvproxy
go test -timeout 20m -v ./test-vfkit

.PHONY: test-mac-debug
test-mac-debug:
go test -timeout 20m -v ./test-vfkit --debug
rm -f ./test-vfkit/__debug_bin*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,7 @@ This is the same behaviour as [slirp](https://wiki.qemu.org/index.php/Documentat
2. Each time, a client sends a http request, the process creates and sends the appropriate Ethernet packets to the VM.
3. The tap device receives the packets and injects them in the kernel.
4. The http server receives the request and send back the response.

### Development

[Development](./DEVELOPMENT.md)
18 changes: 14 additions & 4 deletions test-vfkit/vfkit_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var (
ignFile string
)

var debugEnabled = flag.Bool("debug", false, "enable debugger")

func init() {
flag.StringVar(&tmpDir, "tmpDir", "../tmp", "temporary working directory")
flag.StringVar(&binDir, "bin", "../bin", "directory with compiled binaries")
Expand Down Expand Up @@ -86,9 +88,17 @@ var _ = ginkgo.BeforeSuite(func() {
outer:
for panics := 0; ; panics++ {
_ = os.Remove(sock)

// #nosec
host = exec.Command(filepath.Join(binDir, "gvproxy"), fmt.Sprintf("--ssh-port=%d", sshPort), fmt.Sprintf("--listen=unix://%s", sock), fmt.Sprintf("--listen-vfkit=unixgram://%s", vfkitSock))
_ = os.Remove(vfkitSock)

gvproxyArgs := []string{fmt.Sprintf("--ssh-port=%d", sshPort), fmt.Sprintf("--listen=unix://%s", sock), fmt.Sprintf("--listen-vfkit=unixgram://%s", vfkitSock)}
if *debugEnabled {
dlvArgs := []string{"debug", "--headless", "--listen=:2345", "--continue", "--api-version=2", "--accept-multiclient", "../cmd/gvproxy", "--"}
dlvArgs = append(dlvArgs, gvproxyArgs...)
host = exec.Command("dlv", dlvArgs...)
} else {
// #nosec
host = exec.Command(filepath.Join(binDir, "gvproxy"), gvproxyArgs...)
}

host.Stderr = os.Stderr
host.Stdout = os.Stdout
Expand All @@ -103,7 +113,7 @@ outer:
for {
_, err := os.Stat(sock)
if os.IsNotExist(err) {
log.Info("waiting for socket")
log.Info("waiting for vfkit-api socket")
time.Sleep(100 * time.Millisecond)
continue
}
Expand Down

0 comments on commit 40cadec

Please sign in to comment.