Skip to content

Commit d59cb17

Browse files
committed
MCU8MASS-545 Add all tests besides gps tracker and add timeout for entries
1 parent b420a68 commit d59cb17

File tree

2 files changed

+98
-15
lines changed

2 files changed

+98
-15
lines changed

test/test.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"bodvoltage=1v9,bodmode=disabled,eesave=enable,resetpin=reset,"\
2222
"millis=tcb2,startuptime=8,wiremode=mors2,printf=full"
2323

24-
TIMEOUT = 10
24+
TIMEOUT = 30
2525

2626

2727
def retrieve_examples(examples_directory):
@@ -85,17 +85,25 @@ def test(example, test_data, serial_handle):
8585
expectation = entry.get("expectation", None)
8686
command = entry.get("command", None)
8787
repeat = entry.get("repeat", 1)
88+
timeout = entry.get("timeout", TIMEOUT)
8889

89-
for _ in range(0, repeat):
90+
if not expectation:
91+
return (False, f"No expeted value defined for entry: {entry}")
92+
93+
for i in range(0, repeat):
9094
if command != None:
9195
command_stripped = command.strip("\r")
9296
logging.info(f"\tTesting command: {command_stripped}")
9397

9498
serial_handle.write(str.encode(command))
9599
serial_handle.flush()
96100

97-
# Read until line feed
98-
output = serial_handle.read_until().decode("utf-8")
101+
# Read until line feed or timeout
102+
start = time.time()
103+
output = ""
104+
105+
while time.time() - start < timeout and output == "":
106+
output = serial_handle.read_until().decode("utf-8")
99107

100108
response = re.search(expectation, output)
101109

@@ -148,9 +156,15 @@ def test(example, test_data, serial_handle):
148156
default="tests.json")
149157

150158
parser.add_argument("-e",
151-
"--examplesdir",
159+
"--examples",
160+
type=str,
161+
help="Examples to test (all or some specific example, e.g. sandbox)",
162+
default="all")
163+
164+
parser.add_argument("-s",
165+
"--sketchdir",
152166
type=str,
153-
help="Relative path to the example directory",
167+
help="Relative path to the example directory with the example sketches",
154168
default="../examples")
155169

156170
parser.add_argument("-b",
@@ -182,7 +196,7 @@ def test(example, test_data, serial_handle):
182196
for name in files:
183197
os.remove(os.path.join(root, name))
184198

185-
examples = retrieve_examples(arguments.examplesdir)
199+
examples = retrieve_examples(arguments.sketchdir)
186200

187201
test_config = {}
188202

@@ -195,6 +209,9 @@ def test(example, test_data, serial_handle):
195209

196210
example_name = os.path.splitext(os.path.basename(example))[0]
197211

212+
if example_name != arguments.examples and arguments.examples != "all":
213+
continue
214+
198215
if not example_name in test_config:
199216
examples_test_status[example_name] = {"status": "No test defined", "error": None}
200217
continue
@@ -218,7 +235,7 @@ def test(example, test_data, serial_handle):
218235
if not error:
219236
examples_test_status[example_name] = {"status": "Passed", "error": None}
220237
else:
221-
examples_test_status[example_name] = {"status": "Passed", "error": error}
238+
examples_test_status[example_name] = {"status": "Not passed", "error": error}
222239

223240
except serial.SerialException as exception:
224241
logging.error(f"Got exception while opening serial port: {exception}")
@@ -228,6 +245,8 @@ def test(example, test_data, serial_handle):
228245

229246
backend.disconnect_from_tool()
230247

248+
all_tests_passed = True
249+
231250
print("--------------- Test status ---------------")
232251
for example_name, entry in examples_test_status.items():
233252
status = entry["status"]
@@ -237,5 +256,9 @@ def test(example, test_data, serial_handle):
237256
print(f"{example_name:<30}: {status}")
238257
else:
239258
print(f"{example_name:<30}: {status} - {error}")
259+
all_tests_passed = False
240260

241-
exit(0)
261+
if all_tests_passed:
262+
exit(0)
263+
else:
264+
exit(1)

test/tests.json

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@
234234
}
235235
]
236236
},
237-
"mqtt_polling_aws-not-finished": {
238-
"enabled": false,
237+
"mqtt_polling_aws": {
238+
"enabled": true,
239239
"tests": [
240240
{
241241
"expectation": "\\[INFO\\] Starting initialization of MQTT Polling for AWS"
@@ -269,8 +269,8 @@
269269
}
270270
]
271271
},
272-
"power_down-not-finished": {
273-
"enabled": false,
272+
"power_down": {
273+
"enabled": true,
274274
"tests": [
275275
{
276276
"expectation": "\\[INFO\\] Connecting to operator.{0,}OK!"
@@ -282,7 +282,7 @@
282282
"expectation": "\\[INFO\\] Powering down..."
283283
},
284284
{
285-
"timeout": 65,
285+
"timeout": 90,
286286
"expectation": "\\[INFO\\] Connecting to operator.{0,}OK!"
287287
},
288288
{
@@ -292,5 +292,65 @@
292292
"expectation": "\\[INFO\\] Doing work..."
293293
}
294294
]
295+
},
296+
"power_print_voltage": {
297+
"enabled": true,
298+
"tests": [
299+
{
300+
"expectation": "\\[INFO\\] Starting up example for printing voltage supplied to the board"
301+
},
302+
{
303+
"repeat": 5,
304+
"expectation": "\\[INFO\\] The voltage supplied is: [0-9]\\.[0-9]+"
305+
}
306+
]
307+
},
308+
"power_save": {
309+
"enabled": true,
310+
"tests": [
311+
{
312+
"expectation": "\\[INFO\\] Connecting to operator.{0,}OK!"
313+
},
314+
{
315+
"expectation": "\\[INFO\\] Connected to operator: (.*)"
316+
},
317+
{
318+
"expectation": "\\[INFO\\] Power saving..."
319+
},
320+
{
321+
"timeout": 300,
322+
"expectation": "\\[INFO\\] Woke up!"
323+
},
324+
{
325+
"expectation": "\\[INFO\\] Doing work..."
326+
}
327+
]
328+
},
329+
"sandbox": {
330+
"enabled": true,
331+
"tests": [
332+
{
333+
"expectation": "\\[INFO\\] Starting sandbox / landing page procedure. Version = [0-9]+\\.[0-9]+\\.[0-9]+"
334+
},
335+
{
336+
"expectation": "\\[INFO\\] Board name: [a-z0-9]+"
337+
},
338+
{
339+
"expectation": "\\[INFO\\] Connecting to operator.{0,}OK!"
340+
},
341+
{
342+
"expectation": "\\[INFO\\] Connected to operator: (.*)"
343+
},
344+
{
345+
"expectation": "\\[INFO\\] Connecting to MQTT broker..."
346+
},
347+
{
348+
"expectation": "\\[INFO\\] Connected to MQTT broker, subscribing to topic: \\$aws\/things\/[a-z0-9]+\/shadow\/update\/delta!"
349+
},
350+
{
351+
"repeat": 2,
352+
"expectation": "\\[INFO\\] Sending heartbeat"
353+
}
354+
]
295355
}
296-
}
356+
}

0 commit comments

Comments
 (0)