mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 09:59:12 +00:00
3e1339f9a7
With the major revision 2.0 of VTK-m, many items previously marked as deprecated were removed. If updating to a new version of VTK-m, it is recommended to first update to VTK-m 1.9, which will include the deprecated features but provide warnings (with the right compiler) that will point to the replacement code. Once the deprecations have been fixed, updating to 2.0 should be smoother.
89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
//============================================================================
|
|
// 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/Logging.h>
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
namespace
|
|
{
|
|
|
|
void DoWork()
|
|
{
|
|
VTKM_LOG_SCOPE_FUNCTION(vtkm::cont::LogLevel::Info);
|
|
VTKM_LOG_F(vtkm::cont::LogLevel::Info, "Sleeping for 5 milliseconds...");
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{ 5 });
|
|
}
|
|
|
|
void Scopes(int level = 0)
|
|
{
|
|
VTKM_LOG_SCOPE(vtkm::cont::LogLevel::Info, "Called Scope (level=%d)", level);
|
|
|
|
DoWork();
|
|
|
|
VTKM_LOG_IF_F(vtkm::cont::LogLevel::Info,
|
|
level % 2 != 0,
|
|
"Printing extra log message because level is odd (%d)",
|
|
level);
|
|
if (level < 5)
|
|
{
|
|
VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Recursing to level " << level + 1);
|
|
Scopes(level + 1);
|
|
}
|
|
else
|
|
{
|
|
VTKM_LOG_F(vtkm::cont::LogLevel::Warn, "Reached limit for Scopes test recursion.");
|
|
}
|
|
}
|
|
|
|
void UserDefined()
|
|
{
|
|
VTKM_DEFINE_USER_LOG_LEVEL(CustomLevel, 0);
|
|
VTKM_DEFINE_USER_LOG_LEVEL(CustomLevel2, 2);
|
|
VTKM_DEFINE_USER_LOG_LEVEL(AnotherCustomLevel2, 2);
|
|
VTKM_DEFINE_USER_LOG_LEVEL(BigLevel, 300);
|
|
|
|
vtkm::cont::SetStderrLogLevel(vtkm::cont::LogLevel::UserLast);
|
|
VTKM_LOG_S(CustomLevel, "CustomLevel");
|
|
VTKM_LOG_S(CustomLevel2, "CustomLevel2");
|
|
VTKM_LOG_S(AnotherCustomLevel2, "AnotherCustomLevel2");
|
|
|
|
vtkm::cont::SetStderrLogLevel(vtkm::cont::LogLevel::UserFirst);
|
|
VTKM_LOG_S(BigLevel, "BigLevel"); // should log nothing
|
|
|
|
vtkm::cont::SetStderrLogLevel(vtkm::cont::LogLevel::UserLast);
|
|
VTKM_LOG_S(BigLevel, "BigLevel");
|
|
}
|
|
|
|
void RunTests()
|
|
{
|
|
VTKM_LOG_F(vtkm::cont::LogLevel::Info, "Running tests.");
|
|
|
|
VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Running Scopes test...");
|
|
Scopes();
|
|
|
|
VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Running UserDefined test...");
|
|
UserDefined();
|
|
}
|
|
|
|
} // end anon namespace
|
|
|
|
int UnitTestLogging(int, char*[])
|
|
{
|
|
// Test that parameterless init works:
|
|
VTKM_LOG_S(vtkm::cont::LogLevel::Info, "Log before intialize");
|
|
vtkm::cont::InitLogging();
|
|
|
|
RunTests();
|
|
return 0;
|
|
}
|