mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-02 07:20:26 +00:00
Replace asserts with exceptions in mbedtls_test.py
This commit is contained in:
parent
040b6a2281
commit
b98e6eec58
@ -34,6 +34,11 @@ import binascii
|
|||||||
from mbed_host_tests import BaseHostTest, event_callback
|
from mbed_host_tests import BaseHostTest, event_callback
|
||||||
|
|
||||||
|
|
||||||
|
class TestDataParserError(Exception):
|
||||||
|
"""Indicates error in test data, read from .data file."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestDataParser(object):
|
class TestDataParser(object):
|
||||||
"""
|
"""
|
||||||
parser for mbedtls test data files.
|
parser for mbedtls test data files.
|
||||||
@ -107,7 +112,9 @@ class TestDataParser(object):
|
|||||||
function = int(parts[0])
|
function = int(parts[0])
|
||||||
x = parts[1:]
|
x = parts[1:]
|
||||||
l = len(x)
|
l = len(x)
|
||||||
assert l % 2 == 0, "Number of test arguments should be even: %s" % line
|
if l % 2 != 0:
|
||||||
|
raise TestDataParserError("Number of test arguments should "
|
||||||
|
"be even: %s" % line)
|
||||||
args = [(x[i * 2], x[(i * 2) + 1]) for i in range(len(x)/2)]
|
args = [(x[i * 2], x[(i * 2) + 1]) for i in range(len(x)/2)]
|
||||||
self.tests.append((name, function, deps, args))
|
self.tests.append((name, function, deps, args))
|
||||||
|
|
||||||
@ -194,10 +201,13 @@ class MbedTlsTest(BaseHostTest):
|
|||||||
:param hex_str: Hex in string format.
|
:param hex_str: Hex in string format.
|
||||||
:return: Output Byte array
|
:return: Output Byte array
|
||||||
"""
|
"""
|
||||||
assert hex_str[0] == '"' and hex_str[len(hex_str) - 1] == '"', \
|
if hex_str[0] != '"' or hex_str[len(hex_str) - 1] != '"':
|
||||||
"HEX test parameter missing '\"': %s" % hex_str
|
raise TestDataParserError("HEX test parameter missing '\"':"
|
||||||
|
" %s" % hex_str)
|
||||||
hex_str = hex_str.strip('"')
|
hex_str = hex_str.strip('"')
|
||||||
assert len(hex_str) % 2 == 0, "HEX parameter len should be mod of 2: %s" % hex_str
|
if len(hex_str) % 2 != 0:
|
||||||
|
raise TestDataParserError("HEX parameter len should be mod of "
|
||||||
|
"2: %s" % hex_str)
|
||||||
|
|
||||||
b = binascii.unhexlify(hex_str)
|
b = binascii.unhexlify(hex_str)
|
||||||
return b
|
return b
|
||||||
|
Loading…
x
Reference in New Issue
Block a user