mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
a5d6c9d616
It'll be called a bunch, so worth a bit of effort. Could go further, but not yet. (really, should hook into wgengine/monitor and only re-read on netlink changes?) name old time/op new time/op delta DefaultRouteInterface-8 60.8µs ±11% 44.6µs ± 5% -26.65% (p=0.000 n=20+19) name old alloc/op new alloc/op delta DefaultRouteInterface-8 3.29kB ± 0% 0.55kB ± 0% -83.21% (p=0.000 n=20+20) name old allocs/op new allocs/op delta DefaultRouteInterface-8 9.00 ± 0% 6.00 ± 0% -33.33% (p=0.000 n=20+20)
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package netns
|
|
|
|
import (
|
|
"fmt"
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"testing"
|
|
)
|
|
|
|
// verifies tailscaleBypassMark is in sync with wgengine.
|
|
func TestBypassMarkInSync(t *testing.T) {
|
|
want := fmt.Sprintf("%q", fmt.Sprintf("0x%x", tailscaleBypassMark))
|
|
fset := token.NewFileSet()
|
|
f, err := parser.ParseFile(fset, "../../wgengine/router/router_linux.go", nil, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, decl := range f.Decls {
|
|
gd, ok := decl.(*ast.GenDecl)
|
|
if !ok || gd.Tok != token.CONST {
|
|
continue
|
|
}
|
|
for _, spec := range gd.Specs {
|
|
vs, ok := spec.(*ast.ValueSpec)
|
|
if !ok {
|
|
continue
|
|
}
|
|
for i, ident := range vs.Names {
|
|
if ident.Name != "tailscaleBypassMark" {
|
|
continue
|
|
}
|
|
valExpr := vs.Values[i]
|
|
lit, ok := valExpr.(*ast.BasicLit)
|
|
if !ok {
|
|
t.Errorf("tailscaleBypassMark = %T, expected *ast.BasicLit", valExpr)
|
|
}
|
|
if lit.Value == want {
|
|
// Pass.
|
|
return
|
|
}
|
|
t.Fatalf("router_linux.go's tailscaleBypassMark = %s; not in sync with netns's %s", lit.Value, want)
|
|
}
|
|
}
|
|
}
|
|
t.Errorf("tailscaleBypassMark not found in router_linux.go")
|
|
}
|
|
|
|
func BenchmarkDefaultRouteInterface(b *testing.B) {
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
if _, err := defaultRouteInterface(); err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|