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