wix-incubator / DetoxSync

Synchronization framework for Detox and other testing frameworks
MIT License
34 stars 16 forks source link

Allow running with address sanitizer enabled #34

Closed ball-hayden closed 2 years ago

ball-hayden commented 2 years ago

Currently running with address sanitizer results in infinite recursion leading to a stack overflow.

With the address sanitizer enabled, the actual "original" dispatch_xs are prepended with the word wrap_.

asafkorem commented 2 years ago

The simplification can be also done using macros only:

// With the Address Sanitizer enabled, the actual "original" `dispatch_x` are prepended with the
// word `wrap_`.
#if defined(__has_feature) && __has_feature(address_sanitizer)
# define DTX_ORIG_DISPATCH_NAME(type) [@"wrap_dispatch_" stringByAppendingString:type]
#else
# define DTX_ORIG_DISPATCH_NAME(type) [@"dispatch_" stringByAppendingString:type]
#endif

...

struct rebinding r[] = (struct rebinding[]) {
  DTX_ORIG_DISPATCH_NAME(@"async"), __detox_sync_dispatch_async, (void**)&__orig_dispatch_async,
  DTX_ORIG_DISPATCH_NAME(@"sync"), __detox_sync_dispatch_sync, (void**)&__orig_dispatch_sync,
  ...
};

I have no particular preference between these two, but I prefer one of them instead of the struct duplication.

ball-hayden commented 2 years ago

Yeah - I was just looking at that.

String concatenation involves casting to an NSString and then trying to convince a cast back to const char* for rebinding.

The macro appears to be neater - I'll push what I have shortly.

asafkorem commented 2 years ago

Looking great! But let's put the macros at the top of the file 🙂

asafkorem commented 2 years ago

@ball-hayden, can you please run another test with ASan enabled before we merge this?

ball-hayden commented 2 years ago

Sorry @asafkorem - I missed your last message there. The app builds and launches now with ASan enabled.

Running the Detox e2e suite I see some failures, but I also see them against master.

asafkorem commented 2 years ago

Thanks a lot @ball-hayden, amazing work 👑