aboutsummaryrefslogtreecommitdiff
path: root/tests/InferenceTest.cpp
diff options
context:
space:
mode:
authorJames Ward <james.ward@arm.com>2020-10-12 14:17:36 +0100
committerJames Ward <james.ward@arm.com>2020-10-14 12:41:58 +0000
commitc89829f1f47855227f9a842c979f3a43800ea826 (patch)
tree40d58dfa85ff4f8ebf03f5b594ace1775fae2c22 /tests/InferenceTest.cpp
parentf9f33a04626756b73e6fd5c89092fd4bcb504b16 (diff)
downloadarmnn-c89829f1f47855227f9a842c979f3a43800ea826.tar.gz
IVGCVSW-5280 Switch tests/InferenceTest and derived tests over to cxxopts
* refactor AddCommandLineOptions() functions to allow checking of required options * add CxxoptsUtils.hpp file for convenience functions !referencetests:268500 Signed-off-by: James Ward <james.ward@arm.com> Change-Id: Ica954b210b2981b7cd10995f0d75fcb2a2f7b443
Diffstat (limited to 'tests/InferenceTest.cpp')
-rw-r--r--tests/InferenceTest.cpp66
1 files changed, 32 insertions, 34 deletions
diff --git a/tests/InferenceTest.cpp b/tests/InferenceTest.cpp
index b3b38d1386..3392f6ea51 100644
--- a/tests/InferenceTest.cpp
+++ b/tests/InferenceTest.cpp
@@ -8,7 +8,7 @@
#include <Filesystem.hpp>
#include "../src/armnn/Profiling.hpp"
-#include <boost/program_options.hpp>
+#include <cxxopts/cxxopts.hpp>
#include <fstream>
#include <iostream>
@@ -28,53 +28,51 @@ namespace test
bool ParseCommandLine(int argc, char** argv, IInferenceTestCaseProvider& testCaseProvider,
InferenceTestOptions& outParams)
{
- namespace po = boost::program_options;
-
- po::options_description desc("Options");
+ cxxopts::Options options("InferenceTest", "Inference iteration parameters");
try
{
// Adds generic options needed for all inference tests.
- desc.add_options()
- ("help", "Display help messages")
- ("iterations,i", po::value<unsigned int>(&outParams.m_IterationCount)->default_value(0),
- "Sets the number number of inferences to perform. If unset, a default number will be ran.")
- ("inference-times-file", po::value<std::string>(&outParams.m_InferenceTimesFile)->default_value(""),
- "If non-empty, each individual inference time will be recorded and output to this file")
- ("event-based-profiling,e", po::value<bool>(&outParams.m_EnableProfiling)->default_value(0),
- "Enables built in profiler. If unset, defaults to off.");
+ options
+ .allow_unrecognised_options()
+ .add_options()
+ ("h,help", "Display help messages")
+ ("i,iterations", "Sets the number of inferences to perform. If unset, will only be run once.",
+ cxxopts::value<unsigned int>(outParams.m_IterationCount)->default_value("0"))
+ ("inference-times-file",
+ "If non-empty, each individual inference time will be recorded and output to this file",
+ cxxopts::value<std::string>(outParams.m_InferenceTimesFile)->default_value(""))
+ ("e,event-based-profiling", "Enables built in profiler. If unset, defaults to off.",
+ cxxopts::value<bool>(outParams.m_EnableProfiling)->default_value("0"));
+
+ std::vector<std::string> required; //to be passed as reference to derived inference tests
// Adds options specific to the ITestCaseProvider.
- testCaseProvider.AddCommandLineOptions(desc);
- }
- catch (const std::exception& e)
- {
- // Coverity points out that default_value(...) can throw a bad_lexical_cast,
- // and that desc.add_options() can throw boost::io::too_few_args.
- // They really won't in any of these cases.
- ARMNN_ASSERT_MSG(false, "Caught unexpected exception");
- std::cerr << "Fatal internal error: " << e.what() << std::endl;
- return false;
- }
-
- po::variables_map vm;
+ testCaseProvider.AddCommandLineOptions(options, required);
- try
- {
- po::store(po::parse_command_line(argc, argv, desc), vm);
+ auto result = options.parse(argc, argv);
- if (vm.count("help"))
+ if (result.count("help"))
{
- std::cout << desc << std::endl;
+ std::cout << options.help() << std::endl;
return false;
}
- po::notify(vm);
+ CheckRequiredOptions(result, required);
+
+ }
+ catch (const cxxopts::OptionException& e)
+ {
+ std::cerr << e.what() << std::endl << options.help() << std::endl;
+ return false;
}
- catch (po::error& e)
+ catch (const std::exception& e)
{
- std::cerr << e.what() << std::endl << std::endl;
- std::cerr << desc << std::endl;
+ // Coverity points out that default_value(...) can throw a bad_lexical_cast,
+ // and that desc.add_options() can throw boost::io::too_few_args.
+ // They really won't in any of these cases.
+ ARMNN_ASSERT_MSG(false, "Caught unexpected exception");
+ std::cerr << "Fatal internal error: " << e.what() << std::endl;
return false;
}