Skip to content

Commit 73b0546

Browse files
committed
Add tests for system_reset()
1 parent 4cb47df commit 73b0546

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

TESTS/host_tests/system_reset.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Copyright (c) 2018 ARM Limited
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
import time
17+
from mbed_host_tests import BaseHostTest
18+
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
19+
20+
DEFAULT_CYCLE_PERIOD = 1.0
21+
22+
MSG_VALUE_DUMMY = '0'
23+
24+
MSG_KEY_DEVICE_READY = 'ready'
25+
MSG_KEY_DEVICE_RESET = 'reset'
26+
MSG_KEY_SYNC = '__sync'
27+
28+
class SystemResetTest(BaseHostTest):
29+
"""Test for the system_reset API.
30+
31+
Given a device running code
32+
When the device is restarted using @a system_reset()
33+
Then the device is restarted
34+
"""
35+
36+
def __init__(self):
37+
super(SystemResetTest, self).__init__()
38+
self.reset = False
39+
cycle_s = self.get_config_item('program_cycle_s')
40+
self.program_cycle_s = cycle_s if cycle_s is not None else DEFAULT_CYCLE_PERIOD
41+
42+
self.test_steps_sequence = self.test_steps()
43+
# Advance the coroutine to it's first yield statement.
44+
self.test_steps_sequence.send(None)
45+
46+
def setup(self):
47+
self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready)
48+
49+
def cb_device_ready(self, key, value, timestamp):
50+
"""Acknowledge device rebooted correctly and feed the test execution
51+
"""
52+
self.reset = True
53+
54+
try:
55+
if self.test_steps_sequence.send(value):
56+
self.notify_complete(True)
57+
except (StopIteration, RuntimeError) as exc:
58+
self.notify_complete(False)
59+
60+
def test_steps(self):
61+
"""Reset the device and check the status
62+
"""
63+
system_reset = yield
64+
65+
self.reset = False
66+
self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY)
67+
time.sleep(self.program_cycle_s)
68+
self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
69+
70+
system_reset = yield
71+
72+
if self.reset == False:
73+
raise RuntimeError('Platform did not reset as expected.')
74+
75+
# The sequence is correct -- test passed.
76+
yield True
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "mbed.h"
17+
#include "greentea-client/test_env.h"
18+
#include "unity/unity.h"
19+
20+
#define MSG_VALUE_DUMMY "0"
21+
#define MSG_VALUE_LEN 16
22+
#define MSG_KEY_LEN 16
23+
24+
#define MSG_KEY_DEVICE_READY "ready"
25+
#define MSG_KEY_DEVICE_RESET "reset"
26+
27+
void test_system_reset()
28+
{
29+
// Report readiness
30+
greentea_send_kv(MSG_KEY_DEVICE_READY, MSG_VALUE_DUMMY);
31+
32+
static char _key[MSG_KEY_LEN + 1] = { };
33+
static char _value[MSG_VALUE_LEN + 1] = { };
34+
35+
greentea_parse_kv(_key, _value, MSG_KEY_LEN, MSG_VALUE_LEN);
36+
if (strcmp(_key, MSG_KEY_DEVICE_RESET) == 0) {
37+
system_reset();
38+
TEST_ASSERT_MESSAGE(0, "system_reset() did not reset the device as expected.");
39+
}
40+
41+
TEST_ASSERT_MESSAGE(0, "Unexpected message key.");
42+
}
43+
44+
int main(void)
45+
{
46+
GREENTEA_SETUP(2, "system_reset");
47+
test_system_reset();
48+
GREENTEA_TESTSUITE_RESULT(0); // Fail on any error.
49+
50+
return 0;
51+
}

0 commit comments

Comments
 (0)