Support larger integer test arguments: C part
Change the type of signed integer arguments from int32_t to intmax_t. This allows the C code to work with test function arguments with a range larger than int32_t. A subsequent commit will change the .datax generator to support larger types. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
4ea4ad082b
commit
872948cc72
5 changed files with 12 additions and 14 deletions
|
@ -32,7 +32,7 @@
|
|||
|
||||
typedef union {
|
||||
size_t len;
|
||||
int32_t s32;
|
||||
intmax_t sint;
|
||||
} mbedtls_test_argument_t;
|
||||
|
||||
#endif /* TEST_ARGUMENTS_H */
|
||||
|
|
|
@ -473,7 +473,7 @@ def parse_function_argument(arg, arg_idx, args, local_vars, args_dispatch):
|
|||
typ, _ = m.groups()
|
||||
if typ in INTEGER_TYPES:
|
||||
args.append('int')
|
||||
args_dispatch.append('((mbedtls_test_argument_t*)params[%d])->s32' % arg_idx)
|
||||
args_dispatch.append('((mbedtls_test_argument_t*)params[%d])->sint' % arg_idx)
|
||||
return 1
|
||||
if typ in STRING_TYPES:
|
||||
args.append('char*')
|
||||
|
|
|
@ -487,8 +487,8 @@ class ParseFuncSignature(TestCase):
|
|||
self.assertEqual(local, '')
|
||||
self.assertEqual(arg_dispatch,
|
||||
['(char *) params[0]',
|
||||
'((mbedtls_test_argument_t*)params[1])->s32',
|
||||
'((mbedtls_test_argument_t*)params[2])->s32'])
|
||||
'((mbedtls_test_argument_t*)params[1])->sint',
|
||||
'((mbedtls_test_argument_t*)params[2])->sint'])
|
||||
|
||||
def test_hex_params(self):
|
||||
"""
|
||||
|
@ -503,7 +503,7 @@ class ParseFuncSignature(TestCase):
|
|||
'((mbedtls_test_argument_t*)params[2])->len};\n')
|
||||
self.assertEqual(arg_dispatch, ['(char *) params[0]',
|
||||
'&data1',
|
||||
'((mbedtls_test_argument_t*)params[3])->s32'])
|
||||
'((mbedtls_test_argument_t*)params[3])->sint'])
|
||||
|
||||
def test_unsupported_arg(self):
|
||||
"""
|
||||
|
|
|
@ -32,21 +32,19 @@ int verify_string(char **str)
|
|||
*
|
||||
* \return 0 if success else 1
|
||||
*/
|
||||
int verify_int(char *str, int32_t *p_value)
|
||||
int verify_int(char *str, intmax_t *p_value)
|
||||
{
|
||||
char *end = NULL;
|
||||
errno = 0;
|
||||
/* Limit the range to long: for large integers, the test framework will
|
||||
* use expressions anyway. */
|
||||
long value = strtol(str, &end, 0);
|
||||
if (errno == EINVAL || *end != '\0') {
|
||||
mbedtls_fprintf(stderr,
|
||||
"Expected integer for parameter and got: %s\n", str);
|
||||
return KEY_VALUE_MAPPING_NOT_FOUND;
|
||||
}
|
||||
if (errno == ERANGE
|
||||
#if LONG_MAX > 0x7fffffff
|
||||
|| value > 0x7fffffffL || value < -0x80000000L
|
||||
#endif
|
||||
) {
|
||||
if (errno == ERANGE) {
|
||||
mbedtls_fprintf(stderr, "Integer out of range: %s\n", str);
|
||||
return KEY_VALUE_MAPPING_NOT_FOUND;
|
||||
}
|
||||
|
@ -222,7 +220,7 @@ static int convert_params(size_t cnt, char **params,
|
|||
break;
|
||||
}
|
||||
} else if (strcmp(type, "int") == 0) {
|
||||
if (verify_int(val, &int_params_store->s32) == 0) {
|
||||
if (verify_int(val, &int_params_store->sint) == 0) {
|
||||
*out++ = (char *) int_params_store++;
|
||||
} else {
|
||||
ret = (DISPATCH_INVALID_TEST_DATA);
|
||||
|
@ -245,7 +243,7 @@ static int convert_params(size_t cnt, char **params,
|
|||
}
|
||||
} else if (strcmp(type, "exp") == 0) {
|
||||
int exp_id = strtol(val, NULL, 10);
|
||||
if (get_expression(exp_id, &int_params_store->s32) == 0) {
|
||||
if (get_expression(exp_id, &int_params_store->sint) == 0) {
|
||||
*out++ = (char *) int_params_store++;
|
||||
} else {
|
||||
ret = (DISPATCH_INVALID_TEST_DATA);
|
||||
|
|
|
@ -69,7 +69,7 @@ __MBEDTLS_TEST_TEMPLATE__FUNCTIONS_CODE
|
|||
*
|
||||
* \return 0 if exp_id is found. 1 otherwise.
|
||||
*/
|
||||
int get_expression(int32_t exp_id, int32_t *out_value)
|
||||
int get_expression(int32_t exp_id, intmax_t *out_value)
|
||||
{
|
||||
int ret = KEY_VALUE_MAPPING_FOUND;
|
||||
|
||||
|
|
Loading…
Reference in a new issue