tests: benchmark: fix for too fast archs

benchmark/app_kernel test was giving a float exception
if the operations were performed faster than the
system timer resolution.
Added a safety macro in all divisions to avoid the fault

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
This commit is contained in:
Alberto Escolar Piedras 2017-11-24 11:44:59 +01:00 committed by Anas Nashif
parent 3fe00d91d8
commit 15f9c94ee7
3 changed files with 20 additions and 16 deletions

View File

@ -19,7 +19,7 @@ static struct k_mbox_msg message;
" |\n", output_file))
#define PRINT_ONE_RESULT() \
PRINT_F(output_file, "|%11u|%32.3f|%32f|\n", putsize, puttime / 1000.0,\
(1000.0 * putsize) / puttime)
(1000.0 * putsize) / SAFE_DIVISOR(puttime))
#define PRINT_OVERHEAD() \
PRINT_F(output_file, \
@ -29,7 +29,7 @@ static struct k_mbox_msg message;
#define PRINT_XFER_RATE() \
double netto_transfer_rate; \
netto_transfer_rate = 1000.0 * \
(putsize >> 1) / (puttime - empty_msg_put_time); \
(putsize >> 1) / SAFE_DIVISOR(puttime - empty_msg_put_time); \
PRINT_F(output_file, \
"| raw transfer rate: %10.3f MB/sec (without" \
" overhead) |\n", netto_transfer_rate)
@ -42,7 +42,7 @@ static struct k_mbox_msg message;
#define PRINT_ONE_RESULT() \
PRINT_F(output_file, "|%11u|%32u|%32u|\n", putsize, puttime, \
(u32_t)((1000000 * (u64_t)putsize) / puttime))
(u32_t)((1000000 * (u64_t)putsize) / SAFE_DIVISOR(puttime)))
#define PRINT_OVERHEAD() \
PRINT_F(output_file, \
@ -53,7 +53,7 @@ static struct k_mbox_msg message;
PRINT_F(output_file, "| raw transfer rate: %10u KB/sec (without" \
" overhead) |\n", \
(u32_t)(1000000 * (u64_t)(putsize >> 1) \
/ (puttime - empty_msg_put_time)))
/ SAFE_DIVISOR(puttime - empty_msg_put_time)))
#endif

View File

@ -62,6 +62,10 @@ extern char sline[];
"|--------------------------------------" \
"---------------------------------------|\n"
/*
* To avoid divisions by 0 faults, wrap the divisor with this macro
*/
#define SAFE_DIVISOR(a) (((a) != 0)?(a):1)
/* pipe amount of content to receive (0+, 1+, all) */

View File

@ -20,9 +20,9 @@
"|%5u|%5u|%10.3f|%10.3f|%10.3f|%10.3f|%10.3f|%10.3f|\n", \
putsize, putsize, puttime[0] / 1000.0, puttime[1] / 1000.0, \
puttime[2] / 1000.0, \
(1000.0 * putsize) / puttime[0], \
(1000.0 * putsize) / puttime[1], \
(1000.0 * putsize) / puttime[2])
(1000.0 * putsize) / SAFE_DIVISOR(puttime[0]), \
(1000.0 * putsize) / SAFE_DIVISOR(puttime[1]), \
(1000.0 * putsize) / SAFE_DIVISOR(puttime[2]))
#define PRINT_1_TO_N_HEADER() \
do { \
@ -39,9 +39,9 @@
puttime[0] / 1000.0, \
puttime[1] / 1000.0, \
puttime[2] / 1000.0, \
(1000.0 * putsize) / puttime[0], \
(1000.0 * putsize) / puttime[1], \
(1000.0 * putsize) / puttime[2])
(1000.0 * putsize) / SAFE_DIVISOR(puttime[0]), \
(1000.0 * putsize) / SAFE_DIVISOR(puttime[1]), \
(1000.0 * putsize) / SAFE_DIVISOR(puttime[2]))
#else
#define PRINT_ALL_TO_N_HEADER_UNIT() \
@ -53,9 +53,9 @@
"|%5u|%5u|%10u|%10u|%10u|%10u|%10u|%10u|\n", \
putsize, putsize, puttime[0], puttime[1], \
puttime[2], \
(1000000 * putsize) / puttime[0], \
(1000000 * putsize) / puttime[1], \
(1000000 * putsize) / puttime[2])
(1000000 * putsize) / SAFE_DIVISOR(puttime[0]), \
(1000000 * putsize) / SAFE_DIVISOR(puttime[1]), \
(1000000 * putsize) / SAFE_DIVISOR(puttime[2]))
#define PRINT_1_TO_N_HEADER() \
do { \
@ -72,9 +72,9 @@
puttime[0], \
puttime[1], \
puttime[2], \
(u32_t)((1000000 * (u64_t)putsize) / puttime[0]), \
(u32_t)((1000000 * (u64_t)putsize) / puttime[1]), \
(u32_t)((1000000 * (u64_t)putsize) / puttime[2]))
(u32_t)((1000000 * (u64_t)putsize) / SAFE_DIVISOR(puttime[0])), \
(u32_t)((1000000 * (u64_t)putsize) / SAFE_DIVISOR(puttime[1])), \
(u32_t)((1000000 * (u64_t)putsize) / SAFE_DIVISOR(puttime[2])))
#endif /* FLOAT */
/*