app/test-fib: fix possible division by zero

Message ID 20211223152519.758827-1-vladimir.medvedkin@intel.com (mailing list archive)
State Superseded, archived
Headers
Series app/test-fib: fix possible division by zero |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

Vladimir Medvedkin Dec. 23, 2021, 3:25 p.m. UTC
  This patch fixes the division by 0, which occurs if the number of routes is less than 10.
Can be triggered by passing -n argument with value < 10:

./dpdk-test-fib -- -n 9
...
Floating point exception (core dumped)

Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
Cc: vladimir.medvedkin@intel.com

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 app/test-fib/main.c | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)
  

Comments

Kevin Traynor Jan. 11, 2022, 4:15 p.m. UTC | #1
On 23/12/2021 15:25, Vladimir Medvedkin wrote:
> This patch fixes the division by 0, which occurs if the number of routes is less than 10.
> Can be triggered by passing -n argument with value < 10:
> 

9 causing a divide by zero - another example of inflation :-)

> ./dpdk-test-fib -- -n 9
> ...
> Floating point exception (core dumped)
> 
> Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
> Cc: vladimir.medvedkin@intel.com
> 

You probably want to add 'Cc: stable@dpdk.org' for this.

> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> ---
>   app/test-fib/main.c | 40 ++++++++++++++++++++++++----------------
>   1 file changed, 24 insertions(+), 16 deletions(-)
> 
> diff --git a/app/test-fib/main.c b/app/test-fib/main.c
> index ecd420116a..9bc8b8a7ca 100644
> --- a/app/test-fib/main.c
> +++ b/app/test-fib/main.c
> @@ -902,8 +902,9 @@ run_v4(void)
>   				return -ret;
>   			}
>   		}
> -		printf("AVG FIB add %"PRIu64"\n",
> -			(rte_rdtsc_precise() - start) / j);
> +		if (j != 0)
> +			printf("AVG FIB add %"PRIu64"\n",
> +				(rte_rdtsc_precise() - start) / j);


You are just not printing the result for these cases. Do you think it is 
worth to print a warning message (one), and update any documentation so 
the user is aware of the acceptable bounds?

>   		i += j;
>   	}
>   
> @@ -930,8 +931,9 @@ run_v4(void)
>   					return -ret;
>   				}
>   			}
> -			printf("AVG LPM add %"PRIu64"\n",
> -				(rte_rdtsc_precise() - start) / j);
> +			if (j != 0)
> +				printf("AVG LPM add %"PRIu64"\n",
> +					(rte_rdtsc_precise() - start) / j);
>   			i += j;
>   		}
>   	}
> @@ -984,8 +986,9 @@ run_v4(void)
>   		for (j = 0; j < (config.nb_routes - i) / k; j++)
>   			rte_fib_delete(fib, rt[i + j].addr, rt[i + j].depth);
>   
> -		printf("AVG FIB delete %"PRIu64"\n",
> -			(rte_rdtsc_precise() - start) / j);
> +		if (j != 0)
> +			printf("AVG FIB delete %"PRIu64"\n",
> +				(rte_rdtsc_precise() - start) / j);
>   		i += j;
>   	}
>   
> @@ -996,8 +999,9 @@ run_v4(void)
>   				rte_lpm_delete(lpm, rt[i + j].addr,
>   					rt[i + j].depth);
>   
> -			printf("AVG LPM delete %"PRIu64"\n",
> -				(rte_rdtsc_precise() - start) / j);
> +			if (j != 0)
> +				printf("AVG LPM delete %"PRIu64"\n",
> +					(rte_rdtsc_precise() - start) / j);
>   			i += j;
>   		}
>   	}
> @@ -1097,8 +1101,9 @@ run_v6(void)
>   				return -ret;
>   			}
>   		}
> -		printf("AVG FIB add %"PRIu64"\n",
> -			(rte_rdtsc_precise() - start) / j);
> +		if (j != 0)
> +			printf("AVG FIB add %"PRIu64"\n",
> +				(rte_rdtsc_precise() - start) / j);
>   		i += j;
>   	}
>   
> @@ -1125,8 +1130,9 @@ run_v6(void)
>   					return -ret;
>   				}
>   			}
> -			printf("AVG LPM add %"PRIu64"\n",
> -				(rte_rdtsc_precise() - start) / j);
> +			if (j != 0)
> +				printf("AVG LPM add %"PRIu64"\n",
> +					(rte_rdtsc_precise() - start) / j);
>   			i += j;
>   		}
>   	}
> @@ -1183,8 +1189,9 @@ run_v6(void)
>   		for (j = 0; j < (config.nb_routes - i) / k; j++)
>   			rte_fib6_delete(fib, rt[i + j].addr, rt[i + j].depth);
>   
> -		printf("AVG FIB delete %"PRIu64"\n",
> -			(rte_rdtsc_precise() - start) / j);
> +		if (j != 0)
> +			printf("AVG FIB delete %"PRIu64"\n",
> +				(rte_rdtsc_precise() - start) / j);
>   		i += j;
>   	}
>   
> @@ -1195,8 +1202,9 @@ run_v6(void)
>   				rte_lpm6_delete(lpm, rt[i + j].addr,
>   					rt[i + j].depth);
>   
> -			printf("AVG LPM delete %"PRIu64"\n",
> -				(rte_rdtsc_precise() - start) / j);
> +			if (j != 0)
> +				printf("AVG LPM delete %"PRIu64"\n",
> +					(rte_rdtsc_precise() - start) / j);
>   			i += j;
>   		}
>   	}
>
  
