summaryrefslogtreecommitdiffhomepage
path: root/test/benchmarks/harness
diff options
context:
space:
mode:
Diffstat (limited to 'test/benchmarks/harness')
-rw-r--r--test/benchmarks/harness/harness.go18
-rw-r--r--test/benchmarks/harness/machine.go18
2 files changed, 23 insertions, 13 deletions
diff --git a/test/benchmarks/harness/harness.go b/test/benchmarks/harness/harness.go
index 5c9d0e01e..a853b7ba8 100644
--- a/test/benchmarks/harness/harness.go
+++ b/test/benchmarks/harness/harness.go
@@ -28,18 +28,14 @@ var (
debug = flag.Bool("debug", false, "turns on debug messages for individual benchmarks")
)
-// Harness is a handle for managing state in benchmark runs.
-type Harness struct {
-}
-
// Init performs any harness initilialization before runs.
-func (h *Harness) Init() error {
+func Init() error {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s -- --test.bench=<regex>\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
- if flag.NFlag() == 0 || *help {
+ if *help {
flag.Usage()
os.Exit(0)
}
@@ -47,7 +43,15 @@ func (h *Harness) Init() error {
return nil
}
+// SetFixedBenchmarks causes all benchmarks to run once.
+//
+// This must be set if they cannot scale with N. Note that this uses 1ns
+// instead of 1x due to https://github.com/golang/go/issues/32051.
+func SetFixedBenchmarks() {
+ flag.Set("test.benchtime", "1ns")
+}
+
// GetMachine returns this run's implementation of machine.
-func (h *Harness) GetMachine() (Machine, error) {
+func GetMachine() (Machine, error) {
return &localMachine{}, nil
}
diff --git a/test/benchmarks/harness/machine.go b/test/benchmarks/harness/machine.go
index 88e5e841b..405b646e8 100644
--- a/test/benchmarks/harness/machine.go
+++ b/test/benchmarks/harness/machine.go
@@ -16,6 +16,7 @@ package harness
import (
"context"
+ "errors"
"net"
"os/exec"
@@ -66,14 +67,19 @@ func (l *localMachine) RunCommand(cmd string, args ...string) (string, error) {
// IPAddress implements Machine.IPAddress.
func (l *localMachine) IPAddress() (net.IP, error) {
- conn, err := net.Dial("udp", "8.8.8.8:80")
+ addrs, err := net.InterfaceAddrs()
if err != nil {
- return nil, err
+ return net.IP{}, err
}
- defer conn.Close()
-
- addr := conn.LocalAddr().(*net.UDPAddr)
- return addr.IP, nil
+ for _, a := range addrs {
+ if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
+ if ipnet.IP.To4() != nil {
+ return ipnet.IP, nil
+ }
+ }
+ }
+ // Unable to locate non-loopback address.
+ return nil, errors.New("no IPAddress available")
}
// CleanUp implements Machine.CleanUp and does nothing for localMachine.