6 #include <boost/test/unit_test.hpp> 8 #include "../QuantizationDataSet.hpp" 14 #define BOOST_FILESYSTEM_NO_DEPRECATED 16 #include <boost/filesystem/operations.hpp> 17 #include <boost/filesystem/fstream.hpp> 18 #include <boost/filesystem/path.hpp> 19 #include <boost/optional/optional.hpp> 24 struct CsvTestHelper {
28 BOOST_TEST_MESSAGE(
"setup fixture");
33 BOOST_TEST_MESSAGE(
"teardown fixture");
37 std::string CreateTempCsvFile(std::map<
int, std::vector<float>> csvData)
39 boost::filesystem::path fileDir = boost::filesystem::temp_directory_path();
40 boost::filesystem::path p{fileDir / boost::filesystem::unique_path(
"%%%%-%%%%-%%%%.csv")};
42 boost::filesystem::path tensorInput1{fileDir / boost::filesystem::unique_path(
"input_0_0.raw")};
43 boost::filesystem::path tensorInput2{fileDir / boost::filesystem::unique_path(
"input_1_0.raw")};
44 boost::filesystem::path tensorInput3{fileDir / boost::filesystem::unique_path(
"input_2_0.raw")};
48 boost::filesystem::ofstream ofs{p};
50 boost::filesystem::ofstream ofs1{tensorInput1};
51 boost::filesystem::ofstream ofs2{tensorInput2};
52 boost::filesystem::ofstream ofs3{tensorInput3};
55 for(
auto entry : csvData.at(0))
59 for(
auto entry : csvData.at(1))
63 for(
auto entry : csvData.at(2))
68 ofs <<
"0, 0, " << tensorInput1.c_str() << std::endl;
69 ofs <<
"2, 0, " << tensorInput3.c_str() << std::endl;
70 ofs <<
"1, 0, " << tensorInput2.c_str() << std::endl;
77 catch (std::exception &e)
79 std::cerr <<
"Unable to write to file at location [" << p.c_str() <<
"] : " << e.what() << std::endl;
98 boost::filesystem::remove(*m_CsvFile);
100 catch (std::exception &e)
102 std::cerr <<
"Unable to delete file [" << *m_CsvFile <<
"] : " << e.what() << std::endl;
108 boost::optional<boost::filesystem::path> m_CsvFile;
117 std::map<int, std::vector<float>> csvData;
118 csvData.insert(std::pair<
int, std::vector<float>>(0, { 0.111111f, 0.222222f, 0.333333f }));
119 csvData.insert(std::pair<
int, std::vector<float>>(1, { 0.444444f, 0.555555f, 0.666666f }));
120 csvData.insert(std::pair<
int, std::vector<float>>(2, { 0.777777f, 0.888888f, 0.999999f }));
122 std::string myCsvFile = CsvTestHelper::CreateTempCsvFile(csvData);
124 BOOST_TEST(!dataSet.
IsEmpty());
129 BOOST_TEST(input.GetPassId() == csvRow);
131 BOOST_TEST(input.GetLayerBindingIds().size() == 1);
132 BOOST_TEST(input.GetLayerBindingIds()[0] == 0);
133 BOOST_TEST(input.GetDataForEntry(0).size() == 3);
137 BOOST_TEST(input.GetDataForEntry(0).at(0) == csvData.at(csvRow).at(0));
138 BOOST_TEST(input.GetDataForEntry(0).at(1) == csvData.at(csvRow).at(1));
139 BOOST_TEST(input.GetDataForEntry(0).at(2) == csvData.at(csvRow).at(2));
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
QuantizationDataSet is a structure which is created after parsing a quantization CSV file...
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(CheckDataSet, CsvTestHelper)