Skip to content

Commit

Permalink
ci: Unit tests and workflow to run them
Browse files Browse the repository at this point in the history
  • Loading branch information
cpswan committed Jan 23, 2024
1 parent 297df15 commit 2abfcf3
Show file tree
Hide file tree
Showing 45 changed files with 1,360 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: RunTests
# Runs the workflow on the below events:
# 1. on pull request raised to trunk branch.
# 2. on push event to trunk branch.
on:
push:
branches:
- trunk
pull_request:
branches:
- trunk

permissions: # added using https://github.com/step-security/secure-workflows
contents: read

jobs:
lint-markdown:
runs-on: ubuntu-latest
name: Run Tests
steps:
- name: checkout repo content
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install MicroPython and run tests
run: |
DLURL="https://github.com/atsign-foundation/micropython/releases/download/"
ATMPREL="1.20.0_3faded33f_AES_CTR/micropython_1.20.0_3faded33f_linux_x64.tgz"
wget ${DLURL}${ATMPREL}
tar -xvf ${ATMPREL}
export MICROPY_MICROPYTHON="$(pwd)/micropython"
cd tests
./run-tests.py -d atsign
12 changes: 12 additions & 0 deletions tests/atsign/b42_urlsafe_encode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import sys
TEST_PATH = os.getcwd()
sys.path.append(TEST_PATH+'/../../src')
sys.path.append(TEST_PATH+'/../../src/lib')
import atclient

print(atclient.b42_urlsafe_encode("abc"))
print(atclient.b42_urlsafe_encode("1"))
print(atclient.b42_urlsafe_encode("The quick brown fox jumps over the lazy dog!"))
print(atclient.b42_urlsafe_encode("These characters are {, }, |, \, ^, ~, [, ], and `."))
print(atclient.b42_urlsafe_encode('The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme.'))
5 changes: 5 additions & 0 deletions tests/atsign/b42_urlsafe_encode.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
YWJj
MQ==
VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZyE=
VGhlc2UgY2hhcmFjdGVycyBhcmUgeywgfSwgfCwgXCwgXiwgfiwgWywgXSwgYW5kIGAu
VGhlIGNoYXJhY3RlcnMgIjsiLCAiLyIsICI_IiwgIjoiLCAiQCIsICI9IiBhbmQgIiYiIGFyZSB0aGUgY2hhcmFjdGVycyB3aGljaCBtYXkgYmUgcmVzZXJ2ZWQgZm9yIHNwZWNpYWwgbWVhbmluZyB3aXRoaW4gYSBzY2hlbWUu
1 change: 1 addition & 0 deletions tests/atsign/forty_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("42")
28 changes: 28 additions & 0 deletions tests/atsign/pkcs7pad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import sys
TEST_PATH = os.getcwd()
sys.path.append(TEST_PATH+'/../../src')
sys.path.append(TEST_PATH+'/../../src/lib')
import atclient

