ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
39
packages/mesh-init/nat_linux_test.go
Normal file
39
packages/mesh-init/nat_linux_test.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"runtime"
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Keep each recursive frame live so the stack must grow past its initial allocation.
|
||||
//
|
||||
//go:noinline
|
||||
func growStack(depth byte) byte {
|
||||
var frame [4096]byte
|
||||
frame[0] = depth
|
||||
if depth > 0 {
|
||||
frame[1] = growStack(depth - 1)
|
||||
}
|
||||
runtime.KeepAlive(&frame)
|
||||
return frame[0] + frame[1]
|
||||
}
|
||||
|
||||
func TestPinnedRequest(t *testing.T) {
|
||||
if unsafe.Sizeof(tableInfo{}) != 84 {
|
||||
t.Fatal("native getsockopt layout differs from ipt_getinfo")
|
||||
}
|
||||
done := make(chan [2]uint64, 1)
|
||||
go func() {
|
||||
request := newReplace(config{inbound: 4143, outbound: 4140}, 5)
|
||||
defer request.pins.Unpin()
|
||||
growStack(32)
|
||||
runtime.GC()
|
||||
done <- [2]uint64{binary.NativeEndian.Uint64(request.data[88:]), request.address()}
|
||||
}()
|
||||
addresses := <-done
|
||||
if addresses[0] != addresses[1] {
|
||||
t.Fatalf("counter address moved: %x -> %x", addresses[0], addresses[1])
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue