Skip to content

Commit

Permalink
Fix for CR-1214058 : xrt-smi shows Alveo help when invoked with inval…
Browse files Browse the repository at this point in the history
…id args (#8483)

* Fix for CR-1214058

Signed-off-by: Akshay Tondak <[email protected]>

* Added empty elements check to make the behavior uniform

Signed-off-by: Akshay Tondak <[email protected]>

* Added operation cancelled string back since it didn't make xrt-smi to fail completely

Signed-off-by: Akshay Tondak <[email protected]>

* Error handling code cleanup for xrt-smi validate

Signed-off-by: Akshay Tondak <[email protected]>

---------

Signed-off-by: Akshay Tondak <[email protected]>
Co-authored-by: Akshay Tondak <[email protected]>
  • Loading branch information
aktondak and Akshay Tondak authored Oct 3, 2024
1 parent 81fffb0 commit e0cfdb2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 53 deletions.
5 changes: 4 additions & 1 deletion src/runtime_src/core/tools/common/SubCmdExamineInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ SubCmdExamineInternal::SubCmdExamineInternal(bool _isHidden, bool _isDepricated,

if (m_isUserDomain)
m_hiddenOptions.add_options()
("element,e", boost::program_options::value<decltype(m_elementsFilter)>(&m_elementsFilter)->multitoken(), "Filters individual elements(s) from the report. Format: '/<key>/<key>/...'")
("element,e", boost::program_options::value<decltype(m_elementsFilter)>(&m_elementsFilter)->multitoken()->zero_tokens(), "Filters individual elements(s) from the report. Format: '/<key>/<key>/...'")
;
}

Expand Down Expand Up @@ -138,6 +138,9 @@ SubCmdExamineInternal::execute(const SubCmdOptions& _options) const
if (vm.count("report") && m_reportNames.empty())
throw xrt_core::error("No report given to be produced");

if (vm.count("element") && m_elementsFilter.empty())
throw xrt_core::error("No element filter given to be produced");

// DRC check
// When json is specified, make sure an accompanying output file is also specified
if (!m_format.empty() && m_output.empty())
Expand Down
120 changes: 68 additions & 52 deletions src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,15 @@ SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreli

common_options.add_options()
("device,d", boost::program_options::value<decltype(m_device)>(&m_device), "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest")
("format,f", boost::program_options::value<decltype(m_format)>(&m_format), (std::string("Report output format. Valid values are:\n") + formatOptionValues).c_str() )
("output,o", boost::program_options::value<decltype(m_output)>(&m_output), "Direct the output to the given file")
("pmode", boost::program_options::value<decltype(m_pmode)>(&m_pmode), "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes")
("format,f", boost::program_options::value<decltype(m_format)>(&m_format)->implicit_value(""), (std::string("Report output format. Valid values are:\n") + formatOptionValues).c_str() )
("output,o", boost::program_options::value<decltype(m_output)>(&m_output)->implicit_value(""), "Direct the output to the given file")
("pmode", boost::program_options::value<decltype(m_pmode)>(&m_pmode)->implicit_value(""), "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes")
("help", boost::program_options::bool_switch(&m_help), "Help to use this sub-command")
;

m_hiddenOptions.add_options()
("path,p", boost::program_options::value<decltype(m_xclbin_location)>(&m_xclbin_location)->implicit_value(""), "Path to the directory containing validate xclbins")
("param", boost::program_options::value<decltype(m_param)>(&m_param), (std::string("Extended parameter for a given test. Format: <test-name>:<key>:<value>\n") + extendedKeysOptions()).c_str())
("param", boost::program_options::value<decltype(m_param)>(&m_param)->implicit_value(""), (std::string("Extended parameter for a given test. Format: <test-name>:<key>:<value>\n") + extendedKeysOptions()).c_str())
;

m_commonOptions.add(common_options);
Expand Down Expand Up @@ -520,6 +520,68 @@ SubCmdValidate::print_help_internal() const
printHelp(common_options, m_hiddenOptions, deviceClass, false);
}

