From 9fc8c0f0587d798b927ae4364e0b8a6db808c244 Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Wed, 20 Mar 2019 12:46:58 +0000 Subject: Use unique names for temporary files Change-Id: I06653135c5fef38a52995da6c4b6de7ba5786b6a Signed-off-by: Matthew Bentham --- src/armnn/test/CsvReaderTest.cpp | 32 +++++++++++++++++++------------- src/armnnTfLiteParser/test/LoadModel.cpp | 5 +++-- 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/armnn/test/CsvReaderTest.cpp b/src/armnn/test/CsvReaderTest.cpp index 1fa7b93e2c..22d510bcb6 100644 --- a/src/armnn/test/CsvReaderTest.cpp +++ b/src/armnn/test/CsvReaderTest.cpp @@ -10,6 +10,7 @@ #include #include #include +#include using namespace armnnUtils; @@ -28,8 +29,8 @@ struct TestHelper { std::string CreateTempCsvFile() { - std::string fileDir = boost::filesystem::temp_directory_path().c_str(); - boost::filesystem::path p{fileDir + "/sampleFile.csv"}; + boost::filesystem::path fileDir = boost::filesystem::temp_directory_path(); + boost::filesystem::path p{fileDir / boost::filesystem::unique_path("%%%%-%%%%-%%%%.csv")}; try { boost::filesystem::ofstream ofs{p}; @@ -41,7 +42,9 @@ struct TestHelper { std::cerr << "Unable to write to file at location [" << p.c_str() << "] : " << e.what() << std::endl; BOOST_TEST(false); } - return fileDir + "/sampleFile.csv"; + + m_CsvFile = p; + return p.string(); } int CheckStringsMatch(CsvRow &row, unsigned int index, std::string expectedValue) @@ -56,18 +59,21 @@ struct TestHelper { void RemoveCsvFile() { - std::string fileDir = boost::filesystem::temp_directory_path().c_str(); - std::string filePath = fileDir + "/sampleFile.csv"; - try - { - boost::filesystem::remove(filePath); - } - catch (std::exception &e) + if (m_CsvFile) { - std::cerr << "Unable to delete file [" << filePath << "] : " << e.what() << std::endl; - BOOST_TEST(false); + try + { + boost::filesystem::remove(*m_CsvFile); + } + catch (std::exception &e) + { + std::cerr << "Unable to delete file [" << *m_CsvFile << "] : " << e.what() << std::endl; + BOOST_TEST(false); + } } } + + boost::optional m_CsvFile; }; BOOST_AUTO_TEST_SUITE(CsvReaderTest) @@ -121,4 +127,4 @@ BOOST_FIXTURE_TEST_CASE(TestLoadingFileFromDisk, TestHelper) BOOST_CHECK(CheckStringsMatch(row2, 2, "ice") == 0); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnTfLiteParser/test/LoadModel.cpp b/src/armnnTfLiteParser/test/LoadModel.cpp index 2bb05ba15c..ea490106c4 100644 --- a/src/armnnTfLiteParser/test/LoadModel.cpp +++ b/src/armnnTfLiteParser/test/LoadModel.cpp @@ -198,7 +198,8 @@ BOOST_FIXTURE_TEST_CASE(LoadModelFromBinary, LoadModelFixture) BOOST_FIXTURE_TEST_CASE(LoadModelFromFile, LoadModelFixture) { - std::string fname = boost::filesystem::temp_directory_path().string() + "/testtflite.tflite"; + using namespace boost::filesystem; + std::string fname = unique_path(temp_directory_path() / "%%%%-%%%%-%%%%.tflite").string(); bool saved = flatbuffers::SaveFile(fname.c_str(), reinterpret_cast(m_GraphBinary.data()), m_GraphBinary.size(), true); @@ -213,7 +214,7 @@ BOOST_FIXTURE_TEST_CASE(LoadModelFromFile, LoadModelFixture) tflite::CustomOptionsFormat_FLEXBUFFERS); CheckOperator(model->subgraphs[1]->operators[0], 1, { 0, 2 }, { 1 }, tflite::BuiltinOptions_Conv2DOptions, tflite::CustomOptionsFormat_FLEXBUFFERS); - remove(fname.c_str()); + remove(fname); } BOOST_AUTO_TEST_CASE(LoadNullBinary) -- cgit v1.2.1