diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2017-08-25 13:00:27 -0700 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2017-08-25 16:00:27 -0400 |
| commit | 266be307770abe11c220eb493388807920914b7a (patch) | |
| tree | d3cff1ab1d0ecc1c55747a2f3ebdf21e450fa794 /tests | |
| parent | dd1c4fc8c776d060acd9b66865b1f961e939716a (diff) | |
atmel-samd: Introduce a nvm module for non-volatile byte-level memory access. (#203)
* atmel-samd: Introduce a nvm module for non-volatile byte-level memory access.
This allows for persisting small configuration values even when the file system
is read-only from CircuitPython.
Fixes #160
* Review feedback:
* Add tests.
* Fix non-zero index.
* Fix len()
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/circuitpython/nvm_not_present.py | 6 | ||||
| -rw-r--r-- | tests/circuitpython/nvm_present.py | 22 | ||||
| -rw-r--r-- | tests/skip_if.py | 11 |
3 files changed, 39 insertions, 0 deletions
diff --git a/tests/circuitpython/nvm_not_present.py b/tests/circuitpython/nvm_not_present.py new file mode 100644 index 000000000..141e60b01 --- /dev/null +++ b/tests/circuitpython/nvm_not_present.py @@ -0,0 +1,6 @@ +import skip_if +skip_if.board_not_in("gemma_m0", "trinket_m0") + +import microcontroller + +assert(microcontroller.nvm == None) diff --git a/tests/circuitpython/nvm_present.py b/tests/circuitpython/nvm_present.py new file mode 100644 index 000000000..a2cf3a22c --- /dev/null +++ b/tests/circuitpython/nvm_present.py @@ -0,0 +1,22 @@ +import skip_if +skip_if.board_not_in("metro_m0_express", "feather_m0_express", "circuitplayground_express") + +import microcontroller +import random +nvm = microcontroller.nvm + +len(nvm) + +single = random.randint(0, 255) +nvm[1] = single +assert(nvm[1] == single) + +nvm[0] = single +assert(nvm[0] == single) + +b = bytearray() +for i in range(10): + b.append(random.randint(0, 255)) + +microcontroller.nvm[10:20] = b +assert(microcontroller.nvm[10:20] == b) diff --git a/tests/skip_if.py b/tests/skip_if.py index f6d22b4c1..7b1e06871 100644 --- a/tests/skip_if.py +++ b/tests/skip_if.py @@ -52,6 +52,17 @@ def board_in(*board): if test_env.board in board: skip() +def board_not_in(*board): + try: + import test_env + except ImportError: + class Env: + def __init__(self, board): + self.board = board + test_env = Env("unknown") + if test_env.board not in board: + skip() + def no_cpython_compat(): try: try: |