print(str.encode(atclient.pkcs7pad("abc")))
print(str.encode(atclient.pkcs7pad("")))
print(str.encode(atclient.pkcs7pad("1")))
print(str.encode(atclient.pkcs7pad("12")))
print(str.encode(atclient.pkcs7pad("123")))
print(str.encode(atclient.pkcs7pad("1234")))
print(str.encode(atclient.pkcs7pad("12345")))
print(str.encode(atclient.pkcs7pad("123456")))
print(str.encode(atclient.pkcs7pad("1234567")))
print(str.encode(atclient.pkcs7pad("12345678")))
print(str.encode(atclient.pkcs7pad("123456789")))
print(str.encode(atclient.pkcs7pad("123456789a")))
print(str.encode(atclient.pkcs7pad("123456789ab")))
print(str.encode(atclient.pkcs7pad("123456789abc")))
print(str.encode(atclient.pkcs7pad("123456789abcd")))
print(str.encode(atclient.pkcs7pad("123456789abcde")))
print(str.encode(atclient.pkcs7pad("123456789abcdef")))
print(str.encode(atclient.pkcs7pad("123456789abcdef1")))
print(str.encode(atclient.pkcs7pad("The quick brown fox jumps over the lazy dog!")))
print(str.encode(atclient.pkcs7pad("These characters are {, }, |, \, ^, ~, [, ], and `.")))
print(str.encode(atclient.pkcs7pad('The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme.')))
21 changes: 21 additions & 0 deletions tests/atsign/pkcs7pad.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
b'abc\r\r\r\r\r\r\r\r\r\r\r\r\r'
b'\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10'
b'1\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'
b'12\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e'
b'123\r\r\r\r\r\r\r\r\r\r\r\r\r'
b'1234\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c'
b'12345\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b'
b'123456\n\n\n\n\n\n\n\n\n\n'
b'1234567\t\t\t\t\t\t\t\t\t'
b'12345678\x08\x08\x08\x08\x08\x08\x08\x08'
b'123456789\x07\x07\x07\x07\x07\x07\x07'
b'123456789a\x06\x06\x06\x06\x06\x06'
b'123456789ab\x05\x05\x05\x05\x05'
b'123456789abc\x04\x04\x04\x04'
b'123456789abcd\x03\x03\x03'
b'123456789abcde\x02\x02'
b'123456789abcdef\x01'
b'123456789abcdef1\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10'
b'The quick brown fox jumps over the lazy dog!\x04\x04\x04\x04'
b'These characters are {, }, |, \\, ^, ~, [, ], and `.\r\r\r\r\r\r\r\r\r\r\r\r\r'
b'The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme.\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'
28 changes: 28 additions & 0 deletions tests/atsign/unpad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import sys
TEST_PATH = os.getcwd()
sys.path.append(TEST_PATH+'/../../src')
sys.path.append(TEST_PATH+'/../../src/lib')
import atclient

print(atclient.unpad(b'abc\r\r\r\r\r\r\r\r\r\r\r\r\r'))
print(atclient.unpad(b'\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10'))
print(atclient.unpad(b'1\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'))
print(atclient.unpad(b'12\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e\x0e'))
print(atclient.unpad(b'123\r\r\r\r\r\r\r\r\r\r\r\r\r'))
print(atclient.unpad(b'1234\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c'))
print(atclient.unpad(b'12345\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b'))
print(atclient.unpad(b'123456\n\n\n\n\n\n\n\n\n\n'))
print(atclient.unpad(b'1234567\t\t\t\t\t\t\t\t\t'))
print(atclient.unpad(b'12345678\x08\x08\x08\x08\x08\x08\x08\x08'))
print(atclient.unpad(b'123456789\x07\x07\x07\x07\x07\x07\x07'))
print(atclient.unpad(b'123456789a\x06\x06\x06\x06\x06\x06'))
print(atclient.unpad(b'123456789ab\x05\x05\x05\x05\x05'))
print(atclient.unpad(b'123456789abc\x04\x04\x04\x04'))
print(atclient.unpad(b'123456789abcd\x03\x03\x03'))
print(atclient.unpad(b'123456789abcde\x02\x02'))
print(atclient.unpad(b'123456789abcdef\x01'))
print(atclient.unpad(b'123456789abcdef1\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10'))
print(atclient.unpad(b'The quick brown fox jumps over the lazy dog!\x04\x04\x04\x04'))
print(atclient.unpad(b'These characters are {, }, |, \\, ^, ~, [, ], and `.\r\r\r\r\r\r\r\r\r\r\r\r\r'))
print(atclient.unpad(b'The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme.\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'))
21 changes: 21 additions & 0 deletions tests/atsign/unpad.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
b'abc'
b''
b'1'
b'12'
b'123'
b'1234'
b'12345'
b'123456'
b'1234567'
b'12345678'
b'123456789'
b'123456789a'
b'123456789ab'
b'123456789abc'
b'123456789abcd'
b'123456789abcde'
b'123456789abcdef'
b'123456789abcdef1'
b'The quick brown fox jumps over the lazy dog!'
b'These characters are {, }, |, \\, ^, ~, [, ], and `.'
b'The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme.'
4 changes: 4 additions & 0 deletions tests/feature_check/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This directory doesn't contain real tests, but code snippets to detect
various interpreter features, which can't be/inconvenient to detect by
other means. Scripts here are executed by run-tests.py at the beginning of
testsuite to decide what other test groups to run/exclude.
6 changes: 6 additions & 0 deletions tests/feature_check/async_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# check if async/await keywords are supported
async def foo():
await 1


