This commit is contained in:
JackDoan
2026-07-14 10:40:57 -05:00
parent 6e6cfc89db
commit 9e7646ee62
11 changed files with 99 additions and 204 deletions
+6 -16
View File
@@ -26,10 +26,11 @@ func newTestUserDevice(t *testing.T) *UserDevice {
// TestUserDeviceReadersDistinctBuffers is the regression test for the
// multiqueue packet-corruption bug: Readers() used to hand the same
// *UserDevice (and therefore the same readBuf/batchRet) to every queue, so one
// reader's borrowed Packet.Bytes was overwritten by another reader's
// concurrent Read. Readers() must now return numReaders DISTINCT queue objects,
// each with its own backing buffer.
// *UserDevice (and therefore the same read scratch buffer) to every queue, so
// one reader's borrowed Packet.Bytes was overwritten by another reader's
// concurrent Read. Readers() must now return numReaders DISTINCT queue
// objects, each with its own backing buffer — verified behaviorally below by
// holding one queue's borrowed slice across the other queue's Read.
func TestUserDeviceReadersDistinctBuffers(t *testing.T) {
d := newTestUserDevice(t)
@@ -43,21 +44,10 @@ func TestUserDeviceReadersDistinctBuffers(t *testing.T) {
t.Fatalf("Readers() returned %d queues, want 2", len(readers))
}
q0 := readers[0].(*userDeviceQueue)
q1 := readers[1].(*userDeviceQueue)
// Distinct queue objects.
if q0 == q1 {
if readers[0] == readers[1] {
t.Fatal("Readers() returned the same queue object twice")
}
// Distinct backing buffers (the actual regression: shared readBuf).
if &q0.readBuf[0] == &q1.readBuf[0] {
t.Fatal("queues share the same readBuf backing array")
}
// Shared underlying pipes.
if q0.outboundReader != q1.outboundReader || q0.inboundWriter != q1.inboundWriter {
t.Fatal("queues do not share the underlying pipes")
}
// Drive one packet through each queue and confirm the borrowed bytes from
// the first read are NOT clobbered by the second read. With a shared