Clone of official tools

Committer:
screamer
Date:
Thu Jul 14 20:21:19 2016 +0100
Revision:
13:ab47a20b66f0
Parent:
0:66f3b5499f7f
Apply latest tools

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:66f3b5499f7f 1 """
screamer 0:66f3b5499f7f 2 mbed SDK
screamer 0:66f3b5499f7f 3 Copyright (c) 2011-2013 ARM Limited
screamer 0:66f3b5499f7f 4
screamer 0:66f3b5499f7f 5 Licensed under the Apache License, Version 2.0 (the "License");
screamer 0:66f3b5499f7f 6 you may not use this file except in compliance with the License.
screamer 0:66f3b5499f7f 7 You may obtain a copy of the License at
screamer 0:66f3b5499f7f 8
screamer 0:66f3b5499f7f 9 http://www.apache.org/licenses/LICENSE-2.0
screamer 0:66f3b5499f7f 10
screamer 0:66f3b5499f7f 11 Unless required by applicable law or agreed to in writing, software
screamer 0:66f3b5499f7f 12 distributed under the License is distributed on an "AS IS" BASIS,
screamer 0:66f3b5499f7f 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
screamer 0:66f3b5499f7f 14 See the License for the specific language governing permissions and
screamer 0:66f3b5499f7f 15 limitations under the License.
screamer 0:66f3b5499f7f 16 """
screamer 0:66f3b5499f7f 17
screamer 0:66f3b5499f7f 18 import sys
screamer 0:66f3b5499f7f 19 import uuid
screamer 0:66f3b5499f7f 20 import time
screamer 0:66f3b5499f7f 21 import string
screamer 0:66f3b5499f7f 22 from sys import stdout
screamer 0:66f3b5499f7f 23
screamer 0:66f3b5499f7f 24 class SerialNCRXTest():
screamer 0:66f3b5499f7f 25
screamer 0:66f3b5499f7f 26 def test(self, selftest):
screamer 0:66f3b5499f7f 27 selftest.mbed.flush();
screamer 13:ab47a20b66f0 28 # Wait 0.5 seconds to ensure mbed is listening
screamer 13:ab47a20b66f0 29 time.sleep(0.5)
screamer 13:ab47a20b66f0 30
screamer 13:ab47a20b66f0 31 #handshake with target to sync test start
screamer 13:ab47a20b66f0 32 selftest.mbed.serial_write("S");
screamer 13:ab47a20b66f0 33
screamer 13:ab47a20b66f0 34 strip_chars = string.whitespace + "\0"
screamer 13:ab47a20b66f0 35
screamer 13:ab47a20b66f0 36 out_str = selftest.mbed.serial_readline()
screamer 13:ab47a20b66f0 37
screamer 13:ab47a20b66f0 38 if not out_str:
screamer 13:ab47a20b66f0 39 selftest.notify("HOST: No output detected")
screamer 13:ab47a20b66f0 40 return selftest.RESULT_IO_SERIAL
screamer 13:ab47a20b66f0 41
screamer 13:ab47a20b66f0 42 out_str_stripped = out_str.strip(strip_chars)
screamer 13:ab47a20b66f0 43
screamer 13:ab47a20b66f0 44 if out_str_stripped != "RX OK - Start NC test":
screamer 13:ab47a20b66f0 45 selftest.notify("HOST: Unexpected output. Expected 'RX OK - Expected' but received '%s'" % out_str_stripped)
screamer 13:ab47a20b66f0 46 return selftest.RESULT_FAILURE
screamer 13:ab47a20b66f0 47
screamer 13:ab47a20b66f0 48 # Wait 0.5 seconds to ensure mbed is listening
screamer 13:ab47a20b66f0 49 time.sleep(0.5)
screamer 13:ab47a20b66f0 50
screamer 0:66f3b5499f7f 51 selftest.mbed.serial_write("E");
screamer 0:66f3b5499f7f 52
screamer 0:66f3b5499f7f 53 strip_chars = string.whitespace + "\0"
screamer 0:66f3b5499f7f 54
screamer 0:66f3b5499f7f 55 out_str = selftest.mbed.serial_readline()
screamer 0:66f3b5499f7f 56
screamer 0:66f3b5499f7f 57 if not out_str:
screamer 0:66f3b5499f7f 58 selftest.notify("HOST: No output detected")
screamer 0:66f3b5499f7f 59 return selftest.RESULT_IO_SERIAL
screamer 0:66f3b5499f7f 60
screamer 0:66f3b5499f7f 61 out_str_stripped = out_str.strip(strip_chars)
screamer 0:66f3b5499f7f 62
screamer 0:66f3b5499f7f 63 if out_str_stripped != "RX OK - Expected":
screamer 0:66f3b5499f7f 64 selftest.notify("HOST: Unexpected output. Expected 'RX OK - Expected' but received '%s'" % out_str_stripped)
screamer 0:66f3b5499f7f 65 return selftest.RESULT_FAILURE
screamer 0:66f3b5499f7f 66
screamer 0:66f3b5499f7f 67 # Wait 0.5 seconds to ensure mbed is listening
screamer 0:66f3b5499f7f 68 time.sleep(0.5)
screamer 0:66f3b5499f7f 69
screamer 0:66f3b5499f7f 70 # Send character, mbed shouldn't receive
screamer 0:66f3b5499f7f 71 selftest.mbed.serial_write("U");
screamer 0:66f3b5499f7f 72
screamer 0:66f3b5499f7f 73 out_str = selftest.mbed.serial_readline()
screamer 0:66f3b5499f7f 74
screamer 0:66f3b5499f7f 75 # If no characters received, pass the test
screamer 0:66f3b5499f7f 76 if not out_str:
screamer 0:66f3b5499f7f 77 selftest.notify("HOST: No further output detected")
screamer 0:66f3b5499f7f 78 return selftest.RESULT_SUCCESS
screamer 0:66f3b5499f7f 79 else:
screamer 0:66f3b5499f7f 80 out_str_stripped = out_str.strip(strip_chars)
screamer 0:66f3b5499f7f 81
screamer 0:66f3b5499f7f 82 if out_str_stripped == "RX OK - Unexpected":
screamer 0:66f3b5499f7f 83 selftest.notify("HOST: Unexpected output returned indicating RX still functioning")
screamer 0:66f3b5499f7f 84 else:
screamer 0:66f3b5499f7f 85 selftest.notify("HOST: Extraneous output '%s' detected indicating unknown error" % out_str_stripped)
screamer 0:66f3b5499f7f 86
screamer 0:66f3b5499f7f 87 return selftest.RESULT_FAILURE