Skip to content

Commit d663d8b

Browse files
committed
Made terminate_handdler tests tolerate differences in stacktraces
1 parent 0c09c5d commit d663d8b

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

example/terminate_handler.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -199,49 +199,37 @@ int test_inplace() {
199199
const bool is_noop = !boost::stacktrace::stacktrace();
200200

201201
{
202+
// This is very dependent on compiler and link flags. No sane way to make it work, because:
203+
// * BOOST_NOINLINE could be ignored by MSVC compiler if link-time optimization is enabled.
204+
// * BOOST_FORCEINLINE could be ignored by GCC depending on the std::vector default constructor length.
202205
const std::size_t frames_ss1 = boost::stacktrace::safe_dump_to("./backtrace2.dump");
203206
boost::stacktrace::stacktrace ss2;
204207
std::ifstream ifs("./backtrace2.dump");
205208
boost::stacktrace::stacktrace ss1 = boost::stacktrace::stacktrace::from_dump(ifs);
206209
ifs.close();
207210
boost::filesystem::remove("./backtrace2.dump");
208211

209-
if (ss2.size() != ss1.size()) {
210-
std::cerr << "Stacktraces differ. Dumped size == " << frames_ss1 << ".\n" << ss1 << "\n vs \n" << ss2 << '\n';
211-
return 51;
212+
if (ss1.size() + 1 != frames_ss1 || ss2.size() != ss1.size()) {
213+
std::cerr << "51: Stacktraces differ. Dumped size == " << frames_ss1 << ".\n" << ss1 << "\n vs \n" << ss2 << '\n';
214+
} else if (ss1.size() > 1 && ss1[1].name() != ss2[1].name()) {
215+
std::cerr << "52: Stacktraces differ:\n" << ss1 << "\n vs \n" << ss2 << '\n';
212216
}
217+
}
213218

214-
#if !defined(BOOST_MSVC) && !defined(BOOST_STACKTRACE_USE_WINDBG)
219+
{
215220
// This is very dependent on compiler and link flags. No sane way to make it work, because:
216221
// * BOOST_NOINLINE could be ignored by MSVC compiler if link-time optimization is enabled.
217222
// * BOOST_FORCEINLINE could be ignored by GCC depending on the std::vector default constructor length.
218-
if (ss1.size() > 1 && ss1[1].name() != ss2[1].name()) {
219-
std::cerr << "Stacktraces differ:\n" << ss1 << "\n vs \n" << ss2 << '\n';
220-
return 52;
221-
}
222-
#endif
223-
}
224-
225-
{
226223
void* data[1024];
227224
const std::size_t frames_ss1 = boost::stacktrace::safe_dump_to(data, sizeof(data));
228225
boost::stacktrace::stacktrace ss2;
229226
boost::stacktrace::stacktrace ss1 = boost::stacktrace::stacktrace::from_dump(data, sizeof(data));
230227

231228
if (ss1.size() + 1 != frames_ss1 || ss1.size() != ss2.size()) {
232-
std::cerr << "Stacktraces differ. Dumped size == " << frames_ss1 << ".\n" << ss1 << "\n vs \n" << ss2 << '\n';
233-
return 53;
234-
}
235-
236-
#if !defined(BOOST_MSVC) && !defined(BOOST_STACKTRACE_USE_WINDBG)
237-
// This is very dependent on compiler and link flags. No sane way to make it work, because:
238-
// * BOOST_NOINLINE could be ignored by MSVC compiler if link-time optimization is enabled.
239-
// * BOOST_FORCEINLINE could be ignored by GCC depending on the std::vector default constructor length.
240-
if (ss1.size() > 1 && ss1[1].name() != ss2[1].name()) {
241-
std::cerr << "Stacktraces differ:\n" << ss1 << "\n vs \n" << ss2 << '\n';
242-
return 54;
229+
std::cerr << "53: Stacktraces differ. Dumped size == " << frames_ss1 << ".\n" << ss1 << "\n vs \n" << ss2 << '\n';
230+
} else if (ss1.size() > 1 && ss1[1].name() != ss2[1].name()) {
231+
std::cerr << "54: Stacktraces differ:\n" << ss1 << "\n vs \n" << ss2 << '\n';
243232
}
244-
#endif
245233
}
246234

247235
{

0 commit comments

Comments
 (0)