Vladimir Medvedkin Jan. 12, 2022, 3:49 p.m. UTC | #2
Hi Kevin,

On 11/01/2022 17:15, Kevin Traynor wrote:
> On 23/12/2021 15:25, Vladimir Medvedkin wrote:
>> This patch fixes the division by 0, which occurs if the number of 
>> routes is less than 10.
>> Can be triggered by passing -n argument with value < 10:
>>
> 
> 9 causing a divide by zero - another example of inflation :-)
> 

Too bad that we are not working in a wheel 
(https://en.wikipedia.org/wiki/Wheel_theory), where division by 0 is 
always defined :)

>> ./dpdk-test-fib -- -n 9
>> ...
>> Floating point exception (core dumped)
>>
>> Fixes: 103809d032cd ("app/test-fib: add test application for FIB")
>> Cc: vladimir.medvedkin@intel.com
>>
> 
> You probably want to add 'Cc: stable@dpdk.org' for this.
> 
>> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
>> ---
>>   app/test-fib/main.c | 40 ++++++++++++++++++++++++----------------
>>   1 file changed, 24 insertions(+), 16 deletions(-)
>>
>> diff --git a/app/test-fib/main.c b/app/test-fib/main.c
>> index ecd420116a..9bc8b8a7ca 100644
>> --- a/app/test-fib/main.c
>> +++ b/app/test-fib/main.c
>> @@ -902,8 +902,9 @@ run_v4(void)
>>                   return -ret;
>>               }
>>           }
>> -        printf("AVG FIB add %"PRIu64"\n",
>> -            (rte_rdtsc_precise() - start) / j);
>> +        if (j != 0)
>> +            printf("AVG FIB add %"PRIu64"\n",
>> +                (rte_rdtsc_precise() - start) / j);
> 
> 
> You are just not printing the result for these cases. Do you think it is 
> worth to print a warning message (one), and update any documentation so 
> the user is aware of the acceptable bounds?
> 

Agree, I'll send v2

>>           i += j;
>>       }
>> @@ -930,8 +931,9 @@ run_v4(void)
>>                       return -ret;
>>                   }
>>               }
>> -            printf("AVG LPM add %"PRIu64"\n",
>> -                (rte_rdtsc_precise() - start) / j);
>> +            if (j != 0)
>> +                printf("AVG LPM add %"PRIu64"\n",
>> +                    (rte_rdtsc_precise() - start) / j);
>>               i += j;
>>           }
>>       }
>> @@ -984,8 +986,9 @@ run_v4(void)
>>           for (j = 0; j < (config.nb_routes - i) / k; j++)
>>               rte_fib_delete(fib, rt[i + j].addr, rt[i + j].depth);
>> -        printf("AVG FIB delete %"PRIu64"\n",
>> -            (rte_rdtsc_precise() - start) / j);
>> +        if (j != 0)
>> +            printf("AVG FIB delete %"PRIu64"\n",
>> +                (rte_rdtsc_precise() - start) / j);
>>           i += j;
>>       }
>> @@ -996,8 +999,9 @@ run_v4(void)
>>                   rte_lpm_delete(lpm, rt[i + j].addr,
>>                       rt[i + j].depth);
>> -            printf("AVG LPM delete %"PRIu64"\n",
>> -                (rte_rdtsc_precise() - start) / j);
>> +            if (j != 0)
>> +                printf("AVG LPM delete %"PRIu64"\n",
>> +                    (rte_rdtsc_precise() - start) / j);
>>               i += j;
>>           }
>>       }
>> @@ -1097,8 +1101,9 @@ run_v6(void)
>>                   return -ret;
>>               }
>>           }
>> -        printf("AVG FIB add %"PRIu64"\n",
>> -            (rte_rdtsc_precise() - start) / j);
>> +        if (j != 0)
>> +            printf("AVG FIB add %"PRIu64"\n",
>> +                (rte_rdtsc_precise() - start) / j);
>>           i += j;
>>       }
>> @@ -1125,8 +1130,9 @@ run_v6(void)
>>                       return -ret;
>>                   }
>>               }
>> -            printf("AVG LPM add %"PRIu64"\n",
>> -                (rte_rdtsc_precise() - start) / j);
>> +            if (j != 0)
>> +                printf("AVG LPM add %"PRIu64"\n",
>> +                    (rte_rdtsc_precise() - start) / j);
>>               i += j;
>>           }
>>       }
>> @@ -1183,8 +1189,9 @@ run_v6(void)
>>           for (j = 0; j < (config.nb_routes - i) / k; j++)
>>               rte_fib6_delete(fib, rt[i + j].addr, rt[i + j].depth);
>> -        printf("AVG FIB delete %"PRIu64"\n",
>> -            (rte_rdtsc_precise() - start) / j);
>> +        if (j != 0)
>> +            printf("AVG FIB delete %"PRIu64"\n",
>> +                (rte_rdtsc_precise() - start) / j);
>>           i += j;
>>       }
>> @@ -1195,8 +1202,9 @@ run_v6(void)
>>                   rte_lpm6_delete(lpm, rt[i + j].addr,
>>                       rt[i + j].depth);
>> -            printf("AVG LPM delete %"PRIu64"\n",
>> -                (rte_rdtsc_precise() - start) / j);
>> +            if (j != 0)
>> +                printf("AVG LPM delete %"PRIu64"\n",
>> +                    (rte_rdtsc_precise() - start) / j);
>>               i += j;
>>           }
>>       }
>>
>
  

