Changeset 6677 for trunk/UNIT_TESTER/UnitTester.cxx
- Timestamp:
- 14/07/10 11:15:19 (23 months ago)
- Files:
-
- 1 modified
-
trunk/UNIT_TESTER/UnitTester.cxx (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/UNIT_TESTER/UnitTester.cxx
r6451 r6677 18 18 #include <cstdlib> 19 19 #include <cstdio> 20 21 #include <sys/time.h> 20 22 21 23 #define SIMPLE_ARB_ASSERT … … 72 74 } 73 75 74 static UnitTestResult execute_guarded(UnitTest_function fun) { 76 #define SECOND 1000000 77 78 static UnitTestResult execute_guarded(UnitTest_function fun, long *duration_usec) { 75 79 SigHandler old_handler = signal(SIGSEGV, UT_sigsegv_handler); 80 UnitTestResult result = TEST_OK; 81 timeval t1, t2; 76 82 int trapped = setjmp(UT_return_after_segv); 77 UnitTestResult result = TEST_OK;78 83 79 84 if (trapped) { // trapped … … 83 88 else { // normal execution 84 89 inside_test = true; 90 gettimeofday(&t1, NULL); 85 91 fun(); 86 92 } 93 94 gettimeofday(&t2, NULL); 95 *duration_usec = (t2.tv_sec - t1.tv_sec) * SECOND + (t2.tv_usec - t1.tv_usec); 96 87 97 inside_test = false; 88 98 signal(SIGSEGV, old_handler); … … 96 106 const UnitTest_simple *tests; 97 107 size_t count; 108 double duration_ms; 98 109 99 110 bool perform(size_t which); 100 111 101 112 public: 102 113 SimpleTester(const UnitTest_simple *tests_) … … 108 119 size_t perform_all(); 109 120 size_t get_test_count() const { return count; } 121 122 double overall_duration_ms() const { return duration_ms; } 110 123 }; 111 124 … … 126 139 ut_assert(which<count); 127 140 128 const UnitTest_simple& test = tests[which]; 129 UnitTest_function fun = test.fun; 130 UnitTestResult result = execute_guarded(fun); 141 const UnitTest_simple& test = tests[which]; 142 UnitTest_function fun = test.fun; 131 143 132 trace("* %s = %s\n", test.name, readable_result[result]); 144 long duration_usec; 145 UnitTestResult result = execute_guarded(fun, &duration_usec); 146 double duration_ms_this = duration_usec/1000.0; 147 148 duration_ms += duration_ms_this; 149 trace("* %s = %s (%.1f ms)\n", test.name, readable_result[result], duration_ms_this); 133 150 if (result != TEST_OK) { 134 151 fprintf(stderr, "%s: Error: %s failed (details above)\n", test.location, test.name); … … 144 161 size_t tests = 0; 145 162 size_t passed = 0; 163 double duration_ms; 146 164 147 165 { 148 166 SimpleTester simple_tester(simple_tests); 149 167 150 tests = simple_tester.get_test_count();168 tests = simple_tester.get_test_count(); 151 169 if (tests) passed = simple_tester.perform_all(); 170 duration_ms = simple_tester.overall_duration_ms(); 152 171 } 153 172 154 173 if (tests>0) { 155 174 if (passed == tests) { 156 trace("all unit tests for '%s' passed OK \n", libname);175 trace("all unit tests for '%s' passed OK (%.0f ms)\n\n", libname, duration_ms); 157 176 } 158 177 else { 159 trace("unit tests for '%s': %zu OK / %zu FAILED \n", libname, passed, tests-passed);178 trace("unit tests for '%s': %zu OK / %zu FAILED (%.0f ms)\n\n", libname, passed, tests-passed, duration_ms); 160 179 } 161 180 } 162 181 else { 163 trace("No tests defined for '%s'\n ", libname);182 trace("No tests defined for '%s'\n\n", libname); 164 183 } 165 184
