aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthew Sloyan <matthew.sloyan@arm.com>2020-09-25 11:43:32 +0100
committerMatthew Sloyan <matthew.sloyan@arm.com>2020-10-01 17:29:23 +0100
commit620e0732abede92f505f69d7676bfbd9b5d4584f (patch)
treef80959e116f53ca76e0bdb26a72d6883ef18829e /tests
parent1a758d063a1c1bf6574bf8df78ed2bcc517e93a6 (diff)
downloadarmnn-620e0732abede92f505f69d7676bfbd9b5d4584f.tar.gz
IVGCVSW-5281 Switch tests/ImageCSVFileGenerator over to cxxopts
Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com> Change-Id: I1b2ba4fcaebbafb70693b83b40b79db0071b4522
Diffstat (limited to 'tests')
-rw-r--r--tests/ImageCSVFileGenerator/ImageCSVFileGenerator.cpp128
1 files changed, 80 insertions, 48 deletions
diff --git a/tests/ImageCSVFileGenerator/ImageCSVFileGenerator.cpp b/tests/ImageCSVFileGenerator/ImageCSVFileGenerator.cpp
index 0d2252dfc9..5405df9e16 100644
--- a/tests/ImageCSVFileGenerator/ImageCSVFileGenerator.cpp
+++ b/tests/ImageCSVFileGenerator/ImageCSVFileGenerator.cpp
@@ -4,7 +4,8 @@
//
#include <Filesystem.hpp>
-#include <boost/program_options.hpp>
+#include <cxxopts/cxxopts.hpp>
+#include <boost/range/iterator_range.hpp>
#include <algorithm>
#include <fstream>
@@ -20,6 +21,50 @@ namespace
class CommandLineProcessor
{
public:
+ bool ParseOptions(cxxopts::ParseResult& result)
+ {
+ // indir is mandatory, dir could possibly be changed.
+ if (result.count("indir"))
+ {
+ std::string dir = result["indir"].as<std::string>();
+
+ if (!ValidateDirectory(dir))
+ {
+ return false;
+ }
+
+ m_InputDirectory = dir;
+ }
+ else
+ {
+ std::cerr << "-i/--indir parameter is mandatory." << std::endl;
+ return false;
+ }
+
+ // outfile is mandatory
+ if (result.count("outfile"))
+ {
+ if (!ValidateOutputFile(result["outfile"].as<std::string>()))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ std::cerr << "-o/--outfile parameter is mandatory." << std::endl;
+ return false;
+ }
+
+ if (result.count("layer-binding-id"))
+ {
+ if(!ValidateBindingId(result["layer-binding-id"].as<std::string>()))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
bool ValidateDirectory(std::string& dir)
{
if (dir.empty())
@@ -48,7 +93,7 @@ public:
return true;
}
- bool ValidateOutputFile(std::string& outputFileName)
+ bool ValidateOutputFile(const std::string& outputFileName)
{
if (outputFileName.empty())
{
@@ -80,70 +125,57 @@ public:
bool ValidateBindingId(const std::string& id)
{
- if (!std::all_of(id.begin(), id.end(), ::isdigit))
- {
- std::cerr << "Invalid input binding Id" << std::endl;
- return false;
- }
+ if (!std::all_of(id.begin(), id.end(), ::isdigit))
+ {
+ std::cerr << "Invalid input binding Id" << std::endl;
+ return false;
+ }
return true;
}
bool ProcessCommandLine(int argc, char* argv[])
{
- namespace po = boost::program_options;
-
- po::options_description desc("Options");
- try
- {
- desc.add_options()
- ("help,h", "Display help messages")
- ("indir,i", po::value<std::string>(&m_InputDirectory)->required(),
- "Directory that .raw files are stored in")
- ("outfile,o", po::value<std::string>(&m_OutputFileName)->required(),
- "Output CSV file path")
- ("layer-binding-id,l", po::value<std::string>(&m_InputBindingId)->default_value("0"),
- "Input layer binding Id, Defaults to 0");
- }
- catch (const std::exception& e)
- {
- std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl;
- return false;
- }
-
- po::variables_map vm;
-
try
{
- po::store(po::parse_command_line(argc, argv, desc), vm);
-
- if (vm.count("help"))
+ cxxopts::Options options("ImageCSVFileGenerator",
+ "Program for creating a CSV file that "
+ "contains a list of .raw tensor files. "
+ "These .raw tensor files can be generated using the ImageTensorGenerator");
+
+ options.add_options()
+ ("h,help", "Display help messages")
+ ("i,indir",
+ "Directory that .raw files are stored in",
+ cxxopts::value<std::string>(m_InputDirectory))
+ ("o,outfile",
+ "Output CSV file path",
+ cxxopts::value<std::string>(m_OutputFileName))
+ ("l, layer-binding-id",
+ "Input layer binding Id, Defaults to 0",
+ cxxopts::value<std::string>(m_InputBindingId)->default_value("0"));
+
+ auto result = options.parse(argc, argv);
+
+ if (result.count("help"))
{
- std::cout << desc << std::endl;
+ std::cout << options.help() << std::endl;
return false;
}
- po::notify(vm);
+ // Check for mandatory parameters and validate inputs
+ if(!ParseOptions(result)){
+ return false;
+ }
}
- catch (const po::error& e)
+ catch (const cxxopts::OptionException& e)
{
std::cerr << e.what() << std::endl << std::endl;
- std::cerr << desc << std::endl;
- return false;
- }
-
- if (!ValidateDirectory(m_InputDirectory))
- {
return false;
}
-
- if (!ValidateOutputFile(m_OutputFileName))
- {
- return false;
- }
-
- if(!ValidateBindingId(m_InputBindingId))
+ catch (const std::exception& e)
{
+ std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl;
return false;
}