Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable debugger for tests on macOS #446

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `givisor` execution on start, if debugger is not connected.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

givisor typo (extra i). What do you mean by gvisor though? Is it gvproxy, or is it any program using gvisor-tap-vsock as a package?

> To pause `gvisor` execution until debugger is connected just remove `"--continue"` parameter from this [line](./test-vfkit/vfkit_suite_test.go#L93)

And debug sever with `2345` port, you could use any `delve` client to interact with debugger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sever typo (->server). It occurs a few times in this file.


##### CLI Example

Connect to debugger sever 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 @@ -74,3 +74,8 @@ test-linux: 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 @@ -46,6 +46,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 @@ -84,9 +86,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 @@ -101,7 +111,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
Loading