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

Handle active Sections for fatal errors #2855

Merged
merged 2 commits into from Apr 21, 2024
Merged

Conversation

hbirler
Copy link
Contributor

@hbirler hbirler commented Apr 15, 2024

Closes #1210

When a signal is caught, the destructors of Sections will not be called. Thus, we must call sectionEndedEarly manually for those Sections.

Example test case:

TEST_CASE("broken") {
   SECTION("section") {
      /// Use illegal cpu instruction
      __asm__ __volatile__("ud2" : : : "memory");
   }
}

@hbirler
Copy link
Contributor Author

hbirler commented Apr 15, 2024

I am not familiar with the internals of Catch2, so there might be a nicer way of doing this. For example, I am not sure whether it is possible to properly construct SectionEndInfo endInfo with correct prevAssertions and durationInSeconds

Closes catchorg#1210

When a signal is caught, the destructors of Sections will not be called.
Thus, we must call `sectionEndedEarly` manually for those Sections.

Example test case:
```
TEST_CASE("broken") {
   SECTION("section") {
      /// Use illegal cpu instruction
      __asm__ __volatile__("ud2" : : : "memory");
   }
}
```
@hbirler
Copy link
Contributor Author

hbirler commented Apr 15, 2024

Additionally, it might be safe to do:

auto nl = CATCH_MOVE(m_activeSections.back()->nameAndLocation());

instead of a copy, but I took the "safe" route (allocating memory might also not be the best idea within a signal handler).

Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 91.04%. Comparing base (029fe3b) to head (fe428d6).
Report is 5 commits behind head on devel.

❗ Current head fe428d6 differs from pull request most recent head 0b013eb. Consider uploading reports for the commit 0b013eb to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #2855      +/-   ##
==========================================
- Coverage   91.09%   91.04%   -0.05%     
==========================================
  Files         197      198       +1     
  Lines        8382     8391       +9     
==========================================
+ Hits         7635     7639       +4     
- Misses        747      752       +5     

@hbirler
Copy link
Contributor Author

hbirler commented Apr 15, 2024

The function RunContext::handleFatalErrorCondition seems to not be covered at all by the existing tests, and I wouldn't know how to test signal handlers reliably within the existing framework.

@horenmar
Copy link
Member

Thanks, this has been around for a while.

@horenmar horenmar merged commit efb3968 into catchorg:devel Apr 21, 2024
78 of 79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants