Merge topic 'add_func_2'

ff4ad96ef Do not print extra information on Kokkos and CUDA.
321571fab Make sure operator precedence is correct over macro invocation.
94a32bf64 Improve code in response to review.
568c0b5d2 Small formatting changes.
a8e25da0a Add __func__ to unit test metadata printed on failure.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland <kmorel@acm.org>
Merge-request: !2469
This commit is contained in:
Nick Thompson 2021-04-12 21:52:58 +00:00 committed by Kitware Robot
commit e64a3ce4d4
4 changed files with 71 additions and 42 deletions

@ -26,8 +26,33 @@
#include <vtkm/cont/testing/vtkm_cont_testing_export.h>
#include <sstream>
#include <vtkm/thirdparty/diy/diy.h>
// We could, conceivably, use CUDA or Kokkos specific print statements here.
// But we cannot use std::stringstream on device, so for now, we'll just accept
// that on CUDA and Kokkos we print less actionalble information.
#if defined(VTKM_ENABLE_CUDA) || defined(VTKM_ENABLE_KOKKOS)
#define VTKM_MATH_ASSERT(condition, message) \
{ \
if (!(condition)) \
{ \
this->RaiseError(message); \
} \
}
#else
#define VTKM_MATH_ASSERT(condition, message) \
{ \
if (!(condition)) \
{ \
std::stringstream ss; \
ss << "\n\tError at " << __FILE__ << ":" << __LINE__ << ":" << __func__ << "\n\t" << message \
<< "\n"; \
this->RaiseError(ss.str().c_str()); \
} \
}
#endif
namespace opt = vtkm::cont::internal::option;
namespace vtkm
@ -141,26 +166,26 @@ public:
{
function();
}
catch (vtkm::testing::Testing::TestFailure& error)
catch (vtkm::testing::Testing::TestFailure const& error)
{
std::cout << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << std::endl
<< error.GetMessage() << std::endl;
std::cerr << "Error at " << error.GetFile() << ":" << error.GetLine() << ":"
<< error.GetFunction() << "\n\t" << error.GetMessage() << "\n";
return 1;
}
catch (vtkm::cont::Error& error)
catch (vtkm::cont::Error const& error)
{
std::cout << "***** Uncaught VTKm exception thrown." << std::endl
<< error.GetMessage() << std::endl;
std::cerr << "Uncaught VTKm exception thrown.\n" << error.GetMessage() << "\n";
std::cerr << "Stacktrace:\n" << error.GetStackTrace() << "\n";
return 1;
}
catch (std::exception& error)
catch (std::exception const& error)
{
std::cout << "***** STL exception throw." << std::endl << error.what() << std::endl;
std::cerr << "STL exception throw.\n" << error.what() << "\n";
return 1;
}
catch (...)
{
std::cout << "***** Unidentified exception thrown." << std::endl;
std::cerr << "Unidentified exception thrown.\n";
return 1;
}
return 0;
@ -179,24 +204,24 @@ public:
}
catch (vtkm::testing::Testing::TestFailure& error)
{
std::cout << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << std::endl
<< error.GetMessage() << std::endl;
std::cerr << "Error at " << error.GetFile() << ":" << error.GetLine() << ":"
<< error.GetFunction() << "\n\t" << error.GetMessage() << "\n";
return 1;
}
catch (vtkm::cont::Error& error)
{
std::cout << "***** Uncaught VTKm exception thrown." << std::endl
<< error.GetMessage() << std::endl;
std::cerr << "Uncaught VTKm exception thrown.\n" << error.GetMessage() << "\n";
std::cerr << "Stacktrace:\n" << error.GetStackTrace() << "\n";
return 1;
}
catch (std::exception& error)
{
std::cout << "***** STL exception throw." << std::endl << error.what() << std::endl;
std::cerr << "STL exception throw.\n\t" << error.what() << "\n";
return 1;
}
catch (...)
{
std::cout << "***** Unidentified exception thrown." << std::endl;
std::cerr << "Unidentified exception thrown.\n";
return 1;
}
return 0;

