mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 """
be_bryan 0:b74591d5ab33 2 mbed SDK
be_bryan 0:b74591d5ab33 3 Copyright (c) 2017 ARM Limited
be_bryan 0:b74591d5ab33 4
be_bryan 0:b74591d5ab33 5 Licensed under the Apache License, Version 2.0 (the "License");
be_bryan 0:b74591d5ab33 6 you may not use this file except in compliance with the License.
be_bryan 0:b74591d5ab33 7 You may obtain a copy of the License at
be_bryan 0:b74591d5ab33 8
be_bryan 0:b74591d5ab33 9 http://www.apache.org/licenses/LICENSE-2.0
be_bryan 0:b74591d5ab33 10
be_bryan 0:b74591d5ab33 11 Unless required by applicable law or agreed to in writing, software
be_bryan 0:b74591d5ab33 12 distributed under the License is distributed on an "AS IS" BASIS,
be_bryan 0:b74591d5ab33 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
be_bryan 0:b74591d5ab33 14 See the License for the specific language governing permissions and
be_bryan 0:b74591d5ab33 15 limitations under the License.
be_bryan 0:b74591d5ab33 16 """
be_bryan 0:b74591d5ab33 17
be_bryan 0:b74591d5ab33 18 import unittest
be_bryan 0:b74591d5ab33 19 from mock import patch
be_bryan 0:b74591d5ab33 20 from tools.detect_targets import get_interface_version
be_bryan 0:b74591d5ab33 21
be_bryan 0:b74591d5ab33 22
be_bryan 0:b74591d5ab33 23 class MbedLsToolsMock():
be_bryan 0:b74591d5ab33 24 """
be_bryan 0:b74591d5ab33 25 Mock of mbedls tools
be_bryan 0:b74591d5ab33 26 """
be_bryan 0:b74591d5ab33 27
be_bryan 0:b74591d5ab33 28 def __init__(self, test_type):
be_bryan 0:b74591d5ab33 29 self.interface_test_type = test_type
be_bryan 0:b74591d5ab33 30
be_bryan 0:b74591d5ab33 31 def get_details_txt(self, mount_point):
be_bryan 0:b74591d5ab33 32 return self.details_txt_types[self.interface_test_type];
be_bryan 0:b74591d5ab33 33
be_bryan 0:b74591d5ab33 34 # Static details.txt types.
be_bryan 0:b74591d5ab33 35 details_txt_types = {
be_bryan 0:b74591d5ab33 36 'details_valid_interface_version' : {
be_bryan 0:b74591d5ab33 37 'Unique ID': '0226000029164e45002f0012706e0006f301000097969900',
be_bryan 0:b74591d5ab33 38 'HIF ID': '97969900',
be_bryan 0:b74591d5ab33 39 'Auto Reset': '0',
be_bryan 0:b74591d5ab33 40 'Automation allowed': '0',
be_bryan 0:b74591d5ab33 41 'Daplink Mode': 'Interface',
be_bryan 0:b74591d5ab33 42 'Interface Version': '0240',
be_bryan 0:b74591d5ab33 43 'Git SHA': 'c765cbb590f57598756683254ca38b211693ae5e',
be_bryan 0:b74591d5ab33 44 'Local Mods': '0',
be_bryan 0:b74591d5ab33 45 'USB Interfaces': 'MSD, CDC, HID',
be_bryan 0:b74591d5ab33 46 'Interface CRC': '0x26764ebf'
be_bryan 0:b74591d5ab33 47 },
be_bryan 0:b74591d5ab33 48 'details_valid_version' : {
be_bryan 0:b74591d5ab33 49 'Version': '0226',
be_bryan 0:b74591d5ab33 50 'Build': 'Aug 24 2015 17:06:30',
be_bryan 0:b74591d5ab33 51 'Git Commit SHA': '27a236b9fe39c674a703c5c89655fbd26b8e27e1',
be_bryan 0:b74591d5ab33 52 'Git Local mods': 'Yes'
be_bryan 0:b74591d5ab33 53 },
be_bryan 0:b74591d5ab33 54 'details_missing_interface_version' : {
be_bryan 0:b74591d5ab33 55 'Unique ID': '0226000033514e450044500585d4001de981000097969900',
be_bryan 0:b74591d5ab33 56 'HIC ID': '97969900',
be_bryan 0:b74591d5ab33 57 'Auto Reset': '0',
be_bryan 0:b74591d5ab33 58 'Automation allowed': '0',
be_bryan 0:b74591d5ab33 59 'Overflow detection': '0',
be_bryan 0:b74591d5ab33 60 'Daplink Mode': 'Interface',
be_bryan 0:b74591d5ab33 61 'Git SHA': 'b403a07e3696cee1e116d44cbdd64446e056ce38',
be_bryan 0:b74591d5ab33 62 'Local Mods': '0',
be_bryan 0:b74591d5ab33 63 'USB Interfaces': 'MSD, CDC, HID',
be_bryan 0:b74591d5ab33 64 'Interface CRC': '0x4d98bf7e',
be_bryan 0:b74591d5ab33 65 'Remount count': '0'
be_bryan 0:b74591d5ab33 66 },
be_bryan 0:b74591d5ab33 67 'details_invalid_none' : None
be_bryan 0:b74591d5ab33 68 }
be_bryan 0:b74591d5ab33 69
be_bryan 0:b74591d5ab33 70 """
be_bryan 0:b74591d5ab33 71 Tests for detect_targets.py
be_bryan 0:b74591d5ab33 72 """
be_bryan 0:b74591d5ab33 73
be_bryan 0:b74591d5ab33 74 class DetectTargetsTest(unittest.TestCase):
be_bryan 0:b74591d5ab33 75 """
be_bryan 0:b74591d5ab33 76 Test cases for Detect Target functionality
be_bryan 0:b74591d5ab33 77 """
be_bryan 0:b74591d5ab33 78
be_bryan 0:b74591d5ab33 79 def setUp(self):
be_bryan 0:b74591d5ab33 80 """
be_bryan 0:b74591d5ab33 81 Called before each test case
be_bryan 0:b74591d5ab33 82
be_bryan 0:b74591d5ab33 83 :return:
be_bryan 0:b74591d5ab33 84 """
be_bryan 0:b74591d5ab33 85 self.missing_mount_point = None
be_bryan 0:b74591d5ab33 86 self.mount_point = "D:"
be_bryan 0:b74591d5ab33 87
be_bryan 0:b74591d5ab33 88 def tearDown(self):
be_bryan 0:b74591d5ab33 89 """
be_bryan 0:b74591d5ab33 90 Nothing to tear down.
be_bryan 0:b74591d5ab33 91 Called after each test case
be_bryan 0:b74591d5ab33 92
be_bryan 0:b74591d5ab33 93 :return:
be_bryan 0:b74591d5ab33 94 """
be_bryan 0:b74591d5ab33 95 pass
be_bryan 0:b74591d5ab33 96
be_bryan 0:b74591d5ab33 97 @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_interface_version'))
be_bryan 0:b74591d5ab33 98 def test_interface_version_valid(self, mbed_lstools_mock):
be_bryan 0:b74591d5ab33 99 """
be_bryan 0:b74591d5ab33 100 Test that checks function returns correctly when given a valid Interface Version
be_bryan 0:b74591d5ab33 101
be_bryan 0:b74591d5ab33 102 :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
be_bryan 0:b74591d5ab33 103 :return
be_bryan 0:b74591d5ab33 104 """
be_bryan 0:b74591d5ab33 105
be_bryan 0:b74591d5ab33 106 interface_version = get_interface_version(self.mount_point)
be_bryan 0:b74591d5ab33 107 assert interface_version == '0240'
be_bryan 0:b74591d5ab33 108
be_bryan 0:b74591d5ab33 109 @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_version'))
be_bryan 0:b74591d5ab33 110 def test_version_valid(self, mbed_lstools_mock):
be_bryan 0:b74591d5ab33 111 """
be_bryan 0:b74591d5ab33 112 Test that checks function returns correctly when given a valid Version
be_bryan 0:b74591d5ab33 113
be_bryan 0:b74591d5ab33 114 :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
be_bryan 0:b74591d5ab33 115 :return
be_bryan 0:b74591d5ab33 116 """
be_bryan 0:b74591d5ab33 117
be_bryan 0:b74591d5ab33 118 interface_version = get_interface_version(self.mount_point)
be_bryan 0:b74591d5ab33 119 assert interface_version == '0226'
be_bryan 0:b74591d5ab33 120
be_bryan 0:b74591d5ab33 121 @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_missing_interface_version'))
be_bryan 0:b74591d5ab33 122 def test_interface_version_missing_interface_version(self, mbed_lstools_mock):
be_bryan 0:b74591d5ab33 123 """
be_bryan 0:b74591d5ab33 124 Test that checks function returns correctly when DETAILS.txt is present
be_bryan 0:b74591d5ab33 125 but an interface version is not listed.
be_bryan 0:b74591d5ab33 126
be_bryan 0:b74591d5ab33 127 :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
be_bryan 0:b74591d5ab33 128 :return
be_bryan 0:b74591d5ab33 129 """
be_bryan 0:b74591d5ab33 130
be_bryan 0:b74591d5ab33 131 interface_version = get_interface_version(self.mount_point)
be_bryan 0:b74591d5ab33 132 assert interface_version == 'unknown'
be_bryan 0:b74591d5ab33 133
be_bryan 0:b74591d5ab33 134 @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_invalid_none'))
be_bryan 0:b74591d5ab33 135 def test_version_none(self, mbed_lstools_mock):
be_bryan 0:b74591d5ab33 136 """
be_bryan 0:b74591d5ab33 137 Test that checks function returns correctly when a valid mount point is supplied
be_bryan 0:b74591d5ab33 138 but DETAILS.txt is not present.
be_bryan 0:b74591d5ab33 139
be_bryan 0:b74591d5ab33 140 :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
be_bryan 0:b74591d5ab33 141 :return
be_bryan 0:b74591d5ab33 142 """
be_bryan 0:b74591d5ab33 143
be_bryan 0:b74591d5ab33 144 interface_version = get_interface_version(self.mount_point)
be_bryan 0:b74591d5ab33 145 assert interface_version == 'unknown'
be_bryan 0:b74591d5ab33 146
be_bryan 0:b74591d5ab33 147 @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_invalid_none'))
be_bryan 0:b74591d5ab33 148 def test_interface_version_missing_mount_point(self, mbed_lstools_mock):
be_bryan 0:b74591d5ab33 149 """
be_bryan 0:b74591d5ab33 150 Test that checks function returns correctly when no mount point is supplied.
be_bryan 0:b74591d5ab33 151
be_bryan 0:b74591d5ab33 152 :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
be_bryan 0:b74591d5ab33 153 :return
be_bryan 0:b74591d5ab33 154 """
be_bryan 0:b74591d5ab33 155
be_bryan 0:b74591d5ab33 156 interface_version = get_interface_version(self.missing_mount_point)
be_bryan 0:b74591d5ab33 157 assert interface_version == 'unknown'
be_bryan 0:b74591d5ab33 158
be_bryan 0:b74591d5ab33 159 if __name__ == '__main__':
be_bryan 0:b74591d5ab33 160 unittest.main()