Skip to content

Commit 37a2015

Browse files
author
Daniel Campora
committed
tests/wipy: Add machine module tests.
1 parent 958e273 commit 37a2015

6 files changed

Lines changed: 62 additions & 9 deletions

File tree

cc3200/mods/modmachine.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ STATIC mp_obj_t machine_unique_id(void) {
134134
}
135135
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
136136

137+
STATIC mp_obj_t machine_main(mp_obj_t main) {
138+
if (MP_OBJ_IS_STR(main)) {
139+
MP_STATE_PORT(machine_config_main) = main;
140+
} else {
141+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
142+
}
143+
return mp_const_none;
144+
}
145+
MP_DEFINE_CONST_FUN_OBJ_1(machine_main_obj, machine_main);
146+
137147
STATIC mp_obj_t machine_idle(void) {
138148
__WFI();
139149
return mp_const_none;
@@ -162,8 +172,6 @@ STATIC mp_obj_t machine_wake_reason (void) {
162172
}
163173
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason);
164174

165-
MP_DECLARE_CONST_FUN_OBJ(machine_main_obj); // defined in main.c
166-
167175
STATIC const mp_map_elem_t machine_module_globals_table[] = {
168176
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_machine) },
169177

cc3200/mptask.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,3 @@ STATIC void mptask_create_main_py (void) {
366366
f_close(&fp);
367367
}
368368

369-
STATIC mp_obj_t machine_main(mp_obj_t main) {
370-
if (MP_OBJ_IS_STR(main)) {
371-
MP_STATE_PORT(machine_config_main) = main;
372-
}
373-
return mp_const_none;
374-
}
375-
MP_DEFINE_CONST_FUN_OBJ_1(machine_main_obj, machine_main);

tests/wipy/wlan/machine.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'''
2+
machine test for the CC3200 based boards.
3+
'''
4+
5+
import machine
6+
import os
7+
from network import WLAN
8+
9+
mch = os.uname().machine
10+
if not 'LaunchPad' in mch and not'WiPy' in mch:
11+
raise Exception('Board not supported!')
12+
13+
wifi = WLAN()
14+
15+
print(machine)
16+
machine.idle()
17+
print(machine.freq() == (80000000,))
18+
print(machine.unique_id() == wifi.mac())
19+
20+
machine.main('main.py')
21+
22+
rand_nums = []
23+
for i in range(0, 100):
24+
rand = machine.rng()
25+
if rand not in rand_nums:
26+
rand_nums.append(rand)
27+
else:
28+
print('RNG number repeated')
29+
break
30+
31+
for i in range(0, 10):
32+
machine.idle()
33+
34+
print("Active")
35+
36+
print(machine.reset_cause() >= 0)
37+
print(machine.wake_reason() >= 0)
38+
39+
try:
40+
machine.main(123456)
41+
except:
42+
print('Exception')

tests/wipy/wlan/machine.py.exp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<module 'machine'>
2+
True
3+
True
4+
Active
5+
True
6+
True
7+
Exception

tests/wipy/wlan/wlan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def wait_for_connection(wifi, timeout=10):
9797
# test init again
9898
wifi.init(WLAN.AP, ssid='www.wipy.io', auth=None, channel=5, antenna=WLAN.INT_ANT)
9999

100+
print(len(wlan.mac()) == 6)
101+
100102
# next ones MUST raise
101103
try:
102104
wifi.init(mode=12345)

tests/wipy/wlan/wlan.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ True
3232
True
3333
True
3434
True
35+
True
3536
Exception
3637
Exception
3738
Exception

0 commit comments

Comments
 (0)