timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
testing.hpp File Reference
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include "timemory/backends/dmp.hpp"
#include "timemory/utility/macros.hpp"
+ Include dependency graph for testing.hpp:

Go to the source code of this file.

Macros

#define EXPECT_EQ(lhs, rhs)
 
#define ASSERT_FALSE(expr)
 
#define ASSERT_TRUE(expr)
 
#define rank_cout   std::cout << rank_prefix()
 
#define TEST_SUMMARY(argv_0, ntest_counter, nfail_counter)
 
#define CONFIGURE_TEST_SELECTOR(total_tests)
 
#define RUN_TEST(test_num, func, ntest_counter, nfail_counter)
 

Functions

std::string rank_prefix ()
 

Detailed Description

This is used for C++ testing of the timemory package

Definition in file testing.hpp.

Macro Definition Documentation

◆ ASSERT_FALSE

#define ASSERT_FALSE (   expr)
Value:
if(expr) \
{ \
std::stringstream ss; \
ss << "Expression: ( " << #expr << " ) " \
<< "failed @ line " << __LINE__ << " of " << __FILE__; \
std::cerr << ss.str() << std::endl; \
throw std::runtime_error(ss.str()); \
}

Definition at line 68 of file testing.hpp.

◆ ASSERT_TRUE

#define ASSERT_TRUE (   expr)
Value:
if(!(expr)) \
{ \
std::stringstream ss; \
ss << "Expression: !( " << #expr << " ) " \
<< "failed @ line " << __LINE__ << " of " << __FILE__; \
std::cerr << ss.str() << std::endl; \
throw std::runtime_error(ss.str()); \
}

Definition at line 80 of file testing.hpp.

◆ CONFIGURE_TEST_SELECTOR

#define CONFIGURE_TEST_SELECTOR (   total_tests)
Value:
int total_num_tests = total_tests; \
std::set<int> tests; \
if(argc == 1) \
for(int i = 0; i < total_tests; ++i) \
tests.insert(i + 1); \
for(int i = 1; i < argc; ++i) \
tests.insert(atoi(argv[i]));
char ** argv
Definition: config.cpp:55

Definition at line 131 of file testing.hpp.

◆ EXPECT_EQ

#define EXPECT_EQ (   lhs,
  rhs 
)
Value:
if(lhs != rhs) \
{ \
std::stringstream ss; \
ss << #lhs << " != " << #rhs << " @ line " << __LINE__ << " of " \
<< __FILE__; \
std::cerr << ss.str() << std::endl; \
throw std::runtime_error(ss.str()); \
}

Definition at line 56 of file testing.hpp.

◆ rank_cout

#define rank_cout   std::cout << rank_prefix()

Definition at line 100 of file testing.hpp.

◆ RUN_TEST

#define RUN_TEST (   test_num,
  func,
  ntest_counter,
  nfail_counter 
)
Value:
{ \
if(test_num > total_num_tests || tests.count(test_num) != 0) \
{ \
if(test_num > total_num_tests) \
printf("Warning! Test %i is greater than the specified number of " \
"tests: " \
"%i\n", \
test_num, total_num_tests); \
try \
{ \
ntest_counter += 1; \
func(); \
} catch(std::exception & e) \
{ \
std::cerr << e.what() << std::endl; \
nfail_counter += 1; \
} \
} \
else \
{ \
printf("\n... Skipping test #%i ...\n\n", test_num); \
} \
}

Definition at line 155 of file testing.hpp.

◆ TEST_SUMMARY

#define TEST_SUMMARY (   argv_0,
  ntest_counter,
  nfail_counter 
)
Value:
{ \
std::stringstream rank_sout; \
std::stringstream filler; \
filler.fill('='); \
filler << "#" << std::setw(78) << "" \
<< "#"; \
rank_sout << "\n... [\e[1;33mTESTING COMPLETED\e[0m] ... \n" << std::endl; \
rank_sout << filler.str() << "\n#\n"; \
rank_sout << "#\t" \
<< "[" << argv_0 << "] "; \
if(num_fail > 0) \
rank_sout << "\e[1;31mTESTS FAILED\e[0m: " << nfail_counter << '/' \
<< ntest_counter << std::endl; \
else \
rank_sout << "\e[1;36mTESTS PASSED\e[0m: " \
<< (ntest_counter - nfail_counter) << '/' << ntest_counter \
<< std::endl; \
rank_sout << "#\n" << filler.str() << "\n" << std::endl; \
rank_cout << rank_sout.str(); \
}

Definition at line 103 of file testing.hpp.

Function Documentation

◆ rank_prefix()

std::string rank_prefix ( )
inline

Definition at line 92 of file testing.hpp.

93{
94 std::stringstream ss;
95 if(tim::dmp::is_initialized())
96 ss << "[" << tim::dmp::rank() << "] ";
97 return ss.str();
98}