code stringlengths 1 1.05M | repo_name stringlengths 6 83 | path stringlengths 3 242 | language stringclasses 222
values | license stringclasses 20
values | size int64 1 1.05M |
|---|---|---|---|---|---|
# tests meminfo functions in micropython module
import micropython
# these functions are not always available
if not hasattr(micropython, "mem_info"):
print("SKIP")
else:
micropython.mem_info()
micropython.mem_info(1)
micropython.qstr_info()
micropython.qstr_info(1)
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/meminfo.py | Python | apache-2.0 | 289 |
# tests meminfo functions in micropython module
import micropython
# these functions are not always available
if not hasattr(micropython, "mem_total"):
print("SKIP")
else:
t = micropython.mem_total()
c = micropython.mem_current()
p = micropython.mem_peak()
l = list(range(10000))
print(microp... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/memstats.py | Python | apache-2.0 | 422 |
# test native emitter can handle closures correctly
# basic closure
@micropython.native
def f():
x = 1
@micropython.native
def g():
nonlocal x
return x
return g
print(f()())
# closing over an argument
@micropython.native
def f(x):
@micropython.native
def g():
nonloc... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_closure.py | Python | apache-2.0 | 558 |
# test loading constants in native functions
@micropython.native
def f():
return b"bytes"
print(f())
@micropython.native
def f():
@micropython.native
def g():
return 123
return g
print(f()())
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_const.py | Python | apache-2.0 | 225 |
# check loading constants
@micropython.native
def f():
return 123456789012345678901234567890
print(f())
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_const_intbig.py | Python | apache-2.0 | 112 |
# test for native for loops
@micropython.native
def f1(n):
for i in range(n):
print(i)
f1(4)
@micropython.native
def f2(r):
for i in r:
print(i)
f2(range(4))
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_for.py | Python | apache-2.0 | 190 |
# test for native generators
# simple generator with yield and return
@micropython.native
def gen1(x):
yield x
yield x + 1
return x + 2
g = gen1(3)
print(next(g))
print(next(g))
try:
next(g)
except StopIteration as e:
print(e.args[0])
# using yield from
@micropython.native
def gen2(x):
yield... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_gen.py | Python | apache-2.0 | 358 |
# tests for natively compiled functions
# basic test
@micropython.native
def native_test(x):
print(1, [], x)
native_test(2)
# check that GC doesn't collect the native function
import gc
gc.collect()
native_test(3)
# native with 2 args
@micropython.native
def f(a, b):
print(a + b)
f(1, 2)
# native with ... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_misc.py | Python | apache-2.0 | 597 |
# test native try handling
# basic try-finally
@micropython.native
def f():
try:
fail
finally:
print("finally")
try:
f()
except NameError:
print("NameError")
# nested try-except with try-finally
@micropython.native
def f():
try:
try:
fail
finally:
... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_try.py | Python | apache-2.0 | 634 |
# test native try handling
# deeply nested try (9 deep)
@micropython.native
def f():
try:
try:
try:
try:
try:
try:
try:
try:
try:
... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_try_deep.py | Python | apache-2.0 | 953 |
# test with handling within a native function
class C:
def __init__(self):
print("__init__")
def __enter__(self):
print("__enter__")
def __exit__(self, a, b, c):
print("__exit__", a, b, c)
# basic with
@micropython.native
def f():
with C():
print(1)
f()
# nested ... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/native_with.py | Python | apache-2.0 | 510 |
import micropython as micropython
# check we can get and set the level
micropython.opt_level(0)
print(micropython.opt_level())
micropython.opt_level(1)
print(micropython.opt_level())
# check that the optimisation levels actually differ
micropython.opt_level(0)
exec("print(__debug__)")
micropython.opt_level(1)
exec("p... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/opt_level.py | Python | apache-2.0 | 355 |
import micropython as micropython
# check that level 3 doesn't store line numbers
# the expected output is that any line is printed as "line 1"
micropython.opt_level(3)
exec("try:\n xyz\nexcept NameError as er:\n import usys\n usys.print_exception(er)")
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/opt_level_lineno.py | Python | apache-2.0 | 255 |
# test micropython.schedule() function
import micropython
try:
micropython.schedule
except AttributeError:
print("SKIP")
raise SystemExit
# Basic test of scheduling a function.
def callback(arg):
global done
print(arg)
done = True
done = False
micropython.schedule(callback, 1)
while not d... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/schedule.py | Python | apache-2.0 | 1,275 |
# tests stack_use function in micropython module
import micropython
if not hasattr(micropython, "stack_use"):
print("SKIP")
else:
print(type(micropython.stack_use())) # output varies
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/stack_use.py | Python | apache-2.0 | 193 |
# test passing addresses to viper
@micropython.viper
def get_addr(x: ptr) -> ptr:
return x
@micropython.viper
def memset(dest: ptr8, c: int, n: int):
for i in range(n):
dest[i] = c
@micropython.viper
def memsum(src: ptr8, n: int) -> int:
s = 0
for i in range(n):
s += src[i]
ret... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_addr.py | Python | apache-2.0 | 774 |
# test calling viper functions with different number of args
@micropython.viper
def f0():
print(0)
f0()
@micropython.viper
def f1(x1: int):
print(x1)
f1(1)
@micropython.viper
def f2(x1: int, x2: int):
print(x1, x2)
f2(1, 2)
@micropython.viper
def f3(x1: int, x2: int, x3: int):
print(x1, x2... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_args.py | Python | apache-2.0 | 865 |
# test arithmetic operators
@micropython.viper
def add(x: int, y: int):
print(x + y)
print(y + x)
add(1, 2)
add(42, 3)
add(-1, 2)
add(-42, -3)
@micropython.viper
def sub(x: int, y: int):
print(x - y)
print(y - x)
sub(1, 2)
sub(42, 3)
sub(-1, 2)
sub(-42, -3)
@micropython.viper
def mul(x: int, y... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_arith.py | Python | apache-2.0 | 992 |
# test arithmetic operators with uint type
@micropython.viper
def add(x: uint, y: uint):
return x + y, y + x
print("add")
print(*add(1, 2))
print(*(x & 0xFFFFFFFF for x in add(-1, -2)))
@micropython.viper
def sub(x: uint, y: uint):
return x - y, y - x
print("sub")
print(*(x & 0xFFFFFFFF for x in sub(1, ... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_arith_uint.py | Python | apache-2.0 | 541 |
# test bitwise operators on uint type
@micropython.viper
def shl(x: uint, y: uint) -> uint:
return x << y
print("shl")
print(shl(1, 0))
print(shl(1, 30))
print(shl(-1, 10) & 0xFFFFFFFF)
@micropython.viper
def shr(x: uint, y: uint) -> uint:
return x >> y
print("shr")
print(shr(1, 0))
print(shr(16, 3))
pr... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_bitwise_uint.py | Python | apache-2.0 | 921 |
# test comparison operators
@micropython.viper
def f(x: int, y: int):
if x < y:
print(x, "<", y)
if x > y:
print(x, ">", y)
if x == y:
print(x, "==", y)
if x <= y:
print(x, "<=", y)
if x >= y:
print(x, ">=", y)
if x != y:
print(x, "!=", y)
f(1, 1... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_comp.py | Python | apache-2.0 | 356 |
# comparisons with immediate boundary values
@micropython.viper
def f(a: int):
print(a == -1, a == -255, a == -256, a == -257)
f(-1)
f(-255)
f(-256)
f(-257)
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_comp_imm.py | Python | apache-2.0 | 163 |
# test comparison operators with uint type
@micropython.viper
def f(x: uint, y: uint):
if x < y:
print(" <", end="")
if x > y:
print(" >", end="")
if x == y:
print(" ==", end="")
if x <= y:
print(" <=", end="")
if x >= y:
print(" >=", end="")
if x != y:
... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_comp_uint.py | Python | apache-2.0 | 487 |
# test floor-division and modulo operators
@micropython.viper
def div(x: int, y: int) -> int:
return x // y
@micropython.viper
def mod(x: int, y: int) -> int:
return x % y
def dm(x, y):
print(div(x, y), mod(x, y))
for x in (-6, 6):
for y in range(-7, 8):
if y == 0:
continue
... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_divmod.py | Python | apache-2.0 | 336 |
# test multi comparison operators
@micropython.viper
def f(x: int, y: int):
if 0 < x < y:
print(x, "<", y)
if 3 > x > y:
print(x, ">", y)
if 1 == x == y:
print(x, "==", y)
if -2 == x <= y:
print(x, "<=", y)
if 2 == x >= y:
print(x, ">=", y)
if 2 == x != y:... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_binop_multi_comp.py | Python | apache-2.0 | 391 |
# using False as a conditional
@micropython.viper
def f():
x = False
if x:
pass
else:
print("not x", x)
f()
# using True as a conditional
@micropython.viper
def f():
x = True
if x:
print("x", x)
f()
# using an int as a conditional
@micropython.viper
def g():
y = 1
... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_cond.py | Python | apache-2.0 | 505 |
# test loading constants in viper functions
@micropython.viper
def f():
return b"bytes"
print(f())
@micropython.viper
def f():
@micropython.viper
def g() -> int:
return 123
return g
print(f()())
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_const.py | Python | apache-2.0 | 228 |
# check loading constants
@micropython.viper
def f():
return 123456789012345678901234567890
print(f())
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_const_intbig.py | Python | apache-2.0 | 111 |
# test syntax and type errors specific to viper code generation
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
# viper: annotations must be identifiers
test("@micropython.viper\ndef f(a:1): pass")
test("@micropython.viper\ndef f... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_error.py | Python | apache-2.0 | 2,115 |
# test that viper functions capture their globals context
gl = {}
exec(
"""
@micropython.viper
def f():
return x
""",
gl,
)
# x is not yet in the globals, f should not see it
try:
print(gl["f"]())
except NameError:
print("NameError")
# x is in globals, f should now see it
gl["x"] = 123
print(gl[... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_globals.py | Python | apache-2.0 | 328 |
# test import within viper function
@micropython.viper
def f():
import micropython
print(micropython.const(1))
from micropython import const
print(const(2))
f()
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_import.py | Python | apache-2.0 | 184 |
import micropython
# viper function taking and returning ints
@micropython.viper
def viper_int(x: int, y: int) -> int:
return x + y + 3
print(viper_int(1, 2))
# viper function taking and returning objects
@micropython.viper
def viper_object(x: object, y: object) -> object:
return x + y
print(viper_object(... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_misc.py | Python | apache-2.0 | 2,553 |
# Miscellaneous viper tests
# Test correct use of registers in load and store
@micropython.viper
def expand(dest: ptr8, source: ptr8, length: int):
n = 0
for x in range(0, length, 2):
c = source[x]
d = source[x + 1]
dest[n] = (c & 0xE0) | ((c & 0x1C) >> 1)
n += 1
dest[n]... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_misc2.py | Python | apache-2.0 | 557 |
import micropython
# unsigned ints
@micropython.viper
def viper_uint() -> uint:
return uint(-1)
import usys
print(viper_uint() == (usys.maxsize << 1 | 1))
| YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_misc_intbig.py | Python | apache-2.0 | 163 |
# test loading from ptr16 type
# only works on little endian machines
@micropython.viper
def get(src: ptr16) -> int:
return src[0]
@micropython.viper
def get1(src: ptr16) -> int:
return src[1]
@micropython.viper
def memadd(src: ptr16, n: int) -> int:
sum = 0
for i in range(n):
sum += src[i... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_ptr16_load.py | Python | apache-2.0 | 607 |
# test ptr16 type
@micropython.viper
def set(dest: ptr16, val: int):
dest[0] = val
@micropython.viper
def set1(dest: ptr16, val: int):
dest[1] = val
@micropython.viper
def memset(dest: ptr16, val: int, n: int):
for i in range(n):
dest[i] = val
@micropython.viper
def memset2(dest_in, val: int... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_ptr16_store.py | Python | apache-2.0 | 574 |
# test loading from ptr32 type
@micropython.viper
def get(src: ptr32) -> int:
return src[0]
@micropython.viper
def get1(src: ptr32) -> int:
return src[1]
@micropython.viper
def memadd(src: ptr32, n: int) -> int:
sum = 0
for i in range(n):
sum += src[i]
return sum
@micropython.viper
d... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_ptr32_load.py | Python | apache-2.0 | 616 |
# test store to ptr32 type
@micropython.viper
def set(dest: ptr32, val: int):
dest[0] = val
@micropython.viper
def set1(dest: ptr32, val: int):
dest[1] = val
@micropython.viper
def memset(dest: ptr32, val: int, n: int):
for i in range(n):
dest[i] = val
@micropython.viper
def memset2(dest_in,... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_ptr32_store.py | Python | apache-2.0 | 599 |
# test loading from ptr8 type
@micropython.viper
def get(src: ptr8) -> int:
return src[0]
@micropython.viper
def get1(src: ptr8) -> int:
return src[1]
@micropython.viper
def memadd(src: ptr8, n: int) -> int:
sum = 0
for i in range(n):
sum += src[i]
return sum
@micropython.viper
def m... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_ptr8_load.py | Python | apache-2.0 | 558 |
# test ptr8 type
@micropython.viper
def set(dest: ptr8, val: int):
dest[0] = val
@micropython.viper
def set1(dest: ptr8, val: int):
dest[1] = val
@micropython.viper
def memset(dest: ptr8, val: int, n: int):
for i in range(n):
dest[i] = val
@micropython.viper
def memset2(dest_in, val: int):
... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_ptr8_store.py | Python | apache-2.0 | 543 |
# test standard Python subscr using viper types
@micropython.viper
def get(dest, i: int):
i += 1
return dest[i]
@micropython.viper
def set(dest, i: int, val: int):
i += 1
dest[i] = val + 1
ar = [i for i in range(3)]
for i in range(len(ar)):
set(ar, i - 1, i)
print(ar)
for i in range(len(ar))... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_subscr.py | Python | apache-2.0 | 348 |
# test try handling within a viper function
# basic try-finally
@micropython.viper
def f():
try:
fail
finally:
print("finally")
try:
f()
except NameError:
print("NameError")
# nested try-except with try-finally
@micropython.viper
def f():
try:
try:
fail
... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_try.py | Python | apache-2.0 | 648 |
# test various type conversions
import micropython
# converting incoming arg to bool
@micropython.viper
def f1(x: bool):
print(x)
f1(0)
f1(1)
f1([])
f1([1])
# taking and returning a bool
@micropython.viper
def f2(x: bool) -> bool:
return x
print(f2([]))
print(f2([1]))
# converting to bool within functio... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_types.py | Python | apache-2.0 | 409 |
# test with handling within a viper function
class C:
def __init__(self):
print("__init__")
def __enter__(self):
print("__enter__")
def __exit__(self, a, b, c):
print("__exit__", a, b, c)
# basic with
@micropython.viper
def f():
with C():
print(1)
f()
# nested wi... | YifuLiu/AliOS-Things | components/py_engine/tests/micropython/viper_with.py | Python | apache-2.0 | 507 |
try:
str.count
except AttributeError:
print("SKIP")
raise SystemExit
# mad.py
# Alf Clement 27-Mar-2014
#
zero = 0
three = 3
print("1")
print("2")
print(three)
print("{}".format(4))
five = 25 // 5
print(int(five))
j = 0
for i in range(4):
j += i
print(j)
print(3 + 4)
try:
a = 4 // zero
except:
... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/features.py | Python | apache-2.0 | 2,488 |
# tests for things that are not implemented, or have non-compliant behaviour
try:
import uarray as array
import ustruct
except ImportError:
print("SKIP")
raise SystemExit
# when super can't find self
try:
exec("def f(): super()")
except SyntaxError:
print("SyntaxError")
# store to exception a... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/non_compliant.py | Python | apache-2.0 | 3,349 |
# lexer tests for things that are not implemented, or have non-compliant behaviour
def test(code):
try:
exec(code)
print("no Error")
except SyntaxError:
print("SyntaxError")
except NotImplementedError:
print("NotImplementedError")
# uPy requires spaces between literal num... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/non_compliant_lexer.py | Python | apache-2.0 | 716 |
try:
try:
import uio as io
import usys as sys
except ImportError:
import io
import sys
except ImportError:
print("SKIP")
raise SystemExit
if hasattr(sys, "print_exception"):
print_exception = sys.print_exception
else:
import traceback
print_exception = lambd... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/print_exception.py | Python | apache-2.0 | 2,288 |
# evolve the RGEs of the standard model from electroweak scale up
# by dpgeorge
import math
class RungeKutta(object):
def __init__(self, functions, initConditions, t0, dh, save=True):
self.Trajectory, self.save = [[t0] + initConditions], save
self.functions = [lambda *args: 1.0] + list(functions)... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/rge_sm.py | Python | apache-2.0 | 4,422 |
# test sys.atexit() function
import usys
try:
usys.atexit
except AttributeError:
print("SKIP")
raise SystemExit
some_var = None
def do_at_exit():
print("done at exit:", some_var)
usys.atexit(do_at_exit)
some_var = "ok"
print("done before exit")
| YifuLiu/AliOS-Things | components/py_engine/tests/misc/sys_atexit.py | Python | apache-2.0 | 269 |
try:
import usys as sys
except ImportError:
import sys
try:
sys.exc_info
except:
print("SKIP")
raise SystemExit
def f():
print(sys.exc_info()[0:2])
try:
raise ValueError("value", 123)
except:
print(sys.exc_info()[0:2])
f()
# Outside except block, sys.exc_info() should be back t... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/sys_exc_info.py | Python | apache-2.0 | 450 |
import sys
try:
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit
def print_stacktrace(frame, level=0):
# Ignore CPython specific helpers.
if frame.f_globals["__name__"].find("importlib") != -1:
print_stacktrace(frame.f_back, level)
return
print(
"%2d... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/sys_settrace_features.py | Python | apache-2.0 | 2,585 |
# test sys.settrace with generators
import sys
try:
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit
def print_stacktrace(frame, level=0):
print(
"%2d: %s@%s:%s => %s:%d"
% (
level,
" ",
frame.f_globals["__name__"],
f... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/sys_settrace_generator.py | Python | apache-2.0 | 1,312 |
# test sys.settrace with while and for loops
import sys
try:
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit
def print_stacktrace(frame, level=0):
print(
"%2d: %s@%s:%s => %s:%d"
% (
level,
" ",
frame.f_globals["__name__"],
... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/sys_settrace_loop.py | Python | apache-2.0 | 1,144 |
print("Now comes the language constructions tests.")
# function
def test_func():
def test_sub_func():
print("test_function")
test_sub_func()
# closure
def test_closure(msg):
def make_closure():
print(msg)
return make_closure
# exception
def test_exception():
try:
raise... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/sys_settrace_subdir/sys_settrace_generic.py | Python | apache-2.0 | 1,561 |
print("Yep, I got imported.")
try:
x = const(1)
except NameError:
print("const not defined")
const = lambda x: x
_CNT01 = "CONST01"
_CNT02 = const(123)
A123 = const(123)
a123 = const(123)
def dummy():
return False
def saysomething():
print("There, I said it.")
def neverexecuted():
print("Ne... | YifuLiu/AliOS-Things | components/py_engine/tests/misc/sys_settrace_subdir/sys_settrace_importme.py | Python | apache-2.0 | 361 |
# Test characteristic read/write/notify from both GATTS and GATTC.
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 5000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_GATTS_WRITE = const(3)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_DISCONNECT = const(8)
_I... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_characteristic.py | Python | apache-2.0 | 6,885 |
# Test BLE GAP advertising and scanning
from micropython import const
import time, machine, bluetooth
_IRQ_SCAN_RESULT = const(5)
_IRQ_SCAN_DONE = const(6)
ADV_TIME_S = 3
def instance0():
multitest.globals(BDADDR=ble.config("mac"))
multitest.next()
print("gap_advertise(100_000, connectable=False)")
... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_gap_advertise.py | Python | apache-2.0 | 1,546 |
# Test BLE GAP connect/disconnect
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 4000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_DISCONNECT = const(8)
waiting_events = {}
def irq(event, data):
if event == _I... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_gap_connect.py | Python | apache-2.0 | 2,787 |
# Test BLE GAP device name get/set
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 5000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_DISCONNECT = const(8)
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(11)
_IRQ_GATTC_CHARAC... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_gap_device_name.py | Python | apache-2.0 | 4,006 |
# Test BLE GAP connect/disconnect with pairing, and read an encrypted characteristic
# TODO: add gap_passkey testing
from micropython import const
import time, machine, bluetooth
if not hasattr(bluetooth.BLE, "gap_pair"):
print("SKIP")
raise SystemExit
TIMEOUT_MS = 4000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_gap_pair.py | Python | apache-2.0 | 4,353 |
# Test BLE GAP connect/disconnect with pairing and bonding, and read an encrypted
# characteristic
# TODO: reconnect after bonding to test that the secrets persist
from micropython import const
import time, machine, bluetooth
if not hasattr(bluetooth.BLE, "gap_pair"):
print("SKIP")
raise SystemExit
TIMEOUT_M... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_gap_pair_bond.py | Python | apache-2.0 | 4,495 |
# Test GATTC/S data transfer between peripheral and central, and use of gatts_set_buffer()
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 5000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_GATTS_WRITE = const(3)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_gatt_data_transfer.py | Python | apache-2.0 | 6,161 |
# Test BLE GAP connect/disconnect
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 5000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_DISCONNECT = const(8)
_IRQ_GATTC_SERVICE_RESULT = const(9)
_IRQ_GATTC_SERVICE_DONE = ... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_gattc_discover_services.py | Python | apache-2.0 | 2,795 |
# Test L2CAP COC send/recv.
# Sends a sequence of varying-sized payloads from central->peripheral, and
# verifies that the other device sees the same data, then does the same thing
# peripheral->central.
from micropython import const
import time, machine, bluetooth, random
if not hasattr(bluetooth.BLE, "l2cap_connec... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_l2cap.py | Python | apache-2.0 | 5,657 |
# Test MTU exchange (initiated by both central and peripheral) and the effect on
# notify and write size.
# Seven connections are made (four central->peripheral, three peripheral->central).
#
# Test | Requested | Preferred | Result | Notes
# 0 | 300 (C) | 256 (P) | 256 |
# 1 | 300 (C) | 200 (P) | 200... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_mtu.py | Python | apache-2.0 | 6,620 |
# Test for sending notifications to subscribed clients.
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 5000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_GATTS_WRITE = const(3)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_DISCONNECT = const(8)
_IRQ_GATTC_CH... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/ble_subscribe.py | Python | apache-2.0 | 9,093 |
# Write characteristic from central to peripheral and time data rate.
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 2000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_GATTS_WRITE = const(3)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_DISCONNECT = const(8)... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/perf_gatt_char_write.py | Python | apache-2.0 | 5,254 |
# Ping-pong GATT notifications between two devices.
from micropython import const
import time, machine, bluetooth
TIMEOUT_MS = 2000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_PERIPHERAL_CONNECT = const(7)
_IRQ_PERIPHERAL_DISCONNECT = const(8)
_IRQ_GATTC_CHARACTERISTIC_RESULT = const(11)
... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/perf_gatt_notify.py | Python | apache-2.0 | 4,134 |
# Send L2CAP data as fast as possible and time it.
from micropython import const
import time, machine, bluetooth, random
if not hasattr(bluetooth.BLE, "l2cap_connect"):
print("SKIP")
raise SystemExit
TIMEOUT_MS = 1000
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_PERIPHERAL_CONNECT... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/perf_l2cap.py | Python | apache-2.0 | 4,566 |
# Test concurrency between filesystem access and BLE host. This is
# particularly relevant on STM32WB where the second core is stalled while
# flash operations are in progress.
from micropython import const
import time, machine, bluetooth, os
TIMEOUT_MS = 10000
LOG_PATH_INSTANCE0 = "stress_log_filesystem_0.log"
LOG_... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_bluetooth/stress_log_filesystem.py | Python | apache-2.0 | 6,304 |
# Simple test creating an SSL connection and transferring some data
# This test won't run under CPython because it requires key/cert
import usocket as socket, ussl as ssl
PORT = 8000
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SO... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/ssl_data.py | Python | apache-2.0 | 803 |
# Test recv on socket that just accepted a connection
import socket
PORT = 8000
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1)
... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/tcp_accept_recv.py | Python | apache-2.0 | 672 |
# Test when client does a TCP RST on an open connection
import struct, time, socket, select
PORT = 8000
def convert_poll_list(l):
# To be compatible across all ports/targets
return [ev for _, ev in l]
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/tcp_client_rst.py | Python | apache-2.0 | 1,696 |
# Simple test of a TCP server and client transferring data
import socket
PORT = 8000
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/tcp_data.py | Python | apache-2.0 | 628 |
# Test TCP server with client issuing TCP RST part way through read
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
import struct, time, socket
PORT = 8000
async def handle_connection(reader, writer):
... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/uasyncio_tcp_client_rst.py | Python | apache-2.0 | 1,416 |
# Test uasyncio TCP stream closing then writing
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
PORT = 8000
async def handle_connection(reader, writer):
# Write data to ensure connection
writer.wri... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/uasyncio_tcp_close_write.py | Python | apache-2.0 | 1,424 |
# Test uasyncio stream readexactly() method using TCP server/client
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
PORT = 8000
async def handle_connection(reader, writer):
writer.write(b"a")
await... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/uasyncio_tcp_readexactly.py | Python | apache-2.0 | 1,470 |
# Test uasyncio stream readinto() method using TCP server/client
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
try:
import uarray as array
except ImportError:
try:
import array
except I... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/uasyncio_tcp_readinto.py | Python | apache-2.0 | 1,545 |
# Test uasyncio TCP server and client using start_server() and open_connection()
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
PORT = 8000
async def handle_connection(reader, writer):
# Test that pee... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/uasyncio_tcp_server_client.py | Python | apache-2.0 | 1,299 |
# Simple test of a UDP server and client transferring data
import socket
NUM_NEW_SOCKETS = 4
NUM_TRANSFERS = 4
PORT = 8000
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
multitest.next()
for i in range(NUM_NEW_SOCKETS):
s = socket.socket(socket.AF_INET, socket.SOCK_DGR... | YifuLiu/AliOS-Things | components/py_engine/tests/multi_net/udp_data.py | Python | apache-2.0 | 1,028 |
# test that socket.accept() on a non-blocking socket raises EAGAIN
try:
import usocket as socket
except:
import socket
s = socket.socket()
s.bind(socket.getaddrinfo("127.0.0.1", 8123)[0][-1])
s.setblocking(False)
s.listen(1)
try:
s.accept()
except OSError as er:
print(er.errno == 11) # 11 is EAGAIN
s... | YifuLiu/AliOS-Things | components/py_engine/tests/net_hosted/accept_nonblock.py | Python | apache-2.0 | 329 |
# test that socket.accept() on a socket with timeout raises ETIMEDOUT
try:
import uerrno as errno, usocket as socket
except:
import errno, socket
try:
socket.socket.settimeout
except AttributeError:
print("SKIP")
raise SystemExit
s = socket.socket()
s.bind(socket.getaddrinfo("127.0.0.1", 8123)[0]... | YifuLiu/AliOS-Things | components/py_engine/tests/net_hosted/accept_timeout.py | Python | apache-2.0 | 502 |
# test that socket.connect() on a non-blocking socket raises EINPROGRESS
try:
import usocket as socket
import uerrno as errno
except:
import socket, errno
def test(peer_addr):
s = socket.socket()
s.setblocking(False)
try:
s.connect(peer_addr)
except OSError as er:
print(er... | YifuLiu/AliOS-Things | components/py_engine/tests/net_hosted/connect_nonblock.py | Python | apache-2.0 | 451 |
# test that socket.connect() on a non-blocking socket raises EINPROGRESS
# and that an immediate write/send/read/recv does the right thing
try:
import sys, time
import uerrno as errno, usocket as socket, ussl as ssl
except:
import socket, errno, ssl
isMP = sys.implementation.name == "micropython"
def dp(... | YifuLiu/AliOS-Things | components/py_engine/tests/net_hosted/connect_nonblock_xfer.py | Python | apache-2.0 | 4,928 |
# test that socket.connect() has correct polling behaviour before, during and after
try:
import usocket as socket, uselect as select
except:
import socket, select
def test(peer_addr):
s = socket.socket()
poller = select.poll()
poller.register(s)
# test poll before connect
p = poller.poll... | YifuLiu/AliOS-Things | components/py_engine/tests/net_hosted/connect_poll.py | Python | apache-2.0 | 650 |
# test ssl.getpeercert() method
try:
import usocket as socket
import ussl as ssl
except:
import socket
import ssl
def test(peer_addr):
s = socket.socket()
s.connect(peer_addr)
s = ssl.wrap_socket(s)
cert = s.getpeercert(True)
print(type(cert), len(cert) > 100)
s.close()
if _... | YifuLiu/AliOS-Things | components/py_engine/tests/net_hosted/ssl_getpeercert.py | Python | apache-2.0 | 403 |
# Test basic behaviour of uasyncio.start_server()
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def test():
# Test creating 2 servers using the same address
print("create server1")
serve... | YifuLiu/AliOS-Things | components/py_engine/tests/net_hosted/uasyncio_start_server.py | Python | apache-2.0 | 677 |
try:
import usocket as socket, sys
except:
import socket, sys
def test_non_existent():
try:
res = socket.getaddrinfo("nonexistent.example.com", 80)
print("getaddrinfo returned", res)
except OSError as e:
print("getaddrinfo raised")
def test_bogus():
try:
res = soc... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/getaddrinfo.py | Python | apache-2.0 | 1,281 |
# test that socket.connect() on a non-blocking socket raises EINPROGRESS
# and that an immediate write/send/read/recv does the right thing
import sys
try:
import uerrno as errno, usocket as socket, ussl as ssl
except:
import errno, socket, ssl
def test(addr, hostname, block=True):
print("---", hostname ... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/ssl_errors.py | Python | apache-2.0 | 1,496 |
try:
import usocket as socket, ussl as ssl, uerrno as errno, sys
except:
import socket, ssl, errno, sys, time, select
def test_one(site, opts):
ai = socket.getaddrinfo(site, 443)
addr = ai[0][-1]
print(addr)
# Connect the raw socket
s = socket.socket()
s.setblocking(False)
try:
... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/test_tls_nonblock.py | Python | apache-2.0 | 3,119 |
try:
import usocket as _socket
except:
import _socket
try:
import ussl as ssl
except:
import ssl
# CPython only supports server_hostname with SSLContext
ssl = ssl.SSLContext()
def test_one(site, opts):
ai = _socket.getaddrinfo(site, 443)
addr = ai[0][-1]
s = _socket.socket()
... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/test_tls_sites.py | Python | apache-2.0 | 1,211 |
# test that modtls produces a numerical error message when out of heap
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
# test with heap locked ... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/tls_num_errors.py | Python | apache-2.0 | 1,191 |
# test that modtls produces a text error message
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
def test(addr):
s = socket.socket()
s.connect(addr)
try:
s = ssl.wrap_socket(s)
print("wrap: no exception")
except OSError as e:
# mbedtls p... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/tls_text_errors.py | Python | apache-2.0 | 960 |
# Test cancelling a task waiting on stream IO
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def get(reader):
print("start")
try:
await reader.read(10)
print("fail")
excep... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/uasyncio_cancel_stream.py | Python | apache-2.0 | 712 |
# Test simple HTTP request with uasyncio.open_connection()
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def http_get(url):
reader, writer = await asyncio.open_connection(url, 80)
print("wr... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/uasyncio_open_connection.py | Python | apache-2.0 | 635 |
# Test uasyncio.open_connection() and stream readline()
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def http_get_headers(url):
reader, writer = await asyncio.open_connection(url, 80)
prin... | YifuLiu/AliOS-Things | components/py_engine/tests/net_inet/uasyncio_tcp_read_headers.py | Python | apache-2.0 | 839 |
def bm_run(N, M):
try:
from utime import ticks_us, ticks_diff
except ImportError:
import time
ticks_us = lambda: int(time.perf_counter() * 1000000)
ticks_diff = lambda a, b: a - b
# Pick sensible parameters given N, M
cur_nm = (0, 0)
param = None
for nm, p in bm... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/benchrun.py | Python | apache-2.0 | 708 |
# Source: https://github.com/python/pyperformance
# License: MIT
# create chaosgame-like fractals
# Copyright (C) 2005 Carl Friedrich Bolz
import math
import random
class GVector(object):
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def Mag(self):
retu... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/bm_chaos.py | Python | apache-2.0 | 9,247 |
# Source: https://github.com/python/pyperformance
# License: MIT
# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org/
# Contributed by Sokolov Yura, modified by Tupteq.
def fannkuch(n):
count = list(range(1, n + 1))
max_flips = 0
m = n - 1
r = n
check = 0
perm1 =... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/bm_fannkuch.py | Python | apache-2.0 | 1,495 |