FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
test_system.cpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
7#include <kernel/util/memory_pool.hpp>
8#include <kernel/runtime.hpp>
9
10#include <cstring>
11
12using namespace FEAT;
13using namespace FEAT::TestSystem;
14
15int main(int argc, char** argv)
16{
17 // Initialse FEAT runtime
18 FEAT::Runtime::ScopeGuard runtime_scope_guard(argc, argv);
19
20 std::cout << "CTEST_FULL_OUTPUT\n";
21
22 int result(EXIT_SUCCESS);
23
24 if(argc > 1)
25 {
26 bool all_filter(false);
27 std::list<String> labels;
28 for(int i(1) ; i < argc ; ++i)
29 {
30 if (0 == strcmp(argv[i], "and"))
31 {
32 all_filter = true;
33 continue;
34 }
35
36 //discard any unused parameters, marked by "--"
37 if (strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == '-')
38 continue;
39
40 labels.push_back(argv[i]);
41 }
42
43 for(TestList::Iterator i(TestList::instance()->begin_tests()), i_end(TestList::instance()->end_tests()) ;
44 i != i_end ; )
45 {
46 // any_filter: run test if any one label matches
47 if (all_filter == false)
48 {
49 if((find(labels.begin(), labels.end(), (*i)->get_preferred_backend_name()) == labels.end()) &&
50 (find(labels.begin(), labels.end(), (*i)->get_datatype_name()) == labels.end()) &&
51 (find(labels.begin(), labels.end(), (*i)->get_index_name()) == labels.end()) )
52 {
53 i = TestList::instance()->erase(i);
54 continue;
55 }
56 ++i;
57 }
58 // all_filter: run test if every single label matches
59 else
60 {
61 bool deleted(false);
62 for (auto li(labels.begin()) ; li != labels.end() ; ++li)
63 {
64 if(*li != (*i)->get_preferred_backend_name() &&
65 *li != (*i)->get_datatype_name() &&
66 *li != (*i)->get_index_name())
67 {
68 i = TestList::instance()->erase(i);
69 deleted = true;
70 break;
71 }
72 }
73 if (!deleted)
74 ++i;
75 }
76 }
77 }
78
79 size_t list_size(TestList::instance()->size());
80 size_t tests_passed(0u);
81 size_t tests_failed(0u);
82 unsigned long iterator_index(1);
83 for(TestList::Iterator i(TestList::instance()->begin_tests()), i_end(TestList::instance()->end_tests()) ;
84 i != i_end ; )
85 {
86 try
87 {
88 std::cout << "(" << iterator_index << "/" << list_size << ") " << (*i)->id()
89 << " [Preferred Backend: " << (*i)->get_preferred_backend_name() << "]"
90 << " [Precision: "<< (*i)->get_datatype_name() << "]"
91 << " [Indexing: "<< (*i)->get_index_name() << "]"
92 << "\n";
93 Backend::set_preferred_backend((*i)->get_preferred_backend());
94 (*i)->run();
95 std::cout << "PASSED\n";
96 ++tests_passed;
97 }
98 catch (TestFailedException & e)
99 {
100 std::cout << "FAILED: " << (*i)->id() << "\n" << stringify(e.what()) << "\n";
101 result = EXIT_FAILURE;
102 ++tests_failed;
103 }
104 catch(std::exception& e)
105 {
106 std::cout << "CRASHED: " << (*i)->id() << "\n" << stringify(e.what()) << "\n";
107 result = EXIT_FAILURE;
108 ++tests_failed;
109 }
110 catch(...)
111 {
112 std::cout << "CRASHED: " << (*i)->id() << "\ncaught unknown exception\n";
113 result = EXIT_FAILURE;
114 ++tests_failed;
115 }
116
117 i = TestList::instance()->erase(i);
118 iterator_index++;
119 }
120
121 for(TestList::Iterator i(TestList::instance()->begin_tests()), i_end(TestList::instance()->end_tests()) ;
122 i != i_end ; )
123 {
124 i = TestList::instance()->erase(i);
125 }
126
127 if(result == EXIT_SUCCESS)
128 {
129 std::cout << "All " << list_size << " tests PASSED!\n";
130 }
131 else
132 {
133 std::cout << tests_passed << " of " << list_size << " tests PASSED, "
134 << tests_failed << " tests FAILED!\n";
135 }
136
137 return result;
138}
static void set_preferred_backend(PreferredBackend preferred_backend)
set new preferred backend
Definition: backend.cpp:16
Runtime scope guard class.
Definition: runtime.hpp:38
exception thrown by the check method in UnitTest
Definition: test_system.hpp:45
virtual const char * what() const noexcept override
description
Definition: test_system.hpp:85
static TestList * instance()
Returns the instance.
std::list< UnitTest * >::iterator Iterator
TestList forward iterator.
Iterator erase(Iterator i)
removes iterator target from the TestList
TestSystem namespace.
Definition: test_system.hpp:38
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944