Support to print out cmdline flags that are supported by the TfLite test delegate providers.

PiperOrigin-RevId: 361091579
Change-Id: I9cbe6b694ff6fc79bfa98e9f86385b338bc3a47f
This commit is contained in:
Chao Mei 2021-03-05 00:46:45 -08:00 committed by TensorFlower Gardener
parent 548976c0de
commit 40655bfd65
2 changed files with 22 additions and 6 deletions

View File

@ -37,7 +37,16 @@ bool KernelTestDelegateProviders::InitFromCmdlineArgs(int* argc,
auto one_flags = one->CreateFlags(&params_);
flags.insert(flags.end(), one_flags.begin(), one_flags.end());
}
return tflite::Flags::Parse(argc, argv, flags);
// Note: when "--help" is passed, the 'Parse' function will return false.
// TODO(b/181868587): The above logic to print out the all supported flags is
// not intuitive, so considering adding the "--help" flag explicitly.
const bool parse_result = tflite::Flags::Parse(argc, argv, flags);
if (!parse_result) {
std::string usage = Flags::Usage(argv[0], flags);
TFLITE_LOG(ERROR) << usage;
}
return parse_result;
}
std::vector<tools::TfLiteDelegatePtr>

View File

@ -22,10 +22,13 @@ limitations under the License.
namespace {
void InitKernelTest(int* argc, char** argv) {
bool InitKernelTest(int* argc, char** argv) {
tflite::KernelTestDelegateProviders* const delegate_providers =
tflite::KernelTestDelegateProviders::Get();
delegate_providers->InitFromCmdlineArgs(argc, const_cast<const char**>(argv));
if (!delegate_providers->InitFromCmdlineArgs(
argc, const_cast<const char**>(argv))) {
return false;
}
if (delegate_providers->ConstParams().Get<bool>("use_nnapi")) {
// In Android Q, the NNAPI delegate avoids delegation if the only device
@ -37,13 +40,17 @@ void InitKernelTest(int* argc, char** argv) {
params->Set("disable_nnapi_cpu", false);
}
}
return true;
}
} // namespace
int main(int argc, char** argv) {
::tflite::LogToStderr();
InitKernelTest(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
if (InitKernelTest(&argc, argv)) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
} else {
return EXIT_FAILURE;
}
}