test_psa_constant_names: fix uses of C integer types

Some of the types may in principle be wider than `unsigned`, so use
`unsigned long` in printf.

Add support for signed types: a status is a signed value, and
preferentially printed in decimal.
This commit is contained in:
Gilles Peskine 2019-02-13 18:42:53 +01:00
parent 3f775264d3
commit c4cd2adae8

View file

@ -211,6 +211,12 @@ def remove_file_if_exists(filename):
def run_c(options, type, names):
'''Generate and run a program to print out numerical values for names.'''
if type == 'status':
cast_to = 'long'
printf_format = '%ld'
else:
cast_to = 'unsigned long'
printf_format = '0x%08lx'
c_name = None
exe_name = None
try:
@ -230,7 +236,8 @@ int main(void)
{
''')
for name in names:
c_file.write(' printf("0x%08x\\n", {});\n'.format(name))
c_file.write(' printf("{}\\n", ({}) {});\n'
.format(printf_format, cast_to, name))
c_file.write(''' return 0;
}
''')