Skip to content

Commit

Permalink
CR-1221546, CR-1219147, CR-1219468 (#8732)
Browse files Browse the repository at this point in the history
Signed-off-by: AShivangi <[email protected]>
  • Loading branch information
AShivangi authored Feb 1, 2025
1 parent 74c9888 commit 12c637d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
17 changes: 8 additions & 9 deletions src/runtime_src/core/tools/common/SubCmdExamineInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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<std::string>() : "";
options.m_format = vm.count("format") ? vm["format"].as<std::string>() : "";
options.m_format = vm.count("format") ? vm["format"].as<std::string>() : "JSON";
options.m_output = vm.count("output") ? vm["output"].as<std::string>() : "";
options.m_reportNames = vm.count("report") ? vm["report"].as<std::vector<std::string>>() : std::vector<std::string>();
options.m_help = vm.count("help") ? vm["help"].as<bool>() : false;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/XBHelpMenusCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/runtime_src/core/tools/common/XBMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 12c637d

Please sign in to comment.