l4-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: math.h test


From: Matti Ilgmann
Subject: Re: math.h test
Date: Wed, 27 Apr 2005 23:14:22 +0200

Hi,

I added a few more lines to t-l4-math.c to test l4/math.h.  It turned
out that _L4_lsb does not determine the correct least significant bit set in
its argument.  I have included my t-l4-math.c, the make output
with the unpatched version of l4/math.h and a patch that fixes the bug:

make  check-TESTS
make[1]: Entering directory `/home/matti/hurd-l4/libl4/tests'
PASS: t-l4-kip
PASS: t-l4-message
FAIL: [intern] _L4_lsb (3) == 0x2 != 0x1
FAIL: t-l4-math
===============================
1 of 3 tests failed
Please report to address@hidden
===============================
make[1]: *** [check-TESTS] Error 1
make[1]: Leaving directory `/home/matti/hurd-l4/libl4/tests'
make: *** [check-am] Error 2
make: Target `check' not remade because of errors.

Compilation exited abnormally with code 2 at Wed Apr 27 21:59:36

Here the test code:

/* t-l4-math.c -
   Copyright (C) 2005 Free Software Foundation, Inc.
        [snip]
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <limits.h>

/* This must be included before any libl4 header.  */
#include "environment.h"


#include <l4/math.h>

/* Upper limit test_lsb() is called with.  */
#define MAX 65536


void
test_msb_const ()
{

#ifdef _L4_INTERFACE_INTERN

        check_nr ("[intern]", "test_msb_const", _L4_msb (0), 0);
        check_nr ("[intern]", "test_msb_const", _L4_msb (1), 1);
        check_nr ("[intern]", "test_msb_const", _L4_msb (2), 2);
        check_nr ("[intern]", "test_msb_const", _L4_msb (3), 2);
        check_nr ("[intern]", "test_msb_const", _L4_msb (65535), 16);
        check_nr ("[intern]", "test_msb_const", _L4_msb (65536), 17);
   check_nr ("[intern]", "test_msb_const", _L4_msb (LONG_MAX), _L4_WORDSIZE-1);
#endif

#ifdef _L4_INTERFACE_GNU

        check_nr ("[gnu]", "test_msb_const", l4_msb (0), 0);
        check_nr ("[gnu]", "test_msb_const", l4_msb (1), 1);
        check_nr ("[gnu]", "test_msb_const", l4_msb (2), 2);
        check_nr ("[gnu]", "test_msb_const", l4_msb (3), 2);
   check_nr ("[gnu]", "test_msb_const", l4_msb (LONG_MAX), _L4_WORDSIZE-1);
#endif

}
void
test_lsb_const ()
{

#ifdef _L4_INTERFACE_INTERN

        check_nr ("[intern]", "test_lsb_const", _L4_lsb (0), 0);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (1), 1);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (2), 2);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (3), 1);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (4), 3);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (5), 1);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (8), 4);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (65535), 1);
        check_nr ("[intern]", "test_lsb_const", _L4_lsb (65536), 17);
   check_nr ("[intern]", "test_lsb_const", _L4_lsb (LONG_MAX), 1);
#endif

#ifdef _L4_INTERFACE_GNU

        check_nr ("[gnu]", "test_lsb_const", l4_lsb (0), 0);
        check_nr ("[gnu]", "test_lsb_const", l4_lsb (1), 1);
        check_nr ("[gnu]", "test_lsb_const", l4_lsb (2), 2);
   check_nr ("[gnu]", "test_lsb_const", l4_lsb (LONG_MAX), 1);
#endif

}


void
test_msb (_L4_word_t data, _L4_word_t msb)
{
#ifdef _L4_INTERFACE_INTERN
        check_nr ("[intern]", "test_msb", _L4_msb (data), msb);
#endif

#ifdef _L4_INTERFACE_GNU
        check_nr ("[gnu]", "test_msb", l4_msb (data), msb);
#endif

}


void
test_lsb (_L4_word_t data, _L4_word_t lsb)
{
#ifdef _L4_INTERFACE_INTERN
        check_nr ("[intern]", "test_lsb", _L4_lsb (data), lsb);
#endif

#ifdef _L4_INTERFACE_GNU
        check_nr ("[gnu]", "test_lsb", l4_lsb (data), lsb);
#endif

}



void
test (void)
{
        _L4_word_t data = 0, k = 0;

        test_msb_const ();
        test_lsb_const ();

        test_lsb (data, k);
        test_msb (data, k);

        for (data=1,k=1;k<_L4_WORDSIZE;data*=2,k++)
        {
                test_msb (data, k);
        }

        for (data=1;data<MAX;data+=2)
        {
                test_lsb (data, 1);
        }
}

And here the patch for l4/math.h:

*** /tmp/math.h Wed Apr 27 21:53:38 2005
--- /tmp/math.h.new     Wed Apr 27 21:53:38 2005
***************
*** 82,110 ****
  {
    if (__builtin_constant_p (data))
      {
! #define __L4_LSB_TRY(b) else if (data >= (1 << (b - 1))) return (b)
  #define __L4_LSB_IS(b) else return (b)
  
        if (!data)
        return 0;
! #if _L4_WORDSIZE == 64
!       __L4_LSB_TRY(64); __L4_LSB_TRY(63); __L4_LSB_TRY(62); __L4_LSB_TRY(61);
!       __L4_LSB_TRY(60); __L4_LSB_TRY(59); __L4_LSB_TRY(58); __L4_LSB_TRY(57);
!       __L4_LSB_TRY(56); __L4_LSB_TRY(55); __L4_LSB_TRY(54); __L4_LSB_TRY(53);
!       __L4_LSB_TRY(52); __L4_LSB_TRY(51); __L4_LSB_TRY(50); __L4_LSB_TRY(49);
!       __L4_LSB_TRY(48); __L4_LSB_TRY(47); __L4_LSB_TRY(46); __L4_LSB_TRY(45);
!       __L4_LSB_TRY(44); __L4_LSB_TRY(43); __L4_LSB_TRY(42); __L4_LSB_TRY(41);
!       __L4_LSB_TRY(40); __L4_LSB_TRY(39); __L4_LSB_TRY(38); __L4_LSB_TRY(37);
!       __L4_LSB_TRY(36); __L4_LSB_TRY(35); __L4_LSB_TRY(34); __L4_LSB_TRY(33);
  #endif
-       __L4_LSB_TRY(32); __L4_LSB_TRY(31); __L4_LSB_TRY(30); __L4_LSB_TRY(29);
-       __L4_LSB_TRY(28); __L4_LSB_TRY(27); __L4_LSB_TRY(26); __L4_LSB_TRY(25);
-       __L4_LSB_TRY(24); __L4_LSB_TRY(23); __L4_LSB_TRY(22); __L4_LSB_TRY(21);
-       __L4_LSB_TRY(20); __L4_LSB_TRY(19); __L4_LSB_TRY(18); __L4_LSB_TRY(17);
-       __L4_LSB_TRY(16); __L4_LSB_TRY(15); __L4_LSB_TRY(14); __L4_LSB_TRY(13);
-       __L4_LSB_TRY(12); __L4_LSB_TRY(11); __L4_LSB_TRY(10); __L4_LSB_TRY(9);
-       __L4_LSB_TRY(8); __L4_LSB_TRY(7); __L4_LSB_TRY(6); __L4_LSB_TRY(5);
-       __L4_LSB_TRY(4); __L4_LSB_TRY(3); __L4_LSB_TRY(2); __L4_LSB_IS(1);
      }
  
    if (__builtin_expect (data != 0, 1))
--- 82,113 ----
  {
    if (__builtin_constant_p (data))
      {
! #define __L4_LSB_TRY(b) else if ((data & (1 << (b - 1))) != 0) return (b)
  #define __L4_LSB_IS(b) else return (b)
  
        if (!data)
        return 0;
!       __L4_LSB_TRY(1); __L4_LSB_TRY(2); __L4_LSB_TRY(3); __L4_LSB_TRY(4);
!       __L4_LSB_TRY(5); __L4_LSB_TRY(6); __L4_LSB_TRY(7); __L4_LSB_TRY(8);
!       __L4_LSB_TRY(9); __L4_LSB_TRY(10); __L4_LSB_TRY(11); __L4_LSB_TRY(12);
!       __L4_LSB_TRY(13); __L4_LSB_TRY(14); __L4_LSB_TRY(15); __L4_LSB_TRY(16);
!       __L4_LSB_TRY(17); __L4_LSB_TRY(18); __L4_LSB_TRY(19); __L4_LSB_TRY(20);
!       __L4_LSB_TRY(21); __L4_LSB_TRY(22); __L4_LSB_TRY(23); __L4_LSB_TRY(24);
!       __L4_LSB_TRY(25); __L4_LSB_TRY(26); __L4_LSB_TRY(27); __L4_LSB_TRY(28);
!       __L4_LSB_TRY(29); __L4_LSB_TRY(30); __L4_LSB_TRY(31);
! #if _L4_WORDSIZE == 32
!       __L4_LSB_IS(32);
! #else
!       __L4_LSB_TRY(32);
!       __L4_LSB_TRY(33); __L4_LSB_TRY(34); __L4_LSB_TRY(35); __L4_LSB_TRY(36);
!       __L4_LSB_TRY(37); __L4_LSB_TRY(38); __L4_LSB_TRY(39); __L4_LSB_TRY(40);
!       __L4_LSB_TRY(41); __L4_LSB_TRY(42); __L4_LSB_TRY(43); __L4_LSB_TRY(44);
!       __L4_LSB_TRY(45); __L4_LSB_TRY(46); __L4_LSB_TRY(47); __L4_LSB_TRY(48);
!       __L4_LSB_TRY(49); __L4_LSB_TRY(50); __L4_LSB_TRY(51); __L4_LSB_TRY(52);
!       __L4_LSB_TRY(53); __L4_LSB_TRY(54); __L4_LSB_TRY(55); __L4_LSB_TRY(56);
!       __L4_LSB_TRY(57); __L4_LSB_TRY(58); __L4_LSB_TRY(59); __L4_LSB_TRY(60);
!       __L4_LSB_TRY(61); __L4_LSB_TRY(62); __L4_LSB_TRY(63); __L4_LSB_TRY(64);
  #endif
      }
  
    if (__builtin_expect (data != 0, 1))

With this patch all tests go well.

Thanks,
Matti




reply via email to

[Prev in Thread] Current Thread [Next in Thread]