unix/coverage: Add coverage tests for ringbuf.
This commit is contained in:
parent
42e9bdf19b
commit
f67fd95f8d
|
@ -10,6 +10,7 @@
|
|||
#include "py/builtin.h"
|
||||
#include "py/emit.h"
|
||||
#include "py/formatfloat.h"
|
||||
#include "py/ringbuf.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/bc.h"
|
||||
|
@ -419,6 +420,77 @@ STATIC mp_obj_t extra_coverage(void) {
|
|||
}
|
||||
}
|
||||
|
||||
// ringbuf
|
||||
{
|
||||
byte buf[100];
|
||||
ringbuf_t ringbuf = {buf, sizeof(buf), 0, 0};
|
||||
|
||||
mp_printf(&mp_plat_print, "# ringbuf\n");
|
||||
|
||||
// Single-byte put/get with empty ringbuf.
|
||||
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
|
||||
ringbuf_put(&ringbuf, 22);
|
||||
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&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));
|
||||
|
||||
// Two-byte put/get with empty ringbuf.
|
||||
ringbuf_put16(&ringbuf, 0xaa55);
|
||||
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&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));
|
||||
|
||||
// Two-byte put with full ringbuf.
|
||||
for (int i = 0; i < 99; ++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\n", ringbuf_put16(&ringbuf, 0x11bb));
|
||||
// Two-byte put with one byte free.
|
||||
ringbuf_get(&ringbuf);
|
||||
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
|
||||
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x3377));
|
||||
ringbuf_get(&ringbuf);
|
||||
mp_printf(&mp_plat_print, "%d %d\n", ringbuf_free(&ringbuf), ringbuf_avail(&ringbuf));
|
||||
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0xcc99));
|
||||
for (int i = 0; i < 97; ++i) {
|
||||
ringbuf_get(&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));
|
||||
|
||||
// Two-byte put with wrap around on first byte:
|
||||
ringbuf.iput = 0;
|
||||
ringbuf.iget = 0;
|
||||
for (int i = 0; i < 99; ++i) {
|
||||
ringbuf_put(&ringbuf, i);
|
||||
ringbuf_get(&ringbuf);
|
||||
}
|
||||
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x11bb));
|
||||
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
|
||||
|
||||
// Two-byte put with wrap around on second byte:
|
||||
ringbuf.iput = 0;
|
||||
ringbuf.iget = 0;
|
||||
for (int i = 0; i < 98; ++i) {
|
||||
ringbuf_put(&ringbuf, i);
|
||||
ringbuf_get(&ringbuf);
|
||||
}
|
||||
mp_printf(&mp_plat_print, "%d\n", ringbuf_put16(&ringbuf, 0x22ff));
|
||||
mp_printf(&mp_plat_print, "%04x\n", ringbuf_get16(&ringbuf));
|
||||
|
||||
// Two-byte get from empty ringbuf.
|
||||
ringbuf.iput = 0;
|
||||
ringbuf.iget = 0;
|
||||
mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf));
|
||||
|
||||
// Two-byte get from ringbuf with one byte available.
|
||||
ringbuf.iput = 0;
|
||||
ringbuf.iget = 0;
|
||||
ringbuf_put(&ringbuf, 0xaa);
|
||||
mp_printf(&mp_plat_print, "%d\n", ringbuf_get16(&ringbuf));
|
||||
}
|
||||
|
||||
mp_obj_streamtest_t *s = m_new_obj(mp_obj_streamtest_t);
|
||||
s->base.type = &mp_type_stest_fileio;
|
||||
s->buf = NULL;
|
||||
|
|
|
@ -75,6 +75,28 @@ unlocked
|
|||
1
|
||||
2
|
||||
3
|
||||
# ringbuf
|
||||
99 0
|
||||
98 1
|
||||
22
|
||||
99 0
|
||||
97 2
|
||||
aa55
|
||||
99 0
|
||||
0 99
|
||||
-1
|
||||
1 98
|
||||
-1
|
||||
2 97
|
||||
0
|
||||
cc99
|
||||
99 0
|
||||
0
|
||||
11bb
|
||||
0
|
||||
22ff
|
||||
-1
|
||||
-1
|
||||
0123456789 b'0123456789'
|
||||
7300
|
||||
7300
|
||||
|
|
Loading…
Reference in New Issue