![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/TESTS/host_tests/trng_reset.py@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | """ |
kadonotakashi | 0:8fdf9a60065b | 2 | Copyright (c) 2018 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 4 | you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 5 | You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 6 | |
kadonotakashi | 0:8fdf9a60065b | 7 | http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 8 | |
kadonotakashi | 0:8fdf9a60065b | 9 | Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 10 | distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 12 | See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 13 | limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 14 | """ |
kadonotakashi | 0:8fdf9a60065b | 15 | |
kadonotakashi | 0:8fdf9a60065b | 16 | """ |
kadonotakashi | 0:8fdf9a60065b | 17 | This script is the host script for trng test sequence, it send the |
kadonotakashi | 0:8fdf9a60065b | 18 | step signaling sequence and receive and transmit data to the device after |
kadonotakashi | 0:8fdf9a60065b | 19 | reset if necesarry (default loading and storing mechanism while reseting the device |
kadonotakashi | 0:8fdf9a60065b | 20 | is NVstore, in case NVstore isn't enabled we'll use current infrastructure, |
kadonotakashi | 0:8fdf9a60065b | 21 | for more details see main.cpp file) |
kadonotakashi | 0:8fdf9a60065b | 22 | """ |
kadonotakashi | 0:8fdf9a60065b | 23 | |
kadonotakashi | 0:8fdf9a60065b | 24 | import time |
kadonotakashi | 0:8fdf9a60065b | 25 | from mbed_host_tests import BaseHostTest |
kadonotakashi | 0:8fdf9a60065b | 26 | from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector |
kadonotakashi | 0:8fdf9a60065b | 27 | from time import sleep |
kadonotakashi | 0:8fdf9a60065b | 28 | |
kadonotakashi | 0:8fdf9a60065b | 29 | DEFAULT_CYCLE_PERIOD = 1.0 |
kadonotakashi | 0:8fdf9a60065b | 30 | MSG_VALUE_DUMMY = '0' |
kadonotakashi | 0:8fdf9a60065b | 31 | MSG_TRNG_READY = 'ready' |
kadonotakashi | 0:8fdf9a60065b | 32 | MSG_TRNG_BUFFER = 'buffer' |
kadonotakashi | 0:8fdf9a60065b | 33 | MSG_TRNG_TEST_STEP1 = 'check_step1' |
kadonotakashi | 0:8fdf9a60065b | 34 | MSG_TRNG_TEST_STEP2 = 'check_step2' |
kadonotakashi | 0:8fdf9a60065b | 35 | MSG_KEY_SYNC = '__sync' |
kadonotakashi | 0:8fdf9a60065b | 36 | MSG_KEY_RESET_COMPLETE = 'reset_complete' |
kadonotakashi | 0:8fdf9a60065b | 37 | MSG_KEY_TEST_SUITE_ENDED = 'Test_suite_ended' |
kadonotakashi | 0:8fdf9a60065b | 38 | MSG_KEY_EXIT = 'exit' |
kadonotakashi | 0:8fdf9a60065b | 39 | |
kadonotakashi | 0:8fdf9a60065b | 40 | class TRNGResetTest(BaseHostTest): |
kadonotakashi | 0:8fdf9a60065b | 41 | """Test for the TRNG API. |
kadonotakashi | 0:8fdf9a60065b | 42 | """ |
kadonotakashi | 0:8fdf9a60065b | 43 | |
kadonotakashi | 0:8fdf9a60065b | 44 | def __init__(self): |
kadonotakashi | 0:8fdf9a60065b | 45 | super(TRNGResetTest, self).__init__() |
kadonotakashi | 0:8fdf9a60065b | 46 | self.did_reset = False |
kadonotakashi | 0:8fdf9a60065b | 47 | self.ready = False |
kadonotakashi | 0:8fdf9a60065b | 48 | self.suite_ended = False |
kadonotakashi | 0:8fdf9a60065b | 49 | self.buffer = 0 |
kadonotakashi | 0:8fdf9a60065b | 50 | self.test_steps_sequence = self.test_steps() |
kadonotakashi | 0:8fdf9a60065b | 51 | # Advance the coroutine to it's first yield statement. |
kadonotakashi | 0:8fdf9a60065b | 52 | self.test_steps_sequence.send(None) |
kadonotakashi | 0:8fdf9a60065b | 53 | |
kadonotakashi | 0:8fdf9a60065b | 54 | #define callback functions for msg handling |
kadonotakashi | 0:8fdf9a60065b | 55 | def setup(self): |
kadonotakashi | 0:8fdf9a60065b | 56 | self.register_callback(MSG_TRNG_READY, self.cb_device_ready) |
kadonotakashi | 0:8fdf9a60065b | 57 | self.register_callback(MSG_TRNG_BUFFER, self.cb_trng_buffer) |
kadonotakashi | 0:8fdf9a60065b | 58 | self.register_callback(MSG_KEY_TEST_SUITE_ENDED, self.cb_device_test_suit_ended) |
kadonotakashi | 0:8fdf9a60065b | 59 | self.register_callback(MSG_KEY_RESET_COMPLETE, self.cb_reset_complete) |
kadonotakashi | 0:8fdf9a60065b | 60 | |
kadonotakashi | 0:8fdf9a60065b | 61 | #receive sent data from device before reset |
kadonotakashi | 0:8fdf9a60065b | 62 | def cb_trng_buffer(self, key, value, timestamp): |
kadonotakashi | 0:8fdf9a60065b | 63 | """Acknowledge device rebooted correctly and feed the test execution |
kadonotakashi | 0:8fdf9a60065b | 64 | """ |
kadonotakashi | 0:8fdf9a60065b | 65 | self.buffer = value |
kadonotakashi | 0:8fdf9a60065b | 66 | |
kadonotakashi | 0:8fdf9a60065b | 67 | try: |
kadonotakashi | 0:8fdf9a60065b | 68 | if self.test_steps_sequence.send(value): |
kadonotakashi | 0:8fdf9a60065b | 69 | self.notify_complete(True) |
kadonotakashi | 0:8fdf9a60065b | 70 | except (StopIteration, RuntimeError) as exc: |
kadonotakashi | 0:8fdf9a60065b | 71 | self.notify_complete(False) |
kadonotakashi | 0:8fdf9a60065b | 72 | |
kadonotakashi | 0:8fdf9a60065b | 73 | def cb_device_ready(self, key, value, timestamp): |
kadonotakashi | 0:8fdf9a60065b | 74 | """Acknowledge device rebooted correctly and feed the test execution |
kadonotakashi | 0:8fdf9a60065b | 75 | """ |
kadonotakashi | 0:8fdf9a60065b | 76 | self.ready = True |
kadonotakashi | 0:8fdf9a60065b | 77 | |
kadonotakashi | 0:8fdf9a60065b | 78 | try: |
kadonotakashi | 0:8fdf9a60065b | 79 | if self.test_steps_sequence.send(value): |
kadonotakashi | 0:8fdf9a60065b | 80 | self.notify_complete(True) |
kadonotakashi | 0:8fdf9a60065b | 81 | except (StopIteration, RuntimeError) as exc: |
kadonotakashi | 0:8fdf9a60065b | 82 | self.notify_complete(False) |
kadonotakashi | 0:8fdf9a60065b | 83 | |
kadonotakashi | 0:8fdf9a60065b | 84 | def cb_reset_complete(self, key, value, timestamp): |
kadonotakashi | 0:8fdf9a60065b | 85 | """Acknowledge reset complete |
kadonotakashi | 0:8fdf9a60065b | 86 | """ |
kadonotakashi | 0:8fdf9a60065b | 87 | self.did_reset = True |
kadonotakashi | 0:8fdf9a60065b | 88 | |
kadonotakashi | 0:8fdf9a60065b | 89 | try: |
kadonotakashi | 0:8fdf9a60065b | 90 | if self.test_steps_sequence.send(value): |
kadonotakashi | 0:8fdf9a60065b | 91 | self.notify_complete(True) |
kadonotakashi | 0:8fdf9a60065b | 92 | except (StopIteration, RuntimeError) as exc: |
kadonotakashi | 0:8fdf9a60065b | 93 | self.notify_complete(False) |
kadonotakashi | 0:8fdf9a60065b | 94 | |
kadonotakashi | 0:8fdf9a60065b | 95 | def cb_device_test_suit_ended(self, key, value, timestamp): |
kadonotakashi | 0:8fdf9a60065b | 96 | """Acknowledge device finished a test step correctly and feed the test execution |
kadonotakashi | 0:8fdf9a60065b | 97 | """ |
kadonotakashi | 0:8fdf9a60065b | 98 | self.suite_ended = True |
kadonotakashi | 0:8fdf9a60065b | 99 | |
kadonotakashi | 0:8fdf9a60065b | 100 | try: |
kadonotakashi | 0:8fdf9a60065b | 101 | if self.test_steps_sequence.send(value): |
kadonotakashi | 0:8fdf9a60065b | 102 | self.notify_complete(True) |
kadonotakashi | 0:8fdf9a60065b | 103 | except (StopIteration, RuntimeError) as exc: |
kadonotakashi | 0:8fdf9a60065b | 104 | self.notify_complete(False) |
kadonotakashi | 0:8fdf9a60065b | 105 | |
kadonotakashi | 0:8fdf9a60065b | 106 | #define test steps and actions |
kadonotakashi | 0:8fdf9a60065b | 107 | def test_steps(self): |
kadonotakashi | 0:8fdf9a60065b | 108 | """Test step 1 |
kadonotakashi | 0:8fdf9a60065b | 109 | """ |
kadonotakashi | 0:8fdf9a60065b | 110 | wait_for_communication = yield |
kadonotakashi | 0:8fdf9a60065b | 111 | |
kadonotakashi | 0:8fdf9a60065b | 112 | self.ready = False |
kadonotakashi | 0:8fdf9a60065b | 113 | self.did_reset = False |
kadonotakashi | 0:8fdf9a60065b | 114 | self.suite_ended = False |
kadonotakashi | 0:8fdf9a60065b | 115 | self.send_kv(MSG_TRNG_TEST_STEP1, MSG_VALUE_DUMMY) |
kadonotakashi | 0:8fdf9a60065b | 116 | wait_for_communication = yield |
kadonotakashi | 0:8fdf9a60065b | 117 | if self.buffer == 0: |
kadonotakashi | 0:8fdf9a60065b | 118 | raise RuntimeError('Phase 1: No buffer received.') |
kadonotakashi | 0:8fdf9a60065b | 119 | |
kadonotakashi | 0:8fdf9a60065b | 120 | self.reset() |
kadonotakashi | 0:8fdf9a60065b | 121 | |
kadonotakashi | 0:8fdf9a60065b | 122 | """Test step 2 (After reset) |
kadonotakashi | 0:8fdf9a60065b | 123 | """ |
kadonotakashi | 0:8fdf9a60065b | 124 | wait_for_communication = yield |
kadonotakashi | 0:8fdf9a60065b | 125 | if self.did_reset == False: |
kadonotakashi | 0:8fdf9a60065b | 126 | raise RuntimeError('Phase 1: Platform did not reset as expected.') |
kadonotakashi | 0:8fdf9a60065b | 127 | |
kadonotakashi | 0:8fdf9a60065b | 128 | self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY) |
kadonotakashi | 0:8fdf9a60065b | 129 | |
kadonotakashi | 0:8fdf9a60065b | 130 | wait_for_communication = yield |
kadonotakashi | 0:8fdf9a60065b | 131 | |
kadonotakashi | 0:8fdf9a60065b | 132 | if self.ready == False: |
kadonotakashi | 0:8fdf9a60065b | 133 | raise RuntimeError('Phase 1: Platform not ready as expected.') |
kadonotakashi | 0:8fdf9a60065b | 134 | |
kadonotakashi | 0:8fdf9a60065b | 135 | self.send_kv(MSG_TRNG_TEST_STEP2, self.buffer) |
kadonotakashi | 0:8fdf9a60065b | 136 | |
kadonotakashi | 0:8fdf9a60065b | 137 | wait_for_communication = yield |
kadonotakashi | 0:8fdf9a60065b | 138 | |
kadonotakashi | 0:8fdf9a60065b | 139 | if self.suite_ended == False: |
kadonotakashi | 0:8fdf9a60065b | 140 | raise RuntimeError('Test failed.') |
kadonotakashi | 0:8fdf9a60065b | 141 | |
kadonotakashi | 0:8fdf9a60065b | 142 | self.send_kv(MSG_KEY_EXIT, MSG_VALUE_DUMMY) |
kadonotakashi | 0:8fdf9a60065b | 143 | |
kadonotakashi | 0:8fdf9a60065b | 144 | # The sequence is correct -- test passed. |
kadonotakashi | 0:8fdf9a60065b | 145 | yield |