mity / acutest

Simple header-only C/C++ unit testing facility.
MIT License
346 stars 96 forks source link

Implement debugger detection on Mac OS X (and other platforms) #36

Closed mity closed 3 years ago

mity commented 4 years ago

On systems where supported (all Posix systems and Windows), Acutest by default executes each test in a child process to isolate them from each other. However, in order to improve debugability, this default behavior is suppressed when we detect the main process is executed under a debugger or being traced because, in general, debugging forking processes is much more pain.

This detection is currently implemented only for Windows and Linux. It would be great to have this also for other Posix platforms (if they offer an appropriate API for that). Especially on Mac OS X, given its popularity.

arr2036 commented 4 years ago

Your Linux mechanism is pretty neat.

The way we do this is to fork and have the child try to ptrace its parent. The key to making this work well is to determine if the ptrace/pattach is actually permitted by current process capabilities.

Here's our implementation: https://github.com/FreeRADIUS/freeradius-server/blob/master/src/lib/util/debug.c#L309

Let me know if you want me to send a PR for non Linux/Windows platforms.

mity commented 4 years ago

Let me know if you want me to send a PR for non Linux/Windows platforms.

I don't think all platforms have ptrace. It's not guaranteed by Posix or anything, or is it?

That said, yes, it would be nice to have it for platforms which provide it. I believe that at least all *BSD (and derivatives including MacOS) have it. PR would definitely help.

arr2036 commented 4 years ago

BSDs (+Derivatives) + Solaris IIRC. OK, I'll send something over in the next couple of days. This functionality directly impacts me, so incentivised to fix it :)

hovsater commented 3 years ago

Would love to see this fixed on macOS. 🙂