A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

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