@ -66,13 +66,14 @@
#define VTKM_TEST_ASSERT(...) \
::vtkm::testing::Testing::Assert( \
VTKM_STRINGIFY_FIRST(__VA_ARGS__), __FILE__, __LINE__, __VA_ARGS__)
VTKM_STRINGIFY_FIRST(__VA_ARGS__), __FILE__, __LINE__, __func__, __VA_ARGS__)
/// \def VTKM_TEST_FAIL(messages..)
///
/// Causes a test to fail with the given \a messages. At least one argument must be given.
#define VTKM_TEST_FAIL(...) ::vtkm::testing::Testing::TestFail(__FILE__, __LINE__, __VA_ARGS__)
#define VTKM_TEST_FAIL(...) \
::vtkm::testing::Testing::TestFail(__FILE__, __LINE__, __func__, __VA_ARGS__)
class TestEqualResult
{
@ -295,9 +296,13 @@ public:
{
public:
template <typename... Ts>
VTKM_CONT TestFailure(const std::string& file, vtkm::Id line, Ts&&... messages)
VTKM_CONT TestFailure(const std::string& file,
vtkm::Id line,
const char* func,
Ts&&... messages)
: File(file)
, Line(line)
, Func(func)
{
std::stringstream messageStream;
this->AppendMessages(messageStream, std::forward<Ts>(messages)...);
@ -306,6 +311,7 @@ public:
VTKM_CONT const std::string& GetFile() const { return this->File; }
VTKM_CONT vtkm::Id GetLine() const { return this->Line; }
VTKM_CONT const char* GetFunction() const { return this->Func; }
VTKM_CONT const std::string& GetMessage() const { return this->Message; }
private:
@ -347,6 +353,7 @@ public:
std::string File;
vtkm::Id Line;
const char* Func;
std::string Message;
};
@ -354,6 +361,7 @@ public:
static VTKM_CONT void Assert(const std::string& conditionString,
const std::string& file,
vtkm::Id line,
const char* func,
bool condition,
Ts&&... messages)
{
@ -363,30 +371,36 @@ public:
}
else
{
throw TestFailure(file, line, std::forward<Ts>(messages)..., " (", conditionString, ")");
throw TestFailure(
file, line, func, std::forward<Ts>(messages)..., " (", conditionString, ")");
}
}
static VTKM_CONT void Assert(const std::string& conditionString,
const std::string& file,
const char* func,
vtkm::Id line,
bool condition)
{
Assert(conditionString, file, line, condition, "Test assertion failed");
Assert(conditionString, file, line, func, condition, "Test assertion failed");
}
static VTKM_CONT void Assert(const std::string& conditionString,
const std::string& file,
const char* func,
vtkm::Id line,
const TestEqualResult& result)
{
Assert(conditionString, file, line, static_cast<bool>(result), result.GetMergedMessage());
Assert(conditionString, file, line, func, static_cast<bool>(result), result.GetMergedMessage());
}
template <typename... Ts>
static VTKM_CONT void TestFail(const std::string& file, vtkm::Id line, Ts&&... messages)
static VTKM_CONT void TestFail(const std::string& file,
vtkm::Id line,
const char* func,
Ts&&... messages)
{
throw TestFailure(file, line, std::forward<Ts>(messages)...);
throw TestFailure(file, line, func, std::forward<Ts>(messages)...);
}
#ifndef VTKM_TESTING_IN_CONT
@ -433,20 +447,21 @@ public:
{
function();
}
catch (TestFailure& error)
catch (TestFailure const& error)
{
std::cout << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << std::endl
<< error.GetMessage() << std::endl;
std::cerr << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << ":"
<< error.GetFunction() << "\n"
<< error.GetMessage() << "\n";
return 1;
}
catch (std::exception& error)
catch (std::exception const& error)
{
std::cout << "***** STL exception throw." << std::endl << error.what() << std::endl;
std::cerr << "***** STL exception throw.\n" << error.what() << "\n";
return 1;
}
catch (...)
{
std::cout << "***** Unidentified exception thrown." << std::endl;
std::cerr << "***** Unidentified exception thrown.\n";
return 1;
}
return 0;

@ -20,12 +20,6 @@
#include <vtkm/cont/testing/Testing.h>
#define VTKM_MATH_ASSERT(condition, message) \
if (!(condition)) \
{ \
this->RaiseError(message); \
}
//-----------------------------------------------------------------------------
namespace
{

@ -20,11 +20,6 @@
#include <limits>
#define VTKM_MATH_ASSERT(condition, message) \
if (!(condition)) \
{ \
this->RaiseError(message); \
}
//-----------------------------------------------------------------------------
namespace UnitTestMathNamespace
@ -921,7 +916,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
"Float distance for difference of products is which exceeds 1.5; this is in violation of a "
"theorem "
"proved by Jeannerod in doi.org/10.1090/S0025-5718-2013-02679-8. Is your build compiled "
"with fma's enabled?");
"with FMAs enabled?");
#endif
}
@ -1088,7 +1083,7 @@ struct BitOpTests : public vtkm::exec::FunctorBase
VTKM_MATH_ASSERT(test_equal(vtkm::CountSetBits(word), this->DumbCountBits(word)),
"CountBits returned wrong value.");
VTKM_MATH_ASSERT(test_equal(vtkm::FindFirstSetBit(word), this->DumbFindFirstSetBit(word)),
"FindFirstSetBit returned wrong value.")
"FindFirstSetBit returned wrong value.");
}
VTKM_EXEC vtkm::Int32 DumbCountBits(T word) const