takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers system_reset.py Source File

system_reset.py

00001 """
00002 Copyright (c) 2018 ARM Limited
00003 
00004 Licensed under the Apache License, Version 2.0 (the "License");
00005 you may not use this file except in compliance with the License.
00006 You may obtain a copy of the License at
00007 
00008     http://www.apache.org/licenses/LICENSE-2.0
00009 
00010 Unless required by applicable law or agreed to in writing, software
00011 distributed under the License is distributed on an "AS IS" BASIS,
00012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 See the License for the specific language governing permissions and
00014 limitations under the License.
00015 """
00016 import time
00017 from mbed_host_tests import BaseHostTest
00018 from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
00019 
00020 DEFAULT_CYCLE_PERIOD = 1.0
00021 
00022 MSG_VALUE_DUMMY = '0'
00023 
00024 MSG_KEY_DEVICE_READY = 'ready'
00025 MSG_KEY_DEVICE_RESET = 'reset'
00026 MSG_KEY_SYNC = '__sync'
00027 
00028 class SystemResetTest (BaseHostTest):
00029     """Test for the system_reset API.
00030 
00031     Given a device running code
00032     When the device is restarted using @a system_reset()
00033     Then the device is restarted
00034     """
00035 
00036     def __init__(self):
00037         super(SystemResetTest, self).__init__()
00038         self.reset  = False
00039         self.test_steps_sequence  = self.test_steps ()
00040         # Advance the coroutine to it's first yield statement.
00041         self.test_steps_sequence .send(None)
00042 
00043     def setup(self):
00044         self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready )
00045 
00046     def cb_device_ready (self, key, value, timestamp):
00047         """Acknowledge device rebooted correctly and feed the test execution
00048         """
00049         self.reset  = True
00050 
00051         try:
00052             if self.test_steps_sequence .send(value):
00053                 self.notify_complete(True)
00054         except (StopIteration, RuntimeError) as exc:
00055             self.notify_complete(False)
00056 
00057     def test_steps (self):
00058         """Reset the device and check the status
00059         """
00060         system_reset = yield
00061         self.reset  = False
00062 
00063         wait_after_reset = self.get_config_item('forced_reset_timeout')
00064         wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
00065 
00066         self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY)
00067         time.sleep(wait_after_reset)
00068         self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
00069 
00070         system_reset = yield
00071         if self.reset  == False:
00072             raise RuntimeError('Platform did not reset as expected.')
00073 
00074         # The sequence is correct -- test passed.
00075         yield True