Skip to content

Commit 5f76dfe

Browse files
authored
Merge pull request #12805 from fkjagodzinski/test_update-usb_serial-minimal_printf
Tests: USBSerial: Handle minimal printf limitations
2 parents e88c596 + 9066e67 commit 5f76dfe

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

TESTS/host_tests/usb_device_serial.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
# during terminal reopen test.
4848
TERM_REOPEN_DELAY = 0.1
4949

50-
# 6 (baud) + 2 (bits) + 1 (parity) + 1 (stop) + 3 * comma
51-
LINE_CODING_STRLEN = 13
50+
LINE_CODING_SEP = ','
51+
LINE_CODING_DELIM = ';'
5252

5353

5454
def usb_serial_name(serial_number):
@@ -269,16 +269,17 @@ def change_line_coding(self):
269269
mbed_serial.reset_output_buffer()
270270
mbed_serial.dtr = True
271271
try:
272-
payload = six.ensure_str(mbed_serial.read(LINE_CODING_STRLEN))
273-
while len(payload) == LINE_CODING_STRLEN:
274-
baud, bits, parity, stop = (int(i) for i in payload.split(','))
272+
payload = six.ensure_str(mbed_serial.read_until(LINE_CODING_DELIM))
273+
while len(payload) > 0:
274+
baud, bits, parity, stop = (
275+
int(i) for i in payload.strip(LINE_CODING_DELIM).split(LINE_CODING_SEP))
275276
new_line_coding = {
276277
'baudrate': baud,
277278
'bytesize': self._BYTESIZES[bits],
278279
'parity': self._PARITIES[parity],
279280
'stopbits': self._STOPBITS[stop]}
280281
mbed_serial.apply_settings(new_line_coding)
281-
payload = six.ensure_str(mbed_serial.read(LINE_CODING_STRLEN))
282+
payload = six.ensure_str(mbed_serial.read_until(LINE_CODING_DELIM))
282283
except serial.SerialException as exc:
283284
self.log('TEST ERROR: {}'.format(exc))
284285
self.notify_complete(False)

TESTS/usb_device/serial/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
#define SERIAL_LOOPBACK_REPS 100
8585
#define USB_RECONNECT_DELAY_MS 1
8686

87-
#define LINE_CODING_STRLEN 13 // 6 + 2 + 1 + 1 + 3 * comma
87+
#define LINE_CODING_SEP (',')
88+
#define LINE_CODING_DELIM (';')
8889

8990
#define USB_DEV_SN_LEN (32) // 32 hex digit UUID
9091
#define NONASCII_CHAR ('?')
@@ -776,9 +777,9 @@ void test_serial_line_coding_change()
776777
for (size_t i = 0; i < num_line_codings; i++) {
777778
lc_expected = &(test_codings[i]);
778779
num_expected_callbacks = lc_prev->get_num_diffs(*lc_expected);
779-
rc = usb_serial.printf("%06i,%02i,%01i,%01i", lc_expected->baud, lc_expected->bits, lc_expected->parity,
780-
lc_expected->stop);
781-
TEST_ASSERT_EQUAL_INT(LINE_CODING_STRLEN, rc);
780+
rc = usb_serial.printf("%06i,%02i,%01i,%01i%c", lc_expected->baud, lc_expected->bits, lc_expected->parity,
781+
lc_expected->stop, LINE_CODING_DELIM);
782+
TEST_ASSERT(rc > 0);
782783
// The pyserial Python module does not update all line coding params
783784
// at once. It updates params one by one instead, and since every
784785
// update is followed by port reconfiguration we get multiple

0 commit comments

Comments
 (0)