Skip to content

Commit

Permalink
quic: include ignored frames in test log output
Browse files Browse the repository at this point in the history
When looking at a test log, it's a bit confusing to have
some of the frames silently omitted. Print ignored frames.

Unfortunately, this means we need to do the actual ignoring
of frames after printing the packet. We specify frames to
ignore by the frame number, but after parsing we don't have
a simple way to map from the debugFrame type back to the
number. Add a big, ugly mapping function to do this; it's
clunky, but isolated to one function in tests.

For golang/go#58547

Change-Id: I242f5511dc16be2350fa49030af38588fe92a988
Reviewed-on: https://go-review.googlesource.com/c/net/+/524295
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
neild committed Aug 30, 2023
1 parent 7374d34 commit b82f062
Showing 1 changed file with 74 additions and 3 deletions.
77 changes: 74 additions & 3 deletions internal/quic/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,80 @@ func (tc *testConn) readDatagram() *testDatagram {
buf := tc.sentDatagrams[0]
tc.sentDatagrams = tc.sentDatagrams[1:]
d := tc.parseTestDatagram(buf)
// Log the datagram before removing ignored frames.
// When things go wrong, it's useful to see all the frames.
tc.logDatagram("-> conn under test sends", d)
typeForFrame := func(f debugFrame) byte {
// This is very clunky, and points at a problem
// in how we specify what frames to ignore in tests.
//
// We mark frames to ignore using the frame type,
// but we've got a debugFrame data structure here.
// Perhaps we should be ignoring frames by debugFrame
// type instead: tc.ignoreFrame[debugFrameAck]().
switch f := f.(type) {
case debugFramePadding:
return frameTypePadding
case debugFramePing:
return frameTypePing
case debugFrameAck:
return frameTypeAck
case debugFrameResetStream:
return frameTypeResetStream
case debugFrameStopSending:
return frameTypeStopSending
case debugFrameCrypto:
return frameTypeCrypto
case debugFrameNewToken:
return frameTypeNewToken
case debugFrameStream:
return frameTypeStreamBase
case debugFrameMaxData:
return frameTypeMaxData
case debugFrameMaxStreamData:
return frameTypeMaxStreamData
case debugFrameMaxStreams:
if f.streamType == bidiStream {
return frameTypeMaxStreamsBidi
} else {
return frameTypeMaxStreamsUni
}
case debugFrameDataBlocked:
return frameTypeDataBlocked
case debugFrameStreamDataBlocked:
return frameTypeStreamDataBlocked
case debugFrameStreamsBlocked:
if f.streamType == bidiStream {
return frameTypeStreamsBlockedBidi
} else {
return frameTypeStreamsBlockedUni
}
case debugFrameNewConnectionID:
return frameTypeNewConnectionID
case debugFrameRetireConnectionID:
return frameTypeRetireConnectionID
case debugFramePathChallenge:
return frameTypePathChallenge
case debugFramePathResponse:
return frameTypePathResponse
case debugFrameConnectionCloseTransport:
return frameTypeConnectionCloseTransport
case debugFrameConnectionCloseApplication:
return frameTypeConnectionCloseApplication
case debugFrameHandshakeDone:
return frameTypeHandshakeDone
}
panic(fmt.Errorf("unhandled frame type %T", f))
}
for _, p := range d.packets {
var frames []debugFrame
for _, f := range p.frames {
if !tc.ignoreFrames[typeForFrame(f)] {
frames = append(frames, f)
}
}
p.frames = frames
}
return d
}

Expand Down Expand Up @@ -632,9 +705,7 @@ func (tc *testConn) parseTestFrames(payload []byte) ([]debugFrame, error) {
if n < 0 {
return nil, errors.New("error parsing frames")
}
if !tc.ignoreFrames[payload[0]] {
frames = append(frames, f)
}
frames = append(frames, f)
payload = payload[n:]
}
return frames, nil
Expand Down

0 comments on commit b82f062

Please sign in to comment.