From 5e80c53c115e8b45df598ffdbc45dfdd543be8ac Mon Sep 17 00:00:00 2001 From: Rami Ali Date: Tue, 17 Jan 2017 17:26:59 +1100 Subject: tests/extmod: Improve test coverage of ure module. --- tests/extmod/ure1.py | 4 ++++ tests/extmod/ure_split_notimpl.py | 7 +++++++ tests/extmod/ure_split_notimpl.py.exp | 1 + 3 files changed, 12 insertions(+) create mode 100644 tests/extmod/ure_split_notimpl.py create mode 100644 tests/extmod/ure_split_notimpl.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py index aeadf4e5c..48537c2ea 100644 --- a/tests/extmod/ure1.py +++ b/tests/extmod/ure1.py @@ -11,6 +11,10 @@ try: except IndexError: print("IndexError") +# conversion of re and match to string +str(r) +str(m) + r = re.compile("(.+)1") m = r.match("xyz781") print(m.group(0)) diff --git a/tests/extmod/ure_split_notimpl.py b/tests/extmod/ure_split_notimpl.py new file mode 100644 index 000000000..724e9d43b --- /dev/null +++ b/tests/extmod/ure_split_notimpl.py @@ -0,0 +1,7 @@ +import ure as re + +r = re.compile('( )') +try: + s = r.split("a b c foobar") +except NotImplementedError: + print('NotImplementedError') diff --git a/tests/extmod/ure_split_notimpl.py.exp b/tests/extmod/ure_split_notimpl.py.exp new file mode 100644 index 000000000..437f61670 --- /dev/null +++ b/tests/extmod/ure_split_notimpl.py.exp @@ -0,0 +1 @@ +NotImplementedError -- cgit v1.2.3 From 4c4f586e2c798a28ea441fd3ddd409806672138f Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 19 Jan 2017 23:37:44 +1100 Subject: tests/extmod/framebuf1: Add test for no-op fill_rect. --- tests/extmod/framebuf1.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/extmod') diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index cdc7e5b18..47dd98d7e 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -50,6 +50,7 @@ print('rect', buf) #fill rect fbuf.fill(0) +fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation fbuf.fill_rect(1, 1, 3, 3, 1) print('fill_rect', buf) -- cgit v1.2.3 From fd99690f1859a46aee690355170ad13eed9f0122 Mon Sep 17 00:00:00 2001 From: Oleg Korsak Date: Sun, 1 Jan 2017 04:24:56 +0200 Subject: extmod/modframebuf: Add GS4_HMSB format. --- extmod/modframebuf.c | 59 +++++++++++++++++++++++++++++++++++++++++++++-- tests/extmod/framebuf1.py | 2 +- 2 files changed, 58 insertions(+), 3 deletions(-) (limited to 'tests/extmod') diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index e2441f194..792a3a7fa 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -97,13 +97,66 @@ STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, i } } +// Functions for GS4_HMSB format + +STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) { + uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1]; + + if (x % 2) { + *pixel = ((uint8_t)col & 0x0f) | (*pixel & 0xf0); + } else { + *pixel = ((uint8_t)col << 4) | (*pixel & 0x0f); + } +} + +STATIC uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) { + if (x % 2) { + return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f; + } + + return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] >> 4; +} + +STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) { + col &= 0x0f; + uint8_t *pixel_pair = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1]; + uint8_t col_shifted_left = col << 4; + uint8_t colored_pixel_pair = col_shifted_left | col; + int pixel_count_till_next_line = (fb->stride - w) >> 1; + bool odd_x = (x % 2 == 1); + + while (h--) { + int ww = w; + + if (odd_x && ww > 0) { + *pixel_pair = (*pixel_pair & 0xf0) | col; + pixel_pair++; + ww--; + } + + memset(pixel_pair, colored_pixel_pair, ww >> 1); + pixel_pair += ww >> 1; + + if (ww % 2) { + *pixel_pair = col_shifted_left | (*pixel_pair & 0x0f); + if (!odd_x) { + pixel_pair++; + } + } + + pixel_pair += pixel_count_till_next_line; + } +} + // constants for formats -#define FRAMEBUF_MVLSB (0) -#define FRAMEBUF_RGB565 (1) +#define FRAMEBUF_MVLSB (0) +#define FRAMEBUF_RGB565 (1) +#define FRAMEBUF_GS4_HMSB (2) STATIC mp_framebuf_p_t formats[] = { [FRAMEBUF_MVLSB] = {mvlsb_setpixel, mvlsb_getpixel, mvlsb_fill_rect}, [FRAMEBUF_RGB565] = {rgb565_setpixel, rgb565_getpixel, rgb565_fill_rect}, + [FRAMEBUF_GS4_HMSB] = {gs4_hmsb_setpixel, gs4_hmsb_getpixel, gs4_hmsb_fill_rect}, }; static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { @@ -152,6 +205,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size switch (o->format) { case FRAMEBUF_MVLSB: case FRAMEBUF_RGB565: + case FRAMEBUF_GS4_HMSB: break; default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, @@ -490,6 +544,7 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) }, { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) }, { MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) }, + { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_GS4_HMSB) }, }; STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table); diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index 47dd98d7e..9fed33809 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -91,7 +91,7 @@ print(buf) # test invalid constructor try: - fbuf = framebuf.FrameBuffer(buf, w, h, 2, framebuf.MVLSB) + fbuf = framebuf.FrameBuffer(buf, w, h, 3, framebuf.MVLSB) except ValueError: print("ValueError") -- cgit v1.2.3 From 406fb3cb6084e5b3c6489a99b30affd35330d3fd Mon Sep 17 00:00:00 2001 From: Oleg Korsak Date: Thu, 12 Jan 2017 03:29:23 +0200 Subject: tests/extmod/framebuf4: Add tests for GS4_HMSB framebuf format. --- tests/extmod/framebuf4.py | 54 ++++++++++++++++++++ tests/extmod/framebuf4.py.exp | 112 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 tests/extmod/framebuf4.py create mode 100644 tests/extmod/framebuf4.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/framebuf4.py b/tests/extmod/framebuf4.py new file mode 100644 index 000000000..641f5bfc5 --- /dev/null +++ b/tests/extmod/framebuf4.py @@ -0,0 +1,54 @@ +try: + import framebuf +except ImportError: + print("SKIP") + import sys + sys.exit() + +def printbuf(): + print("--8<--") + for y in range(h): + print(buf[y * w // 2:(y + 1) * w // 2]) + print("-->8--") + +w = 16 +h = 8 +buf = bytearray(w * h // 2) +fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB) + +# fill +fbuf.fill(0x0f) +printbuf() +fbuf.fill(0xa0) +printbuf() + +# put pixel +fbuf.pixel(0, 0, 0x01) +printbuf() +fbuf.pixel(w-1, 0, 0x02) +printbuf() +fbuf.pixel(w-1, h-1, 0x03) +printbuf() +fbuf.pixel(0, h-1, 0x04) +printbuf() + +# get pixel +print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1)) +print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1)) + +# fill rect +fbuf.fill_rect(0, 0, w, h, 0x0f) +printbuf() +fbuf.fill_rect(0, 0, w, h, 0xf0) +fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1) +printbuf() +fbuf.fill_rect(1, 0, w//2+1, 1, 0x10) +fbuf.fill_rect(1, 0, w//2, 1, 0xf1) +printbuf() +fbuf.fill_rect(1, 0, w//2, 1, 0x10) +fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf) +printbuf() +fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0) +fbuf.fill_rect(0, h-4, w//2, 4, 0xaf) +printbuf() +fbuf.fill_rect(0, h-4, w//2, 4, 0xb0) diff --git a/tests/extmod/framebuf4.py.exp b/tests/extmod/framebuf4.py.exp new file mode 100644 index 000000000..0865470a0 --- /dev/null +++ b/tests/extmod/framebuf4.py.exp @@ -0,0 +1,112 @@ +--8<-- +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +-->8-- +--8<-- +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x02') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x02') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x03') +-->8-- +--8<-- +bytearray(b'\x10\x00\x00\x00\x00\x00\x00\x02') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'@\x00\x00\x00\x00\x00\x00\x03') +-->8-- +1 2 3 4 +0 0 0 0 +--8<-- +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff') +-->8-- +--8<-- +bytearray(b'\x01\x11\x11\x11\x11\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x01\x11\x11\x11\x10\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\xf0\x00\x00\x00') +-->8-- +--8<-- +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +bytearray(b'\xff\xff\xff\xff\x00\x00\x00\x00') +-->8-- -- cgit v1.2.3 From bf51200bc10858552f3cc6989afe0fe51b57a4f2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 25 Jan 2017 23:23:50 +1100 Subject: tests/extmod/framebuf1: Fix test for framebuf invalid constructor. --- tests/extmod/framebuf1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index 9fed33809..c204e63aa 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -89,11 +89,11 @@ print(buf) fbuf.text(str(chr(31)), 0, 0) print(buf) -# test invalid constructor +# test invalid constructor, and stride argument try: - fbuf = framebuf.FrameBuffer(buf, w, h, 3, framebuf.MVLSB) + fbuf = framebuf.FrameBuffer(buf, w, h, -1, w) except ValueError: - print("ValueError") + print("ValueError") # test legacy constructor fbuf = framebuf.FrameBuffer1(buf, w, h) -- cgit v1.2.3 From 221f88d1f3f67640e72912ad8473782360b0e306 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 26 Jan 2017 23:45:51 +1100 Subject: tests/extmod: Add test for ure debug printing when compiling a regex. --- tests/extmod/ure_debug.py | 3 +++ tests/extmod/ure_debug.py.exp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/extmod/ure_debug.py create mode 100644 tests/extmod/ure_debug.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py new file mode 100644 index 000000000..303e1789c --- /dev/null +++ b/tests/extmod/ure_debug.py @@ -0,0 +1,3 @@ +# test printing debugging info when compiling +import ure +ure.compile('^a|b[0-9]\w$', ure.DEBUG) diff --git a/tests/extmod/ure_debug.py.exp b/tests/extmod/ure_debug.py.exp new file mode 100644 index 000000000..45f5e20f6 --- /dev/null +++ b/tests/extmod/ure_debug.py.exp @@ -0,0 +1,15 @@ + 0: rsplit 5 (3) + 2: any + 3: jmp 0 (-5) + 5: save 0 + 7: split 14 (5) + 9: assert bol +10: char a +12: jmp 23 (9) +14: char b +16: class 1 0x30-0x39 +20: namedclass w +22: assert eol +23: save 1 +25: match +Bytes: 26, insts: 14 -- cgit v1.2.3 From 94d87fbb308bf26e35cbb50f294fb06f178df871 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 24 Jan 2017 20:55:05 +1100 Subject: test/extmod: Update vfs_fat tests for new OO FatFs library. The new version of FatFs requires a minimum of 50 blocks on the device. Also, some tests no longer make sense with an OO vfs. --- tests/extmod/vfs_fat_fileio.py | 10 +++++----- tests/extmod/vfs_fat_fsusermount.py | 5 +++-- tests/extmod/vfs_fat_fsusermount.py.exp | 1 - tests/extmod/vfs_fat_oldproto.py | 6 +----- tests/extmod/vfs_fat_oldproto.py.exp | 1 - tests/extmod/vfs_fat_ramdisk.py | 16 +--------------- tests/extmod/vfs_fat_ramdisk.py.exp | 5 +---- 7 files changed, 11 insertions(+), 33 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio.py index f050d94e2..fd84cdca8 100644 --- a/tests/extmod/vfs_fat_fileio.py +++ b/tests/extmod/vfs_fat_fileio.py @@ -34,7 +34,7 @@ class RAMFS: try: - bdev = RAMFS(48) + bdev = RAMFS(50) except MemoryError: print("SKIP") sys.exit() @@ -91,7 +91,7 @@ with vfs.open("foo_file.txt") as f2: # using constructor of FileIO type to open a file FileIO = type(f) -with FileIO("foo_file.txt") as f: +with FileIO("/ramdisk/foo_file.txt") as f: print(f.read()) # dirs @@ -118,9 +118,9 @@ except OSError as e: print(e.args[0] == uerrno.ENOENT) try: - vfs.rename("foo_dir", "/null") + vfs.rename("foo_dir", "/null/file") except OSError as e: - print(e.args[0] == uerrno.ENODEV) + print(e.args[0] == uerrno.ENOENT) # file in dir with vfs.open("foo_dir/file-in-dir.txt", "w+t") as f: @@ -139,7 +139,7 @@ except OSError as e: print(e.args[0] == uerrno.EACCES) # trim full path -vfs.rename("foo_dir/file-in-dir.txt", "/ramdisk/foo_dir/file.txt") +vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") print(vfs.listdir("foo_dir")) vfs.rename("foo_dir/file.txt", "moved-to-root.txt") diff --git a/tests/extmod/vfs_fat_fsusermount.py b/tests/extmod/vfs_fat_fsusermount.py index 7326172ee..0ab15d827 100644 --- a/tests/extmod/vfs_fat_fsusermount.py +++ b/tests/extmod/vfs_fat_fsusermount.py @@ -34,7 +34,7 @@ class RAMFS: try: - bdev = RAMFS(48) + bdev = RAMFS(50) except MemoryError: print("SKIP") sys.exit() @@ -75,6 +75,7 @@ uos.vfs_mount(bdev, "/ramdisk") uos.vfs_umount("/ramdisk") # readonly mount +# note: this test doesn't work correctly with new OO FatFs uos.vfs_mount(bdev, "/ramdisk", readonly=True) vfs = uos.VfsFat(bdev, "/ramdisk") try: @@ -89,7 +90,7 @@ uos.vfs_mount(None, "/ramdisk") dev = [] try: for i in range(0,4): - dev.append(RAMFS(48)) + dev.append(RAMFS(50)) uos.vfs_mkfs(dev[i], "/ramdisk" + str(i)) uos.vfs_mount(dev[i], "/ramdisk" + str(i)) except OSError as e: diff --git a/tests/extmod/vfs_fat_fsusermount.py.exp b/tests/extmod/vfs_fat_fsusermount.py.exp index 3b30688dd..3ace58372 100644 --- a/tests/extmod/vfs_fat_fsusermount.py.exp +++ b/tests/extmod/vfs_fat_fsusermount.py.exp @@ -3,5 +3,4 @@ can't mount True can't umount can't umount -EROFS: True too many devices mounted diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index 73983567d..b43fbd286 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -34,7 +34,7 @@ class RAMFS_OLD: try: - bdev = RAMFS_OLD(48) + bdev = RAMFS_OLD(50) except MemoryError: print("SKIP") sys.exit() @@ -57,7 +57,3 @@ print(vfs.listdir()) # umount by device uos.vfs_umount(bdev) -try: - vfs.listdir() -except OSError as e: - print(e.args[0] == uerrno.ENODEV) diff --git a/tests/extmod/vfs_fat_oldproto.py.exp b/tests/extmod/vfs_fat_oldproto.py.exp index 4120c277a..a389a5217 100644 --- a/tests/extmod/vfs_fat_oldproto.py.exp +++ b/tests/extmod/vfs_fat_oldproto.py.exp @@ -1,4 +1,3 @@ ['file.txt'] hello! [] -True diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 184672ff1..1480d52f6 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -34,7 +34,7 @@ class RAMFS: try: - bdev = RAMFS(48) + bdev = RAMFS(50) except MemoryError: print("SKIP") sys.exit() @@ -46,11 +46,6 @@ print(b"hello!" not in bdev.data) vfs = uos.VfsFat(bdev, "/ramdisk") -try: - vfs.statvfs("/null") -except OSError as e: - print(e.args[0] == uerrno.ENODEV) - print("statvfs:", vfs.statvfs("/ramdisk")) print("getcwd:", vfs.getcwd()) @@ -87,15 +82,6 @@ vfs.chdir("..") print("getcwd:", vfs.getcwd()) vfs.umount() -try: - vfs.listdir() -except OSError as e: - print(e.args[0] == uerrno.ENODEV) - -try: - vfs.getcwd() -except OSError as e: - print(e.args[0] == uerrno.ENODEV) vfs = uos.VfsFat(bdev, "/ramdisk") print(vfs.listdir(b"")) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index eaf637199..095620f17 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -1,7 +1,6 @@ True True -True -statvfs: (512, 512, 14, 14, 14, 0, 0, 0, 0, 255) +statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255) getcwd: /ramdisk True ['foo_file.txt'] @@ -14,6 +13,4 @@ getcwd: /ramdisk/foo_dir [] True getcwd: /ramdisk -True -True [b'foo_file.txt', b'foo_dir'] -- cgit v1.2.3 From b9bfaa349aaba4462522fd9330dbc5b21f47d906 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Jan 2017 15:34:36 +1100 Subject: tests/extmod/vfs_fat: Update tests to work with new VFS sub-system. The vfs_fat_fsusermount test is no longer relevant so has been removed. --- tests/extmod/vfs_fat_fileio.py | 37 ++++++++----- tests/extmod/vfs_fat_fileio.py.exp | 1 - tests/extmod/vfs_fat_fsusermount.py | 97 --------------------------------- tests/extmod/vfs_fat_fsusermount.py.exp | 6 -- tests/extmod/vfs_fat_oldproto.py | 16 +++--- tests/extmod/vfs_fat_ramdisk.py | 13 +++-- tests/extmod/vfs_fat_ramdisk.py.exp | 7 +-- 7 files changed, 40 insertions(+), 137 deletions(-) delete mode 100644 tests/extmod/vfs_fat_fsusermount.py delete mode 100644 tests/extmod/vfs_fat_fsusermount.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio.py index fd84cdca8..6fdac0710 100644 --- a/tests/extmod/vfs_fat_fileio.py +++ b/tests/extmod/vfs_fat_fileio.py @@ -1,6 +1,10 @@ import sys -import uos import uerrno +try: + import uos_vfs as uos + open = uos.vfs_open +except ImportError: + import uos try: uos.VfsFat except AttributeError: @@ -40,10 +44,12 @@ except MemoryError: sys.exit() uos.VfsFat.mkfs(bdev) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) +uos.mount(vfs, '/ramdisk') +uos.chdir('/ramdisk') # file IO -f = vfs.open("foo_file.txt", "w") +f = open("foo_file.txt", "w") print(str(f)[:17], str(f)[-1:]) f.write("hello!") f.flush() @@ -65,14 +71,14 @@ except OSError as e: print(e.args[0] == uerrno.EINVAL) try: - vfs.open("foo_file.txt", "x") + open("foo_file.txt", "x") except OSError as e: print(e.args[0] == uerrno.EEXIST) -with vfs.open("foo_file.txt", "a") as f: +with open("foo_file.txt", "a") as f: f.write("world!") -with vfs.open("foo_file.txt") as f2: +with open("foo_file.txt") as f2: print(f2.read()) print(f2.tell()) @@ -90,9 +96,10 @@ with vfs.open("foo_file.txt") as f2: print(f2.read(1)) # using constructor of FileIO type to open a file -FileIO = type(f) -with FileIO("/ramdisk/foo_file.txt") as f: - print(f.read()) +# no longer working with new VFS sub-system +#FileIO = type(f) +#with FileIO("/ramdisk/foo_file.txt") as f: +# print(f.read()) # dirs vfs.mkdir("foo_dir") @@ -123,13 +130,13 @@ except OSError as e: print(e.args[0] == uerrno.ENOENT) # file in dir -with vfs.open("foo_dir/file-in-dir.txt", "w+t") as f: +with open("foo_dir/file-in-dir.txt", "w+t") as f: f.write("data in file") -with vfs.open("foo_dir/file-in-dir.txt", "r+b") as f: +with open("foo_dir/file-in-dir.txt", "r+b") as f: print(f.read()) -with vfs.open("foo_dir/sub_file.txt", "w") as f: +with open("foo_dir/sub_file.txt", "w") as f: f.write("subdir file") # directory not empty @@ -146,11 +153,11 @@ vfs.rename("foo_dir/file.txt", "moved-to-root.txt") print(vfs.listdir()) # check that renaming to existing file will overwrite it -with vfs.open("temp", "w") as f: +with open("temp", "w") as f: f.write("new text") vfs.rename("temp", "moved-to-root.txt") print(vfs.listdir()) -with vfs.open("moved-to-root.txt") as f: +with open("moved-to-root.txt") as f: print(f.read()) # valid removes @@ -163,7 +170,7 @@ print(vfs.listdir()) try: bsize = vfs.statvfs("/ramdisk")[0] free = vfs.statvfs("/ramdisk")[2] + 1 - f = vfs.open("large_file.txt", "wb") + f = open("large_file.txt", "wb") f.write(bytearray(bsize * free)) except OSError as e: print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC diff --git a/tests/extmod/vfs_fat_fileio.py.exp b/tests/extmod/vfs_fat_fileio.py.exp index a09442ae8..4e34e83a8 100644 --- a/tests/extmod/vfs_fat_fileio.py.exp +++ b/tests/extmod/vfs_fat_fileio.py.exp @@ -9,7 +9,6 @@ h e True d -hello!world! True True True diff --git a/tests/extmod/vfs_fat_fsusermount.py b/tests/extmod/vfs_fat_fsusermount.py deleted file mode 100644 index 0ab15d827..000000000 --- a/tests/extmod/vfs_fat_fsusermount.py +++ /dev/null @@ -1,97 +0,0 @@ -import sys -import uos -import uerrno -try: - uos.VfsFat -except AttributeError: - print("SKIP") - sys.exit() - - -class RAMFS: - - SEC_SIZE = 512 - - def __init__(self, blocks): - self.data = bytearray(blocks * self.SEC_SIZE) - - def readblocks(self, n, buf): - #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) - for i in range(len(buf)): - buf[i] = self.data[n * self.SEC_SIZE + i] - - def writeblocks(self, n, buf): - #print("writeblocks(%s, %x)" % (n, id(buf))) - for i in range(len(buf)): - self.data[n * self.SEC_SIZE + i] = buf[i] - - def ioctl(self, op, arg): - #print("ioctl(%d, %r)" % (op, arg)) - if op == 4: # BP_IOCTL_SEC_COUNT - return len(self.data) // self.SEC_SIZE - if op == 5: # BP_IOCTL_SEC_SIZE - return self.SEC_SIZE - - -try: - bdev = RAMFS(50) -except MemoryError: - print("SKIP") - sys.exit() - -# can't mkfs readonly device -try: - uos.vfs_mkfs(bdev, "/ramdisk", readonly=True) -except OSError as e: - print(e) - -# mount before mkfs -try: - uos.vfs_mount(bdev, "/ramdisk") -except OSError as e: - print(e) - -# invalid umount -try: - uos.vfs_umount("/ramdisk") -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - uos.vfs_mount(None, "/ramdisk") -except OSError as e: - print(e) - -try: - uos.vfs_mkfs(None, "/ramdisk") -except OSError as e: - print(e) - -# valid mkfs/mount -uos.vfs_mkfs(bdev, "/ramdisk") -uos.vfs_mount(bdev, "/ramdisk") - -# umount by path -uos.vfs_umount("/ramdisk") - -# readonly mount -# note: this test doesn't work correctly with new OO FatFs -uos.vfs_mount(bdev, "/ramdisk", readonly=True) -vfs = uos.VfsFat(bdev, "/ramdisk") -try: - f = vfs.open("file.txt", "w") -except OSError as e: - print("EROFS:", e.args[0] == 30) # uerrno.EROFS - -# device is None == umount -uos.vfs_mount(None, "/ramdisk") - -# max mounted devices -dev = [] -try: - for i in range(0,4): - dev.append(RAMFS(50)) - uos.vfs_mkfs(dev[i], "/ramdisk" + str(i)) - uos.vfs_mount(dev[i], "/ramdisk" + str(i)) -except OSError as e: - print(e) diff --git a/tests/extmod/vfs_fat_fsusermount.py.exp b/tests/extmod/vfs_fat_fsusermount.py.exp deleted file mode 100644 index 3ace58372..000000000 --- a/tests/extmod/vfs_fat_fsusermount.py.exp +++ /dev/null @@ -1,6 +0,0 @@ -can't mkfs -can't mount -True -can't umount -can't umount -too many devices mounted diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index b43fbd286..03ab76e35 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,10 +1,11 @@ import sys -import uos import uerrno +try: + import uos_vfs as uos +except ImportError: + import uos try: uos.VfsFat - uos.vfs_mkfs - uos.vfs_mount except AttributeError: print("SKIP") sys.exit() @@ -39,11 +40,11 @@ except MemoryError: print("SKIP") sys.exit() -uos.vfs_mkfs(bdev, "/ramdisk") -uos.vfs_mount(bdev, "/ramdisk") +uos.VfsFat.mkfs(bdev) +vfs = uos.VfsFat(bdev) +uos.mount(vfs, "/ramdisk") # file io -vfs = uos.VfsFat(bdev, "/ramdisk") with vfs.open("file.txt", "w") as f: f.write("hello!") @@ -54,6 +55,3 @@ with vfs.open("file.txt", "r") as f: vfs.remove("file.txt") print(vfs.listdir()) - -# umount by device -uos.vfs_umount(bdev) diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 1480d52f6..a9eb1679a 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,6 +1,9 @@ import sys -import uos import uerrno +try: + import uos_vfs as uos +except ImportError: + import uos try: uos.VfsFat except AttributeError: @@ -44,7 +47,8 @@ uos.VfsFat.mkfs(bdev) print(b"FOO_FILETXT" not in bdev.data) print(b"hello!" not in bdev.data) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) +uos.mount(vfs, "/ramdisk") print("statvfs:", vfs.statvfs("/ramdisk")) print("getcwd:", vfs.getcwd()) @@ -59,7 +63,6 @@ with vfs.open("foo_file.txt", "w") as f: print(vfs.listdir()) print("stat root:", vfs.stat("/")) -print("stat disk:", vfs.stat("/ramdisk/")) print("stat file:", vfs.stat("foo_file.txt")) print(b"FOO_FILETXT" in bdev.data) @@ -81,7 +84,7 @@ except OSError as e: vfs.chdir("..") print("getcwd:", vfs.getcwd()) -vfs.umount() +uos.umount(vfs) -vfs = uos.VfsFat(bdev, "/ramdisk") +vfs = uos.VfsFat(bdev) print(vfs.listdir(b"")) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index 095620f17..fda7d300e 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -1,16 +1,15 @@ True True statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255) -getcwd: /ramdisk +getcwd: / True ['foo_file.txt'] stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) -stat disk: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) stat file: (32768, 0, 0, 0, 0, 0, 6, -631238400, -631238400, -631238400) True True -getcwd: /ramdisk/foo_dir +getcwd: /foo_dir [] True -getcwd: /ramdisk +getcwd: / [b'foo_file.txt', b'foo_dir'] -- cgit v1.2.3 From a0c729681faa3a0b1a6150d5462647bad60038bf Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Jan 2017 23:15:09 +1100 Subject: tests/extmod/vfs_fat_ramdisk: Make it work on pyboard. --- tests/extmod/vfs_fat_ramdisk.py | 2 +- tests/extmod/vfs_fat_ramdisk.py.exp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index a9eb1679a..dc4a1c305 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -63,7 +63,7 @@ with vfs.open("foo_file.txt", "w") as f: print(vfs.listdir()) print("stat root:", vfs.stat("/")) -print("stat file:", vfs.stat("foo_file.txt")) +print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs print(b"FOO_FILETXT" in bdev.data) print(b"hello!" in bdev.data) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index fda7d300e..137db5841 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -5,7 +5,7 @@ getcwd: / True ['foo_file.txt'] stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) -stat file: (32768, 0, 0, 0, 0, 0, 6, -631238400, -631238400, -631238400) +stat file: (32768, 0, 0, 0, 0, 0, 6) True True getcwd: /foo_dir -- cgit v1.2.3 From d5e9ab6e61729f533dbed5c2b6b27307ce6c3b55 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 5 Feb 2017 14:20:17 +0300 Subject: extmod/machine_pulse: Make time_pulse_us() not throw exceptions. machine.time_pulse_us() is intended to provide very fine timing, including while working with signal bursts, where each transition is tracked in row. Throwing and handling an exception may take too much time and "signal loss". So instead, in case of a timeout, just return negative value. Cases of timeout while waiting for initial signal stabilization, and during actual timing, are recognized. The documentation is updated accordingly, and rewritten somewhat to clarify the function behavior. --- docs/library/machine.rst | 11 +++++++---- drivers/dht/dht.c | 4 ++-- extmod/machine_pulse.c | 6 ++---- tests/extmod/machine_pulse.py | 11 ++--------- tests/extmod/machine_pulse.py.exp | 4 ++-- 5 files changed, 15 insertions(+), 21 deletions(-) (limited to 'tests/extmod') diff --git a/docs/library/machine.rst b/docs/library/machine.rst index 753f6b417..c6da71585 100644 --- a/docs/library/machine.rst +++ b/docs/library/machine.rst @@ -118,12 +118,15 @@ Miscellaneous functions microseconds. The `pulse_level` argument should be 0 to time a low pulse or 1 to time a high pulse. - The function first waits while the pin input is different to the `pulse_level` - parameter, then times the duration that the pin is equal to `pulse_level`. + If the current input value of the pin is different to `pulse_level`, + the function first (*) waits until the pin input becomes equal to `pulse_level`, + then (**) times the duration that the pin is equal to `pulse_level`. If the pin is already equal to `pulse_level` then timing starts straight away. - The function will raise an OSError with ETIMEDOUT if either of the waits is - longer than the given timeout value (which is in microseconds). + The function will return -2 if there was timeout waiting for condition marked + (*) above, and -1 if there was timeout during the main measurement, marked (**) + above. The timeout is the same for both cases and given by `timeout_us` (which + is in microseconds). .. _machine_constants: diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c index 1f0cffc6f..6bdda44b4 100644 --- a/drivers/dht/dht.c +++ b/drivers/dht/dht.c @@ -65,7 +65,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) { // time pulse, should be 80us ticks = machine_time_pulse_us(pin, 1, 150); - if (ticks == (mp_uint_t)-1) { + if ((mp_int_t)ticks < 0) { goto timeout; } @@ -73,7 +73,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) { uint8_t *buf = bufinfo.buf; for (int i = 0; i < 40; ++i) { ticks = machine_time_pulse_us(pin, 1, 100); - if (ticks == (mp_uint_t)-1) { + if ((mp_int_t)ticks < 0) { goto timeout; } buf[i / 8] = (buf[i / 8] << 1) | (ticks > 48); diff --git a/extmod/machine_pulse.c b/extmod/machine_pulse.c index b2a78d72e..5f837479d 100644 --- a/extmod/machine_pulse.c +++ b/extmod/machine_pulse.c @@ -34,7 +34,7 @@ mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t mp_uint_t start = mp_hal_ticks_us(); while (mp_hal_pin_read(pin) != pulse_level) { if ((mp_uint_t)(mp_hal_ticks_us() - start) >= timeout_us) { - return (mp_uint_t)-1; + return (mp_uint_t)-2; } } start = mp_hal_ticks_us(); @@ -57,9 +57,7 @@ STATIC mp_obj_t machine_time_pulse_us_(size_t n_args, const mp_obj_t *args) { timeout_us = mp_obj_get_int(args[2]); } mp_uint_t us = machine_time_pulse_us(pin, level, timeout_us); - if (us == (mp_uint_t)-1) { - mp_raise_OSError(MP_ETIMEDOUT); - } + // May return -1 or -2 in case of timeout return mp_obj_new_int(us); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj, 2, 3, machine_time_pulse_us_); diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py index b6e126435..6491b5409 100644 --- a/tests/extmod/machine_pulse.py +++ b/tests/extmod/machine_pulse.py @@ -43,12 +43,5 @@ t = machine.time_pulse_us(p, 0) print(type(t)) p = ConstPin(0) -try: - machine.time_pulse_us(p, 1, 10) -except OSError: - print("OSError") - -try: - machine.time_pulse_us(p, 0, 10) -except OSError: - print("OSError") +print(machine.time_pulse_us(p, 1, 10)) +print(machine.time_pulse_us(p, 0, 10)) diff --git a/tests/extmod/machine_pulse.py.exp b/tests/extmod/machine_pulse.py.exp index f9a474218..20d4c1043 100644 --- a/tests/extmod/machine_pulse.py.exp +++ b/tests/extmod/machine_pulse.py.exp @@ -5,5 +5,5 @@ value: 1 value: 0 value: 1 -OSError -OSError +-2 +-1 -- cgit v1.2.3 From f2d732f4596064b3257abe571dc14ab61e02dec9 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 15 Feb 2017 01:56:22 +0300 Subject: tests/extmod: Make tests skippable. --- tests/extmod/machine1.py | 3 ++- tests/extmod/ubinascii_a2b_base64.py | 9 +++++++-- tests/extmod/ubinascii_b2a_base64.py | 9 +++++++-- tests/extmod/ubinascii_crc32.py | 10 ++++++++-- tests/extmod/ubinascii_hexlify.py | 9 +++++++-- tests/extmod/ubinascii_micropython.py | 9 +++++++-- tests/extmod/ubinascii_unhexlify.py | 9 +++++++-- tests/extmod/uctypes_array_assign_le.py | 7 ++++++- tests/extmod/uctypes_array_assign_native_le.py | 6 +++++- tests/extmod/uctypes_bytearray.py | 7 ++++++- tests/extmod/uctypes_le.py | 7 ++++++- tests/extmod/uctypes_le_float.py | 7 ++++++- tests/extmod/uctypes_native_float.py | 7 ++++++- tests/extmod/uctypes_native_le.py | 6 +++++- tests/extmod/uctypes_print.py | 8 ++++++-- tests/extmod/uctypes_ptr_le.py | 6 +++++- tests/extmod/uctypes_ptr_native_le.py | 6 +++++- tests/extmod/uctypes_sizeof.py | 7 ++++++- tests/extmod/uctypes_sizeof_native.py | 7 ++++++- tests/extmod/uheapq1.py | 7 ++++++- tests/extmod/ujson_dumps.py | 7 ++++++- tests/extmod/ujson_dumps_extra.py | 7 ++++++- tests/extmod/ujson_dumps_float.py | 7 ++++++- tests/extmod/ujson_load.py | 9 +++++++-- tests/extmod/ujson_loads.py | 9 +++++++-- tests/extmod/ujson_loads_float.py | 9 +++++++-- tests/extmod/urandom_basic.py | 7 ++++++- tests/extmod/urandom_extra.py | 7 ++++++- tests/extmod/ure1.py | 7 ++++++- tests/extmod/ure_debug.py | 8 +++++++- tests/extmod/ure_error.py | 9 +++++++-- tests/extmod/ure_group.py | 9 +++++++-- tests/extmod/ure_namedclass.py | 9 +++++++-- tests/extmod/ure_split.py | 7 ++++++- tests/extmod/ure_split_empty.py | 7 ++++++- tests/extmod/ure_split_notimpl.py | 7 ++++++- tests/extmod/uzlib_decompio.py | 8 +++++--- tests/extmod/uzlib_decompio_gz.py | 8 +++++--- tests/extmod/uzlib_decompress.py | 7 ++++++- tests/extmod/vfs_fat_oldproto.py | 11 ++++++++--- tests/extmod/vfs_fat_ramdisk.py | 11 ++++++++--- 41 files changed, 254 insertions(+), 62 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/machine1.py b/tests/extmod/machine1.py index 433a18037..e0c561168 100644 --- a/tests/extmod/machine1.py +++ b/tests/extmod/machine1.py @@ -5,7 +5,8 @@ try: import umachine as machine except ImportError: import machine -except ImportError: + machine.mem8 +except: print("SKIP") import sys sys.exit() diff --git a/tests/extmod/ubinascii_a2b_base64.py b/tests/extmod/ubinascii_a2b_base64.py index 97c451950..58eb0b50b 100644 --- a/tests/extmod/ubinascii_a2b_base64.py +++ b/tests/extmod/ubinascii_a2b_base64.py @@ -1,7 +1,12 @@ try: - import ubinascii as binascii + try: + import ubinascii as binascii + except ImportError: + import binascii except ImportError: - import binascii + import sys + print("SKIP") + sys.exit() print(binascii.a2b_base64(b'')) print(binascii.a2b_base64(b'Zg==')) diff --git a/tests/extmod/ubinascii_b2a_base64.py b/tests/extmod/ubinascii_b2a_base64.py index fdcaf32dd..1c0c30311 100644 --- a/tests/extmod/ubinascii_b2a_base64.py +++ b/tests/extmod/ubinascii_b2a_base64.py @@ -1,7 +1,12 @@ try: - import ubinascii as binascii + try: + import ubinascii as binascii + except ImportError: + import binascii except ImportError: - import binascii + import sys + print("SKIP") + sys.exit() print(binascii.b2a_base64(b'')) print(binascii.b2a_base64(b'f')) diff --git a/tests/extmod/ubinascii_crc32.py b/tests/extmod/ubinascii_crc32.py index 2c4017751..b82c44d6b 100644 --- a/tests/extmod/ubinascii_crc32.py +++ b/tests/extmod/ubinascii_crc32.py @@ -1,7 +1,13 @@ try: - import ubinascii as binascii + try: + import ubinascii as binascii + except ImportError: + import binascii except ImportError: - import binascii + import sys + print("SKIP") + sys.exit() + try: binascii.crc32 except AttributeError: diff --git a/tests/extmod/ubinascii_hexlify.py b/tests/extmod/ubinascii_hexlify.py index 14c37cb4b..5d70bda96 100644 --- a/tests/extmod/ubinascii_hexlify.py +++ b/tests/extmod/ubinascii_hexlify.py @@ -1,7 +1,12 @@ try: - import ubinascii as binascii + try: + import ubinascii as binascii + except ImportError: + import binascii except ImportError: - import binascii + import sys + print("SKIP") + sys.exit() print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07')) print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')) diff --git a/tests/extmod/ubinascii_micropython.py b/tests/extmod/ubinascii_micropython.py index d68da3205..96f566bd1 100644 --- a/tests/extmod/ubinascii_micropython.py +++ b/tests/extmod/ubinascii_micropython.py @@ -1,7 +1,12 @@ try: - import ubinascii as binascii + try: + import ubinascii as binascii + except ImportError: + import binascii except ImportError: - import binascii + import sys + print("SKIP") + sys.exit() # two arguments supported in uPy but not CPython a = binascii.hexlify(b'123', ':') diff --git a/tests/extmod/ubinascii_unhexlify.py b/tests/extmod/ubinascii_unhexlify.py index 99c2c0208..e669789ba 100644 --- a/tests/extmod/ubinascii_unhexlify.py +++ b/tests/extmod/ubinascii_unhexlify.py @@ -1,7 +1,12 @@ try: - import ubinascii as binascii + try: + import ubinascii as binascii + except ImportError: + import binascii except ImportError: - import binascii + import sys + print("SKIP") + sys.exit() print(binascii.unhexlify(b'0001020304050607')) print(binascii.unhexlify(b'08090a0b0c0d0e0f')) diff --git a/tests/extmod/uctypes_array_assign_le.py b/tests/extmod/uctypes_array_assign_le.py index 18d63f8bf..bae467d09 100644 --- a/tests/extmod/uctypes_array_assign_le.py +++ b/tests/extmod/uctypes_array_assign_le.py @@ -1,4 +1,9 @@ -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py index 632c4d252..474b7e0f2 100644 --- a/tests/extmod/uctypes_array_assign_native_le.py +++ b/tests/extmod/uctypes_array_assign_native_le.py @@ -1,5 +1,9 @@ import sys -import uctypes +try: + import uctypes +except ImportError: + print("SKIP") + sys.exit() if sys.byteorder != "little": print("SKIP") diff --git a/tests/extmod/uctypes_bytearray.py b/tests/extmod/uctypes_bytearray.py index 7294b7ea4..bf7845ab2 100644 --- a/tests/extmod/uctypes_bytearray.py +++ b/tests/extmod/uctypes_bytearray.py @@ -1,4 +1,9 @@ -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() desc = { "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), diff --git a/tests/extmod/uctypes_le.py b/tests/extmod/uctypes_le.py index 5ae410b01..829beda58 100644 --- a/tests/extmod/uctypes_le.py +++ b/tests/extmod/uctypes_le.py @@ -1,4 +1,9 @@ -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() desc = { "s0": uctypes.UINT16 | 0, diff --git a/tests/extmod/uctypes_le_float.py b/tests/extmod/uctypes_le_float.py index c85b75f36..a61305ba8 100644 --- a/tests/extmod/uctypes_le_float.py +++ b/tests/extmod/uctypes_le_float.py @@ -1,4 +1,9 @@ -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() desc = { "f32": uctypes.FLOAT32 | 0, diff --git a/tests/extmod/uctypes_native_float.py b/tests/extmod/uctypes_native_float.py index 89aac8bf3..80cb54383 100644 --- a/tests/extmod/uctypes_native_float.py +++ b/tests/extmod/uctypes_native_float.py @@ -1,4 +1,9 @@ -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() desc = { "f32": uctypes.FLOAT32 | 0, diff --git a/tests/extmod/uctypes_native_le.py b/tests/extmod/uctypes_native_le.py index ef0f9f5e9..5900224d4 100644 --- a/tests/extmod/uctypes_native_le.py +++ b/tests/extmod/uctypes_native_le.py @@ -2,7 +2,11 @@ # Codepaths for packed vs native structures are different. This test only works # on little-endian machine (no matter if 32 or 64 bit). import sys -import uctypes +try: + import uctypes +except ImportError: + print("SKIP") + sys.exit() if sys.byteorder != "little": print("SKIP") diff --git a/tests/extmod/uctypes_print.py b/tests/extmod/uctypes_print.py index 71981ce7e..76a009dc7 100644 --- a/tests/extmod/uctypes_print.py +++ b/tests/extmod/uctypes_print.py @@ -1,6 +1,10 @@ # test printing of uctypes objects - -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() # we use an address of "0" because we just want to print something deterministic # and don't actually need to set/get any values in the struct diff --git a/tests/extmod/uctypes_ptr_le.py b/tests/extmod/uctypes_ptr_le.py index d0216dfb8..e8a6243ce 100644 --- a/tests/extmod/uctypes_ptr_le.py +++ b/tests/extmod/uctypes_ptr_le.py @@ -1,5 +1,9 @@ import sys -import uctypes +try: + import uctypes +except ImportError: + print("SKIP") + sys.exit() if sys.byteorder != "little": print("SKIP") diff --git a/tests/extmod/uctypes_ptr_native_le.py b/tests/extmod/uctypes_ptr_native_le.py index 6f011c3c2..9b016c04d 100644 --- a/tests/extmod/uctypes_ptr_native_le.py +++ b/tests/extmod/uctypes_ptr_native_le.py @@ -1,5 +1,9 @@ import sys -import uctypes +try: + import uctypes +except ImportError: + print("SKIP") + sys.exit() if sys.byteorder != "little": print("SKIP") diff --git a/tests/extmod/uctypes_sizeof.py b/tests/extmod/uctypes_sizeof.py index fcfd8ecd7..266cd0694 100644 --- a/tests/extmod/uctypes_sizeof.py +++ b/tests/extmod/uctypes_sizeof.py @@ -1,4 +1,9 @@ -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_sizeof_native.py b/tests/extmod/uctypes_sizeof_native.py index f830a1f85..f676c8c6d 100644 --- a/tests/extmod/uctypes_sizeof_native.py +++ b/tests/extmod/uctypes_sizeof_native.py @@ -1,4 +1,9 @@ -import uctypes +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() S1 = {} assert uctypes.sizeof(S1) == 0 diff --git a/tests/extmod/uheapq1.py b/tests/extmod/uheapq1.py index e71f817ef..4b0e5de57 100644 --- a/tests/extmod/uheapq1.py +++ b/tests/extmod/uheapq1.py @@ -1,7 +1,12 @@ try: import uheapq as heapq except: - import heapq + try: + import heapq + except ImportError: + import sys + print("SKIP") + sys.exit() try: heapq.heappop([]) diff --git a/tests/extmod/ujson_dumps.py b/tests/extmod/ujson_dumps.py index c0ee60d73..4a02f5170 100644 --- a/tests/extmod/ujson_dumps.py +++ b/tests/extmod/ujson_dumps.py @@ -1,7 +1,12 @@ try: import ujson as json except ImportError: - import json + try: + import json + except ImportError: + import sys + print("SKIP") + sys.exit() print(json.dumps(False)) print(json.dumps(True)) diff --git a/tests/extmod/ujson_dumps_extra.py b/tests/extmod/ujson_dumps_extra.py index 0e593c3e9..a52e8224c 100644 --- a/tests/extmod/ujson_dumps_extra.py +++ b/tests/extmod/ujson_dumps_extra.py @@ -1,5 +1,10 @@ # test uPy ujson behaviour that's not valid in CPy -import ujson +try: + import ujson +except ImportError: + import sys + print("SKIP") + sys.exit() print(ujson.dumps(b'1234')) diff --git a/tests/extmod/ujson_dumps_float.py b/tests/extmod/ujson_dumps_float.py index f6ba5f113..d949ea6dd 100644 --- a/tests/extmod/ujson_dumps_float.py +++ b/tests/extmod/ujson_dumps_float.py @@ -1,6 +1,11 @@ try: import ujson as json except ImportError: - import json + try: + import json + except ImportError: + import sys + print("SKIP") + sys.exit() print(json.dumps(1.2)) diff --git a/tests/extmod/ujson_load.py b/tests/extmod/ujson_load.py index bf484a207..901132a5f 100644 --- a/tests/extmod/ujson_load.py +++ b/tests/extmod/ujson_load.py @@ -2,8 +2,13 @@ try: from uio import StringIO import ujson as json except: - from io import StringIO - import json + try: + from io import StringIO + import json + except ImportError: + import sys + print("SKIP") + sys.exit() print(json.load(StringIO('null'))) print(json.load(StringIO('"abc\\u0064e"'))) diff --git a/tests/extmod/ujson_loads.py b/tests/extmod/ujson_loads.py index 37576e6ae..b2e18e3af 100644 --- a/tests/extmod/ujson_loads.py +++ b/tests/extmod/ujson_loads.py @@ -1,7 +1,12 @@ try: import ujson as json -except: - import json +except ImportError: + try: + import json + except ImportError: + import sys + print("SKIP") + sys.exit() def my_print(o): if isinstance(o, dict): diff --git a/tests/extmod/ujson_loads_float.py b/tests/extmod/ujson_loads_float.py index f5e754608..b20a412ff 100644 --- a/tests/extmod/ujson_loads_float.py +++ b/tests/extmod/ujson_loads_float.py @@ -1,7 +1,12 @@ try: import ujson as json -except: - import json +except ImportError: + try: + import json + except ImportError: + import sys + print("SKIP") + sys.exit() def my_print(o): print('%.3f' % o) diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/urandom_basic.py index bf00035bd..885b8517f 100644 --- a/tests/extmod/urandom_basic.py +++ b/tests/extmod/urandom_basic.py @@ -1,7 +1,12 @@ try: import urandom as random except ImportError: - import random + try: + import random + except ImportError: + import sys + print("SKIP") + sys.exit() # check getrandbits returns a value within the bit range for b in (1, 2, 3, 4, 16, 32): diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py index 004fb10cc..925dd0dbc 100644 --- a/tests/extmod/urandom_extra.py +++ b/tests/extmod/urandom_extra.py @@ -1,7 +1,12 @@ try: import urandom as random except ImportError: - import random + try: + import random + except ImportError: + import sys + print("SKIP") + sys.exit() try: random.randint diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py index 48537c2ea..b5edeeace 100644 --- a/tests/extmod/ure1.py +++ b/tests/extmod/ure1.py @@ -1,7 +1,12 @@ try: import ure as re except ImportError: - import re + try: + import re + except ImportError: + import sys + print("SKIP") + sys.exit() r = re.compile(".+") m = r.match("abc") diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py index 303e1789c..252df21e3 100644 --- a/tests/extmod/ure_debug.py +++ b/tests/extmod/ure_debug.py @@ -1,3 +1,9 @@ # test printing debugging info when compiling -import ure +try: + import ure +except ImportError: + import sys + print("SKIP") + sys.exit() + ure.compile('^a|b[0-9]\w$', ure.DEBUG) diff --git a/tests/extmod/ure_error.py b/tests/extmod/ure_error.py index 1e9f66a9e..3f16f9158 100644 --- a/tests/extmod/ure_error.py +++ b/tests/extmod/ure_error.py @@ -2,8 +2,13 @@ try: import ure as re -except: - import re +except ImportError: + try: + import re + except ImportError: + import sys + print("SKIP") + sys.exit() def test_re(r): try: diff --git a/tests/extmod/ure_group.py b/tests/extmod/ure_group.py index 8078a0a85..98aae2a73 100644 --- a/tests/extmod/ure_group.py +++ b/tests/extmod/ure_group.py @@ -2,8 +2,13 @@ try: import ure as re -except: - import re +except ImportError: + try: + import re + except ImportError: + import sys + print("SKIP") + sys.exit() def print_groups(match): print('----') diff --git a/tests/extmod/ure_namedclass.py b/tests/extmod/ure_namedclass.py index 25f425ce7..e233f17c8 100644 --- a/tests/extmod/ure_namedclass.py +++ b/tests/extmod/ure_namedclass.py @@ -2,8 +2,13 @@ try: import ure as re -except: - import re +except ImportError: + try: + import re + except ImportError: + import sys + print("SKIP") + sys.exit() def print_groups(match): print('----') diff --git a/tests/extmod/ure_split.py b/tests/extmod/ure_split.py index 620fd9052..1e411c27c 100644 --- a/tests/extmod/ure_split.py +++ b/tests/extmod/ure_split.py @@ -1,7 +1,12 @@ try: import ure as re except ImportError: - import re + try: + import re + except ImportError: + import sys + print("SKIP") + sys.exit() r = re.compile(" ") s = r.split("a b c foobar") diff --git a/tests/extmod/ure_split_empty.py b/tests/extmod/ure_split_empty.py index 6f31e6dc6..ad6334eba 100644 --- a/tests/extmod/ure_split_empty.py +++ b/tests/extmod/ure_split_empty.py @@ -4,7 +4,12 @@ # behaviour will change in a future version. MicroPython just stops # splitting as soon as an empty match is found. -import ure as re +try: + import ure as re +except ImportError: + import sys + print("SKIP") + sys.exit() r = re.compile(" *") s = r.split("a b c foobar") diff --git a/tests/extmod/ure_split_notimpl.py b/tests/extmod/ure_split_notimpl.py index 724e9d43b..eca3ea512 100644 --- a/tests/extmod/ure_split_notimpl.py +++ b/tests/extmod/ure_split_notimpl.py @@ -1,4 +1,9 @@ -import ure as re +try: + import ure as re +except ImportError: + import sys + print("SKIP") + sys.exit() r = re.compile('( )') try: diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py index 75a6df0ca..6f07c048c 100644 --- a/tests/extmod/uzlib_decompio.py +++ b/tests/extmod/uzlib_decompio.py @@ -1,8 +1,10 @@ try: - import zlib -except ImportError: import uzlib as zlib -import uio as io + import uio as io +except ImportError: + import sys + print("SKIP") + sys.exit() # Raw DEFLATE bitstream diff --git a/tests/extmod/uzlib_decompio_gz.py b/tests/extmod/uzlib_decompio_gz.py index c7aac04e8..5ab25354c 100644 --- a/tests/extmod/uzlib_decompio_gz.py +++ b/tests/extmod/uzlib_decompio_gz.py @@ -1,8 +1,10 @@ try: - import zlib -except ImportError: import uzlib as zlib -import uio as io + import uio as io +except ImportError: + import sys + print("SKIP") + sys.exit() # gzip bitstream diff --git a/tests/extmod/uzlib_decompress.py b/tests/extmod/uzlib_decompress.py index 6892808cb..10121ee7e 100644 --- a/tests/extmod/uzlib_decompress.py +++ b/tests/extmod/uzlib_decompress.py @@ -1,7 +1,12 @@ try: import zlib except ImportError: - import uzlib as zlib + try: + import uzlib as zlib + except ImportError: + import sys + print("SKIP") + sys.exit() PATTERNS = [ # Packed results produced by CPy's zlib.compress() diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index 03ab76e35..77d349212 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,9 +1,14 @@ import sys -import uerrno try: - import uos_vfs as uos + import uerrno + try: + import uos_vfs as uos + except ImportError: + import uos except ImportError: - import uos + print("SKIP") + sys.exit() + try: uos.VfsFat except AttributeError: diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index dc4a1c305..81f9418b2 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,9 +1,14 @@ import sys -import uerrno try: - import uos_vfs as uos + import uerrno + try: + import uos_vfs as uos + except ImportError: + import uos except ImportError: - import uos + print("SKIP") + sys.exit() + try: uos.VfsFat except AttributeError: -- cgit v1.2.3 From ecc635d551aa8fa5e02d2cb810b929ec92c54c3f Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 2 Mar 2017 16:09:16 +1100 Subject: tests/extmod: Add test for machine.Signal class. --- tests/extmod/machine_signal.py | 40 ++++++++++++++++++++++++++++++++++++++ tests/extmod/machine_signal.py.exp | 4 ++++ 2 files changed, 44 insertions(+) create mode 100644 tests/extmod/machine_signal.py create mode 100644 tests/extmod/machine_signal.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/machine_signal.py b/tests/extmod/machine_signal.py new file mode 100644 index 000000000..401533f23 --- /dev/null +++ b/tests/extmod/machine_signal.py @@ -0,0 +1,40 @@ +# test machine.Signal class + +try: + import umachine as machine +except ImportError: + import machine +try: + machine.PinBase + machine.Signal +except AttributeError: + print("SKIP") + import sys + sys.exit() + +class Pin(machine.PinBase): + def __init__(self): + self.v = 0 + + def value(self, v=None): + if v is None: + return self.v + else: + self.v = int(v) + + +# test non-inverted +p = Pin() +s = machine.Signal(p) +s.value(0) +print(p.value(), s.value()) +s.value(1) +print(p.value(), s.value()) + +# test inverted, and using on/off methods +p = Pin() +s = machine.Signal(p, inverted=True) +s.off() +print(p.value(), s.value()) +s.on() +print(p.value(), s.value()) diff --git a/tests/extmod/machine_signal.py.exp b/tests/extmod/machine_signal.py.exp new file mode 100644 index 000000000..7e9dd6796 --- /dev/null +++ b/tests/extmod/machine_signal.py.exp @@ -0,0 +1,4 @@ +0 0 +1 1 +1 0 +0 1 -- cgit v1.2.3 From bdd48e67ee54163f195628ba6de476ca7984d327 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 7 Mar 2017 08:39:47 +0100 Subject: tests/uctypes_array_assign_native_le: Split off intbig part. --- tests/extmod/uctypes_array_assign_native_le.py | 10 ----- tests/extmod/uctypes_array_assign_native_le.py.exp | 2 - .../uctypes_array_assign_native_le_intbig.py | 43 ++++++++++++++++++++++ .../uctypes_array_assign_native_le_intbig.py.exp | 2 + 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 tests/extmod/uctypes_array_assign_native_le_intbig.py create mode 100644 tests/extmod/uctypes_array_assign_native_le_intbig.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py index 474b7e0f2..f0ecc0dad 100644 --- a/tests/extmod/uctypes_array_assign_native_le.py +++ b/tests/extmod/uctypes_array_assign_native_le.py @@ -70,16 +70,6 @@ S.arr10[0] = 0x11223344 print(hex(S.arr10[0])) assert hex(S.arr10[0]) == "0x11223344" -# assign int64 -S.arr11[0] = 0x11223344 -print(hex(S.arr11[0])) -assert hex(S.arr11[0]) == "0x11223344" - -# assign uint64 -S.arr12[0] = 0x11223344 -print(hex(S.arr12[0])) -assert hex(S.arr12[0]) == "0x11223344" - # index out of range try: print(S.arr8[2]) diff --git a/tests/extmod/uctypes_array_assign_native_le.py.exp b/tests/extmod/uctypes_array_assign_native_le.py.exp index 4efcdec66..9d67b1c77 100644 --- a/tests/extmod/uctypes_array_assign_native_le.py.exp +++ b/tests/extmod/uctypes_array_assign_native_le.py.exp @@ -6,8 +6,6 @@ True 0x11 0x1122 0x11223344 -0x11223344 -0x11223344 IndexError TypeError TypeError diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py b/tests/extmod/uctypes_array_assign_native_le_intbig.py new file mode 100644 index 000000000..f29a3b66e --- /dev/null +++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py @@ -0,0 +1,43 @@ +import sys +try: + import uctypes +except ImportError: + print("SKIP") + sys.exit() + +if sys.byteorder != "little": + print("SKIP") + sys.exit() + +desc = { + # arr is array at offset 0, of UINT8 elements, array size is 2 + "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), + # arr2 is array at offset 0, size 2, of structures defined recursively + "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}), + "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2), + + # aligned + "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1), + "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}), + + "arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1), + "arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1), + "arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1), + "arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1), + "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1), + "arr13": (uctypes.ARRAY | 1, 1, {"l": {}}), +} + +data = bytearray(8) + +S = uctypes.struct(uctypes.addressof(data), desc) + +# assign int64 +S.arr11[0] = 0x11223344 +print(hex(S.arr11[0])) +assert hex(S.arr11[0]) == "0x11223344" + +# assign uint64 +S.arr12[0] = 0x11223344 +print(hex(S.arr12[0])) +assert hex(S.arr12[0]) == "0x11223344" diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py.exp b/tests/extmod/uctypes_array_assign_native_le_intbig.py.exp new file mode 100644 index 000000000..0394e9ae1 --- /dev/null +++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py.exp @@ -0,0 +1,2 @@ +0x11223344 +0x11223344 -- cgit v1.2.3 From 38f063ea72632e395ea59b644552bb98c962393f Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 9 Mar 2017 13:42:34 +1100 Subject: tests/extmod: Add very basic feature test for ussl module. This test just tests that the basic functions/methods can be called with the appropriate arguments. There is no real test of underlying functionality. Thanks to @hosaka for the initial implementation of this test. --- tests/extmod/ussl_basic.py | 52 ++++++++++++++++++++++++++++++++++++++++++ tests/extmod/ussl_basic.py.exp | 8 +++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/extmod/ussl_basic.py create mode 100644 tests/extmod/ussl_basic.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/ussl_basic.py b/tests/extmod/ussl_basic.py new file mode 100644 index 000000000..e9d435bca --- /dev/null +++ b/tests/extmod/ussl_basic.py @@ -0,0 +1,52 @@ +# very basic test of ssl module, just to test the methods exist + +try: + import uio as io + import ussl as ssl +except ImportError: + print("SKIP") + import sys + sys.exit() + +# create in client mode +try: + ss = ssl.wrap_socket(io.BytesIO()) +except OSError as er: + print('wrap_socket:', repr(er)) + +# create in server mode (can use this object for further tests) +socket = io.BytesIO() +ss = ssl.wrap_socket(socket, server_side=1) + +# print +print(repr(ss)[:12]) + +# setblocking +try: + ss.setblocking(False) +except NotImplementedError: + print('setblocking: NotImplementedError') +ss.setblocking(True) + +# write +print(ss.write(b'aaaa')) + +# read (underlying socket has no data) +print(ss.read(8)) + +# read (underlying socket has data, but it's bad data) +socket.write(b'aaaaaaaaaaaaaaaa') +socket.seek(0) +try: + ss.read(8) +except OSError as er: + print('read:', repr(er)) + +# close +ss.close() + +# write on closed socket +try: + ss.write(b'aaaa') +except OSError as er: + print('write:', repr(er)) diff --git a/tests/extmod/ussl_basic.py.exp b/tests/extmod/ussl_basic.py.exp new file mode 100644 index 000000000..b4dd03860 --- /dev/null +++ b/tests/extmod/ussl_basic.py.exp @@ -0,0 +1,8 @@ +ssl_handshake_status: -256 +wrap_socket: OSError(5,) +<_SSLSocket +setblocking: NotImplementedError +4 +b'' +read: OSError(-261,) +write: OSError(-256,) -- cgit v1.2.3 From ce0b5e078b376dadcc33226647c91c73d6c73600 Mon Sep 17 00:00:00 2001 From: Alex March Date: Tue, 1 Nov 2016 16:43:18 +0000 Subject: tests/extmod: Add websocket tests. These short unit tests test the base uPy methods as well as parts of the websocket protocol, as implemented by uPy. @dpgeorge converted the original socket based tests by @hosaka to ones that only require io.BytesIO. --- tests/extmod/websocket.py | 61 +++++++++++++++++++++++++++++++++++++++++++ tests/extmod/websocket.py.exp | 14 ++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/extmod/websocket.py create mode 100644 tests/extmod/websocket.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/websocket.py b/tests/extmod/websocket.py new file mode 100644 index 000000000..770836c8e --- /dev/null +++ b/tests/extmod/websocket.py @@ -0,0 +1,61 @@ +try: + import uio + import uerrno + import websocket +except ImportError: + import sys + print("SKIP") + sys.exit() + +# put raw data in the stream and do a websocket read +def ws_read(msg, sz): + ws = websocket.websocket(uio.BytesIO(msg)) + return ws.read(sz) + +# do a websocket write and then return the raw data from the stream +def ws_write(msg, sz): + s = uio.BytesIO() + ws = websocket.websocket(s) + ws.write(msg) + s.seek(0) + return s.read(sz) + +# basic frame +print(ws_read(b"\x81\x04ping", 4)) +print(ws_read(b"\x80\x04ping", 4)) # FRAME_CONT +print(ws_write(b"pong", 6)) + +# split frames are not supported +# print(ws_read(b"\x01\x04ping", 4)) + +# extended payloads +print(ws_read(b'\x81~\x00\x80' + b'ping' * 32, 128)) +print(ws_write(b"pong" * 32, 132)) + +# mask (returned data will be 'mask' ^ 'mask') +print(ws_read(b"\x81\x84maskmask", 4)) + +# close control frame +s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE +ws = websocket.websocket(s) +print(ws.read(1)) +s.seek(2) +print(s.read(4)) + +# misc control frames +print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING +print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG + +# close method +ws = websocket.websocket(uio.BytesIO()) +ws.close() + +# ioctl +ws = websocket.websocket(uio.BytesIO()) +print(ws.ioctl(8)) # GET_DATA_OPTS +print(ws.ioctl(9, 2)) # SET_DATA_OPTS +print(ws.ioctl(9)) +try: + ws.ioctl(-1) +except OSError as e: + print("ioctl: EINVAL:", e.args[0] == uerrno.EINVAL) diff --git a/tests/extmod/websocket.py.exp b/tests/extmod/websocket.py.exp new file mode 100644 index 000000000..2d7657b53 --- /dev/null +++ b/tests/extmod/websocket.py.exp @@ -0,0 +1,14 @@ +b'ping' +b'ping' +b'\x81\x04pong' +b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping' +b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong' +b'\x00\x00\x00\x00' +b'' +b'\x81\x02\x88\x00' +b'ping' +b'pong' +0 +1 +2 +ioctl: EINVAL: True -- cgit v1.2.3 From f07a56fa3b10b767960029c82bb2ab7af29e7a04 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2017 15:05:08 +1100 Subject: tests/extmod: Rename websocket test to websocket_basic. This is so that the filename of the test doesn't clash with the module name itself (being "websocket"), and lead to potential problems executing the test. --- tests/extmod/websocket.py | 61 ------------------------------------- tests/extmod/websocket.py.exp | 14 --------- tests/extmod/websocket_basic.py | 61 +++++++++++++++++++++++++++++++++++++ tests/extmod/websocket_basic.py.exp | 14 +++++++++ 4 files changed, 75 insertions(+), 75 deletions(-) delete mode 100644 tests/extmod/websocket.py delete mode 100644 tests/extmod/websocket.py.exp create mode 100644 tests/extmod/websocket_basic.py create mode 100644 tests/extmod/websocket_basic.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/websocket.py b/tests/extmod/websocket.py deleted file mode 100644 index 770836c8e..000000000 --- a/tests/extmod/websocket.py +++ /dev/null @@ -1,61 +0,0 @@ -try: - import uio - import uerrno - import websocket -except ImportError: - import sys - print("SKIP") - sys.exit() - -# put raw data in the stream and do a websocket read -def ws_read(msg, sz): - ws = websocket.websocket(uio.BytesIO(msg)) - return ws.read(sz) - -# do a websocket write and then return the raw data from the stream -def ws_write(msg, sz): - s = uio.BytesIO() - ws = websocket.websocket(s) - ws.write(msg) - s.seek(0) - return s.read(sz) - -# basic frame -print(ws_read(b"\x81\x04ping", 4)) -print(ws_read(b"\x80\x04ping", 4)) # FRAME_CONT -print(ws_write(b"pong", 6)) - -# split frames are not supported -# print(ws_read(b"\x01\x04ping", 4)) - -# extended payloads -print(ws_read(b'\x81~\x00\x80' + b'ping' * 32, 128)) -print(ws_write(b"pong" * 32, 132)) - -# mask (returned data will be 'mask' ^ 'mask') -print(ws_read(b"\x81\x84maskmask", 4)) - -# close control frame -s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE -ws = websocket.websocket(s) -print(ws.read(1)) -s.seek(2) -print(s.read(4)) - -# misc control frames -print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING -print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG - -# close method -ws = websocket.websocket(uio.BytesIO()) -ws.close() - -# ioctl -ws = websocket.websocket(uio.BytesIO()) -print(ws.ioctl(8)) # GET_DATA_OPTS -print(ws.ioctl(9, 2)) # SET_DATA_OPTS -print(ws.ioctl(9)) -try: - ws.ioctl(-1) -except OSError as e: - print("ioctl: EINVAL:", e.args[0] == uerrno.EINVAL) diff --git a/tests/extmod/websocket.py.exp b/tests/extmod/websocket.py.exp deleted file mode 100644 index 2d7657b53..000000000 --- a/tests/extmod/websocket.py.exp +++ /dev/null @@ -1,14 +0,0 @@ -b'ping' -b'ping' -b'\x81\x04pong' -b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping' -b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong' -b'\x00\x00\x00\x00' -b'' -b'\x81\x02\x88\x00' -b'ping' -b'pong' -0 -1 -2 -ioctl: EINVAL: True diff --git a/tests/extmod/websocket_basic.py b/tests/extmod/websocket_basic.py new file mode 100644 index 000000000..770836c8e --- /dev/null +++ b/tests/extmod/websocket_basic.py @@ -0,0 +1,61 @@ +try: + import uio + import uerrno + import websocket +except ImportError: + import sys + print("SKIP") + sys.exit() + +# put raw data in the stream and do a websocket read +def ws_read(msg, sz): + ws = websocket.websocket(uio.BytesIO(msg)) + return ws.read(sz) + +# do a websocket write and then return the raw data from the stream +def ws_write(msg, sz): + s = uio.BytesIO() + ws = websocket.websocket(s) + ws.write(msg) + s.seek(0) + return s.read(sz) + +# basic frame +print(ws_read(b"\x81\x04ping", 4)) +print(ws_read(b"\x80\x04ping", 4)) # FRAME_CONT +print(ws_write(b"pong", 6)) + +# split frames are not supported +# print(ws_read(b"\x01\x04ping", 4)) + +# extended payloads +print(ws_read(b'\x81~\x00\x80' + b'ping' * 32, 128)) +print(ws_write(b"pong" * 32, 132)) + +# mask (returned data will be 'mask' ^ 'mask') +print(ws_read(b"\x81\x84maskmask", 4)) + +# close control frame +s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE +ws = websocket.websocket(s) +print(ws.read(1)) +s.seek(2) +print(s.read(4)) + +# misc control frames +print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING +print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG + +# close method +ws = websocket.websocket(uio.BytesIO()) +ws.close() + +# ioctl +ws = websocket.websocket(uio.BytesIO()) +print(ws.ioctl(8)) # GET_DATA_OPTS +print(ws.ioctl(9, 2)) # SET_DATA_OPTS +print(ws.ioctl(9)) +try: + ws.ioctl(-1) +except OSError as e: + print("ioctl: EINVAL:", e.args[0] == uerrno.EINVAL) diff --git a/tests/extmod/websocket_basic.py.exp b/tests/extmod/websocket_basic.py.exp new file mode 100644 index 000000000..2d7657b53 --- /dev/null +++ b/tests/extmod/websocket_basic.py.exp @@ -0,0 +1,14 @@ +b'ping' +b'ping' +b'\x81\x04pong' +b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingping' +b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong' +b'\x00\x00\x00\x00' +b'' +b'\x81\x02\x88\x00' +b'ping' +b'pong' +0 +1 +2 +ioctl: EINVAL: True -- cgit v1.2.3 From 8891b2e7006334e5333a9a35602ae01f0700b12f Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 13 Mar 2017 21:42:02 +1100 Subject: tests/extmod: Add a test for core VFS functionality, sans any filesystem. --- tests/extmod/vfs_basic.py | 55 +++++++++++++++++++++++++++++++++++++++++++ tests/extmod/vfs_basic.py.exp | 17 +++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/extmod/vfs_basic.py create mode 100644 tests/extmod/vfs_basic.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py new file mode 100644 index 000000000..b481841e6 --- /dev/null +++ b/tests/extmod/vfs_basic.py @@ -0,0 +1,55 @@ +# test VFS functionality without any particular filesystem type + +try: + try: + import uos_vfs as uos + open = uos.vfs_open + except ImportError: + import uos + uos.mount +except (ImportError, AttributeError): + print("SKIP") + import sys + sys.exit() + + +class Filesystem: + def __init__(self, id): + self.id = id + def mount(self, readonly, mkfs): + print(self.id, 'mount', readonly, mkfs) + def umount(self): + print(self.id, 'umount') + def listdir(self, dir): + print(self.id, 'listdir', dir) + return ['a%d' % self.id] + def chdir(self, dir): + print(self.id, 'chdir', dir) + def open(self, file, mode): + print(self.id, 'open', file, mode) + + +# basic mounting and listdir +uos.mount(Filesystem(1), '/test_mnt') +print(uos.listdir()) + +# referencing the mount point in different ways +print(uos.listdir('test_mnt')) +print(uos.listdir('/test_mnt')) + +# mounting another filesystem +uos.mount(Filesystem(2), '/test_mnt2', readonly=True) +print(uos.listdir()) +print(uos.listdir('/test_mnt2')) + +# chdir +uos.chdir('test_mnt') +print(uos.listdir()) + +# open +open('test_file') +open('test_file', 'wb') + +# umount +uos.umount('/test_mnt') +uos.umount('/test_mnt2') diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp new file mode 100644 index 000000000..c9ed65191 --- /dev/null +++ b/tests/extmod/vfs_basic.py.exp @@ -0,0 +1,17 @@ +1 mount False False +['test_mnt'] +1 listdir / +['a1'] +1 listdir / +['a1'] +2 mount True False +['test_mnt', 'test_mnt2'] +2 listdir / +['a2'] +1 chdir / +1 listdir +['a1'] +1 open test_file r +1 open test_file wb +1 umount +2 umount -- cgit v1.2.3 From 773b0bac416907d21f0aa0a0322f355e5588c8ad Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 14 Mar 2017 16:07:30 +1100 Subject: tests/extmod/vfs_basic: Add more tests for basic VFS functionality. --- tests/extmod/vfs_basic.py | 58 ++++++++++++++++++++++++++++++++++++++++--- tests/extmod/vfs_basic.py.exp | 17 +++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index b481841e6..c8f4eaee9 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -25,10 +25,33 @@ class Filesystem: return ['a%d' % self.id] def chdir(self, dir): print(self.id, 'chdir', dir) + def getcwd(self): + print(self.id, 'getcwd') + return 'dir%d' % self.id + def mkdir(self, path): + print(self.id, 'mkdir', path) + def remove(self, path): + print(self.id, 'remove', path) + def rename(self, old_path, new_path): + print(self.id, 'rename', old_path, new_path) + def rmdir(self, path): + print(self.id, 'rmdir', path) + def stat(self, path): + print(self.id, 'stat', path) + return (self.id,) + def statvfs(self, path): + print(self.id, 'statvfs', path) + return (self.id,) def open(self, file, mode): print(self.id, 'open', file, mode) +# stat root dir +print(uos.stat('/')) + +# getcwd when in root dir +print(uos.getcwd()) + # basic mounting and listdir uos.mount(Filesystem(1), '/test_mnt') print(uos.listdir()) @@ -42,14 +65,43 @@ uos.mount(Filesystem(2), '/test_mnt2', readonly=True) print(uos.listdir()) print(uos.listdir('/test_mnt2')) -# chdir +# mounting over an existing mount point +try: + uos.mount(Filesystem(3), '/test_mnt2') +except OSError: + print('OSError') + +# mkdir of a mount point +try: + uos.mkdir('/test_mnt') +except OSError: + print('OSError') + +# rename across a filesystem +try: + uos.rename('/test_mnt/a', '/test_mnt2/b') +except OSError: + print('OSError') + +# delegating to mounted filesystem uos.chdir('test_mnt') print(uos.listdir()) - -# open +print(uos.getcwd()) +uos.mkdir('test_dir') +uos.remove('test_file') +uos.rename('test_file', 'test_file2') +uos.rmdir('test_dir') +print(uos.stat('test_file')) +print(uos.statvfs('/test_mnt')) open('test_file') open('test_file', 'wb') # umount uos.umount('/test_mnt') uos.umount('/test_mnt2') + +# umount a non-existent mount point +try: + uos.umount('/test_mnt') +except OSError: + print('OSError') diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp index c9ed65191..5104a16a6 100644 --- a/tests/extmod/vfs_basic.py.exp +++ b/tests/extmod/vfs_basic.py.exp @@ -1,3 +1,5 @@ +(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) +/ 1 mount False False ['test_mnt'] 1 listdir / @@ -8,10 +10,25 @@ ['test_mnt', 'test_mnt2'] 2 listdir / ['a2'] +3 mount False False +OSError +OSError +OSError 1 chdir / 1 listdir ['a1'] +1 getcwd +/test_mntdir1 +1 mkdir test_dir +1 remove test_file +1 rename test_file test_file2 +1 rmdir test_dir +1 stat test_file +(1,) +1 statvfs / +(1,) 1 open test_file r 1 open test_file wb 1 umount 2 umount +OSError -- cgit v1.2.3 From 4e86ca398f64ceb0351414fd91408fc8f9494907 Mon Sep 17 00:00:00 2001 From: Rami Ali Date: Tue, 14 Mar 2017 16:11:25 +1100 Subject: tests/extmod: Improve re1.5/recursiveloop.c test coverage. --- tests/extmod/ure1.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/extmod') diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py index b5edeeace..a867f1751 100644 --- a/tests/extmod/ure1.py +++ b/tests/extmod/ure1.py @@ -72,6 +72,11 @@ m = re.match('^ab$', 'ab'); print(m.group(0)) m = re.match('a|b', 'b'); print(m.group(0)) m = re.match('a|b|c', 'c'); print(m.group(0)) +# Case where anchors fail to match +r = re.compile("^b|b$") +m = r.search("abc") +print(m) + try: re.compile("*") except: -- cgit v1.2.3 From a49a96bb5d683bb2a721da70c4c3f049cf6ba2f3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 14 Mar 2017 22:08:37 +1100 Subject: tests/extmod/vfs_basic: Unmount all existing devices before doing test. This is so the test can run successfully on targets that already have something mounted. --- tests/extmod/vfs_basic.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index c8f4eaee9..83c83fd22 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -46,6 +46,10 @@ class Filesystem: print(self.id, 'open', file, mode) +# first we umount any existing mount points the target may have +for path in uos.listdir('/'): + uos.umount('/' + path) + # stat root dir print(uos.stat('/')) -- cgit v1.2.3 From 8a57cacd78d3449694f2abbffd6e0ec4444aa8b1 Mon Sep 17 00:00:00 2001 From: Rami Ali Date: Tue, 14 Mar 2017 19:00:56 +1100 Subject: tests/extmod: Improve tinfgzip.c test coverage. --- tests/extmod/uzlib_decompio_gz.py | 10 ++++++++++ tests/extmod/uzlib_decompio_gz.py.exp | 2 ++ 2 files changed, 12 insertions(+) (limited to 'tests/extmod') diff --git a/tests/extmod/uzlib_decompio_gz.py b/tests/extmod/uzlib_decompio_gz.py index 5ab25354c..7572e9693 100644 --- a/tests/extmod/uzlib_decompio_gz.py +++ b/tests/extmod/uzlib_decompio_gz.py @@ -20,6 +20,16 @@ print(inp.read(1)) print(inp.read()) print(buf.seek(0, 1)) +# Check FHCRC field +buf = io.BytesIO(b'\x1f\x8b\x08\x02\x99\x0c\xe5W\x00\x03\x00\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00') +inp = zlib.DecompIO(buf, 16 + 8) +print(inp.read()) + +# Check FEXTRA field +buf = io.BytesIO(b'\x1f\x8b\x08\x04\x99\x0c\xe5W\x00\x03\x01\x00X\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00') +inp = zlib.DecompIO(buf, 16 + 8) +print(inp.read()) + # broken header buf = io.BytesIO(b'\x1f\x8c\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00') try: diff --git a/tests/extmod/uzlib_decompio_gz.py.exp b/tests/extmod/uzlib_decompio_gz.py.exp index 2330580f8..20a30c82a 100644 --- a/tests/extmod/uzlib_decompio_gz.py.exp +++ b/tests/extmod/uzlib_decompio_gz.py.exp @@ -7,5 +7,7 @@ b'lo' b'' b'' 31 +b'hello' +b'hello' ValueError OSError(22,) -- cgit v1.2.3 From 231cfc84a7cae31f93208c334fc33b08278040eb Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Mon, 6 Feb 2017 10:59:44 +0000 Subject: extmod/modframebuf: Add support for monochrome horizontal format. MHLSB and MHMSB formats are added to the framebuf module, which have 8 adjacent horizontal pixels represented in a single byte. --- extmod/modframebuf.c | 48 ++++++++++-- tests/extmod/framebuf1.py | 171 ++++++++++++++++++++++-------------------- tests/extmod/framebuf1.py.exp | 46 ++++++++++++ 3 files changed, 179 insertions(+), 86 deletions(-) (limited to 'tests/extmod') diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index 792a3a7fa..33985dd00 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -53,6 +53,41 @@ typedef struct _mp_framebuf_p_t { fill_rect_t fill_rect; } mp_framebuf_p_t; +// constants for formats +#define FRAMEBUF_MVLSB (0) +#define FRAMEBUF_RGB565 (1) +#define FRAMEBUF_GS4_HMSB (2) +#define FRAMEBUF_MHLSB (3) +#define FRAMEBUF_MHMSB (4) + +// Functions for MHLSB and MHMSB + +STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { + size_t index = (x + y * fb->stride) >> 3; + int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07); + ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((color != 0) << offset); +} + +STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, int x, int y) { + size_t index = (x + y * fb->stride) >> 3; + int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07); + return (((uint8_t*)fb->buf)[index] >> (offset)) & 0x01; +} + +STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) { + int reverse = fb->format == FRAMEBUF_MHMSB; + int advance = fb->stride >> 3; + while (w--) { + uint8_t *b = &((uint8_t*)fb->buf)[(x >> 3) + y * advance]; + int offset = reverse ? x & 7 : 7 - (x & 7); + for (int hh = h; hh; --hh) { + *b = (*b & ~(0x01 << offset)) | ((col != 0) << offset); + b += advance; + } + ++x; + } +} + // Functions for MVLSB format STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { @@ -148,15 +183,12 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, } } -// constants for formats -#define FRAMEBUF_MVLSB (0) -#define FRAMEBUF_RGB565 (1) -#define FRAMEBUF_GS4_HMSB (2) - STATIC mp_framebuf_p_t formats[] = { [FRAMEBUF_MVLSB] = {mvlsb_setpixel, mvlsb_getpixel, mvlsb_fill_rect}, [FRAMEBUF_RGB565] = {rgb565_setpixel, rgb565_getpixel, rgb565_fill_rect}, [FRAMEBUF_GS4_HMSB] = {gs4_hmsb_setpixel, gs4_hmsb_getpixel, gs4_hmsb_fill_rect}, + [FRAMEBUF_MHLSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect}, + [FRAMEBUF_MHMSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect}, }; static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { @@ -207,6 +239,10 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size case FRAMEBUF_RGB565: case FRAMEBUF_GS4_HMSB: break; + case FRAMEBUF_MHLSB: + case FRAMEBUF_MHMSB: + o->stride = (o->stride + 7) & ~7; + break; default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid format")); @@ -545,6 +581,8 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) }, { MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) }, { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_GS4_HMSB) }, + { MP_ROM_QSTR(MP_QSTR_MHLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) }, + { MP_ROM_QSTR(MP_QSTR_MHMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) }, }; STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table); diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index c204e63aa..0a8e1ae55 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -7,87 +7,96 @@ except ImportError: w = 5 h = 16 -buf = bytearray(w * h // 8) -fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.MVLSB) - -# access as buffer -print(memoryview(fbuf)[0]) - -# fill -fbuf.fill(1) -print(buf) -fbuf.fill(0) -print(buf) - -# put pixel -fbuf.pixel(0, 0, 1) -fbuf.pixel(4, 0, 1) -fbuf.pixel(0, 15, 1) -fbuf.pixel(4, 15, 1) -print(buf) - -# clear pixel -fbuf.pixel(4, 15, 0) -print(buf) - -# get pixel -print(fbuf.pixel(0, 0), fbuf.pixel(1, 1)) - -# hline -fbuf.fill(0) -fbuf.hline(0, 1, w, 1) -print('hline', buf) - -# vline -fbuf.fill(0) -fbuf.vline(1, 0, h, 1) -print('vline', buf) - -# rect -fbuf.fill(0) -fbuf.rect(1, 1, 3, 3, 1) -print('rect', buf) - -#fill rect -fbuf.fill(0) -fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation -fbuf.fill_rect(1, 1, 3, 3, 1) -print('fill_rect', buf) - -# line -fbuf.fill(0) -fbuf.line(1, 1, 3, 3, 1) -print('line', buf) - -# line steep negative gradient -fbuf.fill(0) -fbuf.line(3, 3, 2, 1, 1) -print('line', buf) - -# scroll -fbuf.fill(0) -fbuf.pixel(2, 7, 1) -fbuf.scroll(0, 1) -print(buf) -fbuf.scroll(0, -2) -print(buf) -fbuf.scroll(1, 0) -print(buf) -fbuf.scroll(-1, 0) -print(buf) -fbuf.scroll(2, 2) -print(buf) - -# print text -fbuf.fill(0) -fbuf.text("hello", 0, 0, 1) -print(buf) -fbuf.text("hello", 0, 0, 0) # clear -print(buf) - -# char out of font range set to chr(127) -fbuf.text(str(chr(31)), 0, 0) -print(buf) +size = w * h // 8 +buf = bytearray(size) +maps = {framebuf.MVLSB : 'MVLSB', + framebuf.MHLSB : 'MHLSB', + framebuf.MHMSB : 'MHMSB'} + +for mapping in maps.keys(): + for x in range(size): + buf[x] = 0 + fbuf = framebuf.FrameBuffer(buf, w, h, mapping) + print(maps[mapping]) + # access as buffer + print(memoryview(fbuf)[0]) + + # fill + fbuf.fill(1) + print(buf) + fbuf.fill(0) + print(buf) + + # put pixel + fbuf.pixel(0, 0, 1) + fbuf.pixel(4, 0, 1) + fbuf.pixel(0, 15, 1) + fbuf.pixel(4, 15, 1) + print(buf) + + # clear pixel + fbuf.pixel(4, 15, 0) + print(buf) + + # get pixel + print(fbuf.pixel(0, 0), fbuf.pixel(1, 1)) + + # hline + fbuf.fill(0) + fbuf.hline(0, 1, w, 1) + print('hline', buf) + + # vline + fbuf.fill(0) + fbuf.vline(1, 0, h, 1) + print('vline', buf) + + # rect + fbuf.fill(0) + fbuf.rect(1, 1, 3, 3, 1) + print('rect', buf) + + #fill rect + fbuf.fill(0) + fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation + fbuf.fill_rect(1, 1, 3, 3, 1) + print('fill_rect', buf) + + # line + fbuf.fill(0) + fbuf.line(1, 1, 3, 3, 1) + print('line', buf) + + # line steep negative gradient + fbuf.fill(0) + fbuf.line(3, 3, 2, 1, 1) + print('line', buf) + + # scroll + fbuf.fill(0) + fbuf.pixel(2, 7, 1) + fbuf.scroll(0, 1) + print(buf) + fbuf.scroll(0, -2) + print(buf) + fbuf.scroll(1, 0) + print(buf) + fbuf.scroll(-1, 0) + print(buf) + fbuf.scroll(2, 2) + print(buf) + + # print text + fbuf.fill(0) + fbuf.text("hello", 0, 0, 1) + print(buf) + fbuf.text("hello", 0, 0, 0) # clear + print(buf) + + # char out of font range set to chr(127) + fbuf.text(str(chr(31)), 0, 0) + print(buf) + print() # test invalid constructor, and stride argument try: diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp index 83d775d3c..736ad7a45 100644 --- a/tests/extmod/framebuf1.py.exp +++ b/tests/extmod/framebuf1.py.exp @@ -1,3 +1,4 @@ +MVLSB 0 bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') @@ -18,4 +19,49 @@ bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01') bytearray(b'\x00\x7f\x7f\x04\x04\x00\x00\x00\x00\x00') bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') bytearray(b'\xaaU\xaaU\xaa\x00\x00\x00\x00\x00') + +MHLSB +0 +bytearray(b'\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00') +1 0 +hline bytearray(b'\x00\xf8\x00\x00\x00\x00\x00\x00\x00\x00') +vline bytearray(b'@@@@@@@@@@') +rect bytearray(b'\x00pPp\x00\x00\x00\x00\x00\x00') +fill_rect bytearray(b'\x00ppp\x00\x00\x00\x00\x00\x00') +line bytearray(b'\x00@ \x10\x00\x00\x00\x00\x00\x00') +line bytearray(b'\x00 \x10\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00 \x00') +bytearray(b'\x00\x00\x00\x00\x00\x00 \x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00 \x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00') +bytearray(b'``x````\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'P\xa8P\xa8P\xa8P\xa8\x00\x00') + +MHMSB +0 +bytearray(b'\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00') +1 0 +hline bytearray(b'\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00') +vline bytearray(b'\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02') +rect bytearray(b'\x00\x0e\n\x0e\x00\x00\x00\x00\x00\x00') +fill_rect bytearray(b'\x00\x0e\x0e\x0e\x00\x00\x00\x00\x00\x00') +line bytearray(b'\x00\x02\x04\x08\x00\x00\x00\x00\x00\x00') +line bytearray(b'\x00\x04\x04\x08\x00\x00\x00\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00') +bytearray(b'\x06\x06\x1e\x06\x06\x06\x06\x00\x00\x00') +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'\n\x15\n\x15\n\x15\n\x15\x00\x00') + ValueError -- cgit v1.2.3 From b9e9cfcfc1fd8e912f0e76cfe6a90c24b8f461ba Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 2 Apr 2017 21:59:56 +0300 Subject: tests: vfs_fat_fileio.py is too big to be parsed in 16K heap, split in 2. This restores ability to run testsuite with 16K heap. --- tests/extmod/vfs_fat_fileio.py | 176 ------------------------------------ tests/extmod/vfs_fat_fileio.py.exp | 24 ----- tests/extmod/vfs_fat_fileio1.py | 113 +++++++++++++++++++++++ tests/extmod/vfs_fat_fileio1.py.exp | 13 +++ tests/extmod/vfs_fat_fileio2.py | 114 +++++++++++++++++++++++ tests/extmod/vfs_fat_fileio2.py.exp | 11 +++ 6 files changed, 251 insertions(+), 200 deletions(-) delete mode 100644 tests/extmod/vfs_fat_fileio.py delete mode 100644 tests/extmod/vfs_fat_fileio.py.exp create mode 100644 tests/extmod/vfs_fat_fileio1.py create mode 100644 tests/extmod/vfs_fat_fileio1.py.exp create mode 100644 tests/extmod/vfs_fat_fileio2.py create mode 100644 tests/extmod/vfs_fat_fileio2.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_fileio.py b/tests/extmod/vfs_fat_fileio.py deleted file mode 100644 index 6fdac0710..000000000 --- a/tests/extmod/vfs_fat_fileio.py +++ /dev/null @@ -1,176 +0,0 @@ -import sys -import uerrno -try: - import uos_vfs as uos - open = uos.vfs_open -except ImportError: - import uos -try: - uos.VfsFat -except AttributeError: - print("SKIP") - sys.exit() - - -class RAMFS: - - SEC_SIZE = 512 - - def __init__(self, blocks): - self.data = bytearray(blocks * self.SEC_SIZE) - - def readblocks(self, n, buf): - #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) - for i in range(len(buf)): - buf[i] = self.data[n * self.SEC_SIZE + i] - - def writeblocks(self, n, buf): - #print("writeblocks(%s, %x)" % (n, id(buf))) - for i in range(len(buf)): - self.data[n * self.SEC_SIZE + i] = buf[i] - - def ioctl(self, op, arg): - #print("ioctl(%d, %r)" % (op, arg)) - if op == 4: # BP_IOCTL_SEC_COUNT - return len(self.data) // self.SEC_SIZE - if op == 5: # BP_IOCTL_SEC_SIZE - return self.SEC_SIZE - - -try: - bdev = RAMFS(50) -except MemoryError: - print("SKIP") - sys.exit() - -uos.VfsFat.mkfs(bdev) -vfs = uos.VfsFat(bdev) -uos.mount(vfs, '/ramdisk') -uos.chdir('/ramdisk') - -# file IO -f = open("foo_file.txt", "w") -print(str(f)[:17], str(f)[-1:]) -f.write("hello!") -f.flush() -f.close() -f.close() # allowed -try: - f.write("world!") -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - f.read() -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - f.flush() -except OSError as e: - print(e.args[0] == uerrno.EINVAL) - -try: - open("foo_file.txt", "x") -except OSError as e: - print(e.args[0] == uerrno.EEXIST) - -with open("foo_file.txt", "a") as f: - f.write("world!") - -with open("foo_file.txt") as f2: - print(f2.read()) - print(f2.tell()) - - f2.seek(0, 0) # SEEK_SET - print(f2.read(1)) - - f2.seek(0, 1) # SEEK_CUR - print(f2.read(1)) - try: - f2.seek(1, 1) # SEEK_END - except OSError as e: - print(e.args[0] == uerrno.EOPNOTSUPP) - - f2.seek(-2, 2) # SEEK_END - print(f2.read(1)) - -# using constructor of FileIO type to open a file -# no longer working with new VFS sub-system -#FileIO = type(f) -#with FileIO("/ramdisk/foo_file.txt") as f: -# print(f.read()) - -# dirs -vfs.mkdir("foo_dir") - -try: - vfs.rmdir("foo_file.txt") -except OSError as e: - print(e.args[0] == 20) # uerrno.ENOTDIR - -try: - vfs.mkdir("foo_dir") -except OSError as e: - print(e.args[0] == uerrno.EEXIST) - -try: - vfs.remove("foo_dir") -except OSError as e: - print(e.args[0] == uerrno.EISDIR) - -try: - vfs.remove("no_file.txt") -except OSError as e: - print(e.args[0] == uerrno.ENOENT) - -try: - vfs.rename("foo_dir", "/null/file") -except OSError as e: - print(e.args[0] == uerrno.ENOENT) - -# file in dir -with open("foo_dir/file-in-dir.txt", "w+t") as f: - f.write("data in file") - -with open("foo_dir/file-in-dir.txt", "r+b") as f: - print(f.read()) - -with open("foo_dir/sub_file.txt", "w") as f: - f.write("subdir file") - -# directory not empty -try: - vfs.rmdir("foo_dir") -except OSError as e: - print(e.args[0] == uerrno.EACCES) - -# trim full path -vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") -print(vfs.listdir("foo_dir")) - -vfs.rename("foo_dir/file.txt", "moved-to-root.txt") -print(vfs.listdir()) - -# check that renaming to existing file will overwrite it -with open("temp", "w") as f: - f.write("new text") -vfs.rename("temp", "moved-to-root.txt") -print(vfs.listdir()) -with open("moved-to-root.txt") as f: - print(f.read()) - -# valid removes -vfs.remove("foo_dir/sub_file.txt") -vfs.remove("foo_file.txt") -vfs.rmdir("foo_dir") -print(vfs.listdir()) - -# disk full -try: - bsize = vfs.statvfs("/ramdisk")[0] - free = vfs.statvfs("/ramdisk")[2] + 1 - f = open("large_file.txt", "wb") - f.write(bytearray(bsize * free)) -except OSError as e: - print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC diff --git a/tests/extmod/vfs_fat_fileio.py.exp b/tests/extmod/vfs_fat_fileio.py.exp deleted file mode 100644 index 4e34e83a8..000000000 --- a/tests/extmod/vfs_fat_fileio.py.exp +++ /dev/null @@ -1,24 +0,0 @@ - -True -True -True -True -hello!world! -12 -h -e -True -d -True -True -True -True -True -b'data in file' -True -['sub_file.txt', 'file.txt'] -['foo_file.txt', 'foo_dir', 'moved-to-root.txt'] -['foo_file.txt', 'foo_dir', 'moved-to-root.txt'] -new text -['moved-to-root.txt'] -ENOSPC: True diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py new file mode 100644 index 000000000..322f6831e --- /dev/null +++ b/tests/extmod/vfs_fat_fileio1.py @@ -0,0 +1,113 @@ +import sys +import uerrno +try: + import uos_vfs as uos + open = uos.vfs_open +except ImportError: + import uos +try: + uos.VfsFat +except AttributeError: + print("SKIP") + sys.exit() + + +class RAMFS: + + SEC_SIZE = 512 + + def __init__(self, blocks): + self.data = bytearray(blocks * self.SEC_SIZE) + + def readblocks(self, n, buf): + #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) + for i in range(len(buf)): + buf[i] = self.data[n * self.SEC_SIZE + i] + + def writeblocks(self, n, buf): + #print("writeblocks(%s, %x)" % (n, id(buf))) + for i in range(len(buf)): + self.data[n * self.SEC_SIZE + i] = buf[i] + + def ioctl(self, op, arg): + #print("ioctl(%d, %r)" % (op, arg)) + if op == 4: # BP_IOCTL_SEC_COUNT + return len(self.data) // self.SEC_SIZE + if op == 5: # BP_IOCTL_SEC_SIZE + return self.SEC_SIZE + + +try: + bdev = RAMFS(50) +except MemoryError: + print("SKIP") + sys.exit() + +uos.VfsFat.mkfs(bdev) +vfs = uos.VfsFat(bdev) +uos.mount(vfs, '/ramdisk') +uos.chdir('/ramdisk') + +# file IO +f = open("foo_file.txt", "w") +print(str(f)[:17], str(f)[-1:]) +f.write("hello!") +f.flush() +f.close() +f.close() # allowed +try: + f.write("world!") +except OSError as e: + print(e.args[0] == uerrno.EINVAL) + +try: + f.read() +except OSError as e: + print(e.args[0] == uerrno.EINVAL) + +try: + f.flush() +except OSError as e: + print(e.args[0] == uerrno.EINVAL) + +try: + open("foo_file.txt", "x") +except OSError as e: + print(e.args[0] == uerrno.EEXIST) + +with open("foo_file.txt", "a") as f: + f.write("world!") + +with open("foo_file.txt") as f2: + print(f2.read()) + print(f2.tell()) + + f2.seek(0, 0) # SEEK_SET + print(f2.read(1)) + + f2.seek(0, 1) # SEEK_CUR + print(f2.read(1)) + try: + f2.seek(1, 1) # SEEK_END + except OSError as e: + print(e.args[0] == uerrno.EOPNOTSUPP) + + f2.seek(-2, 2) # SEEK_END + print(f2.read(1)) + +# using constructor of FileIO type to open a file +# no longer working with new VFS sub-system +#FileIO = type(f) +#with FileIO("/ramdisk/foo_file.txt") as f: +# print(f.read()) + +# dirs +vfs.mkdir("foo_dir") + +try: + vfs.rmdir("foo_file.txt") +except OSError as e: + print(e.args[0] == 20) # uerrno.ENOTDIR + +vfs.remove("foo_file.txt") +print(vfs.listdir()) diff --git a/tests/extmod/vfs_fat_fileio1.py.exp b/tests/extmod/vfs_fat_fileio1.py.exp new file mode 100644 index 000000000..7959a70ee --- /dev/null +++ b/tests/extmod/vfs_fat_fileio1.py.exp @@ -0,0 +1,13 @@ + +True +True +True +True +hello!world! +12 +h +e +True +d +True +['foo_dir'] diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py new file mode 100644 index 000000000..80a614db7 --- /dev/null +++ b/tests/extmod/vfs_fat_fileio2.py @@ -0,0 +1,114 @@ +import sys +import uerrno +try: + import uos_vfs as uos + open = uos.vfs_open +except ImportError: + import uos +try: + uos.VfsFat +except AttributeError: + print("SKIP") + sys.exit() + + +class RAMFS: + + SEC_SIZE = 512 + + def __init__(self, blocks): + self.data = bytearray(blocks * self.SEC_SIZE) + + def readblocks(self, n, buf): + #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) + for i in range(len(buf)): + buf[i] = self.data[n * self.SEC_SIZE + i] + + def writeblocks(self, n, buf): + #print("writeblocks(%s, %x)" % (n, id(buf))) + for i in range(len(buf)): + self.data[n * self.SEC_SIZE + i] = buf[i] + + def ioctl(self, op, arg): + #print("ioctl(%d, %r)" % (op, arg)) + if op == 4: # BP_IOCTL_SEC_COUNT + return len(self.data) // self.SEC_SIZE + if op == 5: # BP_IOCTL_SEC_SIZE + return self.SEC_SIZE + + +try: + bdev = RAMFS(50) +except MemoryError: + print("SKIP") + sys.exit() + +uos.VfsFat.mkfs(bdev) +vfs = uos.VfsFat(bdev) +uos.mount(vfs, '/ramdisk') +uos.chdir('/ramdisk') + +try: + vfs.mkdir("foo_dir") +except OSError as e: + print(e.args[0] == uerrno.EEXIST) + +try: + vfs.remove("foo_dir") +except OSError as e: + print(e.args[0] == uerrno.EISDIR) + +try: + vfs.remove("no_file.txt") +except OSError as e: + print(e.args[0] == uerrno.ENOENT) + +try: + vfs.rename("foo_dir", "/null/file") +except OSError as e: + print(e.args[0] == uerrno.ENOENT) + +# file in dir +with open("foo_dir/file-in-dir.txt", "w+t") as f: + f.write("data in file") + +with open("foo_dir/file-in-dir.txt", "r+b") as f: + print(f.read()) + +with open("foo_dir/sub_file.txt", "w") as f: + f.write("subdir file") + +# directory not empty +try: + vfs.rmdir("foo_dir") +except OSError as e: + print(e.args[0] == uerrno.EACCES) + +# trim full path +vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") +print(vfs.listdir("foo_dir")) + +vfs.rename("foo_dir/file.txt", "moved-to-root.txt") +print(vfs.listdir()) + +# check that renaming to existing file will overwrite it +with open("temp", "w") as f: + f.write("new text") +vfs.rename("temp", "moved-to-root.txt") +print(vfs.listdir()) +with open("moved-to-root.txt") as f: + print(f.read()) + +# valid removes +vfs.remove("foo_dir/sub_file.txt") +vfs.rmdir("foo_dir") +print(vfs.listdir()) + +# disk full +try: + bsize = vfs.statvfs("/ramdisk")[0] + free = vfs.statvfs("/ramdisk")[2] + 1 + f = open("large_file.txt", "wb") + f.write(bytearray(bsize * free)) +except OSError as e: + print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC diff --git a/tests/extmod/vfs_fat_fileio2.py.exp b/tests/extmod/vfs_fat_fileio2.py.exp new file mode 100644 index 000000000..38ec5c9b9 --- /dev/null +++ b/tests/extmod/vfs_fat_fileio2.py.exp @@ -0,0 +1,11 @@ +True +True +True +b'data in file' +True +['sub_file.txt', 'file.txt'] +['foo_dir', 'moved-to-root.txt'] +['foo_dir', 'moved-to-root.txt'] +new text +['moved-to-root.txt'] +ENOSPC: True -- cgit v1.2.3 From 499ea8b2532010c17b2f52825b90c4991db02aa5 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 3 Apr 2017 00:14:57 +0300 Subject: tests/extmod/vfs_fat_fileio*: Improve skippability. Should be skipped on missing uso, uerrno modules. --- tests/extmod/vfs_fat_fileio1.py | 13 +++++++++---- tests/extmod/vfs_fat_fileio2.py | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index 322f6831e..526b3f5c1 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -1,10 +1,15 @@ import sys -import uerrno try: - import uos_vfs as uos - open = uos.vfs_open + import uerrno + try: + import uos_vfs as uos + open = uos.vfs_open + except ImportError: + import uos except ImportError: - import uos + print("SKIP") + sys.exit() + try: uos.VfsFat except AttributeError: diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index 80a614db7..111abfa7e 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -1,10 +1,15 @@ import sys -import uerrno try: - import uos_vfs as uos - open = uos.vfs_open + import uerrno + try: + import uos_vfs as uos + open = uos.vfs_open + except ImportError: + import uos except ImportError: - import uos + print("SKIP") + sys.exit() + try: uos.VfsFat except AttributeError: -- cgit v1.2.3 From 468c6f9da147d6e752e437a32211e317a116b6df Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Sat, 1 Apr 2017 07:00:09 +0100 Subject: extmod/modframebuf: Make monochrome bitmap formats start with MONO_. MONO_xxx is much easier to read if you're not familiar with the code. MVLSB is deprecated but kept for backwards compatibility, for the time being. This patch also updates the associated docs and tests. --- docs/library/framebuf.rst | 25 ++++++++++++++++++++++++- extmod/modframebuf.c | 5 +++-- tests/extmod/framebuf1.py | 7 ++++--- tests/extmod/framebuf1.py.exp | 7 ++++--- 4 files changed, 35 insertions(+), 9 deletions(-) (limited to 'tests/extmod') diff --git a/docs/library/framebuf.rst b/docs/library/framebuf.rst index 91fc362fd..61f0635f3 100644 --- a/docs/library/framebuf.rst +++ b/docs/library/framebuf.rst @@ -116,9 +116,32 @@ Other methods Constants --------- -.. data:: framebuf.MVLSB +.. data:: framebuf.MONO_VLSB Monochrome (1-bit) color format + This defines a mapping where the bits in a byte are vertically mapped with + bit 0 being nearest the top of the screen. Consequently each byte occupies + 8 vertical pixels. Subsequent bytes appear at successive horizontal + locations until the rightmost edge is reached. Further bytes are rendered + at locations starting at the leftmost edge, 8 pixels lower. + +.. data:: framebuf.MONO_HLSB + + Monochrome (1-bit) color format + This defines a mapping where the bits in a byte are horizontally mapped. + Each byte occupies 8 horizontal pixels with bit 0 being the leftmost. + Subsequent bytes appear at successive horizontal locations until the + rightmost edge is reached. Further bytes are rendered on the next row, one + pixel lower. + +.. data:: framebuf.MONO_HMSB + + Monochrome (1-bit) color format + This defines a mapping where the bits in a byte are horizontally mapped. + Each byte occupies 8 horizontal pixels with bit 7 being the leftmost. + Subsequent bytes appear at successive horizontal locations until the + rightmost edge is reached. Further bytes are rendered on the next row, one + pixel lower. .. data:: framebuf.RGB565 diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index 33985dd00..b8e84fe1c 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -579,10 +579,11 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) }, { MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) }, { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) }, + { MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) }, { MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) }, { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_GS4_HMSB) }, - { MP_ROM_QSTR(MP_QSTR_MHLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) }, - { MP_ROM_QSTR(MP_QSTR_MHMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) }, + { MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) }, + { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) }, }; STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table); diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index 0a8e1ae55..990b0b120 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -9,9 +9,9 @@ w = 5 h = 16 size = w * h // 8 buf = bytearray(size) -maps = {framebuf.MVLSB : 'MVLSB', - framebuf.MHLSB : 'MHLSB', - framebuf.MHMSB : 'MHMSB'} +maps = {framebuf.MONO_VLSB : 'MONO_VLSB', + framebuf.MONO_HLSB : 'MONO_HLSB', + framebuf.MONO_HMSB : 'MONO_HMSB'} for mapping in maps.keys(): for x in range(size): @@ -107,3 +107,4 @@ except ValueError: # test legacy constructor fbuf = framebuf.FrameBuffer1(buf, w, h) fbuf = framebuf.FrameBuffer1(buf, w, h, w) +print(framebuf.MVLSB == framebuf.MONO_VLSB) diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp index 736ad7a45..d954623de 100644 --- a/tests/extmod/framebuf1.py.exp +++ b/tests/extmod/framebuf1.py.exp @@ -1,4 +1,4 @@ -MVLSB +MONO_VLSB 0 bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') @@ -20,7 +20,7 @@ bytearray(b'\x00\x7f\x7f\x04\x04\x00\x00\x00\x00\x00') bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') bytearray(b'\xaaU\xaaU\xaa\x00\x00\x00\x00\x00') -MHLSB +MONO_HLSB 0 bytearray(b'\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8\xf8') bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') @@ -42,7 +42,7 @@ bytearray(b'``x````\x00\x00\x00') bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') bytearray(b'P\xa8P\xa8P\xa8P\xa8\x00\x00') -MHMSB +MONO_HMSB 0 bytearray(b'\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f\x1f') bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') @@ -65,3 +65,4 @@ bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') bytearray(b'\n\x15\n\x15\n\x15\n\x15\x00\x00') ValueError +True -- cgit v1.2.3 From 967cad7434ee8e814c07ecccc6b642704dc46eaf Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 13 Apr 2017 23:34:28 +1000 Subject: tests/extmod/utimeq1: Improve coverage of utimeq module. --- tests/extmod/utimeq1.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/extmod') diff --git a/tests/extmod/utimeq1.py b/tests/extmod/utimeq1.py index 9af723674..68d69e25e 100644 --- a/tests/extmod/utimeq1.py +++ b/tests/extmod/utimeq1.py @@ -34,6 +34,41 @@ try: except IndexError: pass +# unsupported unary op +try: + ~h + assert False +except TypeError: + pass + +# pushing on full queue +h = utimeq(1) +h.push(1, 0, 0) +try: + h.push(2, 0, 0) + assert False +except IndexError: + pass + +# popping into invalid type +try: + h.pop([]) + assert False +except TypeError: + pass + +# length +assert len(h) == 1 + +# peektime +assert h.peektime() == 1 + +# peektime with empty queue +try: + utimeq(1).peektime() + assert False +except IndexError: + pass def pop_all(h): l = [] -- cgit v1.2.3 From 61616e84ce41e1b1a0fad62704488d79b87cfbe2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 12 Apr 2017 13:00:40 +1000 Subject: extmod/machine_signal: Rename "inverted" arg to "invert", it's shorter. A shorter name takes less code size, less room in scripts and is faster to type at the REPL. Tests and HW-API examples are updated to reflect the change. --- examples/hwapi/hwconfig_esp8266_esp12.py | 2 +- extmod/machine_signal.c | 22 +++++++++++----------- tests/extmod/machine_signal.py | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'tests/extmod') diff --git a/examples/hwapi/hwconfig_esp8266_esp12.py b/examples/hwapi/hwconfig_esp8266_esp12.py index fb6d5fe90..198a652d0 100644 --- a/examples/hwapi/hwconfig_esp8266_esp12.py +++ b/examples/hwapi/hwconfig_esp8266_esp12.py @@ -2,4 +2,4 @@ from machine import Pin, Signal # ESP12 module as used by many boards # Blue LED on pin 2, active low (inverted) -LED = Signal(Pin(2, Pin.OUT), inverted=True) +LED = Signal(Pin(2, Pin.OUT), invert=True) diff --git a/extmod/machine_signal.c b/extmod/machine_signal.c index b10d90166..d08931296 100644 --- a/extmod/machine_signal.c +++ b/extmod/machine_signal.c @@ -39,12 +39,12 @@ typedef struct _machine_signal_t { mp_obj_base_t base; mp_obj_t pin; - bool inverted; + bool invert; } machine_signal_t; STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_t pin = args[0]; - bool inverted = false; + bool invert = false; #if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW) mp_pin_p_t *pin_p = NULL; @@ -55,7 +55,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t } if (pin_p == NULL) { - // If first argument isn't a Pin-like object, we filter out "inverted" + // If first argument isn't a Pin-like object, we filter out "invert" // from keyword arguments and pass them all to the exported Pin // constructor to create one. mp_obj_t pin_args[n_args + n_kw * 2]; @@ -64,8 +64,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t mp_obj_t *dst = pin_args + n_args; mp_obj_t *sig_value = NULL; for (size_t cnt = n_kw; cnt; cnt--) { - if (*src == MP_OBJ_NEW_QSTR(MP_QSTR_inverted)) { - inverted = mp_obj_is_true(src[1]); + if (*src == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) { + invert = mp_obj_is_true(src[1]); n_kw--; } else { *dst++ = *src; @@ -80,7 +80,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t src += 2; } - if (inverted && sig_value != NULL) { + if (invert && sig_value != NULL) { *sig_value = mp_obj_is_true(*sig_value) ? MP_OBJ_NEW_SMALL_INT(0) : MP_OBJ_NEW_SMALL_INT(1); } @@ -95,8 +95,8 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t { if (n_args == 1) { if (n_kw == 0) { - } else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_inverted)) { - inverted = mp_obj_is_true(args[1]); + } else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) { + invert = mp_obj_is_true(args[1]); } else { goto error; } @@ -109,7 +109,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t machine_signal_t *o = m_new_obj(machine_signal_t); o->base.type = type; o->pin = pin; - o->inverted = inverted; + o->invert = invert; return MP_OBJ_FROM_PTR(o); } @@ -119,10 +119,10 @@ STATIC mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg switch (request) { case MP_PIN_READ: { - return mp_virtual_pin_read(self->pin) ^ self->inverted; + return mp_virtual_pin_read(self->pin) ^ self->invert; } case MP_PIN_WRITE: { - mp_virtual_pin_write(self->pin, arg ^ self->inverted); + mp_virtual_pin_write(self->pin, arg ^ self->invert); return 0; } } diff --git a/tests/extmod/machine_signal.py b/tests/extmod/machine_signal.py index 401533f23..96b8f43c7 100644 --- a/tests/extmod/machine_signal.py +++ b/tests/extmod/machine_signal.py @@ -33,7 +33,7 @@ print(p.value(), s.value()) # test inverted, and using on/off methods p = Pin() -s = machine.Signal(p, inverted=True) +s = machine.Signal(p, invert=True) s.off() print(p.value(), s.value()) s.on() -- cgit v1.2.3 From 9e8f3163924c1f429f16f44a4a27b0cd33064719 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 21 Apr 2017 16:40:57 +0300 Subject: extmod/moductypes: Fix bigint handling for 32-bit ports. --- extmod/moductypes.c | 2 +- py/objint_mpz.c | 1 + tests/extmod/uctypes_32bit_intbig.py | 54 ++++++++++++++++++++++++++++++++ tests/extmod/uctypes_32bit_intbig.py.exp | 11 +++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/extmod/uctypes_32bit_intbig.py create mode 100644 tests/extmod/uctypes_32bit_intbig.py.exp (limited to 'tests/extmod') diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 6249a4940..d2d2e85de 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -360,7 +360,7 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) { return; } #endif - mp_int_t v = mp_obj_get_int(val); + mp_int_t v = mp_obj_get_int_truncated(val); switch (val_type) { case UINT8: ((uint8_t*)p)[index] = (uint8_t)v; return; diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 2353bd8d6..d818b6f40 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -116,6 +116,7 @@ mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf) { assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int)); mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in); + memset(buf, 0, len); mpz_as_bytes(&self->mpz, big_endian, len, buf); } diff --git a/tests/extmod/uctypes_32bit_intbig.py b/tests/extmod/uctypes_32bit_intbig.py new file mode 100644 index 000000000..a082dc370 --- /dev/null +++ b/tests/extmod/uctypes_32bit_intbig.py @@ -0,0 +1,54 @@ +# This test checks previously known problem values for 32-bit ports. +# It's less useful for 64-bit ports. +try: + import uctypes +except ImportError: + import sys + print("SKIP") + sys.exit() + +buf = b"12345678abcd" +struct = uctypes.struct( + uctypes.addressof(buf), + {"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4}, + uctypes.LITTLE_ENDIAN +) + +struct.f32 = 0x7fffffff +print(buf) + +struct.f32 = 0x80000000 +print(buf) + +struct.f32 = 0xff010203 +print(buf) + +struct.f64 = 0x80000000 +print(buf) + +struct.f64 = 0x80000000 * 2 +print(buf) + +print("=") + +buf = b"12345678abcd" +struct = uctypes.struct( + uctypes.addressof(buf), + {"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4}, + uctypes.BIG_ENDIAN +) + +struct.f32 = 0x7fffffff +print(buf) + +struct.f32 = 0x80000000 +print(buf) + +struct.f32 = 0xff010203 +print(buf) + +struct.f64 = 0x80000000 +print(buf) + +struct.f64 = 0x80000000 * 2 +print(buf) diff --git a/tests/extmod/uctypes_32bit_intbig.py.exp b/tests/extmod/uctypes_32bit_intbig.py.exp new file mode 100644 index 000000000..d1fc1fe35 --- /dev/null +++ b/tests/extmod/uctypes_32bit_intbig.py.exp @@ -0,0 +1,11 @@ +b'\xff\xff\xff\x7f5678abcd' +b'\x00\x00\x00\x805678abcd' +b'\x03\x02\x01\xff5678abcd' +b'\x03\x02\x01\xff\x00\x00\x00\x80\x00\x00\x00\x00' +b'\x03\x02\x01\xff\x00\x00\x00\x00\x01\x00\x00\x00' += +b'\x7f\xff\xff\xff5678abcd' +b'\x80\x00\x00\x005678abcd' +b'\xff\x01\x02\x035678abcd' +b'\xff\x01\x02\x03\x00\x00\x00\x00\x80\x00\x00\x00' +b'\xff\x01\x02\x03\x00\x00\x00\x01\x00\x00\x00\x00' -- cgit v1.2.3 From 6c8b57a90212c63441f8e5165b4781409648e519 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2017 17:13:58 +1100 Subject: tests/extmod: Add more tests for VFS FAT. --- tests/extmod/vfs_fat_more.py | 104 +++++++++++++++++++++++++++++++++++++++ tests/extmod/vfs_fat_more.py.exp | 28 +++++++++++ 2 files changed, 132 insertions(+) create mode 100644 tests/extmod/vfs_fat_more.py create mode 100644 tests/extmod/vfs_fat_more.py.exp (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py new file mode 100644 index 000000000..217d63995 --- /dev/null +++ b/tests/extmod/vfs_fat_more.py @@ -0,0 +1,104 @@ +import sys +import uerrno +try: + import uos_vfs as uos + open = uos.vfs_open +except ImportError: + import uos +try: + uos.VfsFat +except AttributeError: + print("SKIP") + sys.exit() + + +class RAMFS: + + SEC_SIZE = 512 + + def __init__(self, blocks): + self.data = bytearray(blocks * self.SEC_SIZE) + + def readblocks(self, n, buf): + #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf))) + for i in range(len(buf)): + buf[i] = self.data[n * self.SEC_SIZE + i] + + def writeblocks(self, n, buf): + #print("writeblocks(%s, %x)" % (n, id(buf))) + for i in range(len(buf)): + self.data[n * self.SEC_SIZE + i] = buf[i] + + def ioctl(self, op, arg): + #print("ioctl(%d, %r)" % (op, arg)) + if op == 4: # BP_IOCTL_SEC_COUNT + return len(self.data) // self.SEC_SIZE + if op == 5: # BP_IOCTL_SEC_SIZE + return self.SEC_SIZE + + +try: + bdev = RAMFS(50) + bdev2 = RAMFS(50) +except MemoryError: + print("SKIP") + sys.exit() + +uos.VfsFat.mkfs(bdev) +uos.mount(bdev, '/') + +print(uos.getcwd()) + +f = open('test.txt', 'w') +f.write('hello') +f.close() + +print(uos.listdir()) +print(uos.listdir('/')) +print(uos.stat('')[:-3]) +print(uos.stat('/')[:-3]) +print(uos.stat('test.txt')[:-3]) +print(uos.stat('/test.txt')[:-3]) + +f = open('/test.txt') +print(f.read()) +f.close() + +uos.rename('test.txt', 'test2.txt') +print(uos.listdir()) +uos.rename('test2.txt', '/test3.txt') +print(uos.listdir()) +uos.rename('/test3.txt', 'test4.txt') +print(uos.listdir()) +uos.rename('/test4.txt', '/test5.txt') +print(uos.listdir()) + +uos.mkdir('dir') +print(uos.listdir()) +uos.mkdir('/dir2') +print(uos.listdir()) +uos.mkdir('dir/subdir') +print(uos.listdir('dir')) +for exist in ('', '/', 'dir', '/dir', 'dir/subdir'): + try: + uos.mkdir(exist) + except OSError as er: + print('mkdir OSError', er.args[0] == 17) # EEXIST + +uos.chdir('/') +print(uos.stat('test5.txt')[:-3]) + +uos.VfsFat.mkfs(bdev2) +uos.mount(bdev2, '/sys') +print(uos.listdir()) +print(uos.listdir('sys')) +print(uos.listdir('/sys')) + +uos.rmdir('dir2') +uos.remove('test5.txt') +print(uos.listdir()) + +uos.umount('/') +print(uos.getcwd()) +print(uos.listdir()) +print(uos.listdir('sys')) diff --git a/tests/extmod/vfs_fat_more.py.exp b/tests/extmod/vfs_fat_more.py.exp new file mode 100644 index 000000000..aaca3cc75 --- /dev/null +++ b/tests/extmod/vfs_fat_more.py.exp @@ -0,0 +1,28 @@ +/ +['test.txt'] +['test.txt'] +(16384, 0, 0, 0, 0, 0, 0) +(16384, 0, 0, 0, 0, 0, 0) +(32768, 0, 0, 0, 0, 0, 5) +(32768, 0, 0, 0, 0, 0, 5) +hello +['test2.txt'] +['test3.txt'] +['test4.txt'] +['test5.txt'] +['test5.txt', 'dir'] +['test5.txt', 'dir', 'dir2'] +['subdir'] +mkdir OSError True +mkdir OSError True +mkdir OSError True +mkdir OSError True +mkdir OSError True +(32768, 0, 0, 0, 0, 0, 5) +['sys', 'test5.txt', 'dir', 'dir2'] +[] +[] +['sys', 'dir'] +/ +['sys'] +[] -- cgit v1.2.3 From 1b3e3724188af762ccab80cafc959a0e766983bc Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 10 Mar 2017 17:43:49 +1100 Subject: tests/extmod: Add some more VFS tests. --- tests/extmod/vfs_basic.py | 20 ++++++++++++++++++++ tests/extmod/vfs_basic.py.exp | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 83c83fd22..1821a277d 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -109,3 +109,23 @@ try: uos.umount('/test_mnt') except OSError: print('OSError') + +# root dir +uos.mount(Filesystem(3), '/') +print(uos.listdir()) +open('test') + +uos.mount(Filesystem(4), '/mnt') +print(uos.listdir()) +print(uos.listdir('/mnt')) +uos.chdir('/mnt') +print(uos.listdir()) + +# chdir to a subdir within root-mounted vfs, and then listdir +uos.chdir('/subdir') +print(uos.listdir()) +uos.chdir('/') + +uos.umount('/') +print(uos.listdir('/')) +uos.umount('/mnt') diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp index 5104a16a6..416d45961 100644 --- a/tests/extmod/vfs_basic.py.exp +++ b/tests/extmod/vfs_basic.py.exp @@ -32,3 +32,22 @@ OSError 1 umount 2 umount OSError +3 mount False False +3 listdir / +['a3'] +3 open test r +4 mount False False +3 listdir / +['mnt', 'a3'] +4 listdir / +['a4'] +4 chdir / +4 listdir +['a4'] +3 chdir /subdir +3 listdir +['a3'] +3 chdir / +3 umount +['mnt'] +4 umount -- cgit v1.2.3 From 9bd67d9fbc09823e33642e7ec709afbf88d11d0a Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 9 May 2017 15:50:40 +1000 Subject: tests/extmod: Make some vfs tests fully unmount FSs before running. Otherwise the existing FSs can interfere with the tests, and in some cases the tests can write to the real FS on the device. --- tests/extmod/vfs_basic.py | 4 ++++ tests/extmod/vfs_fat_more.py | 8 ++++++++ 2 files changed, 12 insertions(+) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 1821a277d..32bfe8ab4 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -47,6 +47,10 @@ class Filesystem: # first we umount any existing mount points the target may have +try: + uos.umount('/') +except OSError: + pass for path in uos.listdir('/'): uos.umount('/' + path) diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py index 217d63995..6c2df528f 100644 --- a/tests/extmod/vfs_fat_more.py +++ b/tests/extmod/vfs_fat_more.py @@ -44,6 +44,14 @@ except MemoryError: print("SKIP") sys.exit() +# first we umount any existing mount points the target may have +try: + uos.umount('/') +except OSError: + pass +for path in uos.listdir('/'): + uos.umount('/' + path) + uos.VfsFat.mkfs(bdev) uos.mount(bdev, '/') -- cgit v1.2.3 From 852c215d76de082adf57d3724907ab2c8d790e78 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 May 2017 23:35:49 +1000 Subject: tests/extmod/vfs: Update tests to reflect new ilistdir() method. --- tests/extmod/vfs_basic.py | 18 +++++++++++++++--- tests/extmod/vfs_basic.py.exp | 21 ++++++++++++--------- tests/extmod/vfs_fat_fileio1.py | 2 +- tests/extmod/vfs_fat_fileio1.py.exp | 2 +- tests/extmod/vfs_fat_fileio2.py | 8 ++++---- tests/extmod/vfs_fat_fileio2.py.exp | 8 ++++---- tests/extmod/vfs_fat_oldproto.py | 4 ++-- tests/extmod/vfs_fat_oldproto.py.exp | 2 +- tests/extmod/vfs_fat_ramdisk.py | 6 +++--- tests/extmod/vfs_fat_ramdisk.py.exp | 4 ++-- 10 files changed, 45 insertions(+), 30 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 32bfe8ab4..a3b2f3c29 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -20,9 +20,9 @@ class Filesystem: print(self.id, 'mount', readonly, mkfs) def umount(self): print(self.id, 'umount') - def listdir(self, dir): - print(self.id, 'listdir', dir) - return ['a%d' % self.id] + def ilistdir(self, dir): + print(self.id, 'ilistdir', dir) + return iter([('a%d' % self.id, 0, 0)]) def chdir(self, dir): print(self.id, 'chdir', dir) def getcwd(self): @@ -64,6 +64,18 @@ print(uos.getcwd()) uos.mount(Filesystem(1), '/test_mnt') print(uos.listdir()) +# ilistdir +i = uos.ilistdir() +print(next(i)) +try: + next(i) +except StopIteration: + print('StopIteration') +try: + next(i) +except StopIteration: + print('StopIteration') + # referencing the mount point in different ways print(uos.listdir('test_mnt')) print(uos.listdir('/test_mnt')) diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp index 416d45961..8a23aa8ae 100644 --- a/tests/extmod/vfs_basic.py.exp +++ b/tests/extmod/vfs_basic.py.exp @@ -2,20 +2,23 @@ / 1 mount False False ['test_mnt'] -1 listdir / +('test_mnt', 16384, 0) +StopIteration +StopIteration +1 ilistdir / ['a1'] -1 listdir / +1 ilistdir / ['a1'] 2 mount True False ['test_mnt', 'test_mnt2'] -2 listdir / +2 ilistdir / ['a2'] 3 mount False False OSError OSError OSError 1 chdir / -1 listdir +1 ilistdir ['a1'] 1 getcwd /test_mntdir1 @@ -33,19 +36,19 @@ OSError 2 umount OSError 3 mount False False -3 listdir / +3 ilistdir / ['a3'] 3 open test r 4 mount False False -3 listdir / +3 ilistdir / ['mnt', 'a3'] -4 listdir / +4 ilistdir / ['a4'] 4 chdir / -4 listdir +4 ilistdir ['a4'] 3 chdir /subdir -3 listdir +3 ilistdir ['a3'] 3 chdir / 3 umount diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index 526b3f5c1..9036df7a5 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -115,4 +115,4 @@ except OSError as e: print(e.args[0] == 20) # uerrno.ENOTDIR vfs.remove("foo_file.txt") -print(vfs.listdir()) +print(list(vfs.ilistdir())) diff --git a/tests/extmod/vfs_fat_fileio1.py.exp b/tests/extmod/vfs_fat_fileio1.py.exp index 7959a70ee..d777585cf 100644 --- a/tests/extmod/vfs_fat_fileio1.py.exp +++ b/tests/extmod/vfs_fat_fileio1.py.exp @@ -10,4 +10,4 @@ e True d True -['foo_dir'] +[('foo_dir', 16384, 0)] diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index 111abfa7e..b2a0ba70f 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -91,23 +91,23 @@ except OSError as e: # trim full path vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") -print(vfs.listdir("foo_dir")) +print(list(vfs.ilistdir("foo_dir"))) vfs.rename("foo_dir/file.txt", "moved-to-root.txt") -print(vfs.listdir()) +print(list(vfs.ilistdir())) # check that renaming to existing file will overwrite it with open("temp", "w") as f: f.write("new text") vfs.rename("temp", "moved-to-root.txt") -print(vfs.listdir()) +print(list(vfs.ilistdir())) with open("moved-to-root.txt") as f: print(f.read()) # valid removes vfs.remove("foo_dir/sub_file.txt") vfs.rmdir("foo_dir") -print(vfs.listdir()) +print(list(vfs.ilistdir())) # disk full try: diff --git a/tests/extmod/vfs_fat_fileio2.py.exp b/tests/extmod/vfs_fat_fileio2.py.exp index 38ec5c9b9..118dee26b 100644 --- a/tests/extmod/vfs_fat_fileio2.py.exp +++ b/tests/extmod/vfs_fat_fileio2.py.exp @@ -3,9 +3,9 @@ True True b'data in file' True -['sub_file.txt', 'file.txt'] -['foo_dir', 'moved-to-root.txt'] -['foo_dir', 'moved-to-root.txt'] +[('sub_file.txt', 32768, 0), ('file.txt', 32768, 0)] +[('foo_dir', 16384, 0), ('moved-to-root.txt', 32768, 0)] +[('foo_dir', 16384, 0), ('moved-to-root.txt', 32768, 0)] new text -['moved-to-root.txt'] +[('moved-to-root.txt', 32768, 0)] ENOSPC: True diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index 77d349212..3e66758c3 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -53,10 +53,10 @@ uos.mount(vfs, "/ramdisk") with vfs.open("file.txt", "w") as f: f.write("hello!") -print(vfs.listdir()) +print(list(vfs.ilistdir())) with vfs.open("file.txt", "r") as f: print(f.read()) vfs.remove("file.txt") -print(vfs.listdir()) +print(list(vfs.ilistdir())) diff --git a/tests/extmod/vfs_fat_oldproto.py.exp b/tests/extmod/vfs_fat_oldproto.py.exp index a389a5217..ab8338cbb 100644 --- a/tests/extmod/vfs_fat_oldproto.py.exp +++ b/tests/extmod/vfs_fat_oldproto.py.exp @@ -1,3 +1,3 @@ -['file.txt'] +[('file.txt', 32768, 0)] hello! [] diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 81f9418b2..89b40e3a2 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -65,7 +65,7 @@ except OSError as e: with vfs.open("foo_file.txt", "w") as f: f.write("hello!") -print(vfs.listdir()) +print(list(vfs.ilistdir())) print("stat root:", vfs.stat("/")) print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs @@ -76,7 +76,7 @@ print(b"hello!" in bdev.data) vfs.mkdir("foo_dir") vfs.chdir("foo_dir") print("getcwd:", vfs.getcwd()) -print(vfs.listdir()) +print(list(vfs.ilistdir())) with vfs.open("sub_file.txt", "w") as f: f.write("subdir file") @@ -92,4 +92,4 @@ print("getcwd:", vfs.getcwd()) uos.umount(vfs) vfs = uos.VfsFat(bdev) -print(vfs.listdir(b"")) +print(list(vfs.ilistdir(b""))) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index 137db5841..6298a7efd 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -3,7 +3,7 @@ True statvfs: (512, 512, 16, 16, 16, 0, 0, 0, 0, 255) getcwd: / True -['foo_file.txt'] +[('foo_file.txt', 32768, 0)] stat root: (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) stat file: (32768, 0, 0, 0, 0, 0, 6) True @@ -12,4 +12,4 @@ getcwd: /foo_dir [] True getcwd: / -[b'foo_file.txt', b'foo_dir'] +[(b'foo_file.txt', 32768, 0), (b'foo_dir', 16384, 0)] -- cgit v1.2.3 From cda09727b451b6b928cc0129c4be7d3127f1aaad Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 13 May 2017 19:10:15 +1000 Subject: tests/extmod/vfs_fat: Add test for ilistdir of a non-existent directory. --- tests/extmod/vfs_fat_ramdisk.py | 6 ++++++ tests/extmod/vfs_fat_ramdisk.py.exp | 1 + 2 files changed, 7 insertions(+) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 89b40e3a2..fe72a8bef 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -93,3 +93,9 @@ uos.umount(vfs) vfs = uos.VfsFat(bdev) print(list(vfs.ilistdir(b""))) + +# list a non-existent directory +try: + vfs.ilistdir(b"no_exist") +except OSError as e: + print('ENOENT:', e.args[0] == uerrno.ENOENT) diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp index 6298a7efd..ccd0f7134 100644 --- a/tests/extmod/vfs_fat_ramdisk.py.exp +++ b/tests/extmod/vfs_fat_ramdisk.py.exp @@ -13,3 +13,4 @@ getcwd: /foo_dir True getcwd: / [(b'foo_file.txt', 32768, 0), (b'foo_dir', 16384, 0)] +ENOENT: True -- cgit v1.2.3 From 054a381d7c9f3f5b706475a934299c541efdd746 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 13 May 2017 14:13:24 +0300 Subject: tests/extmod/vfs_fat_more: Make skippable is uos is not available. Fixes Zephyr tests. --- tests/extmod/vfs_fat_more.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py index 6c2df528f..dacb21553 100644 --- a/tests/extmod/vfs_fat_more.py +++ b/tests/extmod/vfs_fat_more.py @@ -1,10 +1,15 @@ import sys import uerrno try: - import uos_vfs as uos - open = uos.vfs_open + try: + import uos_vfs as uos + open = uos.vfs_open + except ImportError: + import uos except ImportError: - import uos + print("SKIP") + sys.exit() + try: uos.VfsFat except AttributeError: -- cgit v1.2.3 From f6ef8e3f17222a397e02f93a8b0d283e0f6c9793 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Jun 2017 15:17:45 +1000 Subject: extmod/vfs: Allow to statvfs the root directory. --- extmod/vfs.c | 26 ++++++++++++++++++++++++++ tests/extmod/vfs_basic.py | 5 +++++ tests/extmod/vfs_basic.py.exp | 4 ++++ 3 files changed, 35 insertions(+) (limited to 'tests/extmod') diff --git a/extmod/vfs.c b/extmod/vfs.c index f158bd387..b75ec7516 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -421,6 +421,32 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_stat_obj, mp_vfs_stat); mp_obj_t mp_vfs_statvfs(mp_obj_t path_in) { mp_obj_t path_out; mp_vfs_mount_t *vfs = lookup_path(path_in, &path_out); + if (vfs == MP_VFS_ROOT) { + // statvfs called on the root directory, see if there's anything mounted there + for (vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { + if (vfs->len == 1) { + break; + } + } + + // If there's nothing mounted at root then return a mostly-empty tuple + if (vfs == NULL) { + mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); + + // fill in: bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flags + for (int i = 0; i <= 8; ++i) { + t->items[i] = MP_OBJ_NEW_SMALL_INT(0); + } + + // Put something sensible in f_namemax + t->items[9] = MP_OBJ_NEW_SMALL_INT(MICROPY_ALLOC_PATH_MAX); + + return MP_OBJ_FROM_PTR(t); + } + + // VFS mounted at root so delegate the call to it + path_out = MP_OBJ_NEW_QSTR(MP_QSTR__slash_); + } return mp_vfs_proxy_call(vfs, MP_QSTR_statvfs, 1, &path_out); } MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_statvfs_obj, mp_vfs_statvfs); diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index a3b2f3c29..fc016b8d5 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -57,6 +57,9 @@ for path in uos.listdir('/'): # stat root dir print(uos.stat('/')) +# statvfs root dir +print(uos.statvfs('/')) + # getcwd when in root dir print(uos.getcwd()) @@ -128,6 +131,8 @@ except OSError: # root dir uos.mount(Filesystem(3), '/') +print(uos.stat('/')) +print(uos.statvfs('/')) print(uos.listdir()) open('test') diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp index 8a23aa8ae..f8ecd07ea 100644 --- a/tests/extmod/vfs_basic.py.exp +++ b/tests/extmod/vfs_basic.py.exp @@ -1,4 +1,5 @@ (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) +(0, 0, 0, 0, 0, 0, 0, 0, 0, 4096) / 1 mount False False ['test_mnt'] @@ -36,6 +37,9 @@ OSError 2 umount OSError 3 mount False False +(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) +3 statvfs / +(3,) 3 ilistdir / ['a3'] 3 open test r -- cgit v1.2.3 From 85d809d1f4e35a511e0a56b3411126e05a31c01b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 10 Jun 2017 20:14:16 +0300 Subject: tests: Convert remaining "sys.exit()" to "raise SystemExit". --- tests/extmod/btree1.py | 3 +-- tests/extmod/framebuf1.py | 3 +-- tests/extmod/framebuf16.py | 3 +-- tests/extmod/framebuf4.py | 3 +-- tests/extmod/machine1.py | 3 +-- tests/extmod/machine_pinbase.py | 3 +-- tests/extmod/machine_pulse.py | 3 +-- tests/extmod/machine_signal.py | 3 +-- tests/extmod/time_ms_us.py | 3 +-- tests/extmod/ubinascii_a2b_base64.py | 3 +-- tests/extmod/ubinascii_b2a_base64.py | 3 +-- tests/extmod/ubinascii_crc32.py | 6 ++---- tests/extmod/ubinascii_hexlify.py | 3 +-- tests/extmod/ubinascii_micropython.py | 3 +-- tests/extmod/ubinascii_unhexlify.py | 3 +-- tests/extmod/uctypes_32bit_intbig.py | 3 +-- tests/extmod/uctypes_array_assign_le.py | 3 +-- tests/extmod/uctypes_array_assign_native_le.py | 4 ++-- tests/extmod/uctypes_array_assign_native_le_intbig.py | 4 ++-- tests/extmod/uctypes_bytearray.py | 3 +-- tests/extmod/uctypes_le.py | 3 +-- tests/extmod/uctypes_le_float.py | 3 +-- tests/extmod/uctypes_native_float.py | 3 +-- tests/extmod/uctypes_native_le.py | 4 ++-- tests/extmod/uctypes_print.py | 3 +-- tests/extmod/uctypes_ptr_le.py | 4 ++-- tests/extmod/uctypes_ptr_native_le.py | 4 ++-- tests/extmod/uctypes_sizeof.py | 3 +-- tests/extmod/uctypes_sizeof_native.py | 3 +-- tests/extmod/uhashlib_sha1.py | 5 ++--- tests/extmod/uhashlib_sha256.py | 3 +-- tests/extmod/uheapq1.py | 3 +-- tests/extmod/ujson_dumps.py | 3 +-- tests/extmod/ujson_dumps_extra.py | 3 +-- tests/extmod/ujson_dumps_float.py | 3 +-- tests/extmod/ujson_load.py | 3 +-- tests/extmod/ujson_loads.py | 3 +-- tests/extmod/ujson_loads_float.py | 3 +-- tests/extmod/urandom_basic.py | 3 +-- tests/extmod/urandom_extra.py | 6 ++---- tests/extmod/ure1.py | 3 +-- tests/extmod/ure_debug.py | 3 +-- tests/extmod/ure_error.py | 3 +-- tests/extmod/ure_group.py | 3 +-- tests/extmod/ure_namedclass.py | 3 +-- tests/extmod/ure_split.py | 3 +-- tests/extmod/ure_split_empty.py | 3 +-- tests/extmod/ure_split_notimpl.py | 3 +-- tests/extmod/ussl_basic.py | 3 +-- tests/extmod/utimeq1.py | 3 +-- tests/extmod/utimeq_stable.py | 3 +-- tests/extmod/uzlib_decompio.py | 3 +-- tests/extmod/uzlib_decompio_gz.py | 3 +-- tests/extmod/uzlib_decompress.py | 3 +-- tests/extmod/vfs_basic.py | 3 +-- tests/extmod/vfs_fat_fileio1.py | 7 +++---- tests/extmod/vfs_fat_fileio2.py | 7 +++---- tests/extmod/vfs_fat_more.py | 7 +++---- tests/extmod/vfs_fat_oldproto.py | 7 +++---- tests/extmod/vfs_fat_ramdisk.py | 7 +++---- tests/extmod/websocket_basic.py | 3 +-- tests/io/buffered_writer.py | 3 +-- tests/io/open_append.py | 3 +-- tests/io/open_plus.py | 3 +-- tests/io/resource_stream.py | 2 +- tests/io/write_ext.py | 3 +-- tests/jni/list.py | 3 +-- tests/jni/object.py | 3 +-- tests/jni/system_out.py | 3 +-- tests/micropython/heapalloc_bytesio.py | 3 +-- tests/micropython/heapalloc_iter.py | 3 +-- tests/micropython/heapalloc_traceback.py | 3 +-- tests/micropython/heapalloc_traceback.py.exp | 2 +- tests/micropython/kbd_intr.py | 3 +-- tests/micropython/schedule.py | 3 +-- tests/misc/non_compliant.py | 3 +-- tests/misc/print_exception.py | 2 +- tests/misc/recursive_data.py | 3 +-- tests/misc/recursive_iternext.py | 3 +-- tests/misc/sys_exc_info.py | 2 +- tests/pyb/can.py | 3 +-- tests/pyb/dac.py | 3 +-- tests/pyb/pyb_f405.py | 3 +-- tests/pyb/pyb_f411.py | 3 +-- tests/unix/extra_coverage.py | 3 +-- tests/unix/ffi_callback.py | 3 +-- tests/unix/ffi_float.py | 3 +-- tests/unix/ffi_float2.py | 5 ++--- 88 files changed, 107 insertions(+), 188 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py index 2127554db..59638ef0a 100644 --- a/tests/extmod/btree1.py +++ b/tests/extmod/btree1.py @@ -4,8 +4,7 @@ try: import uerrno except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit #f = open("_test.db", "w+b") f = uio.BytesIO() diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index 990b0b120..2c1366522 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -2,8 +2,7 @@ try: import framebuf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit w = 5 h = 16 diff --git a/tests/extmod/framebuf16.py b/tests/extmod/framebuf16.py index 3aa1d34de..fe81f7f93 100644 --- a/tests/extmod/framebuf16.py +++ b/tests/extmod/framebuf16.py @@ -2,8 +2,7 @@ try: import framebuf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit def printbuf(): print("--8<--") diff --git a/tests/extmod/framebuf4.py b/tests/extmod/framebuf4.py index 641f5bfc5..8358fa55b 100644 --- a/tests/extmod/framebuf4.py +++ b/tests/extmod/framebuf4.py @@ -2,8 +2,7 @@ try: import framebuf except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit def printbuf(): print("--8<--") diff --git a/tests/extmod/machine1.py b/tests/extmod/machine1.py index e0c561168..6ff38cc05 100644 --- a/tests/extmod/machine1.py +++ b/tests/extmod/machine1.py @@ -8,8 +8,7 @@ try: machine.mem8 except: print("SKIP") - import sys - sys.exit() + raise SystemExit print(machine.mem8) diff --git a/tests/extmod/machine_pinbase.py b/tests/extmod/machine_pinbase.py index 5e82823ec..e91775504 100644 --- a/tests/extmod/machine_pinbase.py +++ b/tests/extmod/machine_pinbase.py @@ -6,8 +6,7 @@ try: machine.PinBase except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit class MyPin(machine.PinBase): diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py index 6491b5409..d525974e0 100644 --- a/tests/extmod/machine_pulse.py +++ b/tests/extmod/machine_pulse.py @@ -7,8 +7,7 @@ try: machine.time_pulse_us except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit class ConstPin(machine.PinBase): diff --git a/tests/extmod/machine_signal.py b/tests/extmod/machine_signal.py index 96b8f43c7..53f4f5890 100644 --- a/tests/extmod/machine_signal.py +++ b/tests/extmod/machine_signal.py @@ -9,8 +9,7 @@ try: machine.Signal except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit class Pin(machine.PinBase): def __init__(self): diff --git a/tests/extmod/time_ms_us.py b/tests/extmod/time_ms_us.py index 2078f1bb5..31f07d31b 100644 --- a/tests/extmod/time_ms_us.py +++ b/tests/extmod/time_ms_us.py @@ -1,10 +1,9 @@ -import sys import utime try: utime.sleep_ms except AttributeError: print("SKIP") - sys.exit() + raise SystemExit utime.sleep_ms(1) utime.sleep_us(1) diff --git a/tests/extmod/ubinascii_a2b_base64.py b/tests/extmod/ubinascii_a2b_base64.py index 58eb0b50b..b35f26591 100644 --- a/tests/extmod/ubinascii_a2b_base64.py +++ b/tests/extmod/ubinascii_a2b_base64.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.a2b_base64(b'')) print(binascii.a2b_base64(b'Zg==')) diff --git a/tests/extmod/ubinascii_b2a_base64.py b/tests/extmod/ubinascii_b2a_base64.py index 1c0c30311..f4bb69fe0 100644 --- a/tests/extmod/ubinascii_b2a_base64.py +++ b/tests/extmod/ubinascii_b2a_base64.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.b2a_base64(b'')) print(binascii.b2a_base64(b'f')) diff --git a/tests/extmod/ubinascii_crc32.py b/tests/extmod/ubinascii_crc32.py index b82c44d6b..89664a9b3 100644 --- a/tests/extmod/ubinascii_crc32.py +++ b/tests/extmod/ubinascii_crc32.py @@ -4,16 +4,14 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: binascii.crc32 except AttributeError: print("SKIP") - import sys - sys.exit() + raise SystemExit print(hex(binascii.crc32(b'The quick brown fox jumps over the lazy dog'))) print(hex(binascii.crc32(b'\x00' * 32))) diff --git a/tests/extmod/ubinascii_hexlify.py b/tests/extmod/ubinascii_hexlify.py index 5d70bda96..bc9928747 100644 --- a/tests/extmod/ubinascii_hexlify.py +++ b/tests/extmod/ubinascii_hexlify.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07')) print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')) diff --git a/tests/extmod/ubinascii_micropython.py b/tests/extmod/ubinascii_micropython.py index 96f566bd1..a4c00a2cb 100644 --- a/tests/extmod/ubinascii_micropython.py +++ b/tests/extmod/ubinascii_micropython.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # two arguments supported in uPy but not CPython a = binascii.hexlify(b'123', ':') diff --git a/tests/extmod/ubinascii_unhexlify.py b/tests/extmod/ubinascii_unhexlify.py index e669789ba..865abfe3a 100644 --- a/tests/extmod/ubinascii_unhexlify.py +++ b/tests/extmod/ubinascii_unhexlify.py @@ -4,9 +4,8 @@ try: except ImportError: import binascii except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(binascii.unhexlify(b'0001020304050607')) print(binascii.unhexlify(b'08090a0b0c0d0e0f')) diff --git a/tests/extmod/uctypes_32bit_intbig.py b/tests/extmod/uctypes_32bit_intbig.py index a082dc370..6b4d3d76c 100644 --- a/tests/extmod/uctypes_32bit_intbig.py +++ b/tests/extmod/uctypes_32bit_intbig.py @@ -3,9 +3,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit buf = b"12345678abcd" struct = uctypes.struct( diff --git a/tests/extmod/uctypes_array_assign_le.py b/tests/extmod/uctypes_array_assign_le.py index bae467d09..6afa7e0a2 100644 --- a/tests/extmod/uctypes_array_assign_le.py +++ b/tests/extmod/uctypes_array_assign_le.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py index f0ecc0dad..a538bf9ad 100644 --- a/tests/extmod/uctypes_array_assign_native_le.py +++ b/tests/extmod/uctypes_array_assign_native_le.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py b/tests/extmod/uctypes_array_assign_native_le_intbig.py index f29a3b66e..84dfba0e2 100644 --- a/tests/extmod/uctypes_array_assign_native_le_intbig.py +++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_bytearray.py b/tests/extmod/uctypes_bytearray.py index bf7845ab2..61c7da271 100644 --- a/tests/extmod/uctypes_bytearray.py +++ b/tests/extmod/uctypes_bytearray.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2), diff --git a/tests/extmod/uctypes_le.py b/tests/extmod/uctypes_le.py index 829beda58..7df5ac090 100644 --- a/tests/extmod/uctypes_le.py +++ b/tests/extmod/uctypes_le.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "s0": uctypes.UINT16 | 0, diff --git a/tests/extmod/uctypes_le_float.py b/tests/extmod/uctypes_le_float.py index a61305ba8..84ff2b84c 100644 --- a/tests/extmod/uctypes_le_float.py +++ b/tests/extmod/uctypes_le_float.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "f32": uctypes.FLOAT32 | 0, diff --git a/tests/extmod/uctypes_native_float.py b/tests/extmod/uctypes_native_float.py index 80cb54383..acef47036 100644 --- a/tests/extmod/uctypes_native_float.py +++ b/tests/extmod/uctypes_native_float.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { "f32": uctypes.FLOAT32 | 0, diff --git a/tests/extmod/uctypes_native_le.py b/tests/extmod/uctypes_native_le.py index 5900224d4..8bba03b38 100644 --- a/tests/extmod/uctypes_native_le.py +++ b/tests/extmod/uctypes_native_le.py @@ -6,11 +6,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { diff --git a/tests/extmod/uctypes_print.py b/tests/extmod/uctypes_print.py index 76a009dc7..c310238e5 100644 --- a/tests/extmod/uctypes_print.py +++ b/tests/extmod/uctypes_print.py @@ -2,9 +2,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # we use an address of "0" because we just want to print something deterministic # and don't actually need to set/get any values in the struct diff --git a/tests/extmod/uctypes_ptr_le.py b/tests/extmod/uctypes_ptr_le.py index e8a6243ce..056e45650 100644 --- a/tests/extmod/uctypes_ptr_le.py +++ b/tests/extmod/uctypes_ptr_le.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { "ptr": (uctypes.PTR | 0, uctypes.UINT8), diff --git a/tests/extmod/uctypes_ptr_native_le.py b/tests/extmod/uctypes_ptr_native_le.py index 9b016c04d..24508b1cb 100644 --- a/tests/extmod/uctypes_ptr_native_le.py +++ b/tests/extmod/uctypes_ptr_native_le.py @@ -3,11 +3,11 @@ try: import uctypes except ImportError: print("SKIP") - sys.exit() + raise SystemExit if sys.byteorder != "little": print("SKIP") - sys.exit() + raise SystemExit desc = { diff --git a/tests/extmod/uctypes_sizeof.py b/tests/extmod/uctypes_sizeof.py index 266cd0694..5a6adb437 100644 --- a/tests/extmod/uctypes_sizeof.py +++ b/tests/extmod/uctypes_sizeof.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit desc = { # arr is array at offset 0, of UINT8 elements, array size is 2 diff --git a/tests/extmod/uctypes_sizeof_native.py b/tests/extmod/uctypes_sizeof_native.py index f676c8c6d..32c740e77 100644 --- a/tests/extmod/uctypes_sizeof_native.py +++ b/tests/extmod/uctypes_sizeof_native.py @@ -1,9 +1,8 @@ try: import uctypes except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit S1 = {} assert uctypes.sizeof(S1) == 0 diff --git a/tests/extmod/uhashlib_sha1.py b/tests/extmod/uhashlib_sha1.py index f12fc649a..4f7066899 100644 --- a/tests/extmod/uhashlib_sha1.py +++ b/tests/extmod/uhashlib_sha1.py @@ -1,4 +1,3 @@ -import sys try: import uhashlib as hashlib except ImportError: @@ -8,14 +7,14 @@ except ImportError: # This is neither uPy, nor cPy, so must be uPy with # uhashlib module disabled. print("SKIP") - sys.exit() + raise SystemExit try: hashlib.sha1 except AttributeError: # SHA1 is only available on some ports print("SKIP") - sys.exit() + raise SystemExit sha1 = hashlib.sha1(b'hello') sha1.update(b'world') diff --git a/tests/extmod/uhashlib_sha256.py b/tests/extmod/uhashlib_sha256.py index ff51f2ffa..3200e8f5c 100644 --- a/tests/extmod/uhashlib_sha256.py +++ b/tests/extmod/uhashlib_sha256.py @@ -1,4 +1,3 @@ -import sys try: import uhashlib as hashlib except ImportError: @@ -8,7 +7,7 @@ except ImportError: # This is neither uPy, nor cPy, so must be uPy with # uhashlib module disabled. print("SKIP") - sys.exit() + raise SystemExit h = hashlib.sha256() diff --git a/tests/extmod/uheapq1.py b/tests/extmod/uheapq1.py index 4b0e5de57..7c1fe4e1e 100644 --- a/tests/extmod/uheapq1.py +++ b/tests/extmod/uheapq1.py @@ -4,9 +4,8 @@ except: try: import heapq except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: heapq.heappop([]) diff --git a/tests/extmod/ujson_dumps.py b/tests/extmod/ujson_dumps.py index 4a02f5170..d73271801 100644 --- a/tests/extmod/ujson_dumps.py +++ b/tests/extmod/ujson_dumps.py @@ -4,9 +4,8 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(json.dumps(False)) print(json.dumps(True)) diff --git a/tests/extmod/ujson_dumps_extra.py b/tests/extmod/ujson_dumps_extra.py index a52e8224c..21a388c32 100644 --- a/tests/extmod/ujson_dumps_extra.py +++ b/tests/extmod/ujson_dumps_extra.py @@ -3,8 +3,7 @@ try: import ujson except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(ujson.dumps(b'1234')) diff --git a/tests/extmod/ujson_dumps_float.py b/tests/extmod/ujson_dumps_float.py index d949ea6dd..e8cceb6f1 100644 --- a/tests/extmod/ujson_dumps_float.py +++ b/tests/extmod/ujson_dumps_float.py @@ -4,8 +4,7 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(json.dumps(1.2)) diff --git a/tests/extmod/ujson_load.py b/tests/extmod/ujson_load.py index 901132a5f..9725ab2dd 100644 --- a/tests/extmod/ujson_load.py +++ b/tests/extmod/ujson_load.py @@ -6,9 +6,8 @@ except: from io import StringIO import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit print(json.load(StringIO('null'))) print(json.load(StringIO('"abc\\u0064e"'))) diff --git a/tests/extmod/ujson_loads.py b/tests/extmod/ujson_loads.py index b2e18e3af..adba3c068 100644 --- a/tests/extmod/ujson_loads.py +++ b/tests/extmod/ujson_loads.py @@ -4,9 +4,8 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def my_print(o): if isinstance(o, dict): diff --git a/tests/extmod/ujson_loads_float.py b/tests/extmod/ujson_loads_float.py index b20a412ff..f1b8cc364 100644 --- a/tests/extmod/ujson_loads_float.py +++ b/tests/extmod/ujson_loads_float.py @@ -4,9 +4,8 @@ except ImportError: try: import json except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def my_print(o): print('%.3f' % o) diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/urandom_basic.py index 885b8517f..57e6b26cb 100644 --- a/tests/extmod/urandom_basic.py +++ b/tests/extmod/urandom_basic.py @@ -4,9 +4,8 @@ except ImportError: try: import random except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # check getrandbits returns a value within the bit range for b in (1, 2, 3, 4, 16, 32): diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py index 925dd0dbc..f5a34e168 100644 --- a/tests/extmod/urandom_extra.py +++ b/tests/extmod/urandom_extra.py @@ -4,16 +4,14 @@ except ImportError: try: import random except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: random.randint except AttributeError: - import sys print('SKIP') - sys.exit() + raise SystemExit print('randrange') for i in range(50): diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py index a867f1751..1f38b8087 100644 --- a/tests/extmod/ure1.py +++ b/tests/extmod/ure1.py @@ -4,9 +4,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile(".+") m = r.match("abc") diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py index 252df21e3..cfb264bb6 100644 --- a/tests/extmod/ure_debug.py +++ b/tests/extmod/ure_debug.py @@ -2,8 +2,7 @@ try: import ure except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit ure.compile('^a|b[0-9]\w$', ure.DEBUG) diff --git a/tests/extmod/ure_error.py b/tests/extmod/ure_error.py index 3f16f9158..f52f735c7 100644 --- a/tests/extmod/ure_error.py +++ b/tests/extmod/ure_error.py @@ -6,9 +6,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def test_re(r): try: diff --git a/tests/extmod/ure_group.py b/tests/extmod/ure_group.py index 98aae2a73..4e39468c5 100644 --- a/tests/extmod/ure_group.py +++ b/tests/extmod/ure_group.py @@ -6,9 +6,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def print_groups(match): print('----') diff --git a/tests/extmod/ure_namedclass.py b/tests/extmod/ure_namedclass.py index e233f17c8..215d09613 100644 --- a/tests/extmod/ure_namedclass.py +++ b/tests/extmod/ure_namedclass.py @@ -6,9 +6,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit def print_groups(match): print('----') diff --git a/tests/extmod/ure_split.py b/tests/extmod/ure_split.py index 1e411c27c..317ca9892 100644 --- a/tests/extmod/ure_split.py +++ b/tests/extmod/ure_split.py @@ -4,9 +4,8 @@ except ImportError: try: import re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile(" ") s = r.split("a b c foobar") diff --git a/tests/extmod/ure_split_empty.py b/tests/extmod/ure_split_empty.py index ad6334eba..76ce97ea6 100644 --- a/tests/extmod/ure_split_empty.py +++ b/tests/extmod/ure_split_empty.py @@ -7,9 +7,8 @@ try: import ure as re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile(" *") s = r.split("a b c foobar") diff --git a/tests/extmod/ure_split_notimpl.py b/tests/extmod/ure_split_notimpl.py index eca3ea512..da6e9652d 100644 --- a/tests/extmod/ure_split_notimpl.py +++ b/tests/extmod/ure_split_notimpl.py @@ -1,9 +1,8 @@ try: import ure as re except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit r = re.compile('( )') try: diff --git a/tests/extmod/ussl_basic.py b/tests/extmod/ussl_basic.py index e9d435bca..9f8019a0b 100644 --- a/tests/extmod/ussl_basic.py +++ b/tests/extmod/ussl_basic.py @@ -5,8 +5,7 @@ try: import ussl as ssl except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit # create in client mode try: diff --git a/tests/extmod/utimeq1.py b/tests/extmod/utimeq1.py index 68d69e25e..dc7f3b660 100644 --- a/tests/extmod/utimeq1.py +++ b/tests/extmod/utimeq1.py @@ -5,8 +5,7 @@ try: from utimeq import utimeq except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit DEBUG = 0 diff --git a/tests/extmod/utimeq_stable.py b/tests/extmod/utimeq_stable.py index 9f6ba76d4..9fb522d51 100644 --- a/tests/extmod/utimeq_stable.py +++ b/tests/extmod/utimeq_stable.py @@ -2,8 +2,7 @@ try: from utimeq import utimeq except ImportError: print("SKIP") - import sys - sys.exit() + raise SystemExit h = utimeq(10) diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py index 6f07c048c..112a82597 100644 --- a/tests/extmod/uzlib_decompio.py +++ b/tests/extmod/uzlib_decompio.py @@ -2,9 +2,8 @@ try: import uzlib as zlib import uio as io except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # Raw DEFLATE bitstream diff --git a/tests/extmod/uzlib_decompio_gz.py b/tests/extmod/uzlib_decompio_gz.py index 7572e9693..02087f763 100644 --- a/tests/extmod/uzlib_decompio_gz.py +++ b/tests/extmod/uzlib_decompio_gz.py @@ -2,9 +2,8 @@ try: import uzlib as zlib import uio as io except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # gzip bitstream diff --git a/tests/extmod/uzlib_decompress.py b/tests/extmod/uzlib_decompress.py index 10121ee7e..63247955c 100644 --- a/tests/extmod/uzlib_decompress.py +++ b/tests/extmod/uzlib_decompress.py @@ -4,9 +4,8 @@ except ImportError: try: import uzlib as zlib except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit PATTERNS = [ # Packed results produced by CPy's zlib.compress() diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index fc016b8d5..995874824 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -9,8 +9,7 @@ try: uos.mount except (ImportError, AttributeError): print("SKIP") - import sys - sys.exit() + raise SystemExit class Filesystem: diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index 9036df7a5..d19df120b 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -8,13 +7,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -46,7 +45,7 @@ try: bdev = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) vfs = uos.VfsFat(bdev) diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index b2a0ba70f..b5adb75c9 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -8,13 +7,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -46,7 +45,7 @@ try: bdev = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) vfs = uos.VfsFat(bdev) diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py index dacb21553..baec96787 100644 --- a/tests/extmod/vfs_fat_more.py +++ b/tests/extmod/vfs_fat_more.py @@ -1,4 +1,3 @@ -import sys import uerrno try: try: @@ -8,13 +7,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -47,7 +46,7 @@ try: bdev2 = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit # first we umount any existing mount points the target may have try: diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index 3e66758c3..ef4f1da78 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -7,13 +6,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS_OLD: @@ -43,7 +42,7 @@ try: bdev = RAMFS_OLD(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) vfs = uos.VfsFat(bdev) diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index fe72a8bef..801c69786 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,4 +1,3 @@ -import sys try: import uerrno try: @@ -7,13 +6,13 @@ try: import uos except ImportError: print("SKIP") - sys.exit() + raise SystemExit try: uos.VfsFat except AttributeError: print("SKIP") - sys.exit() + raise SystemExit class RAMFS: @@ -45,7 +44,7 @@ try: bdev = RAMFS(50) except MemoryError: print("SKIP") - sys.exit() + raise SystemExit uos.VfsFat.mkfs(bdev) diff --git a/tests/extmod/websocket_basic.py b/tests/extmod/websocket_basic.py index 770836c8e..9a80503a0 100644 --- a/tests/extmod/websocket_basic.py +++ b/tests/extmod/websocket_basic.py @@ -3,9 +3,8 @@ try: import uerrno import websocket except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # put raw data in the stream and do a websocket read def ws_read(msg, sz): diff --git a/tests/io/buffered_writer.py b/tests/io/buffered_writer.py index bb7b4e8db..c2cedb991 100644 --- a/tests/io/buffered_writer.py +++ b/tests/io/buffered_writer.py @@ -4,9 +4,8 @@ try: io.BytesIO io.BufferedWriter except AttributeError: - import sys print('SKIP') - sys.exit() + raise SystemExit bts = io.BytesIO() buf = io.BufferedWriter(bts, 8) diff --git a/tests/io/open_append.py b/tests/io/open_append.py index 2120b72f0..a696823bc 100644 --- a/tests/io/open_append.py +++ b/tests/io/open_append.py @@ -1,4 +1,3 @@ -import sys try: import uos as os except ImportError: @@ -6,7 +5,7 @@ except ImportError: if not hasattr(os, "unlink"): print("SKIP") - sys.exit() + raise SystemExit # cleanup in case testfile exists try: diff --git a/tests/io/open_plus.py b/tests/io/open_plus.py index 98598ee67..bba96fa2f 100644 --- a/tests/io/open_plus.py +++ b/tests/io/open_plus.py @@ -1,4 +1,3 @@ -import sys try: import uos as os except ImportError: @@ -6,7 +5,7 @@ except ImportError: if not hasattr(os, "unlink"): print("SKIP") - sys.exit() + raise SystemExit # cleanup in case testfile exists try: diff --git a/tests/io/resource_stream.py b/tests/io/resource_stream.py index 86975f118..37d985bf1 100644 --- a/tests/io/resource_stream.py +++ b/tests/io/resource_stream.py @@ -5,7 +5,7 @@ try: uio.resource_stream except AttributeError: print('SKIP') - sys.exit() + raise SystemExit buf = uio.resource_stream("data", "file2") print(buf.read()) diff --git a/tests/io/write_ext.py b/tests/io/write_ext.py index 19b616174..5a6eaa35c 100644 --- a/tests/io/write_ext.py +++ b/tests/io/write_ext.py @@ -5,9 +5,8 @@ import uio try: uio.BytesIO except AttributeError: - import sys print('SKIP') - sys.exit() + raise SystemExit buf = uio.BytesIO() diff --git a/tests/jni/list.py b/tests/jni/list.py index 6725abb5a..d58181d0b 100644 --- a/tests/jni/list.py +++ b/tests/jni/list.py @@ -1,10 +1,9 @@ -import sys import jni try: ArrayList = jni.cls("java/util/ArrayList") except: print("SKIP") - sys.exit() + raise SystemExit l = ArrayList() print(l) diff --git a/tests/jni/object.py b/tests/jni/object.py index 6cf936c4d..aa67615ec 100644 --- a/tests/jni/object.py +++ b/tests/jni/object.py @@ -1,10 +1,9 @@ -import sys import jni try: Integer = jni.cls("java/lang/Integer") except: print("SKIP") - sys.exit() + raise SystemExit # Create object i = Integer(42) diff --git a/tests/jni/system_out.py b/tests/jni/system_out.py index 7a1f18030..86c4b9e11 100644 --- a/tests/jni/system_out.py +++ b/tests/jni/system_out.py @@ -1,9 +1,8 @@ -import sys try: import jni System = jni.cls("java/lang/System") except: print("SKIP") - sys.exit() + raise SystemExit System.out.println("Hello, Java!") diff --git a/tests/micropython/heapalloc_bytesio.py b/tests/micropython/heapalloc_bytesio.py index 2a8d50abe..4aae2abf0 100644 --- a/tests/micropython/heapalloc_bytesio.py +++ b/tests/micropython/heapalloc_bytesio.py @@ -1,9 +1,8 @@ try: import uio except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit import micropython diff --git a/tests/micropython/heapalloc_iter.py b/tests/micropython/heapalloc_iter.py index 45d3519e4..79461f999 100644 --- a/tests/micropython/heapalloc_iter.py +++ b/tests/micropython/heapalloc_iter.py @@ -2,9 +2,8 @@ try: import array except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit try: from micropython import heap_lock, heap_unlock diff --git a/tests/micropython/heapalloc_traceback.py b/tests/micropython/heapalloc_traceback.py index b3795293f..f4212b6ce 100644 --- a/tests/micropython/heapalloc_traceback.py +++ b/tests/micropython/heapalloc_traceback.py @@ -5,9 +5,8 @@ import sys try: import uio except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # preallocate exception instance with some room for a traceback global_exc = StopIteration() diff --git a/tests/micropython/heapalloc_traceback.py.exp b/tests/micropython/heapalloc_traceback.py.exp index facd0af13..291bbd697 100644 --- a/tests/micropython/heapalloc_traceback.py.exp +++ b/tests/micropython/heapalloc_traceback.py.exp @@ -1,5 +1,5 @@ StopIteration Traceback (most recent call last): - File , line 23, in test + File , line 22, in test StopIteration: diff --git a/tests/micropython/kbd_intr.py b/tests/micropython/kbd_intr.py index a7ce7464b..879c9a229 100644 --- a/tests/micropython/kbd_intr.py +++ b/tests/micropython/kbd_intr.py @@ -6,8 +6,7 @@ try: micropython.kbd_intr except AttributeError: print('SKIP') - import sys - sys.exit() + raise SystemExit # just check we can actually call it micropython.kbd_intr(3) diff --git a/tests/micropython/schedule.py b/tests/micropython/schedule.py index 3d584eea4..74f90cb2d 100644 --- a/tests/micropython/schedule.py +++ b/tests/micropython/schedule.py @@ -6,8 +6,7 @@ try: micropython.schedule except AttributeError: print('SKIP') - import sys - sys.exit() + raise SystemExit # Basic test of scheduling a function. diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py index 31074ab01..b4c90e9fc 100644 --- a/tests/misc/non_compliant.py +++ b/tests/misc/non_compliant.py @@ -4,9 +4,8 @@ try: import array import ustruct except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit # when super can't find self try: diff --git a/tests/misc/print_exception.py b/tests/misc/print_exception.py index b833a7981..9ab8e728b 100644 --- a/tests/misc/print_exception.py +++ b/tests/misc/print_exception.py @@ -6,7 +6,7 @@ try: import io except ImportError: print("SKIP") - sys.exit() + raise SystemExit if hasattr(sys, 'print_exception'): print_exception = sys.print_exception diff --git a/tests/misc/recursive_data.py b/tests/misc/recursive_data.py index 383018945..3b7fa5095 100644 --- a/tests/misc/recursive_data.py +++ b/tests/misc/recursive_data.py @@ -2,9 +2,8 @@ try: import uio as io except ImportError: - import sys print("SKIP") - sys.exit() + raise SystemExit l = [1, 2, 3, None] l[-1] = l diff --git a/tests/misc/recursive_iternext.py b/tests/misc/recursive_iternext.py index d90f17716..edb5a843f 100644 --- a/tests/misc/recursive_iternext.py +++ b/tests/misc/recursive_iternext.py @@ -6,9 +6,8 @@ try: max zip except: - import sys print("SKIP") - sys.exit() + raise SystemExit # We need to pick an N that is large enough to hit the recursion # limit, but not too large that we run out of heap memory. diff --git a/tests/misc/sys_exc_info.py b/tests/misc/sys_exc_info.py index de5b82562..4bb2c61e8 100644 --- a/tests/misc/sys_exc_info.py +++ b/tests/misc/sys_exc_info.py @@ -3,7 +3,7 @@ try: sys.exc_info except: print("SKIP") - sys.exit() + raise SystemExit def f(): print(sys.exc_info()[0:2]) diff --git a/tests/pyb/can.py b/tests/pyb/can.py index 7f2d070ec..0fd8c8368 100644 --- a/tests/pyb/can.py +++ b/tests/pyb/can.py @@ -2,8 +2,7 @@ try: from pyb import CAN except ImportError: print('SKIP') - import sys - sys.exit() + raise SystemExit import pyb diff --git a/tests/pyb/dac.py b/tests/pyb/dac.py index 942f30354..6f03bbc64 100644 --- a/tests/pyb/dac.py +++ b/tests/pyb/dac.py @@ -2,8 +2,7 @@ import pyb if not hasattr(pyb, 'DAC'): print('SKIP') - import sys - sys.exit() + raise SystemExit dac = pyb.DAC(1) print(dac) diff --git a/tests/pyb/pyb_f405.py b/tests/pyb/pyb_f405.py index 3c81fe109..2f161ae09 100644 --- a/tests/pyb/pyb_f405.py +++ b/tests/pyb/pyb_f405.py @@ -4,8 +4,7 @@ import os, pyb if not 'STM32F405' in os.uname().machine: print('SKIP') - import sys - sys.exit() + raise SystemExit print(pyb.freq()) print(type(pyb.rng())) diff --git a/tests/pyb/pyb_f411.py b/tests/pyb/pyb_f411.py index 328653965..50de30282 100644 --- a/tests/pyb/pyb_f411.py +++ b/tests/pyb/pyb_f411.py @@ -4,7 +4,6 @@ import os, pyb if not 'STM32F411' in os.uname().machine: print('SKIP') - import sys - sys.exit() + raise SystemExit print(pyb.freq()) diff --git a/tests/unix/extra_coverage.py b/tests/unix/extra_coverage.py index 870e7d5f2..7a496aa87 100644 --- a/tests/unix/extra_coverage.py +++ b/tests/unix/extra_coverage.py @@ -2,8 +2,7 @@ try: extra_coverage except NameError: print("SKIP") - import sys - sys.exit() + raise SystemExit import uerrno import uio diff --git a/tests/unix/ffi_callback.py b/tests/unix/ffi_callback.py index 7f8af15b3..23b058bce 100644 --- a/tests/unix/ffi_callback.py +++ b/tests/unix/ffi_callback.py @@ -1,9 +1,8 @@ -import sys try: import ffi except ImportError: print("SKIP") - sys.exit() + raise SystemExit def ffi_open(names): diff --git a/tests/unix/ffi_float.py b/tests/unix/ffi_float.py index cc12fa7ad..c92a39bcd 100644 --- a/tests/unix/ffi_float.py +++ b/tests/unix/ffi_float.py @@ -1,10 +1,9 @@ # test ffi float support -import sys try: import ffi except ImportError: print("SKIP") - sys.exit() + raise SystemExit def ffi_open(names): diff --git a/tests/unix/ffi_float2.py b/tests/unix/ffi_float2.py index d635a2714..721eb4d19 100644 --- a/tests/unix/ffi_float2.py +++ b/tests/unix/ffi_float2.py @@ -1,10 +1,9 @@ # test ffi float support -import sys try: import ffi except ImportError: print("SKIP") - sys.exit() + raise SystemExit def ffi_open(names): @@ -25,7 +24,7 @@ try: tgammaf = libm.func('f', 'tgammaf', 'f') except OSError: print("SKIP") - sys.exit() + raise SystemExit for fun in (tgammaf,): for val in (0.5, 1, 1.0, 1.5, 4, 4.0): -- cgit v1.2.3 From f55dcddbc79620f2dc2bbce0aa0e95570db9bc2c Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 11 Jun 2017 22:56:27 +1000 Subject: tests/extmod/vfs_basic: Allow test to pass on embedded targets. --- tests/extmod/vfs_basic.py | 4 ++-- tests/extmod/vfs_basic.py.exp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/extmod') diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 995874824..4fc67d34b 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -56,8 +56,8 @@ for path in uos.listdir('/'): # stat root dir print(uos.stat('/')) -# statvfs root dir -print(uos.statvfs('/')) +# statvfs root dir; verify that f_namemax has a sensible size +print(uos.statvfs('/')[9] >= 32) # getcwd when in root dir print(uos.getcwd()) diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp index f8ecd07ea..0ae2c2cc9 100644 --- a/tests/extmod/vfs_basic.py.exp +++ b/tests/extmod/vfs_basic.py.exp @@ -1,5 +1,5 @@ (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) -(0, 0, 0, 0, 0, 0, 0, 0, 0, 4096) +True / 1 mount False False ['test_mnt'] -- cgit v1.2.3