the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
32:8ea194f6145b
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 32:8ea194f6145b 1 """
The Other Jimmy 32:8ea194f6145b 2 mbed SDK
The Other Jimmy 32:8ea194f6145b 3 Copyright (c) 2016 ARM Limited
The Other Jimmy 32:8ea194f6145b 4
The Other Jimmy 32:8ea194f6145b 5 Licensed under the Apache License, Version 2.0 (the "License");
The Other Jimmy 32:8ea194f6145b 6 you may not use this file except in compliance with the License.
The Other Jimmy 32:8ea194f6145b 7 You may obtain a copy of the License at
The Other Jimmy 32:8ea194f6145b 8
The Other Jimmy 32:8ea194f6145b 9 http://www.apache.org/licenses/LICENSE-2.0
The Other Jimmy 32:8ea194f6145b 10
The Other Jimmy 32:8ea194f6145b 11 Unless required by applicable law or agreed to in writing, software
The Other Jimmy 32:8ea194f6145b 12 distributed under the License is distributed on an "AS IS" BASIS,
The Other Jimmy 32:8ea194f6145b 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
The Other Jimmy 32:8ea194f6145b 14 See the License for the specific language governing permissions and
The Other Jimmy 32:8ea194f6145b 15 limitations under the License.
The Other Jimmy 32:8ea194f6145b 16 """
The Other Jimmy 32:8ea194f6145b 17
The Other Jimmy 32:8ea194f6145b 18 import unittest
The Other Jimmy 32:8ea194f6145b 19 from collections import namedtuple
The Other Jimmy 32:8ea194f6145b 20 from mock import patch, MagicMock
The Other Jimmy 32:8ea194f6145b 21 from tools.build_api import prepare_toolchain, build_project, build_library,\
The Other Jimmy 32:8ea194f6145b 22 scan_resources
The Other Jimmy 32:8ea194f6145b 23
The Other Jimmy 32:8ea194f6145b 24 """
The Other Jimmy 32:8ea194f6145b 25 Tests for build_api.py
The Other Jimmy 32:8ea194f6145b 26 """
The Other Jimmy 32:8ea194f6145b 27
The Other Jimmy 32:8ea194f6145b 28 class BuildApiTests(unittest.TestCase):
The Other Jimmy 32:8ea194f6145b 29 """
The Other Jimmy 32:8ea194f6145b 30 Test cases for Build Api
The Other Jimmy 32:8ea194f6145b 31 """
The Other Jimmy 32:8ea194f6145b 32
The Other Jimmy 32:8ea194f6145b 33 def setUp(self):
The Other Jimmy 32:8ea194f6145b 34 """
The Other Jimmy 32:8ea194f6145b 35 Called before each test case
The Other Jimmy 32:8ea194f6145b 36
The Other Jimmy 32:8ea194f6145b 37 :return:
The Other Jimmy 32:8ea194f6145b 38 """
The Other Jimmy 32:8ea194f6145b 39 self.target = "K64F"
The Other Jimmy 32:8ea194f6145b 40 self.src_paths = ['.']
The Other Jimmy 32:8ea194f6145b 41 self.toolchain_name = "ARM"
The Other Jimmy 32:8ea194f6145b 42 self.build_path = "build_path"
The Other Jimmy 32:8ea194f6145b 43
The Other Jimmy 32:8ea194f6145b 44 def tearDown(self):
The Other Jimmy 32:8ea194f6145b 45 """
The Other Jimmy 32:8ea194f6145b 46 Called after each test case
The Other Jimmy 32:8ea194f6145b 47
The Other Jimmy 32:8ea194f6145b 48 :return:
The Other Jimmy 32:8ea194f6145b 49 """
The Other Jimmy 32:8ea194f6145b 50 pass
The Other Jimmy 32:8ea194f6145b 51
The Other Jimmy 32:8ea194f6145b 52 @patch('tools.toolchains.arm.ARM_STD.parse_dependencies',
The Other Jimmy 32:8ea194f6145b 53 return_value=["foo"])
The Other Jimmy 32:8ea194f6145b 54 @patch('tools.toolchains.mbedToolchain.need_update',
The Other Jimmy 32:8ea194f6145b 55 side_effect=[i % 2 for i in range(3000)])
The Other Jimmy 32:8ea194f6145b 56 @patch('os.mkdir')
The Other Jimmy 32:8ea194f6145b 57 @patch('tools.toolchains.exists', return_value=True)
The Other Jimmy 32:8ea194f6145b 58 @patch('tools.utils.run_cmd', return_value=("", "", 0))
The Other Jimmy 32:8ea194f6145b 59 def test_always_complete_build(self, *_):
The Other Jimmy 32:8ea194f6145b 60 with MagicMock() as notify:
The Other Jimmy 32:8ea194f6145b 61 toolchain = prepare_toolchain(self.src_paths, self.target,
The Other Jimmy 32:8ea194f6145b 62 self.toolchain_name, notify=notify)
The Other Jimmy 32:8ea194f6145b 63
The Other Jimmy 32:8ea194f6145b 64 res = scan_resources(self.src_paths, toolchain)
The Other Jimmy 32:8ea194f6145b 65
The Other Jimmy 32:8ea194f6145b 66 toolchain.RESPONSE_FILES=False
The Other Jimmy 32:8ea194f6145b 67 toolchain.config_processed = True
The Other Jimmy 32:8ea194f6145b 68 toolchain.config_file = "junk"
The Other Jimmy 32:8ea194f6145b 69 toolchain.compile_sources(res, self.build_path)
The Other Jimmy 32:8ea194f6145b 70
The Other Jimmy 32:8ea194f6145b 71 assert any('percent' in msg[0] and msg[0]['percent'] == 100.0
The Other Jimmy 32:8ea194f6145b 72 for _, msg, _ in notify.mock_calls if msg)
The Other Jimmy 32:8ea194f6145b 73
The Other Jimmy 32:8ea194f6145b 74
The Other Jimmy 32:8ea194f6145b 75 @patch('tools.build_api.Config')
The Other Jimmy 32:8ea194f6145b 76 def test_prepare_toolchain_app_config(self, mock_config_init):
The Other Jimmy 32:8ea194f6145b 77 """
The Other Jimmy 32:8ea194f6145b 78 Test that prepare_toolchain uses app_config correctly
The Other Jimmy 32:8ea194f6145b 79
The Other Jimmy 32:8ea194f6145b 80 :param mock_config_init: mock of Config __init__
The Other Jimmy 32:8ea194f6145b 81 :return:
The Other Jimmy 32:8ea194f6145b 82 """
The Other Jimmy 32:8ea194f6145b 83 app_config = "app_config"
The Other Jimmy 32:8ea194f6145b 84 mock_config_init.return_value = namedtuple("Config", "target")(
The Other Jimmy 32:8ea194f6145b 85 namedtuple("Target",
The Other Jimmy 32:8ea194f6145b 86 "init_hooks name features core")(lambda _, __ : None,
The Other Jimmy 32:8ea194f6145b 87 "Junk", [], "Cortex-M3"))
The Other Jimmy 32:8ea194f6145b 88
The Other Jimmy 32:8ea194f6145b 89 prepare_toolchain(self.src_paths, self.target, self.toolchain_name,
The Other Jimmy 32:8ea194f6145b 90 app_config=app_config)
The Other Jimmy 32:8ea194f6145b 91
The Other Jimmy 32:8ea194f6145b 92 mock_config_init.assert_called_once_with(self.target, self.src_paths,
The Other Jimmy 32:8ea194f6145b 93 app_config=app_config)
The Other Jimmy 32:8ea194f6145b 94
The Other Jimmy 32:8ea194f6145b 95 @patch('tools.build_api.Config')
The Other Jimmy 32:8ea194f6145b 96 def test_prepare_toolchain_no_app_config(self, mock_config_init):
The Other Jimmy 32:8ea194f6145b 97 """
The Other Jimmy 32:8ea194f6145b 98 Test that prepare_toolchain correctly deals with no app_config
The Other Jimmy 32:8ea194f6145b 99
The Other Jimmy 32:8ea194f6145b 100 :param mock_config_init: mock of Config __init__
The Other Jimmy 32:8ea194f6145b 101 :return:
The Other Jimmy 32:8ea194f6145b 102 """
The Other Jimmy 32:8ea194f6145b 103 mock_config_init.return_value = namedtuple("Config", "target")(
The Other Jimmy 32:8ea194f6145b 104 namedtuple("Target",
The Other Jimmy 32:8ea194f6145b 105 "init_hooks name features core")(lambda _, __ : None,
The Other Jimmy 32:8ea194f6145b 106 "Junk", [], "Cortex-M3"))
The Other Jimmy 32:8ea194f6145b 107
The Other Jimmy 32:8ea194f6145b 108 prepare_toolchain(self.src_paths, self.target, self.toolchain_name)
The Other Jimmy 32:8ea194f6145b 109
The Other Jimmy 32:8ea194f6145b 110 mock_config_init.assert_called_once_with(self.target, self.src_paths,
The Other Jimmy 32:8ea194f6145b 111 app_config=None)
The Other Jimmy 32:8ea194f6145b 112
The Other Jimmy 32:8ea194f6145b 113 @patch('tools.build_api.scan_resources')
The Other Jimmy 32:8ea194f6145b 114 @patch('tools.build_api.mkdir')
The Other Jimmy 32:8ea194f6145b 115 @patch('os.path.exists')
The Other Jimmy 32:8ea194f6145b 116 @patch('tools.build_api.prepare_toolchain')
The Other Jimmy 32:8ea194f6145b 117 def test_build_project_app_config(self, mock_prepare_toolchain, mock_exists, _, __):
The Other Jimmy 32:8ea194f6145b 118 """
The Other Jimmy 32:8ea194f6145b 119 Test that build_project uses app_config correctly
The Other Jimmy 32:8ea194f6145b 120
The Other Jimmy 32:8ea194f6145b 121 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 32:8ea194f6145b 122 :param mock_exists: mock of function os.path.exists
The Other Jimmy 32:8ea194f6145b 123 :param _: mock of function mkdir (not tested)
The Other Jimmy 32:8ea194f6145b 124 :param __: mock of function scan_resources (not tested)
The Other Jimmy 32:8ea194f6145b 125 :return:
The Other Jimmy 32:8ea194f6145b 126 """
The Other Jimmy 32:8ea194f6145b 127 app_config = "app_config"
The Other Jimmy 32:8ea194f6145b 128 mock_exists.return_value = False
The Other Jimmy 32:8ea194f6145b 129 mock_prepare_toolchain().link_program.return_value = 1, 2
The Other Jimmy 32:8ea194f6145b 130
The Other Jimmy 32:8ea194f6145b 131 build_project(self.src_paths, self.build_path, self.target,
The Other Jimmy 32:8ea194f6145b 132 self.toolchain_name, app_config=app_config)
The Other Jimmy 32:8ea194f6145b 133
The Other Jimmy 32:8ea194f6145b 134 args = mock_prepare_toolchain.call_args
The Other Jimmy 32:8ea194f6145b 135 self.assertTrue('app_config' in args[1],
The Other Jimmy 32:8ea194f6145b 136 "prepare_toolchain was not called with app_config")
The Other Jimmy 32:8ea194f6145b 137 self.assertEqual(args[1]['app_config'], app_config,
The Other Jimmy 32:8ea194f6145b 138 "prepare_toolchain was called with an incorrect app_config")
The Other Jimmy 32:8ea194f6145b 139
The Other Jimmy 32:8ea194f6145b 140 @patch('tools.build_api.scan_resources')
The Other Jimmy 32:8ea194f6145b 141 @patch('tools.build_api.mkdir')
The Other Jimmy 32:8ea194f6145b 142 @patch('os.path.exists')
The Other Jimmy 32:8ea194f6145b 143 @patch('tools.build_api.prepare_toolchain')
The Other Jimmy 32:8ea194f6145b 144 def test_build_project_no_app_config(self, mock_prepare_toolchain, mock_exists, _, __):
The Other Jimmy 32:8ea194f6145b 145 """
The Other Jimmy 32:8ea194f6145b 146 Test that build_project correctly deals with no app_config
The Other Jimmy 32:8ea194f6145b 147
The Other Jimmy 32:8ea194f6145b 148 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 32:8ea194f6145b 149 :param mock_exists: mock of function os.path.exists
The Other Jimmy 32:8ea194f6145b 150 :param _: mock of function mkdir (not tested)
The Other Jimmy 32:8ea194f6145b 151 :param __: mock of function scan_resources (not tested)
The Other Jimmy 32:8ea194f6145b 152 :return:
The Other Jimmy 32:8ea194f6145b 153 """
The Other Jimmy 32:8ea194f6145b 154 mock_exists.return_value = False
The Other Jimmy 32:8ea194f6145b 155 # Needed for the unpacking of the returned value
The Other Jimmy 32:8ea194f6145b 156 mock_prepare_toolchain().link_program.return_value = 1, 2
The Other Jimmy 32:8ea194f6145b 157
The Other Jimmy 32:8ea194f6145b 158 build_project(self.src_paths, self.build_path, self.target,
The Other Jimmy 32:8ea194f6145b 159 self.toolchain_name)
The Other Jimmy 32:8ea194f6145b 160
The Other Jimmy 32:8ea194f6145b 161 args = mock_prepare_toolchain.call_args
The Other Jimmy 32:8ea194f6145b 162 self.assertTrue('app_config' in args[1],
The Other Jimmy 32:8ea194f6145b 163 "prepare_toolchain was not called with app_config")
The Other Jimmy 32:8ea194f6145b 164 self.assertEqual(args[1]['app_config'], None,
The Other Jimmy 32:8ea194f6145b 165 "prepare_toolchain was called with an incorrect app_config")
The Other Jimmy 32:8ea194f6145b 166
The Other Jimmy 32:8ea194f6145b 167 @patch('tools.build_api.scan_resources')
The Other Jimmy 32:8ea194f6145b 168 @patch('tools.build_api.mkdir')
The Other Jimmy 32:8ea194f6145b 169 @patch('os.path.exists')
The Other Jimmy 32:8ea194f6145b 170 @patch('tools.build_api.prepare_toolchain')
The Other Jimmy 32:8ea194f6145b 171 def test_build_library_app_config(self, mock_prepare_toolchain, mock_exists, _, __):
The Other Jimmy 32:8ea194f6145b 172 """
The Other Jimmy 32:8ea194f6145b 173 Test that build_library uses app_config correctly
The Other Jimmy 32:8ea194f6145b 174
The Other Jimmy 32:8ea194f6145b 175 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 32:8ea194f6145b 176 :param mock_exists: mock of function os.path.exists
The Other Jimmy 32:8ea194f6145b 177 :param _: mock of function mkdir (not tested)
The Other Jimmy 32:8ea194f6145b 178 :param __: mock of function scan_resources (not tested)
The Other Jimmy 32:8ea194f6145b 179 :return:
The Other Jimmy 32:8ea194f6145b 180 """
The Other Jimmy 32:8ea194f6145b 181 app_config = "app_config"
The Other Jimmy 32:8ea194f6145b 182 mock_exists.return_value = False
The Other Jimmy 32:8ea194f6145b 183
The Other Jimmy 32:8ea194f6145b 184 build_library(self.src_paths, self.build_path, self.target,
The Other Jimmy 32:8ea194f6145b 185 self.toolchain_name, app_config=app_config)
The Other Jimmy 32:8ea194f6145b 186
The Other Jimmy 32:8ea194f6145b 187 args = mock_prepare_toolchain.call_args
The Other Jimmy 32:8ea194f6145b 188 self.assertTrue('app_config' in args[1],
The Other Jimmy 32:8ea194f6145b 189 "prepare_toolchain was not called with app_config")
The Other Jimmy 32:8ea194f6145b 190 self.assertEqual(args[1]['app_config'], app_config,
The Other Jimmy 32:8ea194f6145b 191 "prepare_toolchain was called with an incorrect app_config")
The Other Jimmy 32:8ea194f6145b 192
The Other Jimmy 32:8ea194f6145b 193 @patch('tools.build_api.scan_resources')
The Other Jimmy 32:8ea194f6145b 194 @patch('tools.build_api.mkdir')
The Other Jimmy 32:8ea194f6145b 195 @patch('os.path.exists')
The Other Jimmy 32:8ea194f6145b 196 @patch('tools.build_api.prepare_toolchain')
The Other Jimmy 32:8ea194f6145b 197 def test_build_library_no_app_config(self, mock_prepare_toolchain, mock_exists, _, __):
The Other Jimmy 32:8ea194f6145b 198 """
The Other Jimmy 32:8ea194f6145b 199 Test that build_library correctly deals with no app_config
The Other Jimmy 32:8ea194f6145b 200
The Other Jimmy 32:8ea194f6145b 201 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 32:8ea194f6145b 202 :param mock_exists: mock of function os.path.exists
The Other Jimmy 32:8ea194f6145b 203 :param _: mock of function mkdir (not tested)
The Other Jimmy 32:8ea194f6145b 204 :param __: mock of function scan_resources (not tested)
The Other Jimmy 32:8ea194f6145b 205 :return:
The Other Jimmy 32:8ea194f6145b 206 """
The Other Jimmy 32:8ea194f6145b 207 mock_exists.return_value = False
The Other Jimmy 32:8ea194f6145b 208
The Other Jimmy 32:8ea194f6145b 209 build_library(self.src_paths, self.build_path, self.target,
The Other Jimmy 32:8ea194f6145b 210 self.toolchain_name)
The Other Jimmy 32:8ea194f6145b 211
The Other Jimmy 32:8ea194f6145b 212 args = mock_prepare_toolchain.call_args
The Other Jimmy 32:8ea194f6145b 213 self.assertTrue('app_config' in args[1],
The Other Jimmy 32:8ea194f6145b 214 "prepare_toolchain was not called with app_config")
The Other Jimmy 32:8ea194f6145b 215 self.assertEqual(args[1]['app_config'], None,
The Other Jimmy 32:8ea194f6145b 216 "prepare_toolchain was called with an incorrect app_config")
The Other Jimmy 32:8ea194f6145b 217
The Other Jimmy 32:8ea194f6145b 218 if __name__ == '__main__':
The Other Jimmy 32:8ea194f6145b 219 unittest.main()