Skip to content

Commit

Permalink
tests/wipy: Add machine module tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Campora committed Sep 27, 2015
1 parent 958e273 commit 37a2015
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
12 changes: 10 additions & 2 deletions cc3200/mods/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) },

Expand Down
7 changes: 0 additions & 7 deletions cc3200/mptask.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
42 changes: 42 additions & 0 deletions tests/wipy/wlan/machine.py
Original file line number Diff line number Diff line change
@@ -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')
7 changes: 7 additions & 0 deletions tests/wipy/wlan/machine.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<module 'machine'>
True
True
Active
True
True
Exception
2 changes: 2 additions & 0 deletions tests/wipy/wlan/wlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def wait_for_connection(wifi, timeout=10):
# 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)
Expand Down
1 change: 1 addition & 0 deletions tests/wipy/wlan/wlan.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ True
True
True
True
True
Exception
Exception
Exception
Expand Down

0 comments on commit 37a2015

Please sign in to comment.