From 1ebf006b73c06d037e3d3ae4393136082195096d Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Wed, 27 Mar 2024 19:51:59 -0400 Subject: Remove dead googlemock dependency and related setup code --- indra/test/test.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 61a4eb07c5..cbd1077306 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -53,11 +53,6 @@ # include "ctype_workaround.h" #endif -#ifndef LL_WINDOWS -#include -#include -#endif - #if LL_MSVC #pragma warning (push) #pragma warning (disable : 4702) // warning C4702: unreachable code @@ -522,12 +517,6 @@ static LLTrace::ThreadRecorder* sMasterThreadRecorder = NULL; int main(int argc, char **argv) { - // The following line must be executed to initialize Google Mock - // (and Google Test) before running the tests. -#ifndef LL_WINDOWS - ::testing::InitGoogleMock(&argc, argv); -#endif - ll_init_apr(); apr_getopt_t* os = NULL; if(APR_SUCCESS != apr_getopt_init(&os, gAPRPoolp, argc, argv)) -- cgit v1.2.3 From 1b6e2ef62cec9608d160ea25d99080f0e2964ee5 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 16 May 2024 13:30:14 -0400 Subject: On Windows, defend test.cpp against structured exceptions too. Since August 2023, we've seen occasional GitHub Windows build test runs terminate with 0xC00000FD: stack overflow. We've usually responded by bumping up the default coroutine stack size. On closer examination, it's always llleap_test.cpp that blows up that way -- and llleap_test.cpp doesn't appear to use coroutines at all. So apparently we've been consuming more address space for ALL viewer coroutines without actually addressing the problem. Reset the default coroutine stack size to where it was before we started bumping it up in response to these llleap_test.cpp stack overflow failures. Note that LLCoros already catches and reports Windows structured exceptions, underscoring that the observed stack overflow is not from within a coroutine. While at it, restore the Windows llleap_test.cpp data volume to match Posix. We think the problem that led to reducing that data volume was an APR bug, which we hope has been fixed. Equip test.cpp, the test driver program for all our TUT unit and integration tests, with a Windows structured exception handler. Try to treat a Windows structured exception as a test failure -- instead of silently terminating with 0xC00000FD. Moreover, when a structured exception occurs, output a stack trace so we can try to track it down. --- indra/test/test.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 104 insertions(+), 21 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 61a4eb07c5..0b2abbc650 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -68,10 +68,7 @@ #pragma warning (pop) #endif -#include -#include -#include -#include +#include #include @@ -181,10 +178,6 @@ public: LLTestCallback(bool verbose_mode, std::ostream *stream, std::shared_ptr replayer) : mVerboseMode(verbose_mode), - mTotalTests(0), - mPassedTests(0), - mFailedTests(0), - mSkippedTests(0), // By default, capture a shared_ptr to std::cout, with a no-op "deleter" // so that destroying the shared_ptr makes no attempt to delete std::cout. mStream(std::shared_ptr(&std::cout, [](std::ostream*){})), @@ -220,6 +213,8 @@ public: virtual void group_started(const std::string& name) { LL_INFOS("TestRunner")<<"Unit test group_started name=" << name << LL_ENDL; *mStream << "Unit test group_started name=" << name << std::endl; + mGroup = name; + mGroupTests = 0; super::group_started(name); } @@ -232,6 +227,7 @@ public: virtual void test_completed(const tut::test_result& tr) { ++mTotalTests; + ++mGroupTests; // If this test failed, dump requested log messages BEFORE stating the // test result. @@ -319,12 +315,15 @@ public: super::run_completed(); } + std::string mGroup; + int mGroupTests{ 0 }; + protected: - bool mVerboseMode; - int mTotalTests; - int mPassedTests; - int mFailedTests; - int mSkippedTests; + bool mVerboseMode{ false }; + int mTotalTests{ 0 }; + int mPassedTests{ 0 }; + int mFailedTests{ 0 }; + int mSkippedTests{ 0 }; std::shared_ptr mStream; std::shared_ptr mReplayer; }; @@ -520,6 +519,57 @@ void wouldHaveCrashed(const std::string& message) static LLTrace::ThreadRecorder* sMasterThreadRecorder = NULL; +// this is used in platform-generic code -- define outside #if LL_WINDOWS +struct Windows_SEH_exception: public std::runtime_error +{ + Windows_SEH_exception(const std::string& what): std::runtime_error(what) {} +}; + +#if LL_WINDOWS + +static const U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific + +U32 seh_filter(U32 code, struct _EXCEPTION_POINTERS*) +{ + if (code == STATUS_MSC_EXCEPTION) + { + // C++ exception, go on -- but TUT is supposed to have caught those already?! + return EXCEPTION_CONTINUE_SEARCH; + } + else + { + // This is a non-C++ exception, e.g. hardware check. + // By the time the handler gets control, the stack has been unwound, + // so report the stack trace now at filter() time. + std::cerr << boost::stacktrace::stacktrace() << std::endl; + // pass control into the handler block + return EXCEPTION_EXECUTE_HANDLER; + } +} + +template +void seh_catcher(CALLABLE0&& trycode, CALLABLE1&& handler) +{ + __try + { + trycode(); + } + __except (seh_filter(GetExceptionCode(), GetExceptionInformation())) + { + handler(GetExceptionCode()); + } +} + +#else // not LL_WINDOWS + +template +void seh_catcher(CALLABLE0&& trycode, CALLABLE1&&) +{ + trycode(); +} + +#endif // not LL_WINDOWS + int main(int argc, char **argv) { // The following line must be executed to initialize Google Mock @@ -658,14 +708,47 @@ int main(int argc, char **argv) // a chained_callback subclass must be linked with previous mycallback->link(); - if(test_group.empty()) - { - tut::runner.get().run_tests(); - } - else - { - tut::runner.get().run_tests(test_group); - } + seh_catcher( + // __try + [test_group] + { + if(test_group.empty()) + { + tut::runner.get().run_tests(); + } + else + { + tut::runner.get().run_tests(test_group); + } + }, + // __except + [mycallback](U32 code) + { + static std::map codes = { + { 0xC0000005, "Access Violation" }, + { 0xC00000FD, "Stack Overflow" }, + // ... continue filling in as desired + }; + + auto found{ codes.find(code) }; + const char* name = ((found == codes.end())? "unknown" : found->second); + auto msg{ stringize("test threw ", std::hex, code, " (", name, ")") }; + + // Instead of bombing the whole test run, report this as a test + // failure. Arguably, catching structured exceptions should be + // hacked into TUT itself. + mycallback->test_completed(tut::test_result( + mycallback->mGroup, + mycallback->mGroupTests+1, // test within group + "unknown", // test name + tut::test_result::ex, // result: exception + // we don't have to throw this exception subclass to use it to + // populate the test_result struct + Windows_SEH_exception(msg))); + // we've left the TUT framework -- finish up by hand + mycallback->group_completed(mycallback->mGroup); + mycallback->run_completed(); + }); bool success = (mycallback->getFailedTests() == 0); -- cgit v1.2.3 From f10ec3073cde4810fe01753c1e5b82cb8591a1cb Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 16 May 2024 14:19:20 -0400 Subject: Need magic #define for on Mac. --- indra/test/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 0b2abbc650..c4cf4b2d28 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -68,6 +68,11 @@ #pragma warning (pop) #endif +// On Mac, got: +// #error "Boost.Stacktrace requires `_Unwind_Backtrace` function. Define +// `_GNU_SOURCE` macro or `BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED` if +// _Unwind_Backtrace is available without `_GNU_SOURCE`." +#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED #include #include -- cgit v1.2.3 From f06f84aed26fa7ed294a14ed12dae58c063b0aa3 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 17 May 2024 09:16:53 -0400 Subject: Don't try to report a stack trace on stack overflow (sigh) --- indra/test/test.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index c4cf4b2d28..1239b34d04 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -532,7 +532,8 @@ struct Windows_SEH_exception: public std::runtime_error #if LL_WINDOWS -static const U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific +static constexpr U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific +static constexpr U32 STATUS_STACK_FULL = 0xC00000FD; U32 seh_filter(U32 code, struct _EXCEPTION_POINTERS*) { @@ -546,7 +547,13 @@ U32 seh_filter(U32 code, struct _EXCEPTION_POINTERS*) // This is a non-C++ exception, e.g. hardware check. // By the time the handler gets control, the stack has been unwound, // so report the stack trace now at filter() time. - std::cerr << boost::stacktrace::stacktrace() << std::endl; + // Sadly, even though, at the time of this writing, stack overflow is + // the problem we would most like to diagnose, calling another + // function when the stack is already blown only terminates us faster. + if (code != STATUS_STACK_FULL) + { + std::cerr << boost::stacktrace::stacktrace() << std::endl; + } // pass control into the handler block return EXCEPTION_EXECUTE_HANDLER; } -- cgit v1.2.3 From 71d777ea126e7f02cb46c11bdb606094ca06f75c Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 24 May 2024 17:34:04 -0400 Subject: Promote seh_catcher() et al. to llexception.{h,cpp} for general use. --- indra/test/test.cpp | 68 ++--------------------------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 1239b34d04..d1c65d6aa7 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -36,6 +36,7 @@ #include "linden_common.h" #include "llerrorcontrol.h" +#include "llexception.h" #include "lltut.h" #include "chained_callback.h" #include "stringize.h" @@ -68,13 +69,6 @@ #pragma warning (pop) #endif -// On Mac, got: -// #error "Boost.Stacktrace requires `_Unwind_Backtrace` function. Define -// `_GNU_SOURCE` macro or `BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED` if -// _Unwind_Backtrace is available without `_GNU_SOURCE`." -#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED -#include - #include void wouldHaveCrashed(const std::string& message); @@ -524,64 +518,6 @@ void wouldHaveCrashed(const std::string& message) static LLTrace::ThreadRecorder* sMasterThreadRecorder = NULL; -// this is used in platform-generic code -- define outside #if LL_WINDOWS -struct Windows_SEH_exception: public std::runtime_error -{ - Windows_SEH_exception(const std::string& what): std::runtime_error(what) {} -}; - -#if LL_WINDOWS - -static constexpr U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific -static constexpr U32 STATUS_STACK_FULL = 0xC00000FD; - -U32 seh_filter(U32 code, struct _EXCEPTION_POINTERS*) -{ - if (code == STATUS_MSC_EXCEPTION) - { - // C++ exception, go on -- but TUT is supposed to have caught those already?! - return EXCEPTION_CONTINUE_SEARCH; - } - else - { - // This is a non-C++ exception, e.g. hardware check. - // By the time the handler gets control, the stack has been unwound, - // so report the stack trace now at filter() time. - // Sadly, even though, at the time of this writing, stack overflow is - // the problem we would most like to diagnose, calling another - // function when the stack is already blown only terminates us faster. - if (code != STATUS_STACK_FULL) - { - std::cerr << boost::stacktrace::stacktrace() << std::endl; - } - // pass control into the handler block - return EXCEPTION_EXECUTE_HANDLER; - } -} - -template -void seh_catcher(CALLABLE0&& trycode, CALLABLE1&& handler) -{ - __try - { - trycode(); - } - __except (seh_filter(GetExceptionCode(), GetExceptionInformation())) - { - handler(GetExceptionCode()); - } -} - -#else // not LL_WINDOWS - -template -void seh_catcher(CALLABLE0&& trycode, CALLABLE1&&) -{ - trycode(); -} - -#endif // not LL_WINDOWS - int main(int argc, char **argv) { // The following line must be executed to initialize Google Mock @@ -734,7 +670,7 @@ int main(int argc, char **argv) } }, // __except - [mycallback](U32 code) + [mycallback](U32 code, const std::string& /*stacktrace*/) { static std::map codes = { { 0xC0000005, "Access Violation" }, -- cgit v1.2.3 From 5ed8df22cd59680a685c4ada7daa5555bf59d4fe Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 28 May 2024 13:22:05 -0400 Subject: Fix up llexception.h's cross-platform SEH wrapper. Introduce AlwaysReturn specialization, which always discards any result of calling the specified callable with specified args. Derive new Windows_SEH_exception from LLException, not std::runtime_error. Put the various SEH functions in LL::seh nested namespace, e.g. LL::seh::catcher() as the primary API. Break out more levels of Windows SEH handler to work around the restrictions on functions containing __try/__except. The triadic catcher() overload now does little save declare a std::string stacktrace before forwarding the call to catcher_inner(), passing a reference to stacktrace along with the trycode, filter and handler functions. catcher_inner() accepts the stacktrace and the three function template arguments. It contains the __try/__except logic. It calls a new filter_() wrapper template, which calls fill_stacktrace() before forwarding the call to the caller's filter function. fill_stacktrace(), in the .cpp file, contains the logic to populate the stacktrace string -- unless the Structured Exception is stack overflow, in which case it puts an explanatory string instead. catcher_inner()'s __except clause passes not only the code, but also the stacktrace string, to the caller's handler function. It wraps the caller's handler function in always_return(), where rtype is the type returned by the trycode function. This allows a handler to return a value, while also supporting the void handler case, e.g. one that throws a C++ exception. (This is why we need AlwaysReturn: some trycode() functions are themselves void.) For the dyadic catcher() overload, introduce common_filter() containing the logic to distinguish a C++ exception from any other kind of Structured Exception. The fact that the stacktrace is captured before the filter function is called should permit capturing a stacktrace for a C++ exception as well as for most other Structured Exceptions. As before, the monadic catcher() overload supplies the rethrow() handler, in the .cpp file. Change existing calls from seh_catcher() to LL::seh::catcher(). --- indra/test/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index d1c65d6aa7..64ee702124 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -656,7 +656,7 @@ int main(int argc, char **argv) // a chained_callback subclass must be linked with previous mycallback->link(); - seh_catcher( + LL::seh::catcher( // __try [test_group] { -- cgit v1.2.3 From b347ad5deb1c9abb210ac5da0534766bf5b6f2f0 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 27 Jun 2024 18:06:13 -0400 Subject: Make test.cpp test driver recognize LOGTEST_testname. Setting LOGTEST=DEBUG, when many unit/integration tests must be rebuilt and run, can result in lots of unnecessary output. When we only want DEBUG log output from a specific test program, make test.cpp recognize an environment variable LOGTEST_testname, where 'testname' might be the full basename of the executable, or part of INTEGRATION_TEST_testname or PROJECT_foo_TEST_testname. When test.cpp notices a non-empty variable by that name, it behaves as if LOGTEST were set to that value. --- indra/test/test.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 61a4eb07c5..3cbac41f4a 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -35,13 +35,14 @@ */ #include "linden_common.h" -#include "llerrorcontrol.h" -#include "lltut.h" #include "chained_callback.h" -#include "stringize.h" -#include "namedtempfile.h" +#include "fsyspath.h" +#include "llerrorcontrol.h" #include "lltrace.h" #include "lltracethreadrecorder.h" +#include "lltut.h" +#include "namedtempfile.h" +#include "stringize.h" #include "apr_pools.h" #include "apr_getopt.h" @@ -545,6 +546,27 @@ int main(int argc, char **argv) // LOGTEST overrides default, but can be overridden by --debug. const char* LOGTEST = getenv("LOGTEST"); + // Sometimes we must rebuild much of the viewer before we get to the + // specific test we want to monitor, and some viewer integration tests are + // quite verbose. In addition to noticing plain LOGTEST= (for all tests), + // also notice LOGTEST_progname= (for a specific test). + std::string basename{ fsyspath(argv[0]).stem() }; + // don't make user set LOGTEST_INTEGRATION_TEST_progname or (worse) + // LOGTEST_PROJECT_foo_TEST_bar -- only LOGTEST_progname or LOGTEST_bar + auto _TEST_ = basename.find("_TEST_"); + if (_TEST_ != std::string::npos) + { + basename.erase(0, _TEST_+6); + } + std::string LOGTEST_prog_key{ "LOGTEST_" + basename }; + const char* LOGTEST_prog = getenv(LOGTEST_prog_key.c_str()); +// std::cout << LOGTEST_prog_key << "='" << (LOGTEST_prog? LOGTEST_prog : "") << "'" << std::endl; + if (LOGTEST_prog && *LOGTEST_prog) + { + LOGTEST = LOGTEST_prog; + std::cout << "LOGTEST='" << LOGTEST << "' from " << LOGTEST_prog_key << std::endl; + } + // values used for options parsing apr_status_t apr_err; const char* opt_arg = NULL; -- cgit v1.2.3 From 982ea7fb796924877e95bee2f9ba6b2296219139 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 27 Jun 2024 23:11:18 -0400 Subject: Work around VS refusal to initialize a string --- indra/test/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 3cbac41f4a..22f9ccf334 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -550,7 +550,7 @@ int main(int argc, char **argv) // specific test we want to monitor, and some viewer integration tests are // quite verbose. In addition to noticing plain LOGTEST= (for all tests), // also notice LOGTEST_progname= (for a specific test). - std::string basename{ fsyspath(argv[0]).stem() }; + std::string basename(fsyspath(argv[0]).stem()); // don't make user set LOGTEST_INTEGRATION_TEST_progname or (worse) // LOGTEST_PROJECT_foo_TEST_bar -- only LOGTEST_progname or LOGTEST_bar auto _TEST_ = basename.find("_TEST_"); @@ -558,7 +558,7 @@ int main(int argc, char **argv) { basename.erase(0, _TEST_+6); } - std::string LOGTEST_prog_key{ "LOGTEST_" + basename }; + std::string LOGTEST_prog_key("LOGTEST_" + basename); const char* LOGTEST_prog = getenv(LOGTEST_prog_key.c_str()); // std::cout << LOGTEST_prog_key << "='" << (LOGTEST_prog? LOGTEST_prog : "") << "'" << std::endl; if (LOGTEST_prog && *LOGTEST_prog) -- cgit v1.2.3 From cfd7d8905d686411a774c47bbfc13f49882b65e6 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 28 Jun 2024 08:30:41 -0400 Subject: Work around MSVC limitation: explicitly call fsyspath::string(). --- indra/test/test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/test/test.cpp') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 22f9ccf334..0e863d8084 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -550,7 +550,9 @@ int main(int argc, char **argv) // specific test we want to monitor, and some viewer integration tests are // quite verbose. In addition to noticing plain LOGTEST= (for all tests), // also notice LOGTEST_progname= (for a specific test). - std::string basename(fsyspath(argv[0]).stem()); + // (Why doesn't MSVC notice fsyspath::operator std::string()? + // Why must we explicitly call fsyspath::string()?) + std::string basename(fsyspath(argv[0]).stem().string()); // don't make user set LOGTEST_INTEGRATION_TEST_progname or (worse) // LOGTEST_PROJECT_foo_TEST_bar -- only LOGTEST_progname or LOGTEST_bar auto _TEST_ = basename.find("_TEST_"); -- cgit v1.2.3