Ram Gandikota
/
IOTMetronome
FRDM K64F Metronome
pal/Test/Scripts/perform_test_mbedOS.py@0:dbad57390bd1, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:37:05 2017 +0000
- Revision:
- 0:dbad57390bd1
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:dbad57390bd1 | 1 | # ----------------------------------------------------------------------- |
ram54288 | 0:dbad57390bd1 | 2 | # Copyright (c) 2016 ARM Limited. All rights reserved. |
ram54288 | 0:dbad57390bd1 | 3 | # SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:dbad57390bd1 | 4 | # Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:dbad57390bd1 | 5 | # not use this file except in compliance with the License. |
ram54288 | 0:dbad57390bd1 | 6 | # You may obtain a copy of the License at |
ram54288 | 0:dbad57390bd1 | 7 | # |
ram54288 | 0:dbad57390bd1 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:dbad57390bd1 | 9 | # |
ram54288 | 0:dbad57390bd1 | 10 | # Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:dbad57390bd1 | 11 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:dbad57390bd1 | 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:dbad57390bd1 | 13 | # See the License for the specific language governing permissions and |
ram54288 | 0:dbad57390bd1 | 14 | # limitations under the License. |
ram54288 | 0:dbad57390bd1 | 15 | # ----------------------------------------------------------------------- |
ram54288 | 0:dbad57390bd1 | 16 | |
ram54288 | 0:dbad57390bd1 | 17 | ##################################################################### |
ram54288 | 0:dbad57390bd1 | 18 | # Install and run PAL tests for mbed targets. |
ram54288 | 0:dbad57390bd1 | 19 | # |
ram54288 | 0:dbad57390bd1 | 20 | # Arguments: One or more binary files containing tests to execute. |
ram54288 | 0:dbad57390bd1 | 21 | # |
ram54288 | 0:dbad57390bd1 | 22 | # Output: <binary file>_result.txt - Textual result summary |
ram54288 | 0:dbad57390bd1 | 23 | # <binary file>.xml - Junit result summary |
ram54288 | 0:dbad57390bd1 | 24 | # ARM |
ram54288 | 0:dbad57390bd1 | 25 | # Clive Bluston |
ram54288 | 0:dbad57390bd1 | 26 | ##################################################################### |
ram54288 | 0:dbad57390bd1 | 27 | from mbed import MBED |
ram54288 | 0:dbad57390bd1 | 28 | import os |
ram54288 | 0:dbad57390bd1 | 29 | import sys |
ram54288 | 0:dbad57390bd1 | 30 | import unity_to_junit |
ram54288 | 0:dbad57390bd1 | 31 | from time import sleep |
ram54288 | 0:dbad57390bd1 | 32 | |
ram54288 | 0:dbad57390bd1 | 33 | # Check that at least one test is specified on the command line |
ram54288 | 0:dbad57390bd1 | 34 | if len(sys.argv) < 2: |
ram54288 | 0:dbad57390bd1 | 35 | sys.exit() |
ram54288 | 0:dbad57390bd1 | 36 | else: |
ram54288 | 0:dbad57390bd1 | 37 | tests = sys.argv[1:] |
ram54288 | 0:dbad57390bd1 | 38 | |
ram54288 | 0:dbad57390bd1 | 39 | # List of textual result files. |
ram54288 | 0:dbad57390bd1 | 40 | resultFiles = [] |
ram54288 | 0:dbad57390bd1 | 41 | |
ram54288 | 0:dbad57390bd1 | 42 | # Supported mbed devices. Can add to this list |
ram54288 | 0:dbad57390bd1 | 43 | deviceList = ["K64F"] |
ram54288 | 0:dbad57390bd1 | 44 | |
ram54288 | 0:dbad57390bd1 | 45 | # Loop over attached mbed devices. |
ram54288 | 0:dbad57390bd1 | 46 | for device in deviceList: |
ram54288 | 0:dbad57390bd1 | 47 | mbed = MBED(device) |
ram54288 | 0:dbad57390bd1 | 48 | deviceDetected = mbed.detect() |
ram54288 | 0:dbad57390bd1 | 49 | if deviceDetected: |
ram54288 | 0:dbad57390bd1 | 50 | # Loop over tests |
ram54288 | 0:dbad57390bd1 | 51 | for test in tests: |
ram54288 | 0:dbad57390bd1 | 52 | mbed.install_bin(test) |
ram54288 | 0:dbad57390bd1 | 53 | noSuffix = os.path.splitext(test)[0] |
ram54288 | 0:dbad57390bd1 | 54 | intermediateResultsFile = noSuffix+".int" |
ram54288 | 0:dbad57390bd1 | 55 | # Remove intermediate file just in case it was left over from a failed run. |
ram54288 | 0:dbad57390bd1 | 56 | if os.path.isfile(intermediateResultsFile): |
ram54288 | 0:dbad57390bd1 | 57 | os.remove(intermediateResultsFile) |
ram54288 | 0:dbad57390bd1 | 58 | resultFile = noSuffix+"_result.txt" |
ram54288 | 0:dbad57390bd1 | 59 | # This delay is to allow output that was generated before the reset to be discarded. |
ram54288 | 0:dbad57390bd1 | 60 | sleep(30) |
ram54288 | 0:dbad57390bd1 | 61 | # Capture test results from the serial port |
ram54288 | 0:dbad57390bd1 | 62 | if mbed.run_and_capture_till_timeout(intermediateResultsFile,baud=9600,read_timeout=10,endOfData="***END OF TESTS**"): |
ram54288 | 0:dbad57390bd1 | 63 | # Success. Convert results to Junit format and write to xml file. |
ram54288 | 0:dbad57390bd1 | 64 | unity_to_junit.unity_to_junit("mbedos_" + os.path.basename(noSuffix), intermediateResultsFile, noSuffix+".xml", resultFile) |
ram54288 | 0:dbad57390bd1 | 65 | # Output intermediate results to the console. |
ram54288 | 0:dbad57390bd1 | 66 | with open(intermediateResultsFile, 'r') as fin: |
ram54288 | 0:dbad57390bd1 | 67 | print fin.read() |
ram54288 | 0:dbad57390bd1 | 68 | os.remove(intermediateResultsFile) |
ram54288 | 0:dbad57390bd1 | 69 | # Add result file name to list |
ram54288 | 0:dbad57390bd1 | 70 | resultFiles.append(resultFile) |
ram54288 | 0:dbad57390bd1 | 71 | else: |
ram54288 | 0:dbad57390bd1 | 72 | response = raw_input("Connect Serial port. Enter when ready") |
ram54288 | 0:dbad57390bd1 | 73 | # Clean up. True parameter closes the device opened by mbed.detect() |
ram54288 | 0:dbad57390bd1 | 74 | mbed.end_run(False,True) |
ram54288 | 0:dbad57390bd1 | 75 | |
ram54288 | 0:dbad57390bd1 | 76 | |
ram54288 | 0:dbad57390bd1 | 77 | # Copy result files to standard output |
ram54288 | 0:dbad57390bd1 | 78 | for file in resultFiles: |
ram54288 | 0:dbad57390bd1 | 79 | with open(file, 'r') as fin: |
ram54288 | 0:dbad57390bd1 | 80 | print fin.read() |
ram54288 | 0:dbad57390bd1 | 81 | |
ram54288 | 0:dbad57390bd1 | 82 | |
ram54288 | 0:dbad57390bd1 | 83 |