Commit 37a2015c authored by Daniel Campora's avatar Daniel Campora
Browse files

tests/wipy: Add machine module tests.

parent 958e2733
...@@ -134,6 +134,16 @@ STATIC mp_obj_t machine_unique_id(void) { ...@@ -134,6 +134,16 @@ STATIC mp_obj_t machine_unique_id(void) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
STATIC mp_obj_t machine_main(mp_obj_t main) {
if (MP_OBJ_IS_STR(main)) {
MP_STATE_PORT(machine_config_main) = main;
} else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_main_obj, machine_main);
STATIC mp_obj_t machine_idle(void) { STATIC mp_obj_t machine_idle(void) {
__WFI(); __WFI();
return mp_const_none; return mp_const_none;
...@@ -162,8 +172,6 @@ STATIC mp_obj_t machine_wake_reason (void) { ...@@ -162,8 +172,6 @@ STATIC mp_obj_t machine_wake_reason (void) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason); STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
MP_DECLARE_CONST_FUN_OBJ(machine_main_obj); // defined in main.c
STATIC const mp_map_elem_t machine_module_globals_table[] = { STATIC const mp_map_elem_t machine_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) }, { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) },
......
...@@ -366,10 +366,3 @@ STATIC void mptask_create_main_py (void) { ...@@ -366,10 +366,3 @@ STATIC void mptask_create_main_py (void) {
f_close(&fp); f_close(&fp);
} }
STATIC mp_obj_t machine_main(mp_obj_t main) {
if (MP_OBJ_IS_STR(main)) {
MP_STATE_PORT(machine_config_main) = main;
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(machine_main_obj, machine_main);
'''
machine test for the CC3200 based boards.
'''
import machine
import os
from network import WLAN
mch = os.uname().machine
if not 'LaunchPad' in mch and not'WiPy' in mch:
raise Exception('Board not supported!')
wifi = WLAN()
print(machine)
machine.idle()
print(machine.freq() == (80000000,))
print(machine.unique_id() == wifi.mac())
machine.main('main.py')
rand_nums = []
for i in range(0, 100):
rand = machine.rng()
if rand not in rand_nums:
rand_nums.append(rand)
else:
print('RNG number repeated')
break
for i in range(0, 10):
machine.idle()
print("Active")
print(machine.reset_cause() >= 0)
print(machine.wake_reason() >= 0)
try:
machine.main(123456)
except:
print('Exception')
<module 'machine'>
True
True
Active
True
True
Exception
...@@ -97,6 +97,8 @@ print(wifi.isconnected() == False) ...@@ -97,6 +97,8 @@ print(wifi.isconnected() == False)
# test init again # test init again
wifi.init(WLAN.AP, ssid='www.wipy.io', auth=None, channel=5, antenna=WLAN.INT_ANT) wifi.init(WLAN.AP, ssid='www.wipy.io', auth=None, channel=5, antenna=WLAN.INT_ANT)
print(len(wlan.mac()) == 6)
# next ones MUST raise # next ones MUST raise
try: try:
wifi.init(mode=12345) wifi.init(mode=12345)
......
...@@ -32,6 +32,7 @@ True ...@@ -32,6 +32,7 @@ True
True True
True True
True True
True
Exception Exception
Exception Exception
Exception Exception
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment