Skip to content

Commit

Permalink
tests/extmod: Add btree test for errors raised by btree DB library.
Browse files Browse the repository at this point in the history
This test now passes given the previous two commits.
  • Loading branch information
dpgeorge committed Apr 27, 2020
1 parent bd6ca15 commit 4fa6d93
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/extmod/btree_error.py
@@ -0,0 +1,42 @@
# Test that errno's propagate correctly through btree module.

try:
import btree, uio, uerrno

uio.IOBase
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit


class Device(uio.IOBase):
def __init__(self, read_ret=0, ioctl_ret=0):
self.read_ret = read_ret
self.ioctl_ret = ioctl_ret

def readinto(self, buf):
print("read", len(buf))
return self.read_ret

def ioctl(self, cmd, arg):
print("ioctl", cmd)
return self.ioctl_ret


# Invalid pagesize; errno comes from btree library
try:
db = btree.open(Device(), pagesize=511)
except OSError as er:
print("OSError", er.args[0] == uerrno.EINVAL)

# Valid pagesize, device returns error on read; errno comes from Device.readinto
try:
db = btree.open(Device(-1000), pagesize=512)
except OSError as er:
print(repr(er))

# Valid pagesize, device returns error on seek; errno comes from Device.ioctl
try:
db = btree.open(Device(0, -1001), pagesize=512)
except OSError as er:
print(repr(er))
6 changes: 6 additions & 0 deletions tests/extmod/btree_error.py.exp
@@ -0,0 +1,6 @@
OSError True
read 24
OSError(1000,)
read 24
ioctl 2
OSError(1001,)

0 comments on commit 4fa6d93

Please sign in to comment.