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

initial commit for enhancing fuzz tests #2745

Merged
merged 8 commits into from
Nov 28, 2023
2 changes: 1 addition & 1 deletion fuzz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ fuzz: $(FUZZ_TARGETS:=.out) ## run all fuzz tests
done

clean: ## clean temporary files and directories
$(RM) $(PREFIX)/*.out $(PREFIX)/*.h $(PREFIX)/main.*.go
$(RM) $(PREFIX)/*.out $(PREFIX)/*.a $(PREFIX)/*.h $(PREFIX)/main.*.go
30 changes: 27 additions & 3 deletions fuzz/fuzz_targets/FuzzServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@ import (
"github.com/zalando/skipper/config"
)

var initialized = false
var (
initialized = false
address = ""
)

func findAddress() (string, error) {
l, err := net.ListenTCP("tcp6", &net.TCPAddr{})

if err != nil {
return "", err
}

defer l.Close()

return l.Addr().String(), nil
}

func connect(host string) (net.Conn, error) {
for i := 0; i < 15; i++ {
conn, err := net.Dial("tcp", host)
conn, err := net.Dial("tcp6", host)

if err != nil {
continue
Expand All @@ -31,20 +46,29 @@ func connect(host string) (net.Conn, error) {

func FuzzServer(data []byte) int {
if !initialized {
addr, err := findAddress()

if err != nil {
log.Printf("failed to find address: %v\n", err)
return -1
}

cfg := config.NewConfig()
cfg.InlineRoutes = `r: * -> status(200) -> inlineContent("ok") -> <shunt>`
cfg.ApplicationLogLevel = logrus.PanicLevel
cfg.AccessLogDisabled = true
cfg.ApplicationLog = "/dev/null"
cfg.Address = addr

go func() {
log.Fatal(skipper.Run(cfg.ToOptions()))
}()

initialized = true
address = cfg.Address
}

conn, err := connect("localhost:9090")
conn, err := connect(address)
Copy link
Member

Choose a reason for hiding this comment

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

you need to do something like:

var (
    err error
    conn *tcp.Conn // out of my head so maybe other type
)
for i:=0; i<10; i++ {
    conn, err = connect(address)
    if err != nil {
        time.Sleep(100*time.Millisecond)
        continue
    } 
    break
}


if err != nil {
log.Printf("failed to dial: %v\n", err)
Expand Down
Loading