Skip to content

Commit 0d9a1cc

Browse files
Ashok RaoAshok Rao
authored andcommitted
Adding required host_tests
1 parent 448f609 commit 0d9a1cc

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
Copyright (c) 2018 ARM Limited
3+
SPDX-License-Identifier: Apache-2.0
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
import time
18+
from mbed_host_tests import BaseHostTest
19+
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
20+
21+
DEFAULT_CYCLE_PERIOD = 10.0
22+
23+
MSG_VALUE_DUMMY = '0'
24+
25+
MSG_KEY_DEVICE_READY = 'crash_reporting_ready'
26+
MSG_KEY_DEVICE_ERROR = 'crash_reporting_inject_error'
27+
MSG_KEY_SYNC = '__sync'
28+
29+
class CrashReportingTest(BaseHostTest):
30+
"""Test for the crash reporting feature.
31+
"""
32+
33+
def __init__(self):
34+
super(CrashReportingTest, self).__init__()
35+
self.reset = False
36+
self.test_steps_sequence = self.test_steps()
37+
# Advance the coroutine to it's first yield statement.
38+
self.test_steps_sequence.send(None)
39+
40+
def setup(self):
41+
self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready)
42+
43+
def cb_device_ready(self, key, value, timestamp):
44+
"""Acknowledge device rebooted correctly and feed the test execution
45+
"""
46+
self.reset = True
47+
48+
try:
49+
if self.test_steps_sequence.send(value):
50+
self.notify_complete(True)
51+
except (StopIteration, RuntimeError) as exc:
52+
self.notify_complete(False)
53+
54+
def test_steps(self):
55+
"""Reset the device and check the status
56+
"""
57+
system_reset = yield
58+
self.reset = False
59+
60+
wait_after_reset = self.get_config_item('forced_reset_timeout')
61+
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
62+
63+
#Wait 2 seconds for system to init
64+
time.sleep(7.0)
65+
#self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
66+
self.send_kv(MSG_KEY_DEVICE_ERROR, MSG_VALUE_DUMMY)
67+
time.sleep(5.0)
68+
69+
system_reset = yield
70+
if self.reset == False:
71+
raise RuntimeError('Platform did not auto-reboot as expected.')
72+
73+
# The sequence is correct -- test passed.
74+
yield True
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+
SPDX-License-Identifier: Apache-2.0
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
import time
18+
from mbed_host_tests import BaseHostTest
19+
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
20+
21+
DEFAULT_CYCLE_PERIOD = 1.0
22+
23+
MSG_VALUE_DUMMY = '0'
24+
25+
MSG_KEY_DEVICE_READY = 'ready'
26+
MSG_KEY_DEVICE_RESET = 'reset'
27+
MSG_KEY_SYNC = '__sync'
28+
29+
class SystemResetTest(BaseHostTest):
30+
"""Test for the system_reset API.
31+
32+
Given a device running code
33+
When the device is restarted using @a system_reset()
34+
Then the device is restarted
35+
"""
36+
37+
def __init__(self):
38+
super(SystemResetTest, self).__init__()
39+
self.reset = False
40+
self.test_steps_sequence = self.test_steps()
41+
# Advance the coroutine to it's first yield statement.
42+
self.test_steps_sequence.send(None)
43+
44+
def setup(self):
45+
self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready)
46+
47+
def cb_device_ready(self, key, value, timestamp):
48+
"""Acknowledge device rebooted correctly and feed the test execution
49+
"""
50+
self.reset = True
51+
52+
try:
53+
if self.test_steps_sequence.send(value):
54+
self.notify_complete(True)
55+
except (StopIteration, RuntimeError) as exc:
56+
self.notify_complete(False)
57+
58+
def test_steps(self):
59+
"""Reset the device and check the status
60+
"""
61+
system_reset = yield
62+
self.reset = False
63+
64+
wait_after_reset = self.get_config_item('forced_reset_timeout')
65+
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
66+
67+
self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY)
68+
time.sleep(wait_after_reset)
69+
self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
70+
71+
system_reset = yield
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

0 commit comments

Comments
 (0)