MCPcopy
hub / github.com/WireGuard/wireguard-go / genTestPair

Function genTestPair

device/device_test.go:152–193  ·  view source on GitHub ↗

genTestPair creates a testPair.

(tb testing.TB, realSocket bool)

Source from the content-addressed store, hash-verified

150
151// genTestPair creates a testPair.
152func genTestPair(tb testing.TB, realSocket bool) (pair testPair) {
153 cfg, endpointCfg := genConfigs(tb)
154 var binds [2]conn.Bind
155 if realSocket {
156 binds[0], binds[1] = conn.NewDefaultBind(), conn.NewDefaultBind()
157 } else {
158 binds = bindtest.NewChannelBinds()
159 }
160 // Bring up a ChannelTun for each config.
161 for i := range pair {
162 p := &pair[i]
163 p.tun = tuntest.NewChannelTUN()
164 p.ip = netip.AddrFrom4([4]byte{1, 0, 0, byte(i + 1)})
165 level := LogLevelVerbose
166 if _, ok := tb.(*testing.B); ok && !testing.Verbose() {
167 level = LogLevelError
168 }
169 p.dev = NewDevice(p.tun.TUN(), binds[i], NewLogger(level, fmt.Sprintf("dev%d: ", i)))
170 if err := p.dev.IpcSet(cfg[i]); err != nil {
171 tb.Errorf("failed to configure device %d: %v", i, err)
172 p.dev.Close()
173 continue
174 }
175 if err := p.dev.Up(); err != nil {
176 tb.Errorf("failed to bring up device %d: %v", i, err)
177 p.dev.Close()
178 continue
179 }
180 endpointCfg[i^1] = fmt.Sprintf(endpointCfg[i^1], p.dev.net.port)
181 }
182 for i := range pair {
183 p := &pair[i]
184 if err := p.dev.IpcSet(endpointCfg[i]); err != nil {
185 tb.Errorf("failed to configure device endpoint %d: %v", i, err)
186 p.dev.Close()
187 continue
188 }
189 // The device is ready. Close it when the test completes.
190 tb.Cleanup(p.dev.Close)
191 }
192 return
193}
194
195func TestTwoDevicePing(t *testing.T) {
196 goroutineLeakCheck(t)

Callers 6

TestTwoDevicePingFunction · 0.85
TestUpDownFunction · 0.85
TestConcurrencySafetyFunction · 0.85
BenchmarkLatencyFunction · 0.85
BenchmarkThroughputFunction · 0.85
BenchmarkUAPIGetFunction · 0.85

Calls 10

NewDefaultBindFunction · 0.92
NewChannelBindsFunction · 0.92
NewChannelTUNFunction · 0.92
genConfigsFunction · 0.85
NewDeviceFunction · 0.85
NewLoggerFunction · 0.85
TUNMethod · 0.80
IpcSetMethod · 0.80
UpMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected