summaryrefslogtreecommitdiffstatshomepage
path: root/tests/esp32
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-01-18 16:32:31 +1100
committerDamien George <damien@micropython.org>2024-01-22 11:48:27 +1100
commit7bbcee3cf09a08199b3ffefb6c5e37208cba5f0a (patch)
tree6260794d34aaef18fcf5a6521ff3d103bc962dbf /tests/esp32
parentf93ffc2875c57ce3b8a608ebf5ae9050aa62f069 (diff)
downloadmicropython-7bbcee3cf09a08199b3ffefb6c5e37208cba5f0a.tar.gz
micropython-7bbcee3cf09a08199b3ffefb6c5e37208cba5f0a.zip
tests: Move port-specific test directories into tests/ports/ directory.
To keep them all together, mirroring the top-level directory structure. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/esp32')
-rw-r--r--tests/esp32/check_err_str.py43
-rw-r--r--tests/esp32/check_err_str.py.exp4
-rw-r--r--tests/esp32/esp32_idf_heap_info.py34
-rw-r--r--tests/esp32/esp32_idf_heap_info.py.exp5
-rw-r--r--tests/esp32/esp32_nvs.py67
-rw-r--r--tests/esp32/esp32_nvs.py.exp14
-rw-r--r--tests/esp32/partition_ota.py117
-rw-r--r--tests/esp32/partition_ota.py.exp15
-rw-r--r--tests/esp32/resolve_on_connect.py56
9 files changed, 0 insertions, 355 deletions
diff --git a/tests/esp32/check_err_str.py b/tests/esp32/check_err_str.py
deleted file mode 100644
index 055eecf747..0000000000
--- a/tests/esp32/check_err_str.py
+++ /dev/null
@@ -1,43 +0,0 @@
-try:
- from esp32 import Partition as p
- import micropython
-except ImportError:
- print("SKIP")
- raise SystemExit
-
-# try some vanilla OSError to get std error code
-try:
- open("this filedoesnotexist", "r")
- print("FAILED TO RAISE")
-except OSError as e:
- print(e)
-
-# try to make nvs partition bootable, which ain't gonna work
-part = p.find(type=p.TYPE_DATA)[0]
-fun = p.set_boot
-try:
- fun(part)
- print("FAILED TO RAISE")
-except OSError as e:
- print(e)
-
-# same but with out of memory condition by locking the heap
-exc = "FAILED TO RAISE"
-micropython.heap_lock()
-try:
- fun(part)
-except OSError as e:
- exc = e
-micropython.heap_unlock()
-print("exc:", exc) # exc empty due to no memory
-
-# same again but having an emergency buffer
-micropython.alloc_emergency_exception_buf(256)
-exc = "FAILED TO RAISE"
-micropython.heap_lock()
-try:
- fun(part)
-except Exception as e:
- exc = e
-micropython.heap_unlock()
-print(exc)
diff --git a/tests/esp32/check_err_str.py.exp b/tests/esp32/check_err_str.py.exp
deleted file mode 100644
index d4162d1be0..0000000000
--- a/tests/esp32/check_err_str.py.exp
+++ /dev/null
@@ -1,4 +0,0 @@
-[Errno 2] ENOENT
-(-5379, 'ESP_ERR_OTA_VALIDATE_FAILED')
-exc:
--5379
diff --git a/tests/esp32/esp32_idf_heap_info.py b/tests/esp32/esp32_idf_heap_info.py
deleted file mode 100644
index fdd89161f4..0000000000
--- a/tests/esp32/esp32_idf_heap_info.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# Test the esp32's esp32.idf_heap_info to return sane data
-try:
- import esp32
-except ImportError:
- print("SKIP")
- raise SystemExit
-
-
-# region tuple is: (size, free, largest free, min free)
-# we check that each region's size is > 0 and that the free amounts are smaller than the size
-def chk_heap(kind, regions):
- chk = [True, True, True, True]
- for r in regions:
- chk = [
- chk[0] and r[0] > 0,
- chk[1] and r[1] <= r[0],
- chk[2] and r[2] <= r[0],
- chk[3] and r[3] <= r[0],
- ]
- print(kind, chk)
-
-
-# try getting heap regions
-regions = esp32.idf_heap_info(esp32.HEAP_DATA)
-print("HEAP_DATA >2:", len(regions) > 2)
-chk_heap("HEAP_DATA", regions)
-
-# try getting code regions
-regions = esp32.idf_heap_info(esp32.HEAP_EXEC)
-print("HEAP_EXEC >2:", len(regions) > 2)
-chk_heap("HEAP_EXEC", regions)
-
-# try invalid param
-print(esp32.idf_heap_info(-1))
diff --git a/tests/esp32/esp32_idf_heap_info.py.exp b/tests/esp32/esp32_idf_heap_info.py.exp
deleted file mode 100644
index 2b63bf3259..0000000000
--- a/tests/esp32/esp32_idf_heap_info.py.exp
+++ /dev/null
@@ -1,5 +0,0 @@
-HEAP_DATA >2: True
-HEAP_DATA [True, True, True, True]
-HEAP_EXEC >2: True
-HEAP_EXEC [True, True, True, True]
-[]
diff --git a/tests/esp32/esp32_nvs.py b/tests/esp32/esp32_nvs.py
deleted file mode 100644
index fd8b152ca7..0000000000
--- a/tests/esp32/esp32_nvs.py
+++ /dev/null
@@ -1,67 +0,0 @@
-# Test the esp32 NVS class - access to esp-idf's Non-Volatile-Storage
-
-from esp32 import NVS
-
-nvs = NVS("mp-test")
-
-# test setting and gettin an integer kv
-nvs.set_i32("key1", 1234)
-print(nvs.get_i32("key1"))
-nvs.set_i32("key2", -503)
-print(nvs.get_i32("key2"))
-print(nvs.get_i32("key1"))
-
-# test setting and getting a blob kv using a bytearray
-blob1 = "testing a string as a blob"
-nvs.set_blob("blob1", blob1)
-buf1 = bytearray(len(blob1))
-len1 = nvs.get_blob("blob1", buf1)
-print(buf1)
-print(len(blob1), len1)
-
-# test setting and getting a blob kv using a string
-blob2 = b"testing a bytearray"
-nvs.set_blob("blob2", blob2)
-buf2 = bytearray(len(blob2))
-len2 = nvs.get_blob("blob2", buf2)
-print(buf2)
-print(len(blob2), len2)
-
-# test raising of error exceptions
-nvs.erase_key("key1")
-try:
- nvs.erase_key("key1") # not found
-except OSError as e:
- print(e)
-try:
- nvs.get_i32("key1") # not found
-except OSError as e:
- print(e)
-try:
- nvs.get_i32("blob1") # not found (blob1 exists but diff type)
-except OSError as e:
- print(e)
-try:
- buf3 = bytearray(10)
- nvs.get_blob("blob1", buf3) # invalid length (too short)
-except OSError as e:
- print(e)
-
-nvs.commit() # we're not verifying that this does anything, just doesn't error
-
-# test using a second namespace and that it doesn't interfere with first
-nvs2 = NVS("mp-test2")
-try:
- print(nvs2.get_i32("key2"))
-except OSError as e:
- print(e)
-nvs2.set_i32("key2", 7654)
-print(nvs.get_i32("key2"))
-print(nvs2.get_i32("key2"))
-
-# clean-up (the namespaces will remain)
-nvs.erase_key("key2")
-nvs.erase_key("blob1")
-nvs.erase_key("blob2")
-nvs2.erase_key("key2")
-nvs.commit()
diff --git a/tests/esp32/esp32_nvs.py.exp b/tests/esp32/esp32_nvs.py.exp
deleted file mode 100644
index 33cdfd6df9..0000000000
--- a/tests/esp32/esp32_nvs.py.exp
+++ /dev/null
@@ -1,14 +0,0 @@
-1234
--503
-1234
-bytearray(b'testing a string as a blob')
-26 26
-bytearray(b'testing a bytearray')
-19 19
-(-4354, 'ESP_ERR_NVS_NOT_FOUND')
-(-4354, 'ESP_ERR_NVS_NOT_FOUND')
-(-4354, 'ESP_ERR_NVS_NOT_FOUND')
-(-4364, 'ESP_ERR_NVS_INVALID_LENGTH')
-(-4354, 'ESP_ERR_NVS_NOT_FOUND')
--503
-7654
diff --git a/tests/esp32/partition_ota.py b/tests/esp32/partition_ota.py
deleted file mode 100644
index 65e2742ebb..0000000000
--- a/tests/esp32/partition_ota.py
+++ /dev/null
@@ -1,117 +0,0 @@
-# Test ESP32 OTA updates, including automatic roll-back.
-# Running this test requires firmware with an OTA Partition, such as the GENERIC_OTA "board".
-# This test also requires patience as it copies the boot partition into the other OTA slot.
-
-import machine
-from esp32 import Partition
-
-# start by checking that the running partition table has OTA partitions, 'cause if
-# it doesn't there's nothing we can test
-cur = Partition(Partition.RUNNING)
-cur_name = cur.info()[4]
-if not cur_name.startswith("ota_"):
- print("SKIP")
- raise SystemExit
-
-DEBUG = True
-
-
-def log(*args):
- if DEBUG:
- print(*args)
-
-
-# replace boot.py with the test code that will run on each reboot
-import os
-
-try:
- os.rename("boot.py", "boot-orig.py")
-except:
- pass
-with open("boot.py", "w") as f:
- f.write("DEBUG=" + str(DEBUG))
- f.write(
- """
-import machine
-from esp32 import Partition
-cur = Partition(Partition.RUNNING)
-cur_name = cur.info()[4]
-
-def log(*args):
- if DEBUG: print(*args)
-
-from step import STEP, EXPECT
-log("Running partition: " + cur_name + " STEP=" + str(STEP) + " EXPECT=" + EXPECT)
-if cur_name != EXPECT:
- print("\\x04FAILED: step " + str(STEP) + " expected " + EXPECT + " got " + cur_name + "\\x04")
-
-if STEP == 0:
- log("Not confirming boot ok and resetting back into first")
- nxt = cur.get_next_update()
- with open("step.py", "w") as f:
- f.write("STEP=1\\nEXPECT=\\"" + nxt.info()[4] + "\\"\\n")
- machine.reset()
-elif STEP == 1:
- log("Booting into second partition again")
- nxt = cur.get_next_update()
- nxt.set_boot()
- with open("step.py", "w") as f:
- f.write("STEP=2\\nEXPECT=\\"" + nxt.info()[4] + "\\"\\n")
- machine.reset()
-elif STEP == 2:
- log("Confirming boot ok and rebooting into same partition")
- Partition.mark_app_valid_cancel_rollback()
- with open("step.py", "w") as f:
- f.write("STEP=3\\nEXPECT=\\"" + cur_name + "\\"\\n")
- machine.reset()
-elif STEP == 3:
- log("Booting into original partition")
- nxt = cur.get_next_update()
- nxt.set_boot()
- with open("step.py", "w") as f:
- f.write("STEP=4\\nEXPECT=\\"" + nxt.info()[4] + "\\"\\n")
- machine.reset()
-elif STEP == 4:
- log("Confirming boot ok and DONE!")
- Partition.mark_app_valid_cancel_rollback()
- import os
- os.remove("step.py")
- os.remove("boot.py")
- os.rename("boot-orig.py", "boot.py")
- print("\\nSUCCESS!\\n\\x04\\x04")
-
-"""
- )
-
-
-def copy_partition(src, dest):
- log("Partition copy: {} --> {}".format(src.info(), dest.info()))
- sz = src.info()[3]
- if dest.info()[3] != sz:
- raise ValueError("Sizes don't match: {} vs {}".format(sz, dest.info()[3]))
- addr = 0
- blk = bytearray(4096)
- while addr < sz:
- if sz - addr < 4096:
- blk = blk[: sz - addr]
- if addr & 0xFFFF == 0:
- # need to show progress to run-tests.py else it times out
- print(" ... 0x{:06x}".format(addr))
- src.readblocks(addr >> 12, blk)
- dest.writeblocks(addr >> 12, blk)
- addr += len(blk)
-
-
-# get things started by copying the current partition into the next slot and rebooting
-print("Copying current to next partition")
-nxt = cur.get_next_update()
-copy_partition(cur, nxt)
-print("Partition copied, booting into it")
-nxt.set_boot()
-
-# the step.py file is used to keep track of state across reboots
-# EXPECT is the name of the partition we expect to reboot into
-with open("step.py", "w") as f:
- f.write('STEP=0\nEXPECT="' + nxt.info()[4] + '"\n')
-
-machine.reset()
diff --git a/tests/esp32/partition_ota.py.exp b/tests/esp32/partition_ota.py.exp
deleted file mode 100644
index 9fc2618a15..0000000000
--- a/tests/esp32/partition_ota.py.exp
+++ /dev/null
@@ -1,15 +0,0 @@
-Copying current to next partition
-########
-Partition copied, booting into it
-########
-Not confirming boot ok and resetting back into first
-########
-Booting into second partition again
-########
-Confirming boot ok and rebooting into same partition
-########
-Booting into original partition
-########
-Confirming boot ok and DONE!
-
-SUCCESS!
diff --git a/tests/esp32/resolve_on_connect.py b/tests/esp32/resolve_on_connect.py
deleted file mode 100644
index e604ce9ca0..0000000000
--- a/tests/esp32/resolve_on_connect.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# Test that the esp32's socket module performs DNS resolutions on bind and connect
-import sys
-
-if sys.implementation.name == "micropython" and sys.platform != "esp32":
- print("SKIP")
- raise SystemExit
-
-import socket, sys
-
-
-def test_bind_resolves_0_0_0_0():
- s = socket.socket()
- try:
- s.bind(("0.0.0.0", 31245))
- print("bind actually bound")
- s.close()
- except Exception as e:
- print("bind raised", e)
-
-
-def test_bind_resolves_localhost():
- s = socket.socket()
- try:
- s.bind(("localhost", 31245))
- print("bind actually bound")
- s.close()
- except Exception as e:
- print("bind raised", e)
-
-
-def test_connect_resolves():
- s = socket.socket()
- try:
- s.connect(("micropython.org", 80))
- print("connect actually connected")
- s.close()
- except Exception as e:
- print("connect raised", e)
-
-
-def test_connect_non_existent():
- s = socket.socket()
- try:
- s.connect(("nonexistent.example.com", 80))
- print("connect actually connected")
- s.close()
- except OSError as e:
- print("connect raised OSError")
- except Exception as e:
- print("connect raised", e)
-
-
-test_funs = [n for n in dir() if n.startswith("test_")]
-for f in sorted(test_funs):
- print("--", f, end=": ")
- eval(f + "()")