![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/UNITTESTS/unit_test/utils.py@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | """ |
kadonotakashi | 0:8fdf9a60065b | 2 | Copyright (c) 2018, Arm Limited |
kadonotakashi | 0:8fdf9a60065b | 3 | SPDX-License-Identifier: Apache-2.0 |
kadonotakashi | 0:8fdf9a60065b | 4 | |
kadonotakashi | 0:8fdf9a60065b | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 6 | you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 7 | You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 8 | |
kadonotakashi | 0:8fdf9a60065b | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 10 | |
kadonotakashi | 0:8fdf9a60065b | 11 | Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 14 | See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 15 | limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 16 | |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | UNIT TEST UTILITIES |
kadonotakashi | 0:8fdf9a60065b | 19 | """ |
kadonotakashi | 0:8fdf9a60065b | 20 | |
kadonotakashi | 0:8fdf9a60065b | 21 | import platform |
kadonotakashi | 0:8fdf9a60065b | 22 | import subprocess |
kadonotakashi | 0:8fdf9a60065b | 23 | import logging |
kadonotakashi | 0:8fdf9a60065b | 24 | import sys |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | def is_tool(name): |
kadonotakashi | 0:8fdf9a60065b | 27 | """ |
kadonotakashi | 0:8fdf9a60065b | 28 | Test if tool is found in PATH |
kadonotakashi | 0:8fdf9a60065b | 29 | |
kadonotakashi | 0:8fdf9a60065b | 30 | @param name: executable name |
kadonotakashi | 0:8fdf9a60065b | 31 | @return: true if tool found, false otherwise |
kadonotakashi | 0:8fdf9a60065b | 32 | """ |
kadonotakashi | 0:8fdf9a60065b | 33 | cmd = "where" if platform.system() == "Windows" else "which" |
kadonotakashi | 0:8fdf9a60065b | 34 | try: |
kadonotakashi | 0:8fdf9a60065b | 35 | subprocess.check_output([cmd, name], stderr=subprocess.STDOUT) |
kadonotakashi | 0:8fdf9a60065b | 36 | return True |
kadonotakashi | 0:8fdf9a60065b | 37 | except subprocess.CalledProcessError: |
kadonotakashi | 0:8fdf9a60065b | 38 | return False |
kadonotakashi | 0:8fdf9a60065b | 39 | |
kadonotakashi | 0:8fdf9a60065b | 40 | def execute_program(args, error_msg="An error occurred!", success_msg=None): |
kadonotakashi | 0:8fdf9a60065b | 41 | """ |
kadonotakashi | 0:8fdf9a60065b | 42 | Execute program in a subprocess with given arguments |
kadonotakashi | 0:8fdf9a60065b | 43 | |
kadonotakashi | 0:8fdf9a60065b | 44 | @param args: program and its arguments in a list |
kadonotakashi | 0:8fdf9a60065b | 45 | @param success_msg: message to show in case of success |
kadonotakashi | 0:8fdf9a60065b | 46 | @param error_msg: message to show in case of failure |
kadonotakashi | 0:8fdf9a60065b | 47 | """ |
kadonotakashi | 0:8fdf9a60065b | 48 | |
kadonotakashi | 0:8fdf9a60065b | 49 | try: |
kadonotakashi | 0:8fdf9a60065b | 50 | process = subprocess.Popen(args, |
kadonotakashi | 0:8fdf9a60065b | 51 | stdout=subprocess.PIPE, |
kadonotakashi | 0:8fdf9a60065b | 52 | stderr=subprocess.STDOUT) |
kadonotakashi | 0:8fdf9a60065b | 53 | |
kadonotakashi | 0:8fdf9a60065b | 54 | while process.poll() is None: |
kadonotakashi | 0:8fdf9a60065b | 55 | logging.info(process.stdout.readline().decode("utf8")) |
kadonotakashi | 0:8fdf9a60065b | 56 | |
kadonotakashi | 0:8fdf9a60065b | 57 | retcode = process.wait() |
kadonotakashi | 0:8fdf9a60065b | 58 | |
kadonotakashi | 0:8fdf9a60065b | 59 | if retcode: |
kadonotakashi | 0:8fdf9a60065b | 60 | raise subprocess.CalledProcessError(retcode, args) |
kadonotakashi | 0:8fdf9a60065b | 61 | elif success_msg: |
kadonotakashi | 0:8fdf9a60065b | 62 | logging.info(success_msg) |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | except subprocess.CalledProcessError as error: |
kadonotakashi | 0:8fdf9a60065b | 65 | logging.error(error_msg) |
kadonotakashi | 0:8fdf9a60065b | 66 | sys.exit(error.returncode) |