BA
/
BaBoRo_test2
Backup 1
mbed-os/TESTS/host_tests/system_reset.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | """ |
borlanic | 0:02dd72d1d465 | 2 | Copyright (c) 2018 ARM Limited |
borlanic | 0:02dd72d1d465 | 3 | |
borlanic | 0:02dd72d1d465 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 5 | you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 6 | You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 7 | |
borlanic | 0:02dd72d1d465 | 8 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 9 | |
borlanic | 0:02dd72d1d465 | 10 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 11 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 13 | See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 14 | limitations under the License. |
borlanic | 0:02dd72d1d465 | 15 | """ |
borlanic | 0:02dd72d1d465 | 16 | import time |
borlanic | 0:02dd72d1d465 | 17 | from mbed_host_tests import BaseHostTest |
borlanic | 0:02dd72d1d465 | 18 | from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector |
borlanic | 0:02dd72d1d465 | 19 | |
borlanic | 0:02dd72d1d465 | 20 | DEFAULT_CYCLE_PERIOD = 1.0 |
borlanic | 0:02dd72d1d465 | 21 | |
borlanic | 0:02dd72d1d465 | 22 | MSG_VALUE_DUMMY = '0' |
borlanic | 0:02dd72d1d465 | 23 | |
borlanic | 0:02dd72d1d465 | 24 | MSG_KEY_DEVICE_READY = 'ready' |
borlanic | 0:02dd72d1d465 | 25 | MSG_KEY_DEVICE_RESET = 'reset' |
borlanic | 0:02dd72d1d465 | 26 | MSG_KEY_SYNC = '__sync' |
borlanic | 0:02dd72d1d465 | 27 | |
borlanic | 0:02dd72d1d465 | 28 | class SystemResetTest(BaseHostTest): |
borlanic | 0:02dd72d1d465 | 29 | """Test for the system_reset API. |
borlanic | 0:02dd72d1d465 | 30 | |
borlanic | 0:02dd72d1d465 | 31 | Given a device running code |
borlanic | 0:02dd72d1d465 | 32 | When the device is restarted using @a system_reset() |
borlanic | 0:02dd72d1d465 | 33 | Then the device is restarted |
borlanic | 0:02dd72d1d465 | 34 | """ |
borlanic | 0:02dd72d1d465 | 35 | |
borlanic | 0:02dd72d1d465 | 36 | def __init__(self): |
borlanic | 0:02dd72d1d465 | 37 | super(SystemResetTest, self).__init__() |
borlanic | 0:02dd72d1d465 | 38 | self.reset = False |
borlanic | 0:02dd72d1d465 | 39 | cycle_s = self.get_config_item('program_cycle_s') |
borlanic | 0:02dd72d1d465 | 40 | self.program_cycle_s = cycle_s if cycle_s is not None else DEFAULT_CYCLE_PERIOD |
borlanic | 0:02dd72d1d465 | 41 | |
borlanic | 0:02dd72d1d465 | 42 | self.test_steps_sequence = self.test_steps() |
borlanic | 0:02dd72d1d465 | 43 | # Advance the coroutine to it's first yield statement. |
borlanic | 0:02dd72d1d465 | 44 | self.test_steps_sequence.send(None) |
borlanic | 0:02dd72d1d465 | 45 | |
borlanic | 0:02dd72d1d465 | 46 | def setup(self): |
borlanic | 0:02dd72d1d465 | 47 | self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready) |
borlanic | 0:02dd72d1d465 | 48 | |
borlanic | 0:02dd72d1d465 | 49 | def cb_device_ready(self, key, value, timestamp): |
borlanic | 0:02dd72d1d465 | 50 | """Acknowledge device rebooted correctly and feed the test execution |
borlanic | 0:02dd72d1d465 | 51 | """ |
borlanic | 0:02dd72d1d465 | 52 | self.reset = True |
borlanic | 0:02dd72d1d465 | 53 | |
borlanic | 0:02dd72d1d465 | 54 | try: |
borlanic | 0:02dd72d1d465 | 55 | if self.test_steps_sequence.send(value): |
borlanic | 0:02dd72d1d465 | 56 | self.notify_complete(True) |
borlanic | 0:02dd72d1d465 | 57 | except (StopIteration, RuntimeError) as exc: |
borlanic | 0:02dd72d1d465 | 58 | self.notify_complete(False) |
borlanic | 0:02dd72d1d465 | 59 | |
borlanic | 0:02dd72d1d465 | 60 | def test_steps(self): |
borlanic | 0:02dd72d1d465 | 61 | """Reset the device and check the status |
borlanic | 0:02dd72d1d465 | 62 | """ |
borlanic | 0:02dd72d1d465 | 63 | system_reset = yield |
borlanic | 0:02dd72d1d465 | 64 | |
borlanic | 0:02dd72d1d465 | 65 | self.reset = False |
borlanic | 0:02dd72d1d465 | 66 | self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY) |
borlanic | 0:02dd72d1d465 | 67 | time.sleep(self.program_cycle_s) |
borlanic | 0:02dd72d1d465 | 68 | self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY) |
borlanic | 0:02dd72d1d465 | 69 | |
borlanic | 0:02dd72d1d465 | 70 | system_reset = yield |
borlanic | 0:02dd72d1d465 | 71 | |
borlanic | 0:02dd72d1d465 | 72 | if self.reset == False: |
borlanic | 0:02dd72d1d465 | 73 | raise RuntimeError('Platform did not reset as expected.') |
borlanic | 0:02dd72d1d465 | 74 | |
borlanic | 0:02dd72d1d465 | 75 | # The sequence is correct -- test passed. |
borlanic | 0:02dd72d1d465 | 76 | yield True |