[quagga-dev 16658] Re: [PATCH] tests: Fix test-checksum to move the mod operation up

Athira Rajeev atrajeev at linux.vnet.ibm.com
Thu Aug 31 10:47:01 BST 2017


Hi All,
Please help me with review

Thanks
Athira Rajeev

> On 24-Aug-2017, at 12:45 PM, Athira Rajeev <atrajeev at linux.vnet.ibm.com> wrote:
> 
> From: Athira Rajeev <atrajeev at linux.vnet.ibm.com <mailto:atrajeev at linux.vnet.ibm.com>>
> 
> testchecksum fails with "verify: isisd failed" for few iterations.
> Checking the test code, it calls iso_csum_create followed by verify function
> where it fails in some cases.
> 
> Code snippet:
> 
> isisd = iso_csum_create (buffer, exercise + sizeof(u_int16_t), exercise);
> if (verify (buffer, exercise + sizeof(u_int16_t)))
>  printf ("verify: isisd failed\n");
> 
> In iso_csum_create , code uses modulo ( % ) operation.
> Code snippet:
>  ========
>  mul = (init_len - off) * c0;
> 
>  x = mul - c1 - c0;
>  y = c1 - mul - 1;
> 
>  if (y > 0)
>    y++;
>  if (x < 0)
>    x--;
> 
>  x %= 255;
>  y %= 255;
> 
>  if (x == 0)
>    x = 255;
>  if (y == 0)
>    y = 1;
>  ========
> 
> Moved the modulus operation up the if condition in testcase and
> isisd verify goes fine without reporting fail.
> Referring this mail thread https://lists.gt.net/quagga/dev/17347 <https://lists.gt.net/quagga/dev/17347>
> and https://github.com/Quagga/quagga/commit/5d4b8cf2faba9f5386810a7c70837e5b7fae3572#diff-5fb4cfc11e8bb396af1ce29581abfb89 <https://github.com/Quagga/quagga/commit/5d4b8cf2faba9f5386810a7c70837e5b7fae3572#diff-5fb4cfc11e8bb396af1ce29581abfb89> ,
> mod operation was moved up for "reduce_isisd_mod" in past commits.
> 
> Also observed that without moving mod up and introducing sleep after mod operation also solves the issue :
> 
> --- test-checksum.c.org <http://test-checksum.c.org/>	2017-08-23 12:19:43.688263168 +0000
> +++ test-checksum.c	2017-08-23 12:22:43.400260726 +0000
> @@ -360,6 +360,8 @@ iso_csum_create (u_char * buffer, testsz
>   x %= 255;
>   y %= 255;
> 
> +  sleep(1);
> +
>   if (x == 0)
>     x = 255;
>   if (y == 0)
> 
> Reason behind this appears that modulus operator is slow.
> Reference links:
> https://stackoverflow.com/questions/27977834/why-is-modulus-operator-slow <https://stackoverflow.com/questions/27977834/why-is-modulus-operator-slow>
> 
> But Since "Moving the mod up" was followed as solution in past commits, adding that patch here.
> 
> Signed-off-by: Athira Rajeev <atrajeev at linux.vnet.ibm.com <mailto:atrajeev at linux.vnet.ibm.com>>
> ---
> tests/test-checksum.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/test-checksum.c b/tests/test-checksum.c
> index b6741f30..99d255ef 100644
> --- a/tests/test-checksum.c
> +++ b/tests/test-checksum.c
> @@ -352,14 +352,14 @@ iso_csum_create (u_char * buffer, testsz_t len, testoff_t off)
>   x = mul - c1 - c0;
>   y = c1 - mul - 1;
> 
> +  x %= 255;
> +  y %= 255;
> +
>   if (y > 0)
>     y++;
>   if (x < 0)
>     x--;
> 
> -  x %= 255;
> -  y %= 255;
> -
>   if (x == 0)
>     x = 255;
>   if (y == 0)
> -- 
> 2.11.0 (Apple Git-81)
> _______________________________________________
> Quagga-dev mailing list
> Quagga-dev at lists.quagga.net
> https://lists.quagga.net/mailman/listinfo/quagga-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.quagga.net/pipermail/quagga-dev/attachments/20170831/bb862a8b/attachment.html>


More information about the Quagga-dev mailing list