diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-03-17 14:18:50 -0700 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2021-03-18 00:56:31 +0000 |
commit | c3fbc6cec7c687850712df231c78edc9d48066dc (patch) | |
tree | ff1c151220ee0e416eca78eb141a873475c92a31 /test | |
parent | ed964ba3f17ce9783cdbb76cb34cd664a72232c2 (diff) |
Use singleton pattern for static registered tests.
The original fails with nvcc+msvc - there's a static order of initialization
issue leading to registered tests being cleared. The test then fails on
```
VERIFY(EigenTest::all().size()>0);
```
since `EigenTest` no longer contains any tests. The singleton pattern
fixes this.
Diffstat (limited to 'test')
-rw-r--r-- | test/main.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/test/main.h b/test/main.h index 3e80c9f7d..07f3794ac 100644 --- a/test/main.h +++ b/test/main.h @@ -177,20 +177,22 @@ namespace Eigen EigenTest(const char* a_name, void (*func)(void)) : m_name(a_name), m_func(func) { - ms_registered_tests.push_back(this); + get_registered_tests().push_back(this); } const std::string& name() const { return m_name; } void operator()() const { m_func(); } - static const std::vector<EigenTest*>& all() { return ms_registered_tests; } + static const std::vector<EigenTest*>& all() { return get_registered_tests(); } protected: + static std::vector<EigenTest*>& get_registered_tests() + { + static std::vector<EigenTest*>* ms_registered_tests = new std::vector<EigenTest*>(); + return *ms_registered_tests; + } std::string m_name; void (*m_func)(void); - static std::vector<EigenTest*> ms_registered_tests; }; - std::vector<EigenTest*> EigenTest::ms_registered_tests; - // Declare and register a test, e.g.: // EIGEN_DECLARE_TEST(mytest) { ... } // will create a function: |