Skip to content

Commit

Permalink
Change onnxifi test driver classname (#1396)
Browse files Browse the repository at this point in the history
* change name

* documents
  • Loading branch information
zrphercule authored and houseroad committed Sep 10, 2018
1 parent 0c885cc commit df14e74
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
21 changes: 11 additions & 10 deletions onnx/backend/test/cpp/driver/test_driver.cc
Expand Up @@ -41,7 +41,7 @@ void TestDriver::FetchSingleTestCase(const std::string& case_dir) {
std::string model_name = case_dir;
model_name += "model.onnx";
if (FileExists(model_name)) {
TestCase test_case;
UnsolvedTestCase test_case;
test_case.model_filename_ = model_name;
test_case.model_dirname_ = case_dir;
for (int case_count = 0;; case_count++) {
Expand Down Expand Up @@ -72,7 +72,7 @@ void TestDriver::FetchSingleTestCase(const std::string& case_dir) {
output_filenames.emplace_back(std::move(output_name));
}
}
TestData test_data(input_filenames, output_filenames);
UnsolvedTestData test_data(input_filenames, output_filenames);
test_case.test_data_.emplace_back(std::move(test_data));
}
testcases_.emplace_back(std::move(test_case));
Expand Down Expand Up @@ -161,7 +161,7 @@ bool TestDriver::FetchAllTestCases(const std::string& target) {
return true;
}

std::vector<TestCase> GetTestCase(const std::string& location) {
std::vector<UnsolvedTestCase> GetTestCase(const std::string& location) {
TestDriver test_driver;
test_driver.FetchAllTestCases(location);
return test_driver.testcases_;
Expand All @@ -187,15 +187,15 @@ void LoadSingleFile(const std::string& filename, std::string& filedata) {
}
}

ProtoTestCase LoadSingleTestCase(const TestCase& t) {
ProtoTestCase st;
ResolvedTestCase LoadSingleTestCase(const UnsolvedTestCase& t) {
ResolvedTestCase st;
std::string raw_model;
LoadSingleFile(t.model_filename_, raw_model);
ONNX_NAMESPACE::ParseProtoFromBytes(
&st.model_, raw_model.c_str(), raw_model.size());

for (auto& test_data : t.test_data_) {
ProtoTestData proto_test_data;
ResolvedTestData proto_test_data;

for (auto& input_file : test_data.input_filenames_) {
std::string input_data;
Expand All @@ -217,13 +217,14 @@ ProtoTestCase LoadSingleTestCase(const TestCase& t) {
return st;
}

std::vector<ProtoTestCase> LoadAllTestCases(const std::string& location) {
std::vector<TestCase> t = GetTestCase(location);
std::vector<ResolvedTestCase> LoadAllTestCases(const std::string& location) {
std::vector<UnsolvedTestCase> t = GetTestCase(location);
return LoadAllTestCases(t);
}

std::vector<ProtoTestCase> LoadAllTestCases(const std::vector<TestCase>& t) {
std::vector<ProtoTestCase> st;
std::vector<ResolvedTestCase> LoadAllTestCases(
const std::vector<UnsolvedTestCase>& t) {
std::vector<ResolvedTestCase> st;
for (const auto& i : t) {
st.push_back(LoadSingleTestCase(i));
}
Expand Down
33 changes: 17 additions & 16 deletions onnx/backend/test/cpp/driver/test_driver.h
Expand Up @@ -15,11 +15,11 @@ namespace testing {
* No real data was loaded in this type of class,
* but only data location.
*/
struct TestData {
struct UnsolvedTestData {
std::vector<std::string> input_filenames_;
std::vector<std::string> output_filenames_;
TestData() {}
TestData(
UnsolvedTestData() {}
UnsolvedTestData(
const std::vector<std::string>& input_filenames,
const std::vector<std::string>& output_filenames)
: input_filenames_(input_filenames),
Expand All @@ -32,28 +32,28 @@ struct TestData {
* No real data was loaded in this type of class,
* but only data location.
*/
struct TestCase {
TestCase(
struct UnsolvedTestCase {
UnsolvedTestCase(
const std::string& model_filename,
const std::string& model_dirname,
const std::vector<TestData>& test_data)
const std::vector<UnsolvedTestData>& test_data)
: model_filename_(model_filename),
model_dirname_(model_dirname),
test_data_(test_data) {}

TestCase() {}
UnsolvedTestCase() {}

std::string model_filename_;
std::string model_dirname_;
std::vector<TestData> test_data_;
std::vector<UnsolvedTestData> test_data_;
};

/**
* Store one chunk of test data,
* including raw input/output and protos
* Real data was loaded in this type of class..
*/
struct ProtoTestData {
struct ResolvedTestData {
std::vector<ONNX_NAMESPACE::TensorProto> inputs_;
std::vector<ONNX_NAMESPACE::TensorProto> outputs_;
};
Expand All @@ -63,9 +63,9 @@ struct ProtoTestData {
* including raw model, model proto and several chunks of test data.
* Real data was loaded in this type of class.
*/
struct ProtoTestCase {
struct ResolvedTestCase {
ONNX_NAMESPACE::ModelProto model_;
std::vector<ProtoTestData> proto_test_data_;
std::vector<ResolvedTestData> proto_test_data_;
};

/**
Expand All @@ -76,7 +76,7 @@ class TestDriver {

public:
void SetDefaultDir(const std::string& s);
std::vector<TestCase> testcases_;
std::vector<UnsolvedTestCase> testcases_;
TestDriver(const std::string& default_dir = ".") {
default_dir_ = default_dir_;
}
Expand All @@ -100,7 +100,7 @@ class TestDriver {
void FetchSingleTestCase(const std::string& case_dir);
};

std::vector<TestCase> GetTestCase();
std::vector<UnsolvedTestCase> GetTestCase();

/**
* Load one proto file from filename as string to filedata.
Expand All @@ -110,13 +110,14 @@ void LoadSingleFile(const std::string& filename, std::string& filedata);
/**
* Load one test case.
*/
ProtoTestCase LoadSingleTestCase(const TestCase& t);
ResolvedTestCase LoadSingleTestCase(const UnsolvedTestCase& t);

/**
* Load all test cases.
*/
std::vector<ProtoTestCase> LoadAllTestCases(const std::string& location);
std::vector<ProtoTestCase> LoadAllTestCases(const std::vector<TestCase>& t);
std::vector<ResolvedTestCase> LoadAllTestCases(const std::string& location);
std::vector<ResolvedTestCase> LoadAllTestCases(
const std::vector<UnsolvedTestCase>& t);

} // namespace testing
} // namespace ONNX_NAMESPACE
13 changes: 10 additions & 3 deletions onnx/backend/test/cpp/driver_test.cc
Expand Up @@ -5,6 +5,13 @@
#include "onnx/onnxifi_loader.h"
#include "onnx/string_utils.h"

/**
* In order to not test the backend itself
* but only to test the funcionality of this test driver,
* include IO and integrity checkers,
* please set ONNXIFI_DUMMY_BACKEND to be true when compiling.
* By default it is false.
*/
#ifndef ONNXIFI_DUMMY_BACKEND
#define ONNXIFI_DUMMY_BACKEND false
#endif
Expand All @@ -25,12 +32,12 @@ class CompareOnnxifiData {
}
};
class ONNXCppDriverTest
: public testing::TestWithParam<ONNX_NAMESPACE::testing::ProtoTestCase> {
: public testing::TestWithParam<ONNX_NAMESPACE::testing::ResolvedTestCase> {
protected:
std::vector<ONNX_NAMESPACE::testing::ProtoTestData> protos_;
std::vector<ONNX_NAMESPACE::testing::ResolvedTestData> protos_;
ONNX_NAMESPACE::ModelProto model_;
void SetUp() override {
ONNX_NAMESPACE::testing::ProtoTestCase t = GetParam();
ONNX_NAMESPACE::testing::ResolvedTestCase t = GetParam();
protos_ = t.proto_test_data_;
model_ = t.model_;
}
Expand Down
4 changes: 2 additions & 2 deletions onnx/backend/test/cpp/gtest_utils.cc
@@ -1,5 +1,5 @@
#include "gtest_utils.h"
std::vector<ONNX_NAMESPACE::testing::ProtoTestCase>& GetTestCases() {
static std::vector<ONNX_NAMESPACE::testing::ProtoTestCase> all_test_cases;
std::vector<ONNX_NAMESPACE::testing::ResolvedTestCase>& GetTestCases() {
static std::vector<ONNX_NAMESPACE::testing::ResolvedTestCase> all_test_cases;
return all_test_cases;
}
2 changes: 1 addition & 1 deletion onnx/backend/test/cpp/gtest_utils.h
@@ -1,3 +1,3 @@
#include "gtest/gtest.h"
#include "onnx/backend/test/cpp/driver/test_driver.h"
std::vector<ONNX_NAMESPACE::testing::ProtoTestCase>& GetTestCases();
std::vector<ONNX_NAMESPACE::testing::ResolvedTestCase>& GetTestCases();

0 comments on commit df14e74

Please sign in to comment.