2019-08-14 23:31:35 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
//
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/Error.h>
|
2019-08-15 00:10:25 +00:00
|
|
|
#include <vtkm/cont/ErrorBadValue.h>
|
|
|
|
#include <vtkm/cont/Logging.h>
|
2019-08-14 23:31:35 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void RecursiveFunction(int recurse)
|
|
|
|
{
|
|
|
|
if (recurse < 5)
|
|
|
|
{
|
2019-08-15 00:10:25 +00:00
|
|
|
RecursiveFunction(++recurse);
|
2019-08-14 23:31:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-15 00:10:25 +00:00
|
|
|
throw vtkm::cont::ErrorBadValue("Too much recursion");
|
2019-08-14 23:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateError(const vtkm::cont::Error& error)
|
|
|
|
{
|
|
|
|
std::string message = "Too much recursion";
|
2019-08-29 00:14:07 +00:00
|
|
|
std::string stackTrace = error.GetStackTrace();
|
|
|
|
std::stringstream stackTraceStream(stackTrace);
|
2019-08-21 23:46:29 +00:00
|
|
|
std::string tmp;
|
|
|
|
size_t count = 0;
|
|
|
|
while (std::getline(stackTraceStream, tmp))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2019-08-29 00:14:07 +00:00
|
|
|
// StackTrace may be unavailable on certain Devices
|
|
|
|
if (stackTrace == "(Stack trace unavailable)")
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(count == 1, "Logging disabled, stack trace shouldn't be available");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-12 18:37:55 +00:00
|
|
|
std::string assert_msg = "StackTrace did not recurse: (" + std::to_string(count) + " <= 5)";
|
2019-10-17 17:17:14 +00:00
|
|
|
|
|
|
|
#if defined(NDEBUG)
|
2019-09-12 18:37:55 +00:00
|
|
|
VTKM_TEST_ASSERT(count > 5, assert_msg);
|
2019-10-17 17:17:14 +00:00
|
|
|
#else
|
|
|
|
// The compiler can optimize out the recursive function and any other functions in release
|
|
|
|
// mode, but the backtrace should contain atleast one entry
|
|
|
|
VTKM_TEST_ASSERT(count >= 1, assert_msg);
|
|
|
|
#endif
|
2019-08-29 00:14:07 +00:00
|
|
|
}
|
2019-08-14 23:31:35 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(message, error.GetMessage()), "Message was incorrect");
|
2019-08-29 00:14:07 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(message + "\n" + stackTrace, std::string(error.what())),
|
2019-08-14 23:31:35 +00:00
|
|
|
"what() was incorrect");
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoErrorTest()
|
|
|
|
{
|
2019-09-04 19:03:30 +00:00
|
|
|
VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Check base error messages");
|
2019-08-14 23:31:35 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
RecursiveFunction(0);
|
|
|
|
}
|
|
|
|
catch (const vtkm::cont::Error& e)
|
|
|
|
{
|
|
|
|
ValidateError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
int UnitTestError(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(DoErrorTest, argc, argv);
|
|
|
|
}
|