BA / Mbed OS BaBoRo1
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         cycle_s = self.get_config_item('program_cycle_s')
00040         self.program_cycle_s  = cycle_s if cycle_s is not None else DEFAULT_CYCLE_PERIOD
00041 
00042         self.test_steps_sequence  = self.test_steps ()
00043         # Advance the coroutine to it's first yield statement.
00044         self.test_steps_sequence .send(None)
00045 
00046     def setup(self):
00047         self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready )
00048 
00049     def cb_device_ready (self, key, value, timestamp):
00050         """Acknowledge device rebooted correctly and feed the test execution
00051         """
00052         self.reset  = True
00053 
00054         try:
00055             if self.test_steps_sequence .send(value):
00056                 self.notify_complete(True)
00057         except (StopIteration, RuntimeError) as exc:
00058             self.notify_complete(False)
00059 
00060     def test_steps (self):
00061         """Reset the device and check the status
00062         """
00063         system_reset = yield
00064 
00065         self.reset  = False
00066         self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY)
00067         time.sleep(self.program_cycle_s )
00068         self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
00069 
00070         system_reset = yield
00071 
00072         if self.reset  == False:
00073             raise RuntimeError('Platform did not reset as expected.')
00074 
00075         # The sequence is correct -- test passed.
00076         yield True