Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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