print("async")
Empty file.
5 changes: 5 additions & 0 deletions tests/feature_check/bytearray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
bytearray
print("bytearray")
except NameError:
print("no")
Empty file.
3 changes: 3 additions & 0 deletions tests/feature_check/byteorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sys

print(sys.byteorder)
Empty file.
5 changes: 5 additions & 0 deletions tests/feature_check/complex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
complex
print("complex")
except NameError:
print("no")
Empty file.
2 changes: 2 additions & 0 deletions tests/feature_check/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = const(1)
print(x)
Empty file.
5 changes: 5 additions & 0 deletions tests/feature_check/coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
extra_coverage
print("coverage")
except NameError:
print("no")
Empty file.
13 changes: 13 additions & 0 deletions tests/feature_check/float.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# detect how many bits of precision the floating point implementation has

try:
float
except NameError:
print(0)
else:
if float("1.0000001") == float("1.0"):
print(30)
elif float("1e300") == float("inf"):
print(32)
else:
print(64)
1 change: 1 addition & 0 deletions tests/feature_check/float.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
64
3 changes: 3 additions & 0 deletions tests/feature_check/fstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# check whether f-strings (PEP-498) are supported
a = 1
print(f"a={a}")
1 change: 1 addition & 0 deletions tests/feature_check/fstring.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a=1
10 changes: 10 additions & 0 deletions tests/feature_check/inlineasm_thumb2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# check if Thumb2/ARMV7M instructions are supported


@micropython.asm_thumb
def f():
it(eq)
nop()


print("thumb2")
1 change: 1 addition & 0 deletions tests/feature_check/inlineasm_thumb2.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
thumb2
2 changes: 2 additions & 0 deletions tests/feature_check/int_big.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Check whether arbitrary-precision integers (MPZ) are supported
print(1000000000000000000000000000000000000000000000)
1 change: 1 addition & 0 deletions tests/feature_check/int_big.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000000000000000000000000000000000000000000000
6 changes: 6 additions & 0 deletions tests/feature_check/io_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
try:
import io

print("io")
except ImportError:
print("no")
Empty file.
8 changes: 8 additions & 0 deletions tests/feature_check/native_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# this test for the availability of native emitter
@micropython.native
def f():
pass


f()
print("native")
Empty file.
3 changes: 3 additions & 0 deletions tests/feature_check/repl_emacs_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Check for emacs keys in REPL
t = +11
t == 2
7 changes: 7 additions & 0 deletions tests/feature_check/repl_emacs_check.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MicroPython \.\+ version
Use \.\+
>>> # Check for emacs keys in REPL
>>> t = \.\+
>>> t == 2
True
>>>
4 changes: 4 additions & 0 deletions tests/feature_check/repl_words_move_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# just check if ctrl+w is supported, because it makes sure that
# both MICROPY_REPL_EMACS_WORDS_MOVE and MICROPY_REPL_EXTRA_WORDS_MOVE are enabled.
t = 1231
t == 1
7 changes: 7 additions & 0 deletions tests/feature_check/repl_words_move_check.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MicroPython \.\+ version
Use \.\+
>>> # Check for emacs keys in REPL
>>> t = \.\+
>>> t == 2
True
>>>
9 changes: 9 additions & 0 deletions tests/feature_check/reverse_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo:
def __radd__(self, other):
pass


try:
5 + Foo()
except TypeError:
print("TypeError")
Empty file.
2 changes: 2 additions & 0 deletions tests/feature_check/set_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# check if set literal syntax is supported
print({1})
Empty file.
5 changes: 5 additions & 0 deletions tests/feature_check/slice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
slice
print("slice")
except NameError:
print("no")
Empty file.
1 change: 1 addition & 0 deletions tests/results/_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"args": {"target": "unix", "device": "/dev/ttyACM0", "baudrate": 115200, "user": "micro", "password": "python", "test_dirs": ["atsign"], "result_dir": "/home/chris/git/github.com/atsign-foundation/at_pico_w/tests/results", "filters": [], "write_exp": false, "list_tests": false, "emit": "bytecode", "heapsize": null, "via_mpy": false, "mpy_cross_flags": "-march=host", "keep_path": false, "jobs": 12, "files": [], "print_failures": false, "clean_failures": false, "run_failures": false}, "failed_tests": []}
Loading

0 comments on commit 2abfcf3

Please sign in to comment.