2019-01-03 17:50:05 +00:00
|
|
|
"""
|
2019-01-04 09:24:15 +00:00
|
|
|
Copyright (c) 2017, Arm Limited and affiliates.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2019-01-03 17:50:05 +00:00
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# ice-tea cli commands decorator class
|
|
|
|
|
|
|
|
|
|
|
|
from nfc_messages import NfcErrors
|
|
|
|
import logging
|
|
|
|
import icetea_lib.tools.asserts as asserts
|
|
|
|
|
2019-02-04 18:00:30 +00:00
|
|
|
# Values > 1 k incur large time costs
|
|
|
|
LARGE_BUFFLEN = 400 # Value for large buffer tests, a maximum value can be read from the target with a command
|
2019-01-09 16:20:06 +00:00
|
|
|
|
2019-01-03 17:50:05 +00:00
|
|
|
class CliHelper():
|
|
|
|
"""
|
2019-01-09 16:20:06 +00:00
|
|
|
Helper methods, checks the nfc SDK error-code for you, makes writing a negative test much easier
|
2019-01-03 17:50:05 +00:00
|
|
|
Example:
|
|
|
|
if (target_is_eeprom):
|
|
|
|
nfc_command("dev1", "start", expected_retcode=-2, expected_nfc_error= NfcErrors.nfc_err_unsupported)
|
|
|
|
else:
|
|
|
|
nfc_command("dev1", "start")
|
|
|
|
"""
|
|
|
|
|
|
|
|
def nfc_command(self, k, cmd, # pylint: disable=invalid-name
|
|
|
|
wait=True,
|
|
|
|
timeout=10,
|
|
|
|
expected_retcode=0,
|
|
|
|
asynchronous=False,
|
|
|
|
report_cmd_fail=True,
|
|
|
|
expected_nfc_error=NfcErrors.nfc_ok):
|
2019-01-09 16:20:06 +00:00
|
|
|
"""
|
|
|
|
By default will assert if the NFC result code is non-zero.
|
|
|
|
"""
|
2019-01-03 17:50:05 +00:00
|
|
|
response = self.command(k, cmd, wait, timeout, expected_retcode, asynchronous, report_cmd_fail)
|
|
|
|
asserts.assertEqual(int(response.parsed['lastnfcerror']), expected_nfc_error.value)
|
|
|
|
return response
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def command_is(string, command):
|
|
|
|
return string.split(' ')[0] == command
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def debug_nfc_data(key, value):
|
|
|
|
"""
|
2019-01-09 16:20:06 +00:00
|
|
|
print useful data values for the host/user with a >> preamble to make it easy to spot
|
2019-01-03 17:50:05 +00:00
|
|
|
"""
|
2019-01-09 16:20:06 +00:00
|
|
|
text = ">> %s=%s" % (key, value)
|
2019-01-03 17:50:05 +00:00
|
|
|
logging.Logger.info(text)
|
|
|
|
|
2019-01-15 17:33:35 +00:00
|
|
|
def assert_binary_equal(self, left, right):
|
|
|
|
asserts.assertEqual(len(left), len(right), "Buffers are not same length %d %d" % (len(left), len(right)))
|
2019-01-03 17:50:05 +00:00
|
|
|
i = 0
|
2019-01-15 17:33:35 +00:00
|
|
|
while i < len(left):
|
2019-01-03 17:50:05 +00:00
|
|
|
asserts.assertEqual(left[i], ord(right[i]), ("Missmatch @offset %d 0x%x <> 0x%x" % (i, left[i], ord(right[i]))) )
|
|
|
|
i = i + 1
|
|
|
|
|
2019-01-15 17:33:35 +00:00
|
|
|
def assert_text_equal(self, left, right):
|
2019-01-03 17:50:05 +00:00
|
|
|
"""
|
|
|
|
Asserts if the 2 buffers (Text) differ
|
|
|
|
"""
|
2019-01-15 17:33:35 +00:00
|
|
|
asserts.assertEqual(len(left), len(right), "Buffers are not same length %d %d" % (len(left), len(right)))
|
2019-01-03 17:50:05 +00:00
|
|
|
i = 0
|
2019-01-15 17:33:35 +00:00
|
|
|
while i < len(left):
|
2019-01-03 17:50:05 +00:00
|
|
|
asserts.assertEqual(ord(left[i]), ord(right[i]), ("Missmatch @offset %d %d <> %d" % (i, ord(left[i]), ord(right[i]))) )
|
|
|
|
i = i + 1
|
|
|
|
|