forked from alibaba/MNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MNNTestSuite.cpp
74 lines (66 loc) · 1.82 KB
/
MNNTestSuite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// MNNTestSuite.cpp
// MNN
//
// Created by MNN on 2019/01/10.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include "MNNTestSuite.h"
#include <stdlib.h>
MNNTestSuite* MNNTestSuite::gInstance = NULL;
MNNTestSuite* MNNTestSuite::get() {
if (gInstance == NULL)
gInstance = new MNNTestSuite;
return gInstance;
}
MNNTestSuite::~MNNTestSuite() {
for (int i = 0; i < mTests.size(); ++i) {
delete mTests[i];
}
mTests.clear();
}
void MNNTestSuite::add(MNNTestCase* test, const char* name) {
test->name = name;
mTests.push_back(test);
}
void MNNTestSuite::run(const char* key) {
if (key == NULL || strlen(key) == 0)
return;
auto suite = MNNTestSuite::get();
std::string prefix = key;
std::vector<std::string> wrongs;
for (int i = 0; i < suite->mTests.size(); ++i) {
MNNTestCase* test = suite->mTests[i];
if (test->name.find(prefix) == 0) {
printf("\trunning %s.\n", test->name.c_str());
auto res = test->run();
if (!res) {
wrongs.emplace_back(test->name);
}
}
}
if (wrongs.empty()) {
printf("√√√ all <%s> tests passed.\n", key);
}
for (auto& wrong : wrongs) {
printf("Error: %s\n", wrong.c_str());
}
}
void MNNTestSuite::runAll() {
auto suite = MNNTestSuite::get();
std::vector<std::string> wrongs;
for (int i = 0; i < suite->mTests.size(); ++i) {
MNNTestCase* test = suite->mTests[i];
printf("\trunning %s.\n", test->name.c_str());
auto res = test->run();
if (!res) {
wrongs.emplace_back(test->name);
}
}
if (wrongs.empty()) {
printf("√√√ all tests passed.\n");
}
for (auto& wrong : wrongs) {
printf("Error: %s\n", wrong.c_str());
}
}