2014-04-09 10:32:44 +00:00
|
|
|
"""
|
|
|
|
mbed SDK
|
|
|
|
Copyright (c) 2011-2013 ARM Limited
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
|
|
|
|
2019-11-27 11:08:50 +00:00
|
|
|
class DevNullTest(object):
|
2014-10-21 12:18:22 +00:00
|
|
|
|
2015-01-27 12:51:53 +00:00
|
|
|
def check_readline(self, selftest, text):
|
2014-09-15 10:08:05 +00:00
|
|
|
""" Reads line from serial port and checks if text was part of read string
|
|
|
|
"""
|
|
|
|
result = False
|
2015-01-27 12:51:53 +00:00
|
|
|
c = selftest.mbed.serial_readline()
|
2014-10-21 12:12:32 +00:00
|
|
|
if c and text in c:
|
2014-09-15 10:08:05 +00:00
|
|
|
result = True
|
|
|
|
return result
|
|
|
|
|
2015-01-27 12:51:53 +00:00
|
|
|
def test(self, selftest):
|
2014-09-11 12:38:58 +00:00
|
|
|
result = True
|
2014-09-15 10:08:05 +00:00
|
|
|
# Test should print some text and later stop printing
|
2014-10-21 12:12:32 +00:00
|
|
|
# 'MBED: re-routing stdout to /null'
|
2015-01-27 12:51:53 +00:00
|
|
|
res = self.check_readline(selftest, "re-routing stdout to /null")
|
2014-09-15 10:08:05 +00:00
|
|
|
if not res:
|
|
|
|
# We haven't read preamble line
|
|
|
|
result = False
|
|
|
|
else:
|
|
|
|
# Check if there are printed characters
|
|
|
|
str = ''
|
|
|
|
for i in range(3):
|
2015-01-27 12:51:53 +00:00
|
|
|
c = selftest.mbed.serial_read(32)
|
2014-09-15 10:08:05 +00:00
|
|
|
if c is None:
|
2015-01-27 12:51:53 +00:00
|
|
|
return selftest.RESULT_IO_SERIAL
|
2014-09-15 10:08:05 +00:00
|
|
|
else:
|
|
|
|
str += c
|
|
|
|
if len(str) > 0:
|
|
|
|
result = False
|
|
|
|
break
|
2015-01-27 12:51:53 +00:00
|
|
|
selftest.notify("Received %d bytes: %s"% (len(str), str))
|
|
|
|
return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE
|