summaryrefslogtreecommitdiff
path: root/serial_link/tests
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-02-14 20:07:51 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-02-14 20:07:51 +0200
commit713465fb416785c3a544e8626f85aca7e57dafa1 (patch)
tree2170b0e97ad559377210a6d0e384362ba70bcda6 /serial_link/tests
parent6956c177da8737f999eef72a21f0fc3caea2ac3e (diff)
Add some full round trip tests
Mostly to ensure that the receive and send framing works the same way. Especially for the special case with 254 non-zeros.
Diffstat (limited to 'serial_link/tests')
-rw-r--r--serial_link/tests/byte_stuffer_tests.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/serial_link/tests/byte_stuffer_tests.c b/serial_link/tests/byte_stuffer_tests.c
index 8598cddd30..fbdf39e1b2 100644
--- a/serial_link/tests/byte_stuffer_tests.c
+++ b/serial_link/tests/byte_stuffer_tests.c
@@ -428,3 +428,80 @@ Ensure(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) {
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
}
+
+Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) {
+ uint8_t original_data[] = { 1, 2, 3};
+ send_frame(original_data, sizeof(original_data));
+ expect(recv_frame,
+ when(size, is_equal_to(sizeof(original_data))),
+ when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
+ );
+ int i;
+ for(i=0;i<sent_data_size;i++) {
+ recv_byte(&state, sent_data[i]);
+ }
+}
+
+Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) {
+ uint8_t original_data[] = { 1, 0, 3, 0, 0, 9};
+ send_frame(original_data, sizeof(original_data));
+ expect(recv_frame,
+ when(size, is_equal_to(sizeof(original_data))),
+ when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
+ );
+ int i;
+ for(i=0;i<sent_data_size;i++) {
+ recv_byte(&state, sent_data[i]);
+ }
+}
+
+Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes) {
+ uint8_t original_data[254];
+ int i;
+ for(i=0;i<254;i++) {
+ original_data[i] = i + 1;
+ }
+ send_frame(original_data, sizeof(original_data));
+ expect(recv_frame,
+ when(size, is_equal_to(sizeof(original_data))),
+ when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
+ );
+ for(i=0;i<sent_data_size;i++) {
+ recv_byte(&state, sent_data[i]);
+ }
+}
+
+Ensure(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) {
+ uint8_t original_data[256];
+ int i;
+ for(i=0;i<254;i++) {
+ original_data[i] = i + 1;
+ }
+ original_data[254] = 22;
+ original_data[255] = 23;
+ send_frame(original_data, sizeof(original_data));
+ expect(recv_frame,
+ when(size, is_equal_to(sizeof(original_data))),
+ when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
+ );
+ for(i=0;i<sent_data_size;i++) {
+ recv_byte(&state, sent_data[i]);
+ }
+}
+
+Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) {
+ uint8_t original_data[255];
+ int i;
+ for(i=0;i<254;i++) {
+ original_data[i] = i + 1;
+ }
+ original_data[254] = 0;
+ send_frame(original_data, sizeof(original_data));
+ expect(recv_frame,
+ when(size, is_equal_to(sizeof(original_data))),
+ when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
+ );
+ for(i=0;i<sent_data_size;i++) {
+ recv_byte(&state, sent_data[i]);
+ }
+}