Timing: support ALT implementations in self-test

Don't assume that the context has a timer field if MBEDTLS_TIMING_ALT
is defined.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-05-25 09:19:45 +02:00
parent cc73cc55e8
commit d41d59e900

View file

@ -387,6 +387,21 @@ static void busy_msleep( unsigned long msec )
(void) j; (void) j;
} }
static void print_timers( struct mbedtls_timing_hr_time *hires,
mbedtls_timing_delay_context *ctx )
{
#if defined(MBEDTLS_TIMING_ALT)
mbedtls_printf( " elapsed(hires)=%lu elapsed(ctx)=?? status(ctx)=%d\n",
mbedtls_timing_get_timer( hires, 0 ),
mbedtls_timing_get_delay( ctx ) );
#else
mbedtls_printf( " elapsed(hires)=%lu elapsed(ctx)=%lu status(ctx)=%d\n",
mbedtls_timing_get_timer( hires, 0 ),
mbedtls_timing_get_timer( &ctx->timer, 0 ),
mbedtls_timing_get_delay( ctx ) );
#endif
}
#define FAIL do \ #define FAIL do \
{ \ { \
if( verbose != 0 ) \ if( verbose != 0 ) \
@ -395,10 +410,7 @@ static void busy_msleep( unsigned long msec )
mbedtls_printf( " cycles=%lu ratio=%lu millisecs=%lu secs=%lu hardfail=%d a=%lu b=%lu\n", \ mbedtls_printf( " cycles=%lu ratio=%lu millisecs=%lu secs=%lu hardfail=%d a=%lu b=%lu\n", \
cycles, ratio, millisecs, secs, hardfail, \ cycles, ratio, millisecs, secs, hardfail, \
(unsigned long) a, (unsigned long) b ); \ (unsigned long) a, (unsigned long) b ); \
mbedtls_printf( " elapsed(hires)=%lu elapsed(ctx)=%lu status(ctx)=%d\n", \ print_timers( &hires, &ctx ); \
mbedtls_timing_get_timer( &hires, 0 ), \
mbedtls_timing_get_timer( &ctx.timer, 0 ), \
mbedtls_timing_get_delay( &ctx ) ); \
} \ } \
return( 1 ); \ return( 1 ); \
} while( 0 ) } while( 0 )