IVGCVSW-7666 Add a FileComparisonExecutor to ExecuteNetwork.

* Implement the "-C" command line option of executenetwork.
* Add a FileComparisonExecutorFile which will read tensors from
  a previously written text file and compare them to the execution
  output.

Signed-off-by: Colm Donelan <colm.donelan@arm.com>
Change-Id: I8380fd263028af13d65a67fb6afd89626d1b07b8
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp
index 199a853..1c5b4fc 100644
--- a/src/armnnTfLiteParser/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/TfLiteParser.cpp
@@ -4876,9 +4876,15 @@
         std::stringstream msg;
         msg << "Cannot find the file (" << fileName << ") errorCode: " << errorCode
             << " " << CHECK_LOCATION().AsString();
-
         throw FileNotFoundException(msg.str());
     }
+    if (!fs::is_regular_file(pathToFile))
+    {
+        // Exclude non regular files.
+        throw InvalidArgumentException(fmt::format("File \"{}\" is not a regular file and cannot be loaded.",
+                                                   pathToFile.c_str()));
+    }
+
     std::ifstream file(fileName, std::ios::binary);
     std::string fileContent((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
     return LoadModelFromBinary(reinterpret_cast<const uint8_t *>(fileContent.c_str()),
diff --git a/src/armnnTfLiteParser/test/TfLiteParser.cpp b/src/armnnTfLiteParser/test/TfLiteParser.cpp
index 65bbaea..841c46e 100644
--- a/src/armnnTfLiteParser/test/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/test/TfLiteParser.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -37,4 +37,20 @@
     CHECK_THROWS_AS((RunTest<4, armnn::DataType::QAsymmU8>(0, { }, { 0 })), armnn::ParseException);
 }
 
+TEST_CASE("ParseInvalidFileName")
+{
+    // Nullptr should throw InvalidArgumentException
+    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile(nullptr), armnn::InvalidArgumentException);
+    // Empty string should throw FileNotFoundException.
+    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile(""), armnn::FileNotFoundException);
+    // Garbage string should throw FileNotFoundException.
+    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("askjfhseuirwqeuiy"),
+                    armnn::FileNotFoundException);
+    // Valid directory should throw InvalidArgumentException
+    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("."), armnn::InvalidArgumentException);
+    // Valid file but not a regular file should throw InvalidArgumentException
+    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("/dev/null"),
+                    armnn::InvalidArgumentException);
+}
+
 }