Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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