Skip to content

Commit 4648651

Browse files
committed
quic: add -vv flag for more verbose tests
Add a -vv flag to make tests log each packet sent/received. Disable logging of packets generally not relevant to the test, namely the handshake and the series of pings and acks used to trigger loss detection in loss tests. For golang/go#58547 Change-Id: I69c7f6743436648c2c2f202e38c3f6fb2c73c802 Reviewed-on: https://go-review.googlesource.com/c/net/+/515339 Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent 60ae793 commit 4648651

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

internal/quic/conn_loss_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,19 @@ func (tc *testConn) triggerLossOrPTO(ptype packetType, pto bool) {
3030
if !tc.conn.loss.ptoTimerArmed {
3131
tc.t.Fatalf("PTO timer not armed, expected it to be")
3232
}
33+
if *testVV {
34+
tc.t.Logf("advancing to PTO timer")
35+
}
3336
tc.advanceTo(tc.conn.loss.timer)
3437
return
3538
}
39+
if *testVV {
40+
*testVV = false
41+
defer func() {
42+
tc.t.Logf("cause conn to declare last packet lost")
43+
*testVV = true
44+
}()
45+
}
3646
defer func(ignoreFrames map[byte]bool) {
3747
tc.ignoreFrames = ignoreFrames
3848
}(tc.ignoreFrames)

internal/quic/conn_test.go

+30-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"context"
1212
"crypto/tls"
1313
"errors"
14+
"flag"
1415
"fmt"
1516
"math"
1617
"net/netip"
@@ -20,6 +21,8 @@ import (
2021
"time"
2122
)
2223

24+
var testVV = flag.Bool("vv", false, "even more verbose test output")
25+
2326
func TestConnTestConn(t *testing.T) {
2427
tc := newTestConn(t, serverSide)
2528
if got, want := tc.timeUntilEvent(), defaultMaxIdleTimeout; got != want {
@@ -308,10 +311,34 @@ func (tc *testConn) cleanup() {
308311
tc.conn.exit()
309312
}
310313

314+
func (tc *testConn) logDatagram(text string, d *testDatagram) {
315+
tc.t.Helper()
316+
if !*testVV {
317+
return
318+
}
319+
pad := ""
320+
if d.paddedSize > 0 {
321+
pad = fmt.Sprintf(" (padded to %v)", d.paddedSize)
322+
}
323+
tc.t.Logf("%v datagram%v", text, pad)
324+
for _, p := range d.packets {
325+
switch p.ptype {
326+
case packetType1RTT:
327+
tc.t.Logf(" %v pnum=%v", p.ptype, p.num)
328+
default:
329+
tc.t.Logf(" %v pnum=%v ver=%v dst={%x} src={%x}", p.ptype, p.num, p.version, p.dstConnID, p.srcConnID)
330+
}
331+
for _, f := range p.frames {
332+
tc.t.Logf(" %v", f)
333+
}
334+
}
335+
}
336+
311337
// write sends the Conn a datagram.
312338
func (tc *testConn) write(d *testDatagram) {
313339
tc.t.Helper()
314340
var buf []byte
341+
tc.logDatagram("<- conn under test receives", d)
315342
for _, p := range d.packets {
316343
space := spaceForPacketType(p.ptype)
317344
if p.num >= tc.peerNextPacketNum[space] {
@@ -374,7 +401,9 @@ func (tc *testConn) readDatagram() *testDatagram {
374401
}
375402
buf := tc.sentDatagrams[0]
376403
tc.sentDatagrams = tc.sentDatagrams[1:]
377-
return tc.parseTestDatagram(buf)
404+
d := tc.parseTestDatagram(buf)
405+
tc.logDatagram("-> conn under test sends", d)
406+
return d
378407
}
379408

380409
// readPacket reads the next packet sent by the Conn.

internal/quic/tls_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ import (
1818
// handshake executes the handshake.
1919
func (tc *testConn) handshake() {
2020
tc.t.Helper()
21+
if *testVV {
22+
*testVV = false
23+
defer func() {
24+
*testVV = true
25+
tc.t.Logf("performed connection handshake")
26+
}()
27+
}
2128
defer func(saved map[byte]bool) {
2229
tc.ignoreFrames = saved
2330
}(tc.ignoreFrames)

0 commit comments

Comments
 (0)