Skip to content

Commit

Permalink
Add some more tests for reassembler, sender, and receiver
Browse files Browse the repository at this point in the history
Intention is to help catch errors before integration tests

Credit to Bill Lin and Jared Wasserman

Closes #2
Closes #4
Closes #5
  • Loading branch information
keithw committed Oct 26, 2020
1 parent f989eab commit 0b8c0ea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/fsm_stream_reassembler_single.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ int main() {
test.execute(BytesAvailable{"abcdefgh"});
test.execute(NotAtEof{});
}

// credit for test: Bill Lin (2020)
{
ReassemblerTestHarness test{8};

test.execute(SubmitSegment{"abc", 0});
test.execute(BytesAssembled(3));
test.execute(NotAtEof{});

// Stream re-assembler should ignore empty segments
test.execute(SubmitSegment{"", 6});
test.execute(BytesAssembled(3));
test.execute(NotAtEof{});

test.execute(SubmitSegment{"de", 3}.with_eof(true));
test.execute(BytesAssembled(5));
test.execute(BytesAvailable("abcde"));
test.execute(AtEof{});
}
} catch (const exception &e) {
cerr << "Exception: " << e.what() << endl;
return EXIT_FAILURE;
Expand Down
11 changes: 11 additions & 0 deletions tests/recv_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ int main() {
test.execute(SegmentArrives{}.with_seqno(isn + 3).with_data("cd").with_result(SegmentArrives::Result::OK));
}

// credit for test: Jared Wasserman
{
// A byte with invalid stream index should be ignored
size_t cap = 4;
uint32_t isn = 23452;
TCPReceiverTestHarness test{cap};
test.execute(SegmentArrives{}.with_syn().with_seqno(isn).with_result(SegmentArrives::Result::OK));
test.execute(SegmentArrives{}.with_seqno(isn).with_data("a").with_result(SegmentArrives::Result::OK));
test.execute(ExpectTotalAssembledBytes{0});
}

} catch (const exception &e) {
cerr << e.what() << endl;
return 1;
Expand Down
13 changes: 13 additions & 0 deletions tests/send_ack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ int main() {
test.execute(ExpectNoSegment{});
}

// credit for test: Jared Wasserman (2020)
{
TCPConfig cfg;
WrappingInt32 isn(rd());
cfg.fixed_isn = isn;

TCPSenderTestHarness test{"Impossible ackno (beyond next seqno) is ignored", cfg};
test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT});
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(AckReceived{WrappingInt32{isn + 2}}.with_win(1000));
test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT});
}

/* remove requirement to send corrective ACK for bad ACK
{
TCPConfig cfg;
Expand Down

0 comments on commit 0b8c0ea

Please sign in to comment.