mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 14:25:36 +01:00
Merge remote-tracking branch 'origin/pr/2744' into mbedtls-2.16
* origin/pr/2744: Fix parsing issue when int parameter is in base 16 Refactor receive_uint32() Refactor get_byte function Make the script portable to both pythons Update the test encoding to support python3 update the test script
This commit is contained in:
commit
86f9418399
@ -79,7 +79,7 @@ class TestDataParser(object):
|
|||||||
split_colon_fn = lambda x: re.sub(r'\\' + split_char, split_char, x)
|
split_colon_fn = lambda x: re.sub(r'\\' + split_char, split_char, x)
|
||||||
if len(split_char) > 1:
|
if len(split_char) > 1:
|
||||||
raise ValueError('Expected split character. Found string!')
|
raise ValueError('Expected split character. Found string!')
|
||||||
out = map(split_colon_fn, re.split(r'(?<!\\)' + split_char, inp_str))
|
out = list(map(split_colon_fn, re.split(r'(?<!\\)' + split_char, inp_str)))
|
||||||
out = [x for x in out if x]
|
out = [x for x in out if x]
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@ -99,11 +99,11 @@ class TestDataParser(object):
|
|||||||
|
|
||||||
# Check dependencies
|
# Check dependencies
|
||||||
dependencies = []
|
dependencies = []
|
||||||
line = data_f.next().strip()
|
line = next(data_f).strip()
|
||||||
match = re.search('depends_on:(.*)', line)
|
match = re.search('depends_on:(.*)', line)
|
||||||
if match:
|
if match:
|
||||||
dependencies = [int(x) for x in match.group(1).split(':')]
|
dependencies = [int(x) for x in match.group(1).split(':')]
|
||||||
line = data_f.next().strip()
|
line = next(data_f).strip()
|
||||||
|
|
||||||
# Read test vectors
|
# Read test vectors
|
||||||
line = line.replace('\\n', '\n')
|
line = line.replace('\\n', '\n')
|
||||||
@ -115,7 +115,7 @@ class TestDataParser(object):
|
|||||||
err_str_fmt = "Number of test arguments({}) should be even: {}"
|
err_str_fmt = "Number of test arguments({}) should be even: {}"
|
||||||
raise TestDataParserError(err_str_fmt.format(args_count, line))
|
raise TestDataParserError(err_str_fmt.format(args_count, line))
|
||||||
grouped_args = [(args[i * 2], args[(i * 2) + 1])
|
grouped_args = [(args[i * 2], args[(i * 2) + 1])
|
||||||
for i in range(len(args)/2)]
|
for i in range(int(len(args)/2))]
|
||||||
self.tests.append((name, function_name, dependencies,
|
self.tests.append((name, function_name, dependencies,
|
||||||
grouped_args))
|
grouped_args))
|
||||||
|
|
||||||
@ -261,21 +261,21 @@ class MbedTlsTest(BaseHostTest):
|
|||||||
data_bytes += bytearray([function_id, len(parameters)])
|
data_bytes += bytearray([function_id, len(parameters)])
|
||||||
for typ, param in parameters:
|
for typ, param in parameters:
|
||||||
if typ == 'int' or typ == 'exp':
|
if typ == 'int' or typ == 'exp':
|
||||||
i = int(param)
|
i = int(param, 0)
|
||||||
data_bytes += 'I' if typ == 'int' else 'E'
|
data_bytes += b'I' if typ == 'int' else b'E'
|
||||||
self.align_32bit(data_bytes)
|
self.align_32bit(data_bytes)
|
||||||
data_bytes += self.int32_to_big_endian_bytes(i)
|
data_bytes += self.int32_to_big_endian_bytes(i)
|
||||||
elif typ == 'char*':
|
elif typ == 'char*':
|
||||||
param = param.strip('"')
|
param = param.strip('"')
|
||||||
i = len(param) + 1 # + 1 for null termination
|
i = len(param) + 1 # + 1 for null termination
|
||||||
data_bytes += 'S'
|
data_bytes += b'S'
|
||||||
self.align_32bit(data_bytes)
|
self.align_32bit(data_bytes)
|
||||||
data_bytes += self.int32_to_big_endian_bytes(i)
|
data_bytes += self.int32_to_big_endian_bytes(i)
|
||||||
data_bytes += bytearray(list(param))
|
data_bytes += bytearray(param, encoding='ascii')
|
||||||
data_bytes += '\0' # Null terminate
|
data_bytes += b'\0' # Null terminate
|
||||||
elif typ == 'hex':
|
elif typ == 'hex':
|
||||||
binary_data = self.hex_str_bytes(param)
|
binary_data = self.hex_str_bytes(param)
|
||||||
data_bytes += 'H'
|
data_bytes += b'H'
|
||||||
self.align_32bit(data_bytes)
|
self.align_32bit(data_bytes)
|
||||||
i = len(binary_data)
|
i = len(binary_data)
|
||||||
data_bytes += self.int32_to_big_endian_bytes(i)
|
data_bytes += self.int32_to_big_endian_bytes(i)
|
||||||
@ -310,7 +310,7 @@ class MbedTlsTest(BaseHostTest):
|
|||||||
|
|
||||||
param_bytes, length = self.test_vector_to_bytes(function_id,
|
param_bytes, length = self.test_vector_to_bytes(function_id,
|
||||||
dependencies, args)
|
dependencies, args)
|
||||||
self.send_kv(length, param_bytes)
|
self.send_kv(''.join('{:02x}'.format(x) for x in length), ''.join('{:02x}'.format(x) for x in param_bytes))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_result(value):
|
def get_result(value):
|
||||||
|
@ -59,10 +59,29 @@ int verify_dependencies( uint8_t count, uint8_t * dep_p )
|
|||||||
return( DEPENDENCY_SUPPORTED );
|
return( DEPENDENCY_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Receives hex string on serial interface, and converts to a byte.
|
||||||
|
*
|
||||||
|
* \param none
|
||||||
|
*
|
||||||
|
* \return unsigned int8
|
||||||
|
*/
|
||||||
|
uint8_t receive_byte()
|
||||||
|
{
|
||||||
|
uint8_t byte;
|
||||||
|
uint8_t c[3];
|
||||||
|
char *endptr;
|
||||||
|
c[0] = greentea_getc();
|
||||||
|
c[1] = greentea_getc();
|
||||||
|
c[2] = '\0';
|
||||||
|
|
||||||
|
assert( unhexify( &byte, c ) != 2 );
|
||||||
|
return( byte );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Receives unsigned integer on serial interface.
|
* \brief Receives unsigned integer on serial interface.
|
||||||
* Integers are encoded in network order.
|
* Integers are encoded in network order, and sent as hex ascii string.
|
||||||
*
|
*
|
||||||
* \param none
|
* \param none
|
||||||
*
|
*
|
||||||
@ -71,10 +90,17 @@ int verify_dependencies( uint8_t count, uint8_t * dep_p )
|
|||||||
uint32_t receive_uint32()
|
uint32_t receive_uint32()
|
||||||
{
|
{
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
value = (uint8_t)greentea_getc() << 24;
|
const uint8_t c[9] = { greentea_getc(),
|
||||||
value |= (uint8_t)greentea_getc() << 16;
|
greentea_getc(),
|
||||||
value |= (uint8_t)greentea_getc() << 8;
|
greentea_getc(),
|
||||||
value |= (uint8_t)greentea_getc();
|
greentea_getc(),
|
||||||
|
greentea_getc(),
|
||||||
|
greentea_getc(),
|
||||||
|
greentea_getc(),
|
||||||
|
greentea_getc(),
|
||||||
|
'\0'
|
||||||
|
};
|
||||||
|
assert( unhexify( &value, c ) != 8 );
|
||||||
return( (uint32_t)value );
|
return( (uint32_t)value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +158,7 @@ uint8_t * receive_data( uint32_t * data_len )
|
|||||||
greentea_getc(); // read ';' received after key i.e. *data_len
|
greentea_getc(); // read ';' received after key i.e. *data_len
|
||||||
|
|
||||||
for( i = 0; i < *data_len; i++ )
|
for( i = 0; i < *data_len; i++ )
|
||||||
data[i] = greentea_getc();
|
data[i] = receive_byte();
|
||||||
|
|
||||||
/* Read closing braces */
|
/* Read closing braces */
|
||||||
for( i = 0; i < 2; i++ )
|
for( i = 0; i < 2; i++ )
|
||||||
|
Loading…
Reference in New Issue
Block a user