Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break the debugger when a test failed #2830

Merged
merged 2 commits into from Aug 30, 2017
Merged

Conversation

Naios
Copy link
Contributor

@Naios Naios commented Aug 13, 2017

  • Currently only implemented for the MSVC debugger if attached

The main idea is that we instantly see which test failed if we execute a test inside a debugger.

I would like to hear your opinion about this:

  • Maybe we could allow to enable/disable this from CMake.
  • Maybe we could move this up to the test macros which could yield a better stack trace

@hkaiser
Copy link
Member

hkaiser commented Aug 14, 2017

I like this idea. However, I'd suggest to use the already existing facilities in HPX. See here for an example usage. This code looks up whether there was a command line option --hpx:attach-debugger=exception. I think we could add a --hpx:attach-debugger=test-failure which would enable attaching a debugger for your use case. See here for the relevant spots:

So your code would look like:

if (hpx::get_config_entry("hpx.attach_debugger", "") == "test-failure")
{
    hpx::util::attach_debugger();
}

That would however require to extract the corresponding declaration into a separate header file: https://github.com/STEllAR-GROUP/hpx/blob/master/hpx/util/command_line_handling.hpp#L93.

@Naios
Copy link
Contributor Author

Naios commented Aug 14, 2017

@hkaiser This sounds great. I thought it would be comfortable if this would work automaitically without requiring any argument, since many unit tests don't even parse their arguments.
But I also think that one should be able to disable this.

Do you think that there is a solution which solves both ideas?

@hkaiser
Copy link
Member

hkaiser commented Aug 14, 2017

@Naios Hmmm, I'd prefer if this was not ON by default. But I agree that many tests don't handle command line options, I didn't think of this...

Internally HPX relies on extracting the information about any possible --hpx:attach-debugger=... option from its internal configuration database (using the key hpx.attach_debugger). This allows to enable extracting this information from the execution environment as well. If we added

"attach_debugger = ${HPX_ATTACH_DEBUGGER}",

here: https://github.com/STEllAR-GROUP/hpx/blob/master/src/util/runtime_configuration.cpp#L197.

Now setting HPX_ATTACH_DEBUGGER=test-failure in the execution environment would trigger the desired functionality. Note that you could still overwrite this by using a command line option if we added off as a valid argument for it (see link posted earlier).

Similarly we could add a compile-time configuration option enabling this by default:

#if defined(HPX_HAVE_TESTS_ATTACH_DEBUGGER_ON_FAILURE)
    "attach_debugger = ${HPX_ATTACH_DEBUGGER:test-failure}",
#else
    "attach_debugger = ${HPX_ATTACH_DEBUGGER}",
#endif

@Naios
Copy link
Contributor Author

Naios commented Aug 14, 2017

@hkaiser Perfect, thanks for your quick reply. That was the implementation I thought about 👍

@Naios Naios force-pushed the test_break branch 2 times, most recently from 29dee3f to 980b405 Compare August 21, 2017 10:31
@Naios
Copy link
Contributor Author

Naios commented Aug 21, 2017

@hkaiser I applied the requested changes:

  • attach_debugger() was refactored out
  • The option is now enabled by default if HPX_WITH_ATTACH_DEBUGGER_ON_TEST_FAILURE is set

{ HPX_ASSERT(false); return; }
}
}
void increment(counter_type c);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be HPX_EXPORTed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that too, however lightweight_test.cpp is built into the hpx_init static library and thus we don't need to export the symbol.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks!

{ HPX_ASSERT(false); return 0; }
}
}
std::size_t get(counter_type c) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: HPX_EXPORT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Member

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot!

@Naios Naios force-pushed the test_break branch 2 times, most recently from 30652a9 to d861187 Compare August 21, 2017 21:06
@hkaiser
Copy link
Member

hkaiser commented Aug 22, 2017

@Naios: one more thing - may I ask you to add support for --hpx:attach-debugger=off (or similar) allowing to disable the pre-set test-failure if -DHPX_WITH_ATTACH_DEBUGGER_ON_TEST_FAILURE=On?

@Naios
Copy link
Contributor Author

Naios commented Aug 22, 2017

@hkaiser Yes, good idea. I'll add it.

* Set the cmake variable
  -DHPX_WITH_ATTACH_DEBUGGER_ON_TEST_FAILURE
  to enable this without to set it inside the config.
* Move some methods from the test fixture to its
  compilation unit.
@Naios
Copy link
Contributor Author

Naios commented Aug 27, 2017

@hkaiser I applied the requested change

std::cerr <<
"hpx::init: command line warning: --hpx:attach-debugger: "
"invalid option: " << option << ". Allowed values are "
"'startup' or 'exception'" << std::endl;
"'off, startup', 'exception' or 'test-failure'" << std::endl;
Copy link
Member

@hkaiser hkaiser Aug 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: this misses apostrophes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/fixed

* Useful when HPX_WITH_ATTACH_DEBUGGER_ON_TEST_FAILURE
  is set in CMake, and we want to disable this
  option at runtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants