summaryrefslogtreecommitdiffhomepage
path: root/device/device_test.go
AgeCommit message (Collapse)Author
2021-01-28global: bump copyrightJason A. Donenfeld
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-01-26device: combine debug and info log levels into 'verbose'Jason A. Donenfeld
There are very few cases, if any, in which a user only wants one of these levels, so combine it into a single level. While we're at it, reduce indirection on the loggers by using an empty function rather than a nil function pointer. It's not like we have retpolines anyway, and we were always calling through a function with a branch prior, so this seems like a net gain. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-01-26device: add benchmark for UAPI Device.IpcGetOperationJosh Bleecher Snyder
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: add latency and throughput benchmarksJosh Bleecher Snyder
These obviously don't perfectly capture real world performance, in which syscalls and network links have a significant impact. Nevertheless, they capture some of the internal performance factors, and they're easy and convenient to work with. Hat tip to Avery Pennarun for help designing the throughput benchmark. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: use LogLevelError for benchmarkingJosh Bleecher Snyder
This keeps the output minimal and focused on the benchmark results. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: make test infrastructure usable with benchmarksJosh Bleecher Snyder
Switch from *testing.T to testing.TB. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: fix races from changing private_keyJosh Bleecher Snyder
Access keypair.sendNonce atomically. Eliminate one unnecessary initialization to zero. Mutate handshake.lastSentHandshake with the mutex held. Co-authored-by: David Anderson <danderson@tailscale.com> Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: fix persistent_keepalive_interval data racesJosh Bleecher Snyder
Co-authored-by: David Anderson <danderson@tailscale.com> Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: use channel close to shut down and drain encryption channelJosh Bleecher Snyder
The new test introduced in this commit used to deadlock about 1% of the time. I believe that the deadlock occurs as follows: * The test completes, calling device.Close. * device.Close closes device.signals.stop. * RoutineEncryption stops. * The deferred function in RoutineEncryption drains device.queue.encryption. * RoutineEncryption exits. * A peer's RoutineNonce processes an element queued in peer.queue.nonce. * RoutineNonce puts that element into the outbound and encryption queues. * RoutineSequentialSender reads that elements from the outbound queue. * It waits for that element to get Unlocked by RoutineEncryption. * RoutineEncryption has already exited, so RoutineSequentialSender blocks forever. * device.RemoveAllPeers calls peer.Stop on all peers. * peer.Stop waits for peer.routines.stopping, which blocks forever. Rather than attempt to add even more ordering to the already complex centralized shutdown orchestration, this commit moves towards a data-flow-oriented shutdown. The device.queue.encryption gets closed when there will be no more writes to it. All device.queue.encryption readers always read until the channel is closed and then exit. We thus guarantee that any element that enters the encryption queue also exits it. This removes the need for central control of the lifetime of RoutineEncryption, removes the need to drain the encryption queue on shutdown, and simplifies RoutineEncryption. This commit also fixes a data race. When RoutineSequentialSender drains its queue on shutdown, it needs to lock the elem before operating on it, just as the main body does. The new test in this commit passed 50k iterations with the race detector enabled and 150k iterations with the race detector disabled, with no failures. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: add a helper to generate uapi configsJosh Bleecher Snyder
This makes it easier to work with configs in tests. It'll see heavier use over upcoming commits; this commit only adds the infrastructure. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: increase timeout in testsJosh Bleecher Snyder
When running many concurrent test processing using https://godoc.org/golang.org/x/tools/cmd/stress the processing sometimes cannot complete a ping in under 300ms. Increase the timeout to 5s to reduce the rate of false positives. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-07device: make test setup more robustJosh Bleecher Snyder
Picking two free ports to use for a test is difficult. The free port we selected might no longer be free when we reach for it a second time. On my machine, this failure mode led to failures approximately once per thousand test runs. Since failures are rare, and threading through and checking for all possible errors is complicated, fix this with a big hammer: Retry if either device fails to come up. Also, if you accidentally pick the same port twice, delightful confusion ensues. The handshake failures manifest as crypto errors, which look scary. Again, fix with retries. To make these retries easier to implement, use testing.T.Cleanup instead of defer to close devices. This requires Go 1.14. Update go.mod accordingly. Go 1.13 is no longer supported anyway. With these fixes, 'go test -race' ran 100,000 times without failure. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2020-07-31device: get free port when testingSina Siadat
Signed-off-by: Sina Siadat <siadat@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-05-02global: update header comments and modulesJason A. Donenfeld
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-05-02tuntest: split out testing packageDavid Crawshaw
This code is useful to other packages writing tests. Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2019-10-16device: test packets between two fake devicesDavid Crawshaw
Signed-off-by: David Crawshaw <crawshaw@tailscale.io>
2019-06-04device: use bytes.Equal for equality check, simplify assertEqualMatt Layher
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2019-05-29device, tun: rearrange code and fix device testsMatt Layher
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2019-03-03global: begin modularizationJason A. Donenfeld