[PATCH] test: reduce range of byte-padding macro tests.

Julien Cristau jcristau at debian.org
Mon Nov 22 09:09:33 PST 2010


On Fri, Nov 19, 2010 at 11:38:03 +1000, Peter Hutterer wrote:

> Byte padding and conversion is interesting for the rage of 0-8 bytes, and
> then interesting towards the end of the valid range (INT_MAX - 7 and INT_MAX
> - 3).
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> This significantly speeds up make check and I figured if the byte padding
> goes wrong somewhere at bit 18271, we have other problems…
> 
>  test/input.c |   71 ++++++++++++++++++++++++++++++++++++++++++++--------------
>  1 files changed, 54 insertions(+), 17 deletions(-)
> 
> diff --git a/test/input.c b/test/input.c
> index 13a441e..4ccfaff 100644
> --- a/test/input.c
> +++ b/test/input.c
> @@ -683,45 +683,82 @@ static void dix_grab_matching(void)
>      g_assert(rc == TRUE);
>  }
>  
> -static void include_byte_padding_macros(void)
> +static void test_bits_to_byte(int i)
>  {
> -    int i;
> -    g_test_message("Testing bits_to_bytes()");
> -
> -    /* the macros don't provide overflow protection */
> -    for (i = 0; i < INT_MAX - 7; i++)
> -    {
>          int expected_bytes;
>          expected_bytes = (i + 7)/8;
>  
>          g_assert(bits_to_bytes(i) >= i/8);
>          g_assert((bits_to_bytes(i) * 8) - i <= 7);
>          g_assert(expected_bytes == bits_to_bytes(i));
> -    }
> +}
>  
> -    g_test_message("Testing bytes_to_int32()");
> -    for (i = 0; i < INT_MAX - 3; i++)
> -    {
> +static void test_bytes_to_int32(int i)
> +{
>          int expected_4byte;
>          expected_4byte = (i + 3)/4;
>  
>          g_assert(bytes_to_int32(i) <= i);
>          g_assert((bytes_to_int32(i) * 4) - i <= 3);
>          g_assert(expected_4byte == bytes_to_int32(i));
> -    }
> -
> -    g_test_message("Testing pad_to_int32");
> +}
>  
> -    for (i = 0; i < INT_MAX - 3; i++)
> -    {
> +static void test_pad_to_int32(int i)
> +{
>          int expected_bytes;
>          expected_bytes = ((i + 3)/4) * 4;
>  
>          g_assert(pad_to_int32(i) >= i);
>          g_assert(pad_to_int32(i) - i <= 3);
>          g_assert(expected_bytes == pad_to_int32(i));
> -    }
> +}
> +static void include_byte_padding_macros(void)
> +{
> +    g_test_message("Testing bits_to_bytes()");
> +
> +    /* the macros don't provide overflow protection */
> +    test_bits_to_byte(0);
> +    test_bits_to_byte(1);
> +    test_bits_to_byte(2);
> +    test_bits_to_byte(7);
> +    test_bits_to_byte(8);
> +    test_bits_to_byte(0xFF);
> +    test_bits_to_byte(0x100);
> +    test_bits_to_byte(INT_MAX - 9);
> +    test_bits_to_byte(INT_MAX - 8);
> +
> +    g_test_message("Testing bytes_to_int32()");
> +
> +    test_bytes_to_int32(0);
> +    test_bytes_to_int32(1);
> +    test_bytes_to_int32(2);
> +    test_bytes_to_int32(7);
> +    test_bytes_to_int32(8);
> +    test_bytes_to_int32(0xFF);
> +    test_bytes_to_int32(0x100);
> +    test_bytes_to_int32(0xFFFF);
> +    test_bytes_to_int32(0x10000);
> +    test_bytes_to_int32(0xFFFFFF);
> +    test_bytes_to_int32(0x1000000);
> +    test_bytes_to_int32(INT_MAX - 4);
> +    test_bytes_to_int32(INT_MAX - 3);
> +
This changes the max for bytes_to_int32 from INT_MAX - 4 to INT_MAX - 3?
Should still work, but might be worth mentioning in the commit message.

> +    g_test_message("Testing pad_to_int32");
>  
> +    test_pad_to_int32(0);
> +    test_pad_to_int32(0);
> +    test_pad_to_int32(1);
> +    test_pad_to_int32(2);
> +    test_pad_to_int32(7);
> +    test_pad_to_int32(8);
> +    test_pad_to_int32(0xFF);
> +    test_pad_to_int32(0x100);
> +    test_pad_to_int32(0xFFFF);
> +    test_pad_to_int32(0x10000);
> +    test_pad_to_int32(0xFFFFFF);
> +    test_pad_to_int32(0x1000000);
> +    test_pad_to_int32(INT_MAX - 4);
> +    test_pad_to_int32(INT_MAX - 3);

Same here.

>  }
>  
>  static void xi_unregister_handlers(void)

Other than that,
Reviewed-by: Julien Cristau <jcristau at debian.org>

Cheers,
Julien


More information about the xorg-devel mailing list