unit test not passing on my computer

Matthieu Patou mat at samba.org
Tue Jun 22 22:55:05 MDT 2010


On 23/06/2010 03:30, Lukasz Zalewski wrote:
> Hi Jelmer,
> On 22/06/2010 23:30, Jelmer Vernooij wrote:
>> Hi Lukasz, Matthias,
>>
>> On Tue, 2010-06-22 at 09:15 +0100, Lukasz Zalewski wrote:
>>> On 22/06/2010 07:26, Matthias Dieter Wallnöfer wrote:
>>>> Hi Lukasz,
>>>>
>>>> if grouptype is not None:
>>>>
>>>> - ldbmessage["groupType"] = "%d" % ((grouptype)-2**32)
>>>>
>>>> + ldbmessage["groupType"] = "%d" % ((grouptype + 2**31) % 2**32 - 
>>>> 2**31
>>>>
>>>> ^^^ isn't this "groupType" alignment easier to do? Shouldn't 
>>>> "groupType
>>>> % 2**32" alone fit ?
>>> just using
>>> "%d" % ((grouptype) % 2**32)
>>> seems to break on both 32 and 64bit:
>>> On 32:
>>> groupType= -2147483644
>>> groupType (grouptype % 2**32)= 2147483652
>>>
>>> on 64bit:
>>> groupType= 2147483652
>>> groupType (grouptype % 2**32)= 2147483652
>>>
>>> Note: on 32bit the value is correct to start with so no conversion 
>>> would
>>> be necessary
>>>
>>> Maybe Jelmer can shed some light on this
>> This is definitely not the right fix, as the user in Python shouldn't
>> have to care about the endianness of the machine on which the code is
>> running.
>>
>> I don't really understand what the problem is that you're trying to
>> solve though - what test is failing and in what way ?
>>
>> Cheers,
>>
>> Jelmer
> The problem is as follows:
> The possible values for groupType are imported from samba.dsdb
> from samba.dsdb import (
>     GTYPE_SECURITY_DOMAIN_LOCAL_GROUP,
>     GTYPE_SECURITY_GLOBAL_GROUP,
>     GTYPE_SECURITY_UNIVERSAL_GROUP,
>     GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP,
>     GTYPE_DISTRIBUTION_GLOBAL_GROUP,
>     GTYPE_DISTRIBUTION_UNIVERSAL_GROUP,
> )
> Then the appropriate value is assingned through
> ldbmessage["groupType"] = "%d" % ...
>
> given GTYPE_SECURITY_DOMAIN_LOCAL_GROUP
> on 32bit
> the following statement
> ldbmessage["groupType"] = "%d" % groupType
> produces correct value of -2147483644
>
> however on 64bit
> the value is 2147483652
Well it's 0x80000004 which look quite normal

In the same time in 32bit -2147483644 is -2147483648 + 4.
In 32bit 0x80000000 is in fact -2147483648 (the highest bit is -(2^31)), 
so -2147483644 is also 0x80000004 (the highest bit has the sign and to 
calculate the value you add the different value of 2, ie. 0x8000000F is 
-2147483648 + 15 => -2147483633).

So I guess ldbmessage["groupType"] = "%d" % grouptype should be just ok 
(at least it is on 32 bit).



>
> now to fix this problem on 64bit
> ldbmessage["groupType"] = ((grouptype)-2**32)
> hack was used - but as Matthieu noticed this breaks tests on 32 bit 
> builds as it produces ivalid value and ldbadd bails out
>
> I do agree its a nasty hack (to fix another, broken hack) - i'm just 
> not sure what the solution is - as you say python should take care of 
> this automatically, but it doesn't for some reason
>
> Regards
>
> Luk
>
>>
>>>> Matthias
>>>>
>>>> Lukasz Zalewski wrote:
>>>>> Matthieu,
>>>>> Attached is the patch that fixes the problems when assigning
>>>>> (converting) grouptype value on 64 and 32 bit architectures. I have
>>>>> tested this on both architectures and both produce exactly the same
>>>>> values. Please let me know if this works for you
>>>>>
>>>>> Luk
>>>>
>>>
>>
>>
>


-- 
Matthieu Patou
Samba Team        http://samba.org



More information about the samba-technical mailing list