Skip to content

Commit 8822f85

Browse files
BootloaderTest: Test too short and too long reads
1 parent bc8f28d commit 8822f85

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

BootloaderTest/BootloaderTest.ino

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,48 @@ test(060_reread_protocol_version) {
271271
assertEqual(version, PROTOCOL_VERSION);
272272
}
273273

274+
test(065_short_long_read) {
275+
uint8_t status, len, dummy;
276+
uint8_t data[2];
277+
278+
// Send a command
279+
assertTrue(write_command(Commands::GET_PROTOCOL_VERSION, nullptr, 0));
280+
281+
// Do a short read, just enough to read the length byte
282+
assertAck(bus.startRead(cfg.curAddr));
283+
assertAck(bus.readThenAck(status));
284+
assertOk(status);
285+
assertAck(bus.readThenNack(len));
286+
assertEqual(len, sizeof(data));
287+
if (!cfg.repStartAfterRead)
288+
bus.stop();
289+
290+
// Check that we can still read a valid reply after that
291+
assertTrue(read_status(&status, data, sizeof(data), 0));
292+
assertOk(status);
293+
uint16_t version = data[0] << 8 | data[1];
294+
assertEqual(version, PROTOCOL_VERSION);
295+
296+
// Do a long read, way past the CRC
297+
assertAck(bus.startRead(cfg.curAddr));
298+
assertAck(bus.readThenAck(status));
299+
assertOk(status);
300+
assertAck(bus.readThenAck(len));
301+
assertEqual(len, sizeof(data));
302+
for (uint8_t i = 0; i < 10; ++i) {
303+
assertAck(bus.readThenAck(dummy));
304+
}
305+
assertAck(bus.readThenNack(dummy));
306+
if (!cfg.repStartAfterRead)
307+
bus.stop();
308+
309+
// Check that we can still read a valid reply after that
310+
assertTrue(read_status(&status, data, sizeof(data), 0));
311+
assertOk(status);
312+
version = data[0] << 8 | data[1];
313+
assertEqual(version, PROTOCOL_VERSION);
314+
}
315+
274316
test(070_get_hardware_info) {
275317
uint8_t data[5];
276318
assertTrue(run_transaction_ok(Commands::GET_HARDWARE_INFO, nullptr, 0, data, sizeof(data)));

0 commit comments

Comments
 (0)