[haiku-development] Re: Help needed with the unit testing framework

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 29 Jul 2014 21:19:56 +0200

On 29.07.2014 16:26, pulkomandy wrote:
On Mon, Jul 28, 2014 at 08:33:59PM +0200, Ingo Weinhold wrote:
On 28.07.2014 12:54, pulkomandy wrote:
Knowing that this only happens with gcc2, I think it somehow misses the fact
that the method is virtual when compiling the base class, and generates a
direct call instead of a virtual one (going through the vtable).

It's fairly easy to verify/refute that theory by using objdump on the code
that invokes the method (objdump -D --demangle ...). If you build with debug
info you can even interleave the disassembly with the source code (-S
option).

Ok, using this I noticed that a proper virtual call was generated, but
the offset to the vtable was different. This helped me understand the
problem. The TestShell class has some optional features that are
disabled by the NO_ELF_SYMBOL_PATCHING define. This define is set when
compiling the lib, but not when compiling UnitTester, and with gcc2 it
seems the vtable layout is different (even though I see no extra virtual
method being defined when the define is unset).

You sure that the offset into the vtable is different, not the offset of the vtable pointer in the object? IIRC that is something that changed between the gcc 2 and the Itanium ABI. Possibly something like after vs. before the attributes of the first polymorphic base class (which would explain why it works for gcc 4).

Adding the define to UnitTester jamfile fixes the issue, and shows that
the implementation of LoadDynamicTests there is crashing. I will fix
that before I commit the change.

What's the best way to deal with this define? I can think of several
solutions but not sure which is the best:
* Have the methods defined in all cases, and move the define to their
implementations, so the vtable layout is the same in both case
* Remove support for symbol patching, as it looks like it can only used
in BeOS (I'm not sure if running our tests on BeOS using the unit test
framework is still possible)
* Make sure the define is always set properly, for example by adding it
to the UnitTest and UnitTestLib rules.

The reason why the symbol patching was introduced is support for asserting debugger() calls [1]. The reason the macro was introduced is (better) support for the Metrowerks compiler [2]. So the macro can definitely be dropped. ATM I'm unaware of any reason why the symbol patching shouldn't work on Haiku (it could probably be done more elegantly due to symbol preemption support, though).

CU, Ingo

[1] http://cgit.haiku-os.org/haiku/commit/?id=257e63ba7f655d72955a2110dc028a3356cebe5a [2] http://cgit.haiku-os.org/haiku/commit/?id=1b89aa98ffe3057ab801dab67b9f5de6d1f933a5


Other related posts: