diff --git a/tests/benchmarks/app_kernel/src/mailbox_b.c b/tests/benchmarks/app_kernel/src/mailbox_b.c index acbae27c53f..86c11fc7a28 100644 --- a/tests/benchmarks/app_kernel/src/mailbox_b.c +++ b/tests/benchmarks/app_kernel/src/mailbox_b.c @@ -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 diff --git a/tests/benchmarks/app_kernel/src/master.h b/tests/benchmarks/app_kernel/src/master.h index 5a694f75c2c..4c61b82b10c 100644 --- a/tests/benchmarks/app_kernel/src/master.h +++ b/tests/benchmarks/app_kernel/src/master.h @@ -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) */ diff --git a/tests/benchmarks/app_kernel/src/pipe_b.c b/tests/benchmarks/app_kernel/src/pipe_b.c index ff5f99e62a0..bf3c0d44241 100644 --- a/tests/benchmarks/app_kernel/src/pipe_b.c +++ b/tests/benchmarks/app_kernel/src/pipe_b.c @@ -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 */ /*