Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
trng_reset.py
00001 """ 00002 Copyright (c) 2018 ARM Limited 00003 Licensed under the Apache License, Version 2.0 (the "License"); 00004 you may not use this file except in compliance with the License. 00005 You may obtain a copy of the License at 00006 00007 http://www.apache.org/licenses/LICENSE-2.0 00008 00009 Unless required by applicable law or agreed to in writing, software 00010 distributed under the License is distributed on an "AS IS" BASIS, 00011 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 See the License for the specific language governing permissions and 00013 limitations under the License. 00014 """ 00015 00016 """ 00017 This script is the host script for trng test sequence, it send the 00018 step signaling sequence and receive and transmit data to the device after 00019 reset if necesarry (default loading and storing mechanism while reseting the device 00020 is NVstore, in case NVstore isn't enabled we'll use current infrastructure, 00021 for more details see main.cpp file) 00022 """ 00023 00024 import time 00025 from mbed_host_tests import BaseHostTest 00026 from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector 00027 from time import sleep 00028 00029 DEFAULT_CYCLE_PERIOD = 1.0 00030 MSG_VALUE_DUMMY = '0' 00031 MSG_TRNG_READY = 'ready' 00032 MSG_TRNG_BUFFER = 'buffer' 00033 MSG_TRNG_TEST_STEP1 = 'check_step1' 00034 MSG_TRNG_TEST_STEP2 = 'check_step2' 00035 MSG_KEY_SYNC = '__sync' 00036 MSG_KEY_RESET_COMPLETE = 'reset_complete' 00037 MSG_KEY_TEST_SUITE_ENDED = 'Test_suite_ended' 00038 MSG_KEY_EXIT = 'exit' 00039 00040 class TRNGResetTest (BaseHostTest): 00041 """Test for the TRNG API. 00042 """ 00043 00044 def __init__(self): 00045 super(TRNGResetTest, self).__init__() 00046 self.did_reset = False 00047 self.ready = False 00048 self.suite_ended = False 00049 self.buffer = 0 00050 self.test_steps_sequence = self.test_steps () 00051 # Advance the coroutine to it's first yield statement. 00052 self.test_steps_sequence .send(None) 00053 00054 #define callback functions for msg handling 00055 def setup(self): 00056 self.register_callback(MSG_TRNG_READY, self.cb_device_ready ) 00057 self.register_callback(MSG_TRNG_BUFFER, self.cb_trng_buffer ) 00058 self.register_callback(MSG_KEY_TEST_SUITE_ENDED, self.cb_device_test_suit_ended ) 00059 self.register_callback(MSG_KEY_RESET_COMPLETE, self.cb_reset_complete ) 00060 00061 #receive sent data from device before reset 00062 def cb_trng_buffer (self, key, value, timestamp): 00063 """Acknowledge device rebooted correctly and feed the test execution 00064 """ 00065 self.buffer = value 00066 00067 try: 00068 if self.test_steps_sequence .send(value): 00069 self.notify_complete(True) 00070 except (StopIteration, RuntimeError) as exc: 00071 self.notify_complete(False) 00072 00073 def cb_device_ready (self, key, value, timestamp): 00074 """Acknowledge device rebooted correctly and feed the test execution 00075 """ 00076 self.ready = True 00077 00078 try: 00079 if self.test_steps_sequence .send(value): 00080 self.notify_complete(True) 00081 except (StopIteration, RuntimeError) as exc: 00082 self.notify_complete(False) 00083 00084 def cb_reset_complete (self, key, value, timestamp): 00085 """Acknowledge reset complete 00086 """ 00087 self.did_reset = True 00088 00089 try: 00090 if self.test_steps_sequence .send(value): 00091 self.notify_complete(True) 00092 except (StopIteration, RuntimeError) as exc: 00093 self.notify_complete(False) 00094 00095 def cb_device_test_suit_ended (self, key, value, timestamp): 00096 """Acknowledge device finished a test step correctly and feed the test execution 00097 """ 00098 self.suite_ended = True 00099 00100 try: 00101 if self.test_steps_sequence .send(value): 00102 self.notify_complete(True) 00103 except (StopIteration, RuntimeError) as exc: 00104 self.notify_complete(False) 00105 00106 #define test steps and actions 00107 def test_steps (self): 00108 """Test step 1 00109 """ 00110 wait_for_communication = yield 00111 00112 self.ready = False 00113 self.did_reset = False 00114 self.suite_ended = False 00115 self.send_kv(MSG_TRNG_TEST_STEP1, MSG_VALUE_DUMMY) 00116 wait_for_communication = yield 00117 if self.buffer == 0: 00118 raise RuntimeError('Phase 1: No buffer received.') 00119 00120 self.reset() 00121 00122 """Test step 2 (After reset) 00123 """ 00124 wait_for_communication = yield 00125 if self.did_reset == False: 00126 raise RuntimeError('Phase 1: Platform did not reset as expected.') 00127 00128 self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY) 00129 00130 wait_for_communication = yield 00131 00132 if self.ready == False: 00133 raise RuntimeError('Phase 1: Platform not ready as expected.') 00134 00135 self.send_kv(MSG_TRNG_TEST_STEP2, self.buffer ) 00136 00137 wait_for_communication = yield 00138 00139 if self.suite_ended == False: 00140 raise RuntimeError('Test failed.') 00141 00142 self.send_kv(MSG_KEY_EXIT, MSG_VALUE_DUMMY) 00143 00144 # The sequence is correct -- test passed. 00145 yield
Generated on Tue Aug 9 2022 00:37:23 by
 1.7.2
 1.7.2