From 12c637dd3ba7f44bd7989405a8730b521cc2fe84 Mon Sep 17 00:00:00 2001 From: AShivangi <124935354+AShivangi@users.noreply.github.com> Date: Sat, 1 Feb 2025 23:58:05 +0530 Subject: [PATCH] CR-1221546, CR-1219147, CR-1219468 (#8732) Signed-off-by: AShivangi --- .../core/tools/common/SubCmdExamineInternal.cpp | 17 ++++++++--------- .../core/tools/common/XBHelpMenusCore.cpp | 2 +- src/runtime_src/core/tools/common/XBMain.cpp | 9 ++++++++- .../core/tools/xbutil2/SubCmdValidate.cpp | 5 +++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/runtime_src/core/tools/common/SubCmdExamineInternal.cpp b/src/runtime_src/core/tools/common/SubCmdExamineInternal.cpp index cd785fbbbc9..0aee962fb1a 100644 --- a/src/runtime_src/core/tools/common/SubCmdExamineInternal.cpp +++ b/src/runtime_src/core/tools/common/SubCmdExamineInternal.cpp @@ -94,8 +94,7 @@ SubCmdExamineInternal::execute(const SubCmdOptions& _options) const return; } - const auto validated_format = options.m_format.empty() ? "json" : options.m_format; - Report::SchemaVersion schemaVersion = Report::getSchemaDescription(validated_format).schemaVersion; + Report::SchemaVersion schemaVersion = Report::getSchemaDescription(options.m_format).schemaVersion; try{ if (vm.count("output") && options.m_output.empty()) throw xrt_core::error("Output file not specified"); @@ -106,16 +105,16 @@ SubCmdExamineInternal::execute(const SubCmdOptions& _options) const if (vm.count("element") && options.m_elementsFilter.empty()) throw xrt_core::error("No element filter given to be produced"); + if (schemaVersion == Report::SchemaVersion::unknown) + throw xrt_core::error((boost::format("Unknown output format: '%s'") % options.m_format).str()); + // DRC check // When json is specified, make sure an accompanying output file is also specified - if (!options.m_format.empty() && options.m_output.empty()) + if (vm.count("format") && options.m_output.empty()) throw xrt_core::error("Please specify an output file to redirect the json to"); - if (schemaVersion == Report::SchemaVersion::unknown) - throw xrt_core::error((boost::format("ERROR: Unsupported --format option value '%s'. Supported values can be found in --format's help section below.") % validated_format).str()); - if (!options.m_output.empty() && std::filesystem::exists(options.m_output) && !XBU::getForce()) - throw xrt_core::error((boost::format("ERROR: The output file '%s' already exists. Please either remove it or execute this command again with the '--force' option to overwrite it.") % options.m_output).str()); + throw xrt_core::error((boost::format("The output file '%s' already exists. Please either remove it or execute this command again with the '--force' option to overwrite it") % options.m_output).str()); } catch (const xrt_core::error& e) { // Catch only the exceptions that we have generated earlier @@ -206,7 +205,7 @@ SubCmdExamineInternal::execute(const SubCmdOptions& _options) const fOutput << oSchemaOutput.str(); - std::cout << boost::format("Successfully wrote the %s file: %s") % validated_format % options.m_output << std::endl; + std::cout << boost::format("Successfully wrote the %s file: %s") % options.m_format % options.m_output << std::endl; } if (!is_report_output_valid) @@ -215,7 +214,7 @@ SubCmdExamineInternal::execute(const SubCmdOptions& _options) const void SubCmdExamineInternal::fill_option_values(const po::variables_map& vm, SubCmdExamineOptions& options) const { options.m_device = vm.count("device") ? vm["device"].as() : ""; - options.m_format = vm.count("format") ? vm["format"].as() : ""; + options.m_format = vm.count("format") ? vm["format"].as() : "JSON"; options.m_output = vm.count("output") ? vm["output"].as() : ""; options.m_reportNames = vm.count("report") ? vm["report"].as>() : std::vector(); options.m_help = vm.count("help") ? vm["help"].as() : false; diff --git a/src/runtime_src/core/tools/common/XBHelpMenusCore.cpp b/src/runtime_src/core/tools/common/XBHelpMenusCore.cpp index 8fa9c3c6a45..b73104b2f9f 100644 --- a/src/runtime_src/core/tools/common/XBHelpMenusCore.cpp +++ b/src/runtime_src/core/tools/common/XBHelpMenusCore.cpp @@ -303,7 +303,7 @@ XBUtilities::report_commands_help( const std::string &_executable, boost::program_options::positional_options_description emptyPOD; std::string usage = XBU::create_usage_string(_optionDescription, emptyPOD); usage += " [command [commandArgs]]"; - boost::format fmtUsage(fgc_header + "\nUSAGE: " + fgc_usageBody + "%s%s\n" + fgc_reset); + boost::format fmtUsage(fgc_header + "\nUSAGE: " + fgc_usageBody + "%s %s\n" + fgc_reset); std::cout << fmtUsage % _executable % usage; // -- Sort the SubCommands diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index 7434836fcf8..8703b261d2f 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -130,7 +130,14 @@ void main_(int argc, char** argv, // If there is a device value, parse for valid subcommands for this device. SubCmdsCollection devSubCmds; if (!sDevice.empty()) { - const std::string deviceClass = XBU::get_device_class(sDevice, isUserDomain); + std::string deviceClass; + try { + deviceClass = XBU::get_device_class(sDevice, isUserDomain); //can throw + } catch (const std::runtime_error& e) { + // Catch only the exceptions that we have generated earlier + std::cerr << boost::format("ERROR: %s\n") % e.what(); + throw xrt_core::error(std::errc::operation_canceled); + } const auto& configs = JSONConfigurable::parse_configuration_tree(configurations); for (auto & subCmdEntry : _subCmds) { auto it = configs.find(subCmdEntry->getName()); diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp index 41e4fb387e5..3f4c1f097f8 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp @@ -454,8 +454,9 @@ SubCmdValidate::handle_errors_and_validate_tests(const boost::program_options::v if (vm.count("pmode") && options.m_pmode.empty()) throw xrt_core::error("Power mode not specified"); - if (vm.count("format") && options.m_format.empty()) - throw xrt_core::error("Output format not specified"); + // When json is specified, make sure an accompanying output file is also specified + if (vm.count("format") && options.m_output.empty()) + throw xrt_core::error("Please specify an output file to redirect the json to"); if (!options.m_output.empty() && !XBU::getForce() && std::filesystem::exists(options.m_output)) throw xrt_core::error((boost::format("Output file already exists: '%s'") % options.m_output).str());