void
SubCmdValidate::handle_errors_and_validate_tests(po::variables_map& vm,
std::vector<std::string>& validatedTests,
std::vector<std::string>& param) const
{
const auto testNameDescription = getTestNameDescriptions(true /* Add "all" and "quick" options*/);

if (vm.count("output") && m_output.empty())
throw xrt_core::error("Output file not specified");

if (vm.count("path") && m_xclbin_location.empty())
throw xrt_core::error("xclbin path not specified");

if (vm.count("param") && m_param.empty())
throw xrt_core::error("Parameter not specified");

if (vm.count("pmode") && m_pmode.empty())
throw xrt_core::error("Power mode not specified");

if (vm.count("format") && m_format.empty())
throw xrt_core::error("Output format not specified");

if (!m_output.empty() && !XBU::getForce() && std::filesystem::exists(m_output))
throw xrt_core::error((boost::format("Output file already exists: '%s'") % m_output).str());

if (m_tests_to_run.empty())
throw xrt_core::error("No test given to validate against.");

// Validate the user test requests
for (auto &userTestName : m_tests_to_run) {
const auto validateTestName = boost::algorithm::to_lower_copy(userTestName);

if ((validateTestName == "all") && (m_tests_to_run.size() > 1))
throw xrt_core::error("The 'all' value for the tests to run cannot be used with any other named tests.");

if ((validateTestName == "quick") && (m_tests_to_run.size() > 1))
throw xrt_core::error("The 'quick' value for the tests to run cannot be used with any other name tests.");

// Verify the current user test request exists in the test suite
doesTestExist(validateTestName, testNameDescription);
validatedTests.push_back(validateTestName);
}
//check if param option is provided
if (!m_param.empty()) {
XBU::verbose("Sub command: --param");
boost::split(param, m_param, boost::is_any_of(":")); // eg: dma:block-size:1024

//check parameter format
if (param.size() != 3)
throw xrt_core::error((boost::format("Invalid parameter format (expected 3 positional arguments): '%s'") % m_param).str());

//check test case name
doesTestExist(param[0], testNameDescription);

//check parameter name
auto iter = std::find_if( extendedKeysCollection.begin(), extendedKeysCollection.end(),
[&param](const ExtendedKeysStruct& collection){ return collection.param_name == param[1];} );
if (iter == extendedKeysCollection.end())
throw xrt_core::error((boost::format("Unsupported parameter name '%s' for validation test '%s'") % param[1] % param[2]).str());
}
}

void
SubCmdValidate::execute(const SubCmdOptions& _options) const
{
Expand Down Expand Up @@ -555,40 +617,14 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const
std::vector<std::string> param;
std::vector<std::string> validatedTests;
std::string validateXclbinPath = m_xclbin_location;
const auto testNameDescription = getTestNameDescriptions(true /* Add "all" and "quick" options*/);
try {
// Output Format
schemaVersion = Report::getSchemaDescription(m_format).schemaVersion;
if (schemaVersion == Report::SchemaVersion::unknown)
throw xrt_core::error((boost::format("Unknown output format: '%s'") % m_format).str());

// Output file
if (vm.count("output") && m_output.empty())
throw xrt_core::error("Output file not specified");

if (vm.count("path") && m_xclbin_location.empty())
throw xrt_core::error("xclbin path not specified");

if (!m_output.empty() && !XBU::getForce() && std::filesystem::exists(m_output))
throw xrt_core::error((boost::format("Output file already exists: '%s'") % m_output).str());

if (m_tests_to_run.empty())
throw xrt_core::error("No test given to validate against.");

// Validate the user test requests
for (auto &userTestName : m_tests_to_run) {
const auto validateTestName = boost::algorithm::to_lower_copy(userTestName);

if ((validateTestName == "all") && (m_tests_to_run.size() > 1))
throw xrt_core::error("The 'all' value for the tests to run cannot be used with any other named tests.");

if ((validateTestName == "quick") && (m_tests_to_run.size() > 1))
throw xrt_core::error("The 'quick' value for the tests to run cannot be used with any other name tests.");

// Verify the current user test request exists in the test suite
doesTestExist(validateTestName, testNameDescription);
validatedTests.push_back(validateTestName);
}
// All Error Handling for xrt-smi validate should go here
handle_errors_and_validate_tests(vm, validatedTests, param);

// check if xclbin folder path is provided
if (!validateXclbinPath.empty()) {
Expand All @@ -600,26 +636,6 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const
if (validateXclbinPath.back() != '/')
validateXclbinPath.append("/");
}

//check if param option is provided
if (!m_param.empty()) {
XBU::verbose("Sub command: --param");
boost::split(param, m_param, boost::is_any_of(":")); // eg: dma:block-size:1024

//check parameter format
if (param.size() != 3)
throw xrt_core::error((boost::format("Invalid parameter format (expected 3 positional arguments): '%s'") % m_param).str());

//check test case name
doesTestExist(param[0], testNameDescription);

//check parameter name
auto iter = std::find_if( extendedKeysCollection.begin(), extendedKeysCollection.end(),
[&param](const ExtendedKeysStruct& collection){ return collection.param_name == param[1];} );
if (iter == extendedKeysCollection.end())
throw xrt_core::error((boost::format("Unsupported parameter name '%s' for validation test '%s'") % param[1] % param[2]).str());
}

} catch (const xrt_core::error& e) {
// Catch only the exceptions that we have generated earlier
std::cerr << boost::format("ERROR: %s\n") % e.what();
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_src/core/tools/xbutil2/SubCmdValidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef __SubCmdValidate_h_
#define __SubCmdValidate_h_

#include <boost/program_options.hpp>
#include "tools/common/SubCmd.h"
#include "tools/common/XBHelpMenus.h"

Expand All @@ -26,6 +27,9 @@ class SubCmdValidate : public SubCmd {
bool m_help;

void print_help_internal() const;
void handle_errors_and_validate_tests(boost::program_options::variables_map&,
std::vector<std::string>&,
std::vector<std::string>&) const;
XBUtilities::VectorPairStrings getTestNameDescriptions(const bool addAdditionOptions) const;
};

Expand Down

0 comments on commit e0cfdb2

Please sign in to comment.