fix ringbuf differences

This commit is contained in:
Jeff Epler 2023-09-22 13:38:56 -05:00
parent 886285cedc
commit 87feeab922
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
1 changed files with 14 additions and 18 deletions

View File

@ -613,45 +613,44 @@ STATIC mp_obj_t extra_coverage(void) {
// ringbuf // ringbuf
{ {
byte buf[100]; byte buf[100];
ringbuf_t ringbuf = {buf, sizeof(buf), 0, 0}; ringbuf_t ringbuf = {buf, sizeof(buf), 0, 0, 0};
mp_printf(&mp_plat_print, "# ringbuf\n"); mp_printf(&mp_plat_print, "# ringbuf\n");
// Single-byte put/get with empty ringbuf. // Single-byte put/get with empty ringbuf.
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
ringbuf_put(&ringbuf, 22); ringbuf_put(&ringbuf, 22);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_get(&ringbuf)); mp_printf(&mp_plat_print, "%d\n", ringbuf_get(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
// Two-byte put/get with empty ringbuf. // Two-byte put/get with empty ringbuf.
ringbuf_put16(&ringbuf, 0xaa55); ringbuf_put16(&ringbuf, 0xaa55);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf)); mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
// Two-byte put with full ringbuf. // Two-byte put with full ringbuf.
for (int i = 0; i < 99; ++i) { for (int i = 0; i < 99; ++i) {
ringbuf_put(&ringbuf, i); ringbuf_put(&ringbuf, i);
} }
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x11bb)); mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x11bb));
// Two-byte put with one byte free. // Two-byte put with one byte free.
ringbuf_get(&ringbuf); ringbuf_get(&ringbuf);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x3377)); mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x3377));
ringbuf_get(&ringbuf); ringbuf_get(&ringbuf);
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0xcc99)); mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0xcc99));
for (int i = 0; i < 97; ++i) { for (int i = 0; i < 97; ++i) {
ringbuf_get(&ringbuf); ringbuf_get(&ringbuf);
} }
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf)); mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf)); mp_printf(&mp_plat_print, "%d %d\n", ringbuf_num_empty(&ringbuf), ringbuf_num_filled(&ringbuf));
// Two-byte put with wrap around on first byte: // Two-byte put with wrap around on first byte:
ringbuf.iput = 0; ringbuf_clear(&ringbuf);
ringbuf.iget = 0;
for (int i = 0; i < 99; ++i) { for (int i = 0; i < 99; ++i) {
ringbuf_put(&ringbuf, i); ringbuf_put(&ringbuf, i);
ringbuf_get(&ringbuf); ringbuf_get(&ringbuf);
@ -660,8 +659,7 @@ STATIC mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf)); mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
// Two-byte put with wrap around on second byte: // Two-byte put with wrap around on second byte:
ringbuf.iput = 0; ringbuf_clear(&ringbuf);
ringbuf.iget = 0;
for (int i = 0; i < 98; ++i) { for (int i = 0; i < 98; ++i) {
ringbuf_put(&ringbuf, i); ringbuf_put(&ringbuf, i);
ringbuf_get(&ringbuf); ringbuf_get(&ringbuf);
@ -670,13 +668,11 @@ STATIC mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf)); mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
// Two-byte get from empty ringbuf. // Two-byte get from empty ringbuf.
ringbuf.iput = 0; ringbuf_clear(&ringbuf);
ringbuf.iget = 0;
mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf)); mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf));
// Two-byte get from ringbuf with one byte available. // Two-byte get from ringbuf with one byte available.
ringbuf.iput = 0; ringbuf_clear(&ringbuf);
ringbuf.iget = 0;
ringbuf_put(&ringbuf, 0xaa); ringbuf_put(&ringbuf, 0xaa);
mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf)); mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf));
} }