FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:35:07 2017 +0000
Revision:
0:a2cb7295a1f7
Initial commit

Who changed what in which revision?

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