tests/wipy: Add machine module tests.

This commit is contained in:
Daniel Campora 2015-09-27 17:04:49 +02:00
parent 958e273336
commit 37a2015cc5
6 changed files with 62 additions and 9 deletions

View File

@ -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_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) {
__WFI();
return mp_const_none;
@ -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);
MP_DECLARE_CONST_FUN_OBJ(machine_main_obj); // defined in main.c
STATIC const mp_map_elem_t machine_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) },

View File

@ -366,10 +366,3 @@ STATIC void mptask_create_main_py (void) {
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);

View File

@ -0,0 +1,42 @@
'''
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')

View File

@ -0,0 +1,7 @@
<module 'machine'>
True
True
Active
True
True
Exception

View File

@ -97,6 +97,8 @@ print(wifi.isconnected() == False)
# test init again
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
try:
wifi.init(mode=12345)

View File

@ -32,6 +32,7 @@ True
True
True
True
True
Exception
Exception
Exception