Skip to content

Commit 3a2ca8f

Browse files
committed
Polish the unittest.
1 parent 5fc0bc5 commit 3a2ca8f

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

tests/test.h

+13
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@
55
#include <stdexcept>
66
#include <vector>
77
#include <random>
8+
#include <string>
89

910
#include <ctc.h>
1011

12+
#define CHECK_STATUS(func_call, status) \
13+
{ \
14+
bool s = func_call; \
15+
std::string funcname = #func_call; \
16+
if (s) { \
17+
std::cout << "-- TEST " << funcname << " PASS!\n"; \
18+
} else { \
19+
std::cout << "-- TEST " << funcname << " FAILED!\n"; \
20+
} \
21+
status &= s; \
22+
}
23+
1124
inline void throw_on_error(ctcStatus_t status, const char* message) {
1225
if (status != CTC_STATUS_SUCCESS) {
1326
throw std::runtime_error(message + (", stat = " +

tests/test_cpu.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,16 @@ int main(void) {
374374
std::cout << "Running CPU tests" << std::endl;
375375

376376
bool status = true;
377-
status &= small_test();
378-
status &= options_test();
379-
status &= inf_test();
380-
status &= run_tests();
377+
CHECK_STATUS(small_test(), status);
378+
CHECK_STATUS(options_test(), status);
379+
CHECK_STATUS(inf_test(), status);
380+
CHECK_STATUS(run_tests(), status);
381381

382382
if (status) {
383-
std::cout << "Tests pass" << std::endl;
383+
std::cout << "All tests PASS!" << std::endl;
384384
return 0;
385385
} else {
386-
std::cout << "Some or all tests fail" << std::endl;
386+
std::cout << "Some or all tests FAILED!" << std::endl;
387387
return 1;
388388
}
389389
}

tests/test_gpu.cu

+6-6
Original file line numberDiff line numberDiff line change
@@ -678,16 +678,16 @@ int main(void) {
678678
#endif
679679

680680
bool status = true;
681-
status &= small_test();
682-
status &= options_test();
683-
status &= inf_test();
684-
status &= run_tests();
681+
CHECK_STATUS(small_test(), status);
682+
CHECK_STATUS(options_test(), status);
683+
CHECK_STATUS(inf_test(), status);
684+
CHECK_STATUS(run_tests(), status);
685685

686686
if (status) {
687-
std::cout << "Tests pass" << std::endl;
687+
std::cout << "All tests PASS!" << std::endl;
688688
return 0;
689689
} else {
690-
std::cout << "Some or all tests fail" << std::endl;
690+
std::cout << "Some or all tests FAILED!" << std::endl;
691691
return 1;
692692
}
693693
}

0 commit comments

Comments
 (0)