Skip to content

Commit

Permalink
format tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Nov 19, 2023
1 parent 3594fb1 commit 1de2ebc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions stack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (

func TestStackEstablish(t *testing.T) {
client, server := createTCPClientServerPair(t)

// 3 way handshake needs 3 exchanges to complete.
const maxTransactions = 3
txDone, numBytesSent := txStacks(t, maxTransactions, client.PortStack(), server.PortStack())

const expectedData = (eth.SizeEthernetHeader + eth.SizeIPv4Header + eth.SizeTCPHeader) * 4
if numBytesSent < expectedData {
t.Error("too little data exchanged", numBytesSent, " want>=", expectedData)
Expand Down Expand Up @@ -49,10 +51,12 @@ func TestStackSendReceive(t *testing.T) {
if err != nil {
t.Fatal(err)
}

txStacks(t, 1, client.PortStack(), server.PortStack())
if client.State() != seqs.StateEstablished || server.State() != seqs.StateEstablished {
t.Fatal("not established")
}

var buf [len(data)]byte
n, err := server.Recv(buf[:])
if err != nil {
Expand All @@ -68,6 +72,7 @@ func isDroppedPacket(err error) bool {
}

func txStacks(t *testing.T, maxTransactions int, stacks ...*stack.PortStack) (tx, bytesSent int) {
t.Helper()
var pipe [2048]byte
zeroPipe := func() { pipe = [2048]byte{} }
sprintErr := func(err error) (s string) {
Expand Down Expand Up @@ -116,6 +121,7 @@ func txStacks(t *testing.T, maxTransactions int, stacks ...*stack.PortStack) (tx
}

func createTCPClientServerPair(t *testing.T) (client, server *stack.TCPSocket) {
t.Helper()
const (
clientPort = 1025
clientISS = 100
Expand Down Expand Up @@ -150,6 +156,7 @@ func createTCPClientServerPair(t *testing.T) (client, server *stack.TCPSocket) {
}

func createPortStacks(t *testing.T, n int) (stacks []*stack.PortStack) {
t.Helper()
if n > math.MaxUint16 {
t.Fatal("too many stacks")
}
Expand Down

0 comments on commit 1de2ebc

Please sign in to comment.