Patch

diff --git a/app/test-fib/main.c b/app/test-fib/main.c
index ecd420116a..9bc8b8a7ca 100644
--- a/app/test-fib/main.c
+++ b/app/test-fib/main.c
@@ -902,8 +902,9 @@  run_v4(void)
 				return -ret;
 			}
 		}
-		printf("AVG FIB add %"PRIu64"\n",
-			(rte_rdtsc_precise() - start) / j);
+		if (j != 0)
+			printf("AVG FIB add %"PRIu64"\n",
+				(rte_rdtsc_precise() - start) / j);
 		i += j;
 	}
 
@@ -930,8 +931,9 @@  run_v4(void)
 					return -ret;
 				}
 			}
-			printf("AVG LPM add %"PRIu64"\n",
-				(rte_rdtsc_precise() - start) / j);
+			if (j != 0)
+				printf("AVG LPM add %"PRIu64"\n",
+					(rte_rdtsc_precise() - start) / j);
 			i += j;
 		}
 	}
@@ -984,8 +986,9 @@  run_v4(void)
 		for (j = 0; j < (config.nb_routes - i) / k; j++)
 			rte_fib_delete(fib, rt[i + j].addr, rt[i + j].depth);
 
-		printf("AVG FIB delete %"PRIu64"\n",
-			(rte_rdtsc_precise() - start) / j);
+		if (j != 0)
+			printf("AVG FIB delete %"PRIu64"\n",
+				(rte_rdtsc_precise() - start) / j);
 		i += j;
 	}
 
@@ -996,8 +999,9 @@  run_v4(void)
 				rte_lpm_delete(lpm, rt[i + j].addr,
 					rt[i + j].depth);
 
-			printf("AVG LPM delete %"PRIu64"\n",
-				(rte_rdtsc_precise() - start) / j);
+			if (j != 0)
+				printf("AVG LPM delete %"PRIu64"\n",
+					(rte_rdtsc_precise() - start) / j);
 			i += j;
 		}
 	}
@@ -1097,8 +1101,9 @@  run_v6(void)
 				return -ret;
 			}
 		}
-		printf("AVG FIB add %"PRIu64"\n",
-			(rte_rdtsc_precise() - start) / j);
+		if (j != 0)
+			printf("AVG FIB add %"PRIu64"\n",
+				(rte_rdtsc_precise() - start) / j);
 		i += j;
 	}
 
@@ -1125,8 +1130,9 @@  run_v6(void)
 					return -ret;
 				}
 			}
-			printf("AVG LPM add %"PRIu64"\n",
-				(rte_rdtsc_precise() - start) / j);
+			if (j != 0)
+				printf("AVG LPM add %"PRIu64"\n",
+					(rte_rdtsc_precise() - start) / j);
 			i += j;
 		}
 	}
@@ -1183,8 +1189,9 @@  run_v6(void)
 		for (j = 0; j < (config.nb_routes - i) / k; j++)
 			rte_fib6_delete(fib, rt[i + j].addr, rt[i + j].depth);
 
-		printf("AVG FIB delete %"PRIu64"\n",
-			(rte_rdtsc_precise() - start) / j);
+		if (j != 0)
+			printf("AVG FIB delete %"PRIu64"\n",
+				(rte_rdtsc_precise() - start) / j);
 		i += j;
 	}
 
@@ -1195,8 +1202,9 @@  run_v6(void)
 				rte_lpm6_delete(lpm, rt[i + j].addr,
 					rt[i + j].depth);
 
-			printf("AVG LPM delete %"PRIu64"\n",
-				(rte_rdtsc_precise() - start) / j);
+			if (j != 0)
+				printf("AVG LPM delete %"PRIu64"\n",
+					(rte_rdtsc_precise() - start) / j);
 			i += j;
 		}
 	}