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 |
|---|---|---|---|---|---|
# Copyright (c) 2019 Project Nayuki. (MIT License)
# https://www.nayuki.io/page/free-small-fft-in-multiple-languages
import math, cmath
def transform_radix2(vector, inverse):
# Returns the integer whose value is the reverse of the lowest 'bits' bits of the integer 'x'.
def reverse(x, bits):
y = 0
... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/bm_fft.py | Python | apache-2.0 | 2,107 |
# Source: https://github.com/python/pyperformance
# License: MIT
# Artificial, floating point-heavy benchmark originally used by Factor.
from math import sin, cos, sqrt
class Point(object):
__slots__ = ("x", "y", "z")
def __init__(self, i):
self.x = x = sin(i)
self.y = cos(i) * 3
se... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/bm_float.py | Python | apache-2.0 | 1,657 |
# Source: https://github.com/python/pyperformance
# License: MIT
# Solver of Hexiom board game.
# Benchmark from Laurent Vaucher.
# Source: https://github.com/slowfrog/hexiom : hexiom2.py, level36.txt
# (Main function tweaked by Armin Rigo.)
##################################
class Dir(object):
def __init__(self... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/bm_hexiom.py | Python | apache-2.0 | 16,870 |
# Source: https://github.com/python/pyperformance
# License: MIT
# Simple, brute-force N-Queens solver.
# author: collinwinter@google.com (Collin Winter)
# n_queens function: Copyright 2009 Raymond Hettinger
# Pure-Python implementation of itertools.permutations().
def permutations(iterable, r=None):
"""permutati... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/bm_nqueens.py | Python | apache-2.0 | 1,935 |
# Source: https://github.com/python/pyperformance
# License: MIT
# Calculating some of the digits of π.
# This benchmark stresses big integer arithmetic.
# Adapted from code on: http://benchmarksgame.alioth.debian.org/
def compose(a, b):
aq, ar, as_, at = a
bq, br, bs, bt = b
return (aq * bq, aq * br + a... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/bm_pidigits.py | Python | apache-2.0 | 1,375 |
# Pure Python AES encryption routines.
#
# AES is integer based and inplace so doesn't use the heap. It is therefore
# a good test of raw performance and correctness of the VM/runtime.
#
# The AES code comes first (code originates from a C version authored by D.P.George)
# and then the test harness at the bottom.
#
# ... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/misc_aes.py | Python | apache-2.0 | 7,652 |
# Compute the Mandelbrot set, to test complex numbers
def mandelbrot(w, h):
def in_set(c):
z = 0
for i in range(32):
z = z * z + c
if abs(z) > 100:
return i
return 0
img = bytearray(w * h)
xscale = (w - 1) / 2.4
yscale = (h - 1) / 3.2
... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/misc_mandel.py | Python | apache-2.0 | 724 |
"""
"PYSTONE" Benchmark Program
Version: Python/1.2 (corresponds to C/1.1 plus 3 Pystone fixes)
Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013.
Translated from ADA to C by Rick Richardson.
Every method to preserve ADA-likeness has been used,
... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/misc_pystone.py | Python | apache-2.0 | 5,799 |
# A simple ray tracer
# MIT license; Copyright (c) 2019 Damien P. George
INF = 1e30
EPS = 1e-6
class Vec:
def __init__(self, x, y, z):
self.x, self.y, self.z = x, y, z
def __neg__(self):
return Vec(-self.x, -self.y, -self.z)
def __add__(self, rhs):
return Vec(self.x + rhs.x, sel... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/misc_raytrace.py | Python | apache-2.0 | 7,296 |
@micropython.viper
def f0():
pass
@micropython.native
def call(r):
f = f0
for _ in r:
f()
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] ... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/viper_call0.py | Python | apache-2.0 | 335 |
@micropython.viper
def f1a(x):
return x
@micropython.native
def call(r):
f = f1a
for _ in r:
f(1)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (pa... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/viper_call1a.py | Python | apache-2.0 | 343 |
@micropython.viper
def f1b(x) -> int:
return int(x)
@micropython.native
def call(r):
f = f1b
for _ in r:
f(1)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])),... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/viper_call1b.py | Python | apache-2.0 | 355 |
@micropython.viper
def f1c(x: int) -> int:
return x
@micropython.native
def call(r):
f = f1c
for _ in r:
f(1)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])),... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/viper_call1c.py | Python | apache-2.0 | 355 |
@micropython.viper
def f2a(x, y):
return x
@micropython.native
def call(r):
f = f2a
for _ in r:
f(1, 2)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(range(params[0])), lambd... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/viper_call2a.py | Python | apache-2.0 | 349 |
@micropython.viper
def f2b(x: int, y: int) -> int:
return x + y
@micropython.native
def call(r):
f = f2b
for _ in r:
f(1, 2)
bm_params = {
(50, 10): (15000,),
(100, 10): (30000,),
(1000, 10): (300000,),
(5000, 10): (1500000,),
}
def bm_setup(params):
return lambda: call(ran... | YifuLiu/AliOS-Things | components/py_engine/tests/perf_bench/viper_call2b.py | Python | apache-2.0 | 370 |
import pyb
if not hasattr(pyb, "Accel"):
print("SKIP")
raise SystemExit
accel = pyb.Accel()
print(accel)
accel.x()
accel.y()
accel.z()
accel.tilt()
accel.filtered_xyz()
| YifuLiu/AliOS-Things | components/py_engine/tests/pyb/accel.py | Python | apache-2.0 | 179 |
from pyb import ADC, Timer
adct = ADC(16) # Temperature 930 -> 20C
print(str(adct)[:19])
adcv = ADC(17) # Voltage 1500 -> 3.3V
print(adcv)
# read single sample; 2.5V-5V is pass range
val = adcv.read()
assert val > 1000 and val < 2000
# timer for read_timed
tim = Timer(5, freq=500)
# read into bytearray
buf = byte... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/adc.py | Python | apache-2.0 | 1,546 |
from pyb import Pin, ADCAll
pins = [Pin.cpu.A0, Pin.cpu.A1, Pin.cpu.A2, Pin.cpu.A3]
# set pins to IN mode, init ADCAll, then check pins are ANALOG
for p in pins:
p.init(p.IN)
adc = ADCAll(12)
for p in pins:
print(p)
# set pins to IN mode, init ADCAll with mask, then check some pins are ANALOG
for p in pins:
... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/adcall.py | Python | apache-2.0 | 699 |
# Test board-specific items on PYBv1.x
import os, pyb
if not "PYBv1." in os.uname().machine:
print("SKIP")
raise SystemExit
# test creating UART by id/name
for bus in (1, 2, 3, 4, 5, 6, 7, "XA", "XB", "YA", "YB", "Z"):
try:
pyb.UART(bus, 9600)
print("UART", bus)
except ValueError:
... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/board_pybv1x.py | Python | apache-2.0 | 911 |
try:
from pyb import CAN
except ImportError:
print("SKIP")
raise SystemExit
from array import array
import micropython
import pyb
# test we can correctly create by id (2 handled in can2.py test)
for bus in (-1, 0, 1, 3):
try:
CAN(bus, CAN.LOOPBACK)
print("CAN", bus)
except ValueErr... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/can.py | Python | apache-2.0 | 6,398 |
try:
from pyb import CAN
CAN(2)
except (ImportError, ValueError):
print("SKIP")
raise SystemExit
# Testing rtr messages
bus2 = CAN(2, CAN.LOOPBACK, extframe=True)
while bus2.any(0):
bus2.recv(0)
bus2.setfilter(0, CAN.LIST32, 0, (1, 2), rtr=(True, True))
bus2.setfilter(1, CAN.LIST32, 0, (3, 4), rtr... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/can2.py | Python | apache-2.0 | 637 |
import pyb
if not hasattr(pyb, "DAC"):
print("SKIP")
raise SystemExit
dac = pyb.DAC(1)
print(dac)
dac.noise(100)
dac.triangle(100)
dac.write(0)
dac.write_timed(bytearray(10), 100, mode=pyb.DAC.NORMAL)
pyb.delay(20)
dac.write(0)
# test buffering arg
dac = pyb.DAC(1, buffering=True)
dac.write(0)
| YifuLiu/AliOS-Things | components/py_engine/tests/pyb/dac.py | Python | apache-2.0 | 306 |
import pyb
# test basic functionality
ext = pyb.ExtInt("X5", pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l: print("line:", l))
ext.disable()
ext.enable()
print(ext.line())
ext.swint()
# test swint while disabled, then again after re-enabled
ext.disable()
ext.swint()
ext.enable()
ext.swint()
# disable now that t... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/extint.py | Python | apache-2.0 | 354 |
import pyb
from pyb import I2C
# test we can correctly create by id
for bus in (-1, 0, 1):
try:
I2C(bus)
print("I2C", bus)
except ValueError:
print("ValueError", bus)
i2c = I2C(1)
i2c.init(I2C.CONTROLLER, baudrate=400000)
print(i2c.scan())
i2c.deinit()
| YifuLiu/AliOS-Things | components/py_engine/tests/pyb/i2c.py | Python | apache-2.0 | 288 |
# use accelerometer to test i2c bus
import pyb
from pyb import I2C
if not hasattr(pyb, "Accel"):
print("SKIP")
raise SystemExit
accel_addr = 76
pyb.Accel() # this will init the MMA for us
i2c = I2C(1, I2C.CONTROLLER, baudrate=400000)
print(i2c.scan())
print(i2c.is_ready(accel_addr))
print(i2c.mem_read(1... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/i2c_accel.py | Python | apache-2.0 | 455 |
# test I2C errors, with polling (disabled irqs) and DMA
import pyb
from pyb import I2C
if not hasattr(pyb, "Accel"):
print("SKIP")
raise SystemExit
# init accelerometer
pyb.Accel()
# get I2C bus
i2c = I2C(1, I2C.CONTROLLER, dma=True)
# test polling mem_read
pyb.disable_irq()
i2c.mem_read(1, 76, 0x0A) # sh... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/i2c_error.py | Python | apache-2.0 | 1,214 |
import pyb
def test_irq():
# test basic disable/enable
i1 = pyb.disable_irq()
print(i1)
pyb.enable_irq() # by default should enable IRQ
# check that interrupts are enabled by waiting for ticks
pyb.delay(10)
# check nested disable/enable
i1 = pyb.disable_irq()
i2 = pyb.disable_ir... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/irq.py | Python | apache-2.0 | 481 |
import os, pyb
machine = os.uname().machine
if "PYBv1." in machine or "PYBLITEv1." in machine:
leds = [pyb.LED(i) for i in range(1, 5)]
pwm_leds = leds[2:]
elif "PYBD" in machine:
leds = [pyb.LED(i) for i in range(1, 4)]
pwm_leds = []
else:
print("SKIP")
raise SystemExit
# test printing
for i ... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/led.py | Python | apache-2.0 | 865 |
# test stm module
import stm
import pyb
# test storing a full 32-bit number
# turn on then off the A15(=yellow) LED
BSRR = 0x18
stm.mem32[stm.GPIOA + BSRR] = 0x00008000
pyb.delay(100)
print(hex(stm.mem32[stm.GPIOA + stm.GPIO_ODR] & 0x00008000))
stm.mem32[stm.GPIOA + BSRR] = 0x80000000
print(hex(stm.mem32[stm.GPIOA + ... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/modstm.py | Python | apache-2.0 | 349 |
import time
DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def is_leap(year):
return (year % 4) == 0
def test():
seconds = 0
wday = 5 # Jan 1, 2000 was a Saturday
for year in range(2000, 2034):
print("Testing %d" % year)
yday = 1
for month in range(1, ... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/modtime.py | Python | apache-2.0 | 2,902 |
from pyb import Pin
p = Pin("X8", Pin.IN)
print(p)
print(p.name())
print(p.pin())
print(p.port())
p = Pin("X8", Pin.IN, Pin.PULL_UP)
p = Pin("X8", Pin.IN, pull=Pin.PULL_UP)
p = Pin("X8", mode=Pin.IN, pull=Pin.PULL_UP)
print(p)
print(p.value())
p.init(p.IN, p.PULL_DOWN)
p.init(p.IN, pull=p.PULL_DOWN)
p.init(mode=p.IN... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/pin.py | Python | apache-2.0 | 554 |
# basic tests of pyb module
import pyb
# test delay
pyb.delay(-1)
pyb.delay(0)
pyb.delay(1)
start = pyb.millis()
pyb.delay(17)
print((pyb.millis() - start) // 5) # should print 3
# test udelay
pyb.udelay(-1)
pyb.udelay(0)
pyb.udelay(1)
start = pyb.millis()
pyb.udelay(17000)
print((pyb.millis() - start) // 5) #... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/pyb1.py | Python | apache-2.0 | 502 |
# test pyb module on F405 MCUs
import os, pyb
if not "STM32F405" in os.uname().machine:
print("SKIP")
raise SystemExit
print(pyb.freq())
print(type(pyb.rng()))
# test HAL error specific to F405
i2c = pyb.I2C(2, pyb.I2C.CONTROLLER)
try:
i2c.recv(1, 1)
except OSError as e:
print(repr(e))
| YifuLiu/AliOS-Things | components/py_engine/tests/pyb/pyb_f405.py | Python | apache-2.0 | 307 |
# test pyb module on F411 MCUs
import os, pyb
if not "STM32F411" in os.uname().machine:
print("SKIP")
raise SystemExit
print(pyb.freq())
| YifuLiu/AliOS-Things | components/py_engine/tests/pyb/pyb_f411.py | Python | apache-2.0 | 148 |
import pyb, stm
from pyb import RTC
rtc = RTC()
rtc.init()
print(rtc)
# make sure that 1 second passes correctly
rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
pyb.delay(1002)
print(rtc.datetime()[:7])
def set_and_print(datetime):
rtc.datetime(datetime)
print(rtc.datetime()[:7])
# make sure that setting works ... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/rtc.py | Python | apache-2.0 | 2,216 |
from pyb import Servo
servo = Servo(1)
print(servo)
servo.angle(0)
servo.angle(10, 100)
servo.speed(-10)
servo.speed(10, 100)
servo.pulse_width(1500)
print(servo.pulse_width())
servo.calibration(630, 2410, 1490, 2460, 2190)
print(servo.calibration())
| YifuLiu/AliOS-Things | components/py_engine/tests/pyb/servo.py | Python | apache-2.0 | 256 |
from pyb import SPI
# test we can correctly create by id
for bus in (-1, 0, 1, 2):
try:
SPI(bus)
print("SPI", bus)
except ValueError:
print("ValueError", bus)
spi = SPI(1)
print(spi)
spi = SPI(1, SPI.CONTROLLER)
spi = SPI(1, SPI.CONTROLLER, baudrate=500000)
spi = SPI(
1, SPI.CONTR... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/spi.py | Python | apache-2.0 | 833 |
from pyb import Switch
sw = Switch()
print(sw())
sw.callback(print)
sw.callback(None)
| YifuLiu/AliOS-Things | components/py_engine/tests/pyb/switch.py | Python | apache-2.0 | 87 |
# check basic functionality of the timer class
import pyb
from pyb import Timer
tim = Timer(4)
tim = Timer(4, prescaler=100, period=200)
print(tim.prescaler())
print(tim.period())
tim.prescaler(300)
print(tim.prescaler())
tim.period(400)
print(tim.period())
# Setting and printing frequency
tim = Timer(2, freq=100)
p... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/timer.py | Python | apache-2.0 | 388 |
# check callback feature of the timer class
import pyb
from pyb import Timer
# callback function that disables the callback when called
def cb1(t):
print("cb1")
t.callback(None)
# callback function that disables the timer when called
def cb2(t):
print("cb2")
t.deinit()
# callback where cb4 closes ... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/timer_callback.py | Python | apache-2.0 | 1,006 |
from pyb import UART
# test we can correctly create by id
for bus in (-1, 0, 1, 2, 5, 6):
try:
UART(bus, 9600)
print("UART", bus)
except ValueError:
print("ValueError", bus)
uart = UART(1)
uart = UART(1, 9600)
uart = UART(1, 9600, bits=8, parity=None, stop=1)
print(uart)
uart.init(240... | YifuLiu/AliOS-Things | components/py_engine/tests/pyb/uart.py | Python | apache-2.0 | 854 |
import time, pyb
@micropython.native
def f(led, n, d):
led.off()
i = 0
while i < n:
print(i)
led.toggle()
time.sleep_ms(d)
i += 1
led.off()
f(pyb.LED(1), 2, 150)
f(pyb.LED(2), 4, 50)
| YifuLiu/AliOS-Things | components/py_engine/tests/pybnative/while.py | Python | apache-2.0 | 235 |
import native_frozen_align
native_frozen_align.native_x(1)
native_frozen_align.native_y(2)
native_frozen_align.native_z(3)
| YifuLiu/AliOS-Things | components/py_engine/tests/qemu-arm/native_test.py | Python | apache-2.0 | 124 |
#! /usr/bin/env python3
import os
import subprocess
import sys
import argparse
import re
from glob import glob
from collections import defaultdict
# Tests require at least CPython 3.3. If your default python3 executable
# is of lower version, you can point MICROPY_CPYTHON3 environment var
# to the correct executable.... | YifuLiu/AliOS-Things | components/py_engine/tests/run-internalbench.py | Python | apache-2.0 | 3,276 |
#!/usr/bin/env python3
# This file is part of the MicroPython project, http://micropython.org/
# The MIT License (MIT)
# Copyright (c) 2020 Damien P. George
import sys, os, time, re, select
import argparse
import itertools
import subprocess
import tempfile
sys.path.append("../tools")
import pyboard
if os.name == "n... | YifuLiu/AliOS-Things | components/py_engine/tests/run-multitests.py | Python | apache-2.0 | 16,235 |
#!/usr/bin/env python3
# This file is part of the MicroPython project, http://micropython.org/
# The MIT License (MIT)
# Copyright (c) 2019 Damien P. George
import os
import subprocess
import sys
import argparse
sys.path.append("../tools")
import pyboard
# Paths for host executables
CPYTHON3 = os.getenv("MICROPY_CP... | YifuLiu/AliOS-Things | components/py_engine/tests/run-natmodtests.py | Python | apache-2.0 | 5,851 |
#!/usr/bin/env python3
# This file is part of the MicroPython project, http://micropython.org/
# The MIT License (MIT)
# Copyright (c) 2019 Damien P. George
import os
import subprocess
import sys
import argparse
from glob import glob
sys.path.append("../tools")
import pyboard
# Paths for host executables
if os.name... | YifuLiu/AliOS-Things | components/py_engine/tests/run-perfbench.py | Python | apache-2.0 | 8,890 |
#! /usr/bin/env python3
import os
import subprocess
import sys
import platform
import argparse
import inspect
import re
from glob import glob
import multiprocessing
from multiprocessing.pool import ThreadPool
import threading
import tempfile
# See stackoverflow.com/questions/2632199: __file__ nor sys.argv[0]
# are gu... | YifuLiu/AliOS-Things | components/py_engine/tests/run-tests.py | Python | apache-2.0 | 34,439 |
# copying a large dictionary
a = {i: 2 * i for i in range(1000)}
b = a.copy()
for i in range(1000):
print(i, b[i])
print(len(b))
| YifuLiu/AliOS-Things | components/py_engine/tests/stress/dict_copy.py | Python | apache-2.0 | 134 |
# create a large dictionary
d = {}
x = 1
while x < 1000:
d[x] = x
x += 1
print(d[500])
| YifuLiu/AliOS-Things | components/py_engine/tests/stress/dict_create.py | Python | apache-2.0 | 96 |
# The aim with this test is to hit the maximum resize/rehash size of a dict,
# where there are no more primes in the table of growing allocation sizes.
# This value is 54907 items.
d = {}
try:
for i in range(54908):
d[i] = i
except MemoryError:
pass
# Just check the dict still has the first value
prin... | YifuLiu/AliOS-Things | components/py_engine/tests/stress/dict_create_max.py | Python | apache-2.0 | 328 |
# test that the GC can trace nested objects
try:
import gc
except ImportError:
print("SKIP")
raise SystemExit
# test a big shallow object pointing to many unique objects
lst = [[i] for i in range(200)]
gc.collect()
print(lst)
# test a deep object
lst = [
[[[[(i, j, k, l)] for i in range(3)] for j in ... | YifuLiu/AliOS-Things | components/py_engine/tests/stress/gc_trace.py | Python | apache-2.0 | 393 |
# test large list sorting (should not stack overflow)
l = list(range(2000))
l.sort()
print(l[0], l[-1])
l.sort(reverse=True)
print(l[0], l[-1])
| YifuLiu/AliOS-Things | components/py_engine/tests/stress/list_sort.py | Python | apache-2.0 | 144 |
# Test interning qstrs that go over the limit of the maximum qstr length
# (which is 255 bytes for the default configuration)
def make_id(n, base="a"):
return "".join(chr(ord(base) + i % 26) for i in range(n))
# identifiers in parser
for l in range(254, 259):
g = {}
var = make_id(l)
try:
exe... | YifuLiu/AliOS-Things | components/py_engine/tests/stress/qstr_limit.py | Python | apache-2.0 | 1,992 |
def foo():
foo()
try:
foo()
except RuntimeError:
print("RuntimeError")
| YifuLiu/AliOS-Things | components/py_engine/tests/stress/recursion.py | Python | apache-2.0 | 85 |
# This tests that printing recursive data structure doesn't lead to segfault.
try:
import uio as io
except ImportError:
print("SKIP")
raise SystemExit
l = [1, 2, 3, None]
l[-1] = l
try:
print(l, file=io.StringIO())
except RuntimeError:
print("RuntimeError")
| YifuLiu/AliOS-Things | components/py_engine/tests/stress/recursive_data.py | Python | apache-2.0 | 279 |
# test deeply recursive generators
# simple "yield from" recursion
def gen():
yield from gen()
try:
list(gen())
except RuntimeError:
print("RuntimeError")
# recursion via an iterator over a generator
def gen2():
for x in gen2():
yield x
try:
next(gen2())
except RuntimeError:
print(... | YifuLiu/AliOS-Things | components/py_engine/tests/stress/recursive_gen.py | Python | apache-2.0 | 336 |
# This tests that recursion with iternext doesn't lead to segfault.
try:
enumerate
filter
map
max
zip
except:
print("SKIP")
raise SystemExit
# We need to pick an N that is large enough to hit the recursion
# limit, but not too large that we run out of heap memory.
try:
# large stack/hea... | YifuLiu/AliOS-Things | components/py_engine/tests/stress/recursive_iternext.py | Python | apache-2.0 | 1,015 |
# test concurrent mutating access to a shared bytearray object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
# the shared bytearray
ba = bytearray()
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
l = len(b... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/mutate_bytearray.py | Python | apache-2.0 | 1,014 |
# test concurrent mutating access to a shared dict object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
# the shared dict
di = {"a": "A", "b": "B", "c": "C", "d": "D"}
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/mutate_dict.py | Python | apache-2.0 | 924 |
# test concurrent mutating access to a shared user instance
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
# the shared user class and instance
class User:
def __init__(self):
self.a = "A"
self.b = "B"
self.c = "C"
user = User()
# main thread ... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/mutate_instance.py | Python | apache-2.0 | 1,083 |
# test concurrent mutating access to a shared list object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
# the shared list
li = list()
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
li.append(i)
... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/mutate_list.py | Python | apache-2.0 | 930 |
# test concurrent mutating access to a shared set object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
# the shared set
se = set([-1, -2, -3, -4])
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/mutate_set.py | Python | apache-2.0 | 761 |
# Stress test for threads using AES encryption routines.
#
# AES was chosen because it is integer based and inplace so doesn't use the
# heap. It is therefore a good test of raw performance and correctness of the
# VM/runtime. It can be used to measure threading performance (concurrency is
# in principle possible) an... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/stress_aes.py | Python | apache-2.0 | 9,136 |
# stress test for creating many threads
try:
import utime
sleep_ms = utime.sleep_ms
except ImportError:
import time
sleep_ms = lambda t: time.sleep(t / 1000)
import _thread
def thread_entry(n):
pass
thread_num = 0
while thread_num < 500:
try:
_thread.start_new_thread(thread_entry,... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/stress_create.py | Python | apache-2.0 | 634 |
# stress test for the heap by allocating lots of objects within threads
# allocates about 5mb on the heap
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
def last(l):
return l[-1]
def thread_entry(n):
... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/stress_heap.py | Python | apache-2.0 | 1,102 |
# test hitting the function recursion limit within a thread
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo():
foo()
def thread_entry():
try:
foo()
except RuntimeError:
print("RuntimeError")
global finished
finished = True
fin... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/stress_recurse.py | Python | apache-2.0 | 455 |
# This test ensures that the scheduler doesn't trigger any assertions
# while dealing with concurrent access from multiple threads.
import _thread
import utime
import micropython
import gc
try:
micropython.schedule
except AttributeError:
print("SKIP")
raise SystemExit
gc.disable()
_NUM_TASKS = 10000
_TI... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/stress_schedule.py | Python | apache-2.0 | 1,061 |
# test raising and catching an exception within a thread
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo():
raise ValueError
def thread_entry():
try:
foo()
except ValueError:
pass
with lock:
global n_finished
n_finis... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_exc1.py | Python | apache-2.0 | 663 |
# test raising exception within thread which is not caught
import utime
import _thread
def thread_entry():
raise ValueError
_thread.start_new_thread(thread_entry, ())
utime.sleep(1)
print("done")
| YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_exc2.py | Python | apache-2.0 | 204 |
# test _thread.exit() function
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
def thread_entry():
_thread.exit()
for i in range(2):
while True:
try:
_thread.start_new_thread(thr... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_exit1.py | Python | apache-2.0 | 452 |
# test raising SystemExit to finish a thread
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
def thread_entry():
raise SystemExit
for i in range(2):
while True:
try:
_thread.star... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_exit2.py | Python | apache-2.0 | 468 |
# test that we can run the garbage collector within threads
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import gc
import _thread
def thread_entry(n):
# allocate a bytearray and fill it
data = bytearray(i for i in range(256))
# do some work and call gc.collect() a few time... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_gc1.py | Python | apache-2.0 | 843 |
# test interaction of micropython.heap_lock with threads
import _thread, micropython
lock1 = _thread.allocate_lock()
lock2 = _thread.allocate_lock()
def thread_entry():
lock1.acquire()
print([1, 2, 3])
lock2.release()
lock1.acquire()
lock2.acquire()
_thread.start_new_thread(thread_entry, ())
micropy... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_heap_lock.py | Python | apache-2.0 | 428 |
# test _thread.get_ident() function
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def thread_entry():
tid = _thread.get_ident()
print("thread", type(tid) == int, tid != 0, tid != tid_main)
global finished
finished = True
tid_main = _thread.get_ident()
pr... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_ident1.py | Python | apache-2.0 | 475 |
# test _thread lock object using a single thread
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
# create lock
lock = _thread.allocate_lock()
print(type(lock) == _thread.LockType)
# should be unlocked
print(lock.locked())
# basic acquire and release
print(lock.acquire())
... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_lock1.py | Python | apache-2.0 | 918 |
# test _thread lock objects with multiple threads
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
lock = _thread.allocate_lock()
def thread_entry():
lock.acquire()
print("have it")
lock.release()... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_lock2.py | Python | apache-2.0 | 467 |
# test thread coordination using a lock object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0
def thread_entry(idx):
global n_finished
while True:
with lock:
if n_finished == idx:
... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_lock3.py | Python | apache-2.0 | 570 |
# test using lock to coordinate access to global mutable objects
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
def fac(n):
x = 1
for i in range(1, n + 1):
x *= i
return x
def thread_en... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_lock4.py | Python | apache-2.0 | 1,109 |
# test _thread lock objects where a lock is acquired/released by a different thread
import _thread
def thread_entry():
print("thread about to release lock")
lock.release()
lock = _thread.allocate_lock()
lock.acquire()
_thread.start_new_thread(thread_entry, ())
lock.acquire()
print("main has lock")
lock.rel... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_lock5.py | Python | apache-2.0 | 327 |
# test concurrent interning of strings
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
# function to check the interned string
def check(s, val):
assert type(s) == str
assert int(s) == val
# main thr... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_qstr1.py | Python | apache-2.0 | 898 |
# test capability for threads to access a shared immutable data structure
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
loc... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_shared1.py | Python | apache-2.0 | 606 |
# test capability for threads to access a shared mutable data structure
# (without contention because they access different parts of the structure)
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo(lst, i):
lst[i] += 1
def thread_entry(n, lst, idx):
for i in... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_shared2.py | Python | apache-2.0 | 715 |
# test threads sleeping
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime
sleep_ms = utime.sleep_ms
except ImportError:
import time
sleep_ms = lambda t: time.sleep(t / 1000)
import _thread
lock = _thread.allocate_lock()
n_thread = 4
n_finished = 0
def t... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_sleep1.py | Python | apache-2.0 | 616 |
# test setting the thread stack size
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import usys as sys
except ImportError:
import sys
import _thread
# different implementations have different minimum sizes
if sys.implementation.name == "micropython":
sz = 2 * 1024
else:
... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_stacksize1.py | Python | apache-2.0 | 1,131 |
# test basic capability to start a new thread
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
def foo():
pass
def thread_entry(n):
for i in range(n):
foo()
for i in range(2):
while Tru... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_start1.py | Python | apache-2.0 | 521 |
# test capability to start a thread with keyword args
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
import _thread
def thread_entry(a0, a1, a2, a3):
print("thread", a0, a1, a2, a3)
# spawn thread using kw args
_thre... | YifuLiu/AliOS-Things | components/py_engine/tests/thread/thread_start2.py | Python | apache-2.0 | 605 |
f = open("unicode/data/utf-8_1.txt", encoding="utf-8")
l = f.readline()
print(l)
print(len(l))
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/file1.py | Python | apache-2.0 | 95 |
# test reading a given number of characters
def do(mode):
if mode == "rb":
enc = None
else:
enc = "utf-8"
f = open("unicode/data/utf-8_2.txt", mode=mode, encoding=enc)
print(f.read(1))
print(f.read(1))
print(f.read(2))
print(f.read(4))
# skip to end of line
f.readl... | YifuLiu/AliOS-Things | components/py_engine/tests/unicode/file2.py | Python | apache-2.0 | 511 |
# Test a UTF-8 encoded literal
s = "asdf©qwer"
for i in range(len(s)):
print("s[%d]: %s %X" % (i, s[i], ord(s[i])))
# Test all three forms of Unicode escape, and
# all blocks of UTF-8 byte patterns
s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C"
for i in range(-len(s), len(s)):
print("s[%d]: %s %X" % (i, s[i],... | YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode.py | Python | apache-2.0 | 1,362 |
# test builtin chr with unicode characters
print(chr(945))
print(chr(0x800))
print(chr(0x10000))
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_chr.py | Python | apache-2.0 | 98 |
# test unicode in identifiers
# comment
# αβγδϵφζ
# global identifiers
α = 1
αβγ = 2
bβ = 3
βb = 4
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
print(β, γ, δ)
α(1, 2)
# class, method identifiers
class φ:
def __init__(self):
pass
def δ(self, ϵ):
... | YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_id.py | Python | apache-2.0 | 433 |
print("Привет".find("т"))
print("Привет".find("П"))
print("Привет".rfind("т"))
print("Привет".rfind("П"))
print("Привет".index("т"))
print("Привет".index("П"))
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_index.py | Python | apache-2.0 | 202 |
for c in "Hello":
print(c)
for c in "Привет":
print(c)
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_iter.py | Python | apache-2.0 | 69 |
# test builtin ord with unicode characters
print(ord("α"))
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_ord.py | Python | apache-2.0 | 61 |
# str methods with explicit start/end pos
print("Привет".startswith("П"))
print("Привет".startswith("р", 1))
print("абвба".find("а", 1))
print("абвба".find("а", 1, -1))
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_pos.py | Python | apache-2.0 | 195 |
# Test slicing of Unicode strings
s = "Привет"
print(s[:])
print(s[2:])
print(s[:5])
print(s[2:5])
print(s[2:5:1])
print(s[2:10])
print(s[-3:10])
print(s[-4:10])
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_slice.py | Python | apache-2.0 | 170 |
# test handling of unicode chars in format strings
print("α".format())
print("{α}".format(α=1))
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_str_format.py | Python | apache-2.0 | 100 |
# test handling of unicode chars in string % formatting
print("α" % ())
| YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_str_modulo.py | Python | apache-2.0 | 74 |
a = "¢пр"
print(a[0], a[0:1])
print(a[1], a[1:2])
print(a[2], a[2:3])
try:
print(a[3])
except IndexError:
print("IndexError")
print(a[3:4])
print(a[-1])
print(a[-2], a[-2:-1])
print(a[-3], a[-3:-2])
try:
print(a[-4])
except IndexError:
print("IndexError")
print(a[-4:-3])
print(a[0:2])
print(a[1:3])
p... | YifuLiu/AliOS-Things | components/py_engine/tests/unicode/unicode_subscr.py | Python | apache-2.0 | 336 |