takashi kadono
/
Nucleo_446
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/tools/test/detect_targets_test.py@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | """ |
kadonotakashi | 0:8fdf9a60065b | 2 | mbed SDK |
kadonotakashi | 0:8fdf9a60065b | 3 | Copyright (c) 2017 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 4 | |
kadonotakashi | 0:8fdf9a60065b | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 6 | you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 7 | You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 8 | |
kadonotakashi | 0:8fdf9a60065b | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 10 | |
kadonotakashi | 0:8fdf9a60065b | 11 | Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 14 | See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 15 | limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 16 | """ |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | import unittest |
kadonotakashi | 0:8fdf9a60065b | 19 | from mock import patch |
kadonotakashi | 0:8fdf9a60065b | 20 | from tools.detect_targets import get_interface_version |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | class MbedLsToolsMock(): |
kadonotakashi | 0:8fdf9a60065b | 24 | """ |
kadonotakashi | 0:8fdf9a60065b | 25 | Mock of mbedls tools |
kadonotakashi | 0:8fdf9a60065b | 26 | """ |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | def __init__(self, test_type): |
kadonotakashi | 0:8fdf9a60065b | 29 | self.interface_test_type = test_type |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | def list_mbeds(self, unique_names=False, read_details_txt=False): |
kadonotakashi | 0:8fdf9a60065b | 32 | return self.mbed_types[self.interface_test_type]; |
kadonotakashi | 0:8fdf9a60065b | 33 | |
kadonotakashi | 0:8fdf9a60065b | 34 | # Static details.txt types. |
kadonotakashi | 0:8fdf9a60065b | 35 | mbed_types = { |
kadonotakashi | 0:8fdf9a60065b | 36 | 'details_valid_interface_version' : [{ |
kadonotakashi | 0:8fdf9a60065b | 37 | 'daplink_hic_id': u'97969900', |
kadonotakashi | 0:8fdf9a60065b | 38 | 'daplink_version': u'0244', |
kadonotakashi | 0:8fdf9a60065b | 39 | 'target_id': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 40 | 'serial_port': u'COM3', |
kadonotakashi | 0:8fdf9a60065b | 41 | 'target_id_usb_id': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 42 | 'daplink_auto_reset': u'0', |
kadonotakashi | 0:8fdf9a60065b | 43 | 'daplink_git_sha': u'392f85aa88a41125dec0b963ce73c6795b8bdd0d', |
kadonotakashi | 0:8fdf9a60065b | 44 | 'daplink_interface_version': u'0244', |
kadonotakashi | 0:8fdf9a60065b | 45 | 'daplink_overflow_detection': u'0', |
kadonotakashi | 0:8fdf9a60065b | 46 | 'daplink_daplink_mode': u'Interface', |
kadonotakashi | 0:8fdf9a60065b | 47 | 'target_id_mbed_htm': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 48 | 'mount_point': 'D:', |
kadonotakashi | 0:8fdf9a60065b | 49 | 'daplink_automation_allowed': u'0', |
kadonotakashi | 0:8fdf9a60065b | 50 | 'daplink_interface_crc': u'0xc525d856', |
kadonotakashi | 0:8fdf9a60065b | 51 | 'daplink_local_mods': u'0', |
kadonotakashi | 0:8fdf9a60065b | 52 | 'daplink_unique_id': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 53 | 'daplink_remount_count': u'0', |
kadonotakashi | 0:8fdf9a60065b | 54 | 'daplink_bootloader_crc': u'0xc4ebf65c', |
kadonotakashi | 0:8fdf9a60065b | 55 | 'platform_name': u'K64F', |
kadonotakashi | 0:8fdf9a60065b | 56 | 'platform_name_unique': u'K64F[0]', |
kadonotakashi | 0:8fdf9a60065b | 57 | 'daplink_bootloader_version': u'0244', |
kadonotakashi | 0:8fdf9a60065b | 58 | 'daplink_usb_interfaces': u'MSD, CDC, HID' |
kadonotakashi | 0:8fdf9a60065b | 59 | |
kadonotakashi | 0:8fdf9a60065b | 60 | }], |
kadonotakashi | 0:8fdf9a60065b | 61 | 'details_missing_interface_version' : [{ |
kadonotakashi | 0:8fdf9a60065b | 62 | 'daplink_hic_id': u'97969900', |
kadonotakashi | 0:8fdf9a60065b | 63 | 'target_id': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 64 | 'serial_port': u'COM3', |
kadonotakashi | 0:8fdf9a60065b | 65 | 'target_id_usb_id': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 66 | 'daplink_auto_reset': u'0', |
kadonotakashi | 0:8fdf9a60065b | 67 | 'daplink_git_sha': u'392f85aa88a41125dec0b963ce73c6795b8bdd0d', |
kadonotakashi | 0:8fdf9a60065b | 68 | 'daplink_interface_version': u'0244', |
kadonotakashi | 0:8fdf9a60065b | 69 | 'daplink_overflow_detection': u'0', |
kadonotakashi | 0:8fdf9a60065b | 70 | 'daplink_daplink_mode': u'Interface', |
kadonotakashi | 0:8fdf9a60065b | 71 | 'target_id_mbed_htm': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 72 | 'mount_point': 'D:', |
kadonotakashi | 0:8fdf9a60065b | 73 | 'daplink_automation_allowed': u'0', |
kadonotakashi | 0:8fdf9a60065b | 74 | 'daplink_interface_crc': u'0xc525d856', |
kadonotakashi | 0:8fdf9a60065b | 75 | 'daplink_local_mods': u'0', |
kadonotakashi | 0:8fdf9a60065b | 76 | 'daplink_unique_id': u'0240000034544e45001500048e41001b8321000097969900', |
kadonotakashi | 0:8fdf9a60065b | 77 | 'daplink_remount_count': u'0', |
kadonotakashi | 0:8fdf9a60065b | 78 | 'daplink_bootloader_crc': u'0xc4ebf65c', |
kadonotakashi | 0:8fdf9a60065b | 79 | 'platform_name': u'K64F', |
kadonotakashi | 0:8fdf9a60065b | 80 | 'platform_name_unique': u'K64F[0]', |
kadonotakashi | 0:8fdf9a60065b | 81 | 'daplink_bootloader_version': u'0244', |
kadonotakashi | 0:8fdf9a60065b | 82 | 'daplink_usb_interfaces': u'MSD, CDC, HID' |
kadonotakashi | 0:8fdf9a60065b | 83 | |
kadonotakashi | 0:8fdf9a60065b | 84 | }], |
kadonotakashi | 0:8fdf9a60065b | 85 | 'details_invalid_none' : None |
kadonotakashi | 0:8fdf9a60065b | 86 | } |
kadonotakashi | 0:8fdf9a60065b | 87 | |
kadonotakashi | 0:8fdf9a60065b | 88 | """ |
kadonotakashi | 0:8fdf9a60065b | 89 | Tests for detect_targets.py |
kadonotakashi | 0:8fdf9a60065b | 90 | """ |
kadonotakashi | 0:8fdf9a60065b | 91 | |
kadonotakashi | 0:8fdf9a60065b | 92 | class DetectTargetsTest(unittest.TestCase): |
kadonotakashi | 0:8fdf9a60065b | 93 | """ |
kadonotakashi | 0:8fdf9a60065b | 94 | Test cases for Detect Target functionality |
kadonotakashi | 0:8fdf9a60065b | 95 | """ |
kadonotakashi | 0:8fdf9a60065b | 96 | |
kadonotakashi | 0:8fdf9a60065b | 97 | def setUp(self): |
kadonotakashi | 0:8fdf9a60065b | 98 | """ |
kadonotakashi | 0:8fdf9a60065b | 99 | Called before each test case |
kadonotakashi | 0:8fdf9a60065b | 100 | |
kadonotakashi | 0:8fdf9a60065b | 101 | :return: |
kadonotakashi | 0:8fdf9a60065b | 102 | """ |
kadonotakashi | 0:8fdf9a60065b | 103 | self.missing_mount_point = None |
kadonotakashi | 0:8fdf9a60065b | 104 | self.mount_point = "D:" |
kadonotakashi | 0:8fdf9a60065b | 105 | self.invalid_mount_point = "F:" |
kadonotakashi | 0:8fdf9a60065b | 106 | |
kadonotakashi | 0:8fdf9a60065b | 107 | def tearDown(self): |
kadonotakashi | 0:8fdf9a60065b | 108 | """ |
kadonotakashi | 0:8fdf9a60065b | 109 | Nothing to tear down. |
kadonotakashi | 0:8fdf9a60065b | 110 | Called after each test case |
kadonotakashi | 0:8fdf9a60065b | 111 | |
kadonotakashi | 0:8fdf9a60065b | 112 | :return: |
kadonotakashi | 0:8fdf9a60065b | 113 | """ |
kadonotakashi | 0:8fdf9a60065b | 114 | pass |
kadonotakashi | 0:8fdf9a60065b | 115 | |
kadonotakashi | 0:8fdf9a60065b | 116 | @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_interface_version')) |
kadonotakashi | 0:8fdf9a60065b | 117 | def test_interface_version_valid(self, mbed_lstools_mock): |
kadonotakashi | 0:8fdf9a60065b | 118 | """ |
kadonotakashi | 0:8fdf9a60065b | 119 | Test that checks function returns correctly when given a valid Interface Version |
kadonotakashi | 0:8fdf9a60065b | 120 | |
kadonotakashi | 0:8fdf9a60065b | 121 | :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock |
kadonotakashi | 0:8fdf9a60065b | 122 | :return |
kadonotakashi | 0:8fdf9a60065b | 123 | """ |
kadonotakashi | 0:8fdf9a60065b | 124 | |
kadonotakashi | 0:8fdf9a60065b | 125 | interface_version = get_interface_version(self.mount_point) |
kadonotakashi | 0:8fdf9a60065b | 126 | assert interface_version == '0244' |
kadonotakashi | 0:8fdf9a60065b | 127 | |
kadonotakashi | 0:8fdf9a60065b | 128 | @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_missing_interface_version')) |
kadonotakashi | 0:8fdf9a60065b | 129 | def test_interface_version_missing_interface_version(self, mbed_lstools_mock): |
kadonotakashi | 0:8fdf9a60065b | 130 | """ |
kadonotakashi | 0:8fdf9a60065b | 131 | Test that checks function returns correctly when DETAILS.txt is present |
kadonotakashi | 0:8fdf9a60065b | 132 | but an interface version is not listed. |
kadonotakashi | 0:8fdf9a60065b | 133 | |
kadonotakashi | 0:8fdf9a60065b | 134 | :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock |
kadonotakashi | 0:8fdf9a60065b | 135 | :return |
kadonotakashi | 0:8fdf9a60065b | 136 | """ |
kadonotakashi | 0:8fdf9a60065b | 137 | |
kadonotakashi | 0:8fdf9a60065b | 138 | interface_version = get_interface_version(self.mount_point) |
kadonotakashi | 0:8fdf9a60065b | 139 | assert interface_version == 'unknown' |
kadonotakashi | 0:8fdf9a60065b | 140 | |
kadonotakashi | 0:8fdf9a60065b | 141 | @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_invalid_none')) |
kadonotakashi | 0:8fdf9a60065b | 142 | def test_version_none(self, mbed_lstools_mock): |
kadonotakashi | 0:8fdf9a60065b | 143 | """ |
kadonotakashi | 0:8fdf9a60065b | 144 | Test that checks function returns correctly when a valid mount point is supplied |
kadonotakashi | 0:8fdf9a60065b | 145 | but DETAILS.txt is not present. |
kadonotakashi | 0:8fdf9a60065b | 146 | |
kadonotakashi | 0:8fdf9a60065b | 147 | :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock |
kadonotakashi | 0:8fdf9a60065b | 148 | :return |
kadonotakashi | 0:8fdf9a60065b | 149 | """ |
kadonotakashi | 0:8fdf9a60065b | 150 | |
kadonotakashi | 0:8fdf9a60065b | 151 | interface_version = get_interface_version(self.mount_point) |
kadonotakashi | 0:8fdf9a60065b | 152 | assert interface_version == 'unknown' |
kadonotakashi | 0:8fdf9a60065b | 153 | |
kadonotakashi | 0:8fdf9a60065b | 154 | @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_interface_version')) |
kadonotakashi | 0:8fdf9a60065b | 155 | def test_interface_version_wrong_mount_point(self, mbed_lstools_mock): |
kadonotakashi | 0:8fdf9a60065b | 156 | """ |
kadonotakashi | 0:8fdf9a60065b | 157 | Test that checks function returns correctly when there is no board attached to supplied mount point. |
kadonotakashi | 0:8fdf9a60065b | 158 | |
kadonotakashi | 0:8fdf9a60065b | 159 | :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock |
kadonotakashi | 0:8fdf9a60065b | 160 | :return |
kadonotakashi | 0:8fdf9a60065b | 161 | """ |
kadonotakashi | 0:8fdf9a60065b | 162 | |
kadonotakashi | 0:8fdf9a60065b | 163 | interface_version = get_interface_version(self.invalid_mount_point) |
kadonotakashi | 0:8fdf9a60065b | 164 | assert interface_version == 'unknown' |
kadonotakashi | 0:8fdf9a60065b | 165 | |
kadonotakashi | 0:8fdf9a60065b | 166 | @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_invalid_none')) |
kadonotakashi | 0:8fdf9a60065b | 167 | def test_interface_version_missing_mount_point(self, mbed_lstools_mock): |
kadonotakashi | 0:8fdf9a60065b | 168 | """ |
kadonotakashi | 0:8fdf9a60065b | 169 | Test that checks function returns correctly when no mount point is supplied. |
kadonotakashi | 0:8fdf9a60065b | 170 | |
kadonotakashi | 0:8fdf9a60065b | 171 | :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock |
kadonotakashi | 0:8fdf9a60065b | 172 | :return |
kadonotakashi | 0:8fdf9a60065b | 173 | """ |
kadonotakashi | 0:8fdf9a60065b | 174 | |
kadonotakashi | 0:8fdf9a60065b | 175 | interface_version = get_interface_version(self.missing_mount_point) |
kadonotakashi | 0:8fdf9a60065b | 176 | assert interface_version == 'unknown' |
kadonotakashi | 0:8fdf9a60065b | 177 | |
kadonotakashi | 0:8fdf9a60065b | 178 | if __name__ == '__main__': |
kadonotakashi | 0:8fdf9a60065b | 179 | unittest.main() |