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/runtime.hpp>
8#include <kernel/backend.hpp>
9#include <kernel/util/time_stamp.hpp>
10
11#include <cstring>
12
13using namespace FEAT;
14using namespace FEAT::TestSystem;
15
16int main(int argc, char** argv)
17{
18 // Initialse FEAT runtime
19 FEAT::Runtime::ScopeGuard runtime_scope_guard(argc, argv);
20
21 std::cout << "CTEST_FULL_OUTPUT\n";
22
23 int result(EXIT_SUCCESS);
24
25 TimeStamp t_start;
26
27 if(argc > 1)
28 {
29 bool all_filter(false);
30 std::list<String> labels;
31 for(int i(1) ; i < argc ; ++i)
32 {
33 if (0 == strcmp(argv[i], "and"))
34 {
35 all_filter = true;
36 continue;
37 }
38
39 //discard any unused parameters, marked by "--"
40 if (strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == '-')
41 continue;
42
43 labels.push_back(argv[i]);
44 }
45
46 for(TestList::Iterator i(TestList::instance()->begin_tests()), i_end(TestList::instance()->end_tests()) ;
47 i != i_end ; )
48 {
49 // any_filter: run test if any one label matches
50 if (all_filter == false)
51 {
52 if((find(labels.begin(), labels.end(), (*i)->get_preferred_backend_name()) == labels.end()) &&
53 (find(labels.begin(), labels.end(), (*i)->get_datatype_name()) == labels.end()) &&
54 (find(labels.begin(), labels.end(), (*i)->get_index_name()) == labels.end()) )
55 {
56 i = TestList::instance()->erase(i);
57 continue;
58 }
59 ++i;
60 }
61 // all_filter: run test if every single label matches
62 else
63 {
64 bool deleted(false);
65 for (auto li(labels.begin()) ; li != labels.end() ; ++li)
66 {
67 if(*li != (*i)->get_preferred_backend_name() &&
68 *li != (*i)->get_datatype_name() &&
69 *li != (*i)->get_index_name())
70 {
71 i = TestList::instance()->erase(i);
72 deleted = true;
73 break;
74 }
75 }
76 if (!deleted)
77 ++i;
78 }
79 }
80 }
81
82 size_t list_size(TestList::instance()->size());
83 size_t tests_passed(0u);
84 size_t tests_failed(0u);
85 unsigned long iterator_index(1);
86 for(TestList::Iterator i(TestList::instance()->begin_tests()), i_end(TestList::instance()->end_tests()) ;
87 i != i_end ; )
88 {
89 try
90 {
91 std::cout << "(" << iterator_index << "/" << list_size << ") " << (*i)->id()
92 << " [Preferred Backend: " << (*i)->get_preferred_backend_name() << "]"
93 << " [Precision: "<< (*i)->get_datatype_name() << "]"
94 << " [Indexing: "<< (*i)->get_index_name() << "]"
95 << "\n";
96 Backend::set_preferred_backend((*i)->get_preferred_backend());
97 TimeStamp t1;
98 (*i)->run();
99 TimeStamp t2;
100 std::cout << "PASSED in " << t2.elapsed_string(t1) <<" seconds\n";
101 ++tests_passed;
102 }
103 catch (TestFailedException & e)
104 {
105 std::cout << "FAILED: " << (*i)->id() << "\n" << stringify(e.what()) << "\n";
106 result = EXIT_FAILURE;
107 ++tests_failed;
108 }
109 /*
110 catch(std::exception& e)
111 {
112 std::cout << "CRASHED: " << (*i)->id() << "\n" << stringify(e.what()) << "\n";
113 result = EXIT_FAILURE;
114 ++tests_failed;
115 }
116 catch(...)
117 {
118 std::cout << "CRASHED: " << (*i)->id() << "\ncaught unknown exception\n";
119 result = EXIT_FAILURE;
120 ++tests_failed;
121 }
122 */
123
124 i = TestList::instance()->erase(i);
125 iterator_index++;
126 }
127
128 for(TestList::Iterator i(TestList::instance()->begin_tests()), i_end(TestList::instance()->end_tests()) ;
129 i != i_end ; )
130 {
131 i = TestList::instance()->erase(i);
132 }
133
134 std::cout << "\n";
135 if(result == EXIT_SUCCESS)
136 {
137 std::cout << "All " << list_size << " tests PASSED!\n";
138 }
139 else
140 {
141 std::cout << tests_passed << " of " << list_size << " tests PASSED, "
142 << tests_failed << " tests FAILED!\n";
143 }
144
145 TimeStamp t_end;
146 std::cout << "Total Runtime: " << t_end.elapsed_string(t_start) << " seconds\n";
147
148 return result;
149}
static void set_preferred_backend(PreferredBackend preferred_backend)
set new preferred backend
Definition: backend.cpp:19
Runtime scope guard class.
Definition: runtime.hpp:32
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
Time stamp class.
Definition: time_stamp.hpp:54
String elapsed_string(const TimeStamp &before, TimeFormat format=TimeFormat::s_m) const
Return the time elapsed between two time stamps as a string.
Definition: time_stamp.hpp:253
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:993