libMesh
Loading...
Searching...
No Matches
libmesh_cppunit.h
Go to the documentation of this file.
1
2#ifndef LIBMESH_LIBMESH_CPPUNIT_H
3#define LIBMESH_LIBMESH_CPPUNIT_H
4
5// Ignore unused parameter warnings coming from cppunit headers
6#include <libmesh/ignore_warnings.h>
7#include <cppunit/extensions/HelperMacros.h>
8#include <cppunit/TestCase.h>
9#include <libmesh/restore_warnings.h>
10
11#include <libmesh/libmesh_logging.h>
12
13#if defined(LIBMESH_DEFAULT_QUADRUPLE_PRECISION) || \
14 defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
15# define LIBMESH_ASSERT_FP_EQUAL(expected,actual,tolerance) \
16 CPPUNIT_ASSERT_DOUBLES_EQUAL(double((expected)-(actual)),0,double(tolerance))
17#else
18# define LIBMESH_ASSERT_FP_EQUAL(expected,actual,tolerance) \
19 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,tolerance)
20#endif
21
22# define LIBMESH_ASSERT_COMPLEX_EQUAL(expected,actual,tolerance) \
23 do { \
24 LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(expected),libMesh::libmesh_real(actual),tolerance); \
25 LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_imag(expected),libMesh::libmesh_imag(actual),tolerance); \
26 } while (0)
27
28#ifdef LIBMESH_USE_COMPLEX_NUMBERS
29# define LIBMESH_ASSERT_NUMBERS_EQUAL(expected,actual,tolerance) \
30 LIBMESH_ASSERT_COMPLEX_EQUAL(expected,actual,tolerance)
31#else
32# define LIBMESH_ASSERT_NUMBERS_EQUAL(expected,actual,tolerance) \
33 LIBMESH_ASSERT_FP_EQUAL(expected,actual,tolerance)
34#endif
35
36
37#define LIBMESH_ASSERT_REALVEC_EQUAL(expected,actual,tolerance) \
38 do { \
39 VectorValue<Real> expected_vec{expected}; \
40 VectorValue<Real> actual_vec{actual}; \
41 for (int realvec_d=0; realvec_d != LIBMESH_DIM; ++realvec_d) \
42 LIBMESH_ASSERT_FP_EQUAL(expected_vec(realvec_d), actual_vec(realvec_d), tolerance); \
43 } while(0)
44
45// THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
46// std::auto_ptr, which in turn produces -Wdeprecated-declarations
47// warnings. These can be ignored in GCC as long as we wrap the
48// offending code in appropriate pragmas. We can't get away with a
49// single ignore_warnings.h inclusion at the beginning of this file,
50// since the libmesh headers pull in a restore_warnings.h at some
51// point. This should thus be the *last* header included in our test
52// suite files.
53#include <libmesh/ignore_warnings.h>
54#ifdef __clang__
55#pragma clang diagnostic ignored "-Wdeprecated-declarations"
56#endif
57#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
58#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
59#pragma GCC diagnostic push
60#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
61#endif // GCC > 4.5
62#endif // __GNUC__ && !__INTEL_COMPILER
63
64
66
67// Our regular libMesh::PerfItem uses fast_push/pop, so doesn't work
68// well with strings like TestCase::getName() that get destructed
69// before we're done printing logs. Per-unit-test timings are
70// coarse-grained so we can enable them regardless of --enable-perflog
71// setting.
73{
74public:
75 UnitPerfItem(std::string label,
76 std::string header,
77 libMesh::PerfLog & my_perflog) :
78 _label(std::move(label)),
79 _header(std::move(header)),
80 _perflog(my_perflog)
81 {
83 }
84
89
90private:
91 const std::string _label;
92 const std::string _header;
94};
95
96#define LIBMESH_CPPUNIT_TEST_SUITE(ATestFixtureType) \
97 protected: \
98 std::string libmesh_suite_name = #ATestFixtureType; \
99 CPPUNIT_TEST_SUITE(ATestFixtureType)
100
101
102#define LOG_UNIT_TEST UnitPerfItem TOKENPASTE2(perf_item_, __LINE__)(__func__,this->libmesh_suite_name,*unitlog)
103
104
105#endif // LIBMESH_LIBMESH_CPPUNIT_H
UnitPerfItem(std::string label, std::string header, libMesh::PerfLog &my_perflog)
const std::string _header
const std::string _label
libMesh::PerfLog & _perflog
The PerfLog class allows monitoring of specific events.
Definition perf_log.h:154
void pop(const char *label, const char *header="")
Pop the event label off the stack, resuming any lower event.
Definition perf_log.C:185
void push(const char *label, const char *header="")
Push the event label onto the stack, pausing any active event.
Definition perf_log.C:147
libMesh::PerfLog * unitlog
Definition driver.C:220