Add ids command to ocloc

New command usage: ocloc ids <acronym>.
It will allow the user to query all matched
<major>.<minor>.<revision> for the specified acronym.
E.g.
ocloc ids dg1
Matched ids:
12.10.0

Signed-off-by: Daria Hinz <daria.hinz@intel.com>
Related-To: NEO-7159
This commit is contained in:
Daria Hinz
2022-07-05 14:24:35 +02:00
committed by Compute-Runtime-Automation
parent d68dedba3b
commit ea2edbef3d
9 changed files with 299 additions and 65 deletions

View File

@ -179,6 +179,39 @@ TEST(OclocApiTests, GivenInvalidQueryWhenQueryingThenErrorIsReturned) {
EXPECT_STREQ("Error: Invalid command line. Uknown argument unknown_query.", output.c_str());
}
TEST(OclocApiTests, givenNoAcronymWhenIdsCommandIsInvokeThenErrorIsReported) {
const char *argv[] = {
"ocloc",
"ids"};
unsigned int argc = sizeof(argv) / sizeof(const char *);
testing::internal::CaptureStdout();
int retVal = oclocInvoke(argc, argv,
0, nullptr, nullptr, nullptr,
0, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr);
std::string output = testing::internal::GetCapturedStdout();
EXPECT_EQ(retVal, NEO::OclocErrorCode::INVALID_COMMAND_LINE);
EXPECT_STREQ("Error: Invalid command line. Expected ocloc ids <acronym>.\n", output.c_str());
}
TEST(OclocApiTests, givenUnknownAcronymWhenIdsCommandIsInvokeThenErrorIsReported) {
const char *argv[] = {
"ocloc",
"ids",
"unk"};
unsigned int argc = sizeof(argv) / sizeof(const char *);
testing::internal::CaptureStdout();
int retVal = oclocInvoke(argc, argv,
0, nullptr, nullptr, nullptr,
0, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr);
std::string output = testing::internal::GetCapturedStdout();
EXPECT_EQ(retVal, NEO::OclocErrorCode::INVALID_COMMAND_LINE);
EXPECT_STREQ("Error: Invalid command line. Uknown acronym unk.\n", output.c_str());
}
TEST(OclocApiTests, WhenGoodFamilyNameIsProvidedThenSuccessIsReturned) {
std::string clFileName(clFiles + "copybuffer.cl");
std::unique_ptr<OclocArgHelper> argHelper = std::make_unique<OclocArgHelper>();

View File

@ -702,6 +702,133 @@ TEST_F(OfflineCompilerTests, GivenHelpOptionOnQueryThenSuccessIsReturned) {
EXPECT_EQ(OclocErrorCode::SUCCESS, retVal);
}
TEST_F(OfflineCompilerTests, GivenHelpOptionOnIdsThenSuccessIsReturned) {
std::vector<ConstStringRef> helpFlags = {"-h", "--help"};
for (const auto &helpFlag : helpFlags) {
std::vector<std::string> argv = {
"ocloc",
"ids",
helpFlag.str()};
testing::internal::CaptureStdout();
int retVal = OfflineCompiler::queryAcronymIds(argv.size(), argv, oclocArgHelperWithoutInput.get());
std::string output = testing::internal::GetCapturedStdout();
std::stringstream expectedOutput;
expectedOutput << R"===(
Depending on <acronym> will return all
matched versions (<major>.<minor>.<revision>)
that correspond to the given name.
All supported acronyms: )===";
expectedOutput << getSupportedDevices(oclocArgHelperWithoutInput.get()) << ".\n";
EXPECT_STREQ(output.c_str(), expectedOutput.str().c_str());
EXPECT_EQ(OclocErrorCode::SUCCESS, retVal);
}
}
TEST_F(OfflineCompilerTests, givenFamilyAcronymWhenIdsCommandIsInvokeThenSuccessAndCorrectIdsAreReturned) {
auto enabledFamilies = oclocArgHelperWithoutInput->getEnabledFamiliesAcronyms();
if (enabledFamilies.empty()) {
GTEST_SKIP();
}
auto supportedDevicesConfigs = oclocArgHelperWithoutInput->getAllSupportedDeviceConfigs();
for (const auto &familyAcronym : enabledFamilies) {
std::vector<std::string> expected{};
auto family = ProductConfigHelper::returnFamilyForAcronym(familyAcronym.str());
for (const auto &device : supportedDevicesConfigs) {
if (device.family == family) {
auto config = ProductConfigHelper::parseMajorMinorRevisionValue(device.aotConfig);
expected.push_back(config);
}
}
std::vector<std::string> argv = {
"ocloc",
"ids",
familyAcronym.str()};
std::stringstream expectedOutput;
testing::internal::CaptureStdout();
int retVal = OfflineCompiler::queryAcronymIds(argv.size(), argv, oclocArgHelperWithoutInput.get());
std::string output = testing::internal::GetCapturedStdout();
expectedOutput << "Matched ids:";
for (const auto &prefix : expected) {
expectedOutput << "\n" + prefix;
}
EXPECT_STREQ(expectedOutput.str().c_str(), output.c_str());
EXPECT_EQ(OclocErrorCode::SUCCESS, retVal);
}
}
TEST_F(OfflineCompilerTests, givenReleaseAcronymWhenIdsCommandIsInvokeThenSuccessAndCorrectIdsAreReturned) {
auto enabledReleases = oclocArgHelperWithoutInput->getEnabledReleasesAcronyms();
if (enabledReleases.empty()) {
GTEST_SKIP();
}
auto supportedDevicesConfigs = oclocArgHelperWithoutInput->getAllSupportedDeviceConfigs();
for (const auto &releaseAcronym : enabledReleases) {
std::vector<std::string> expected{};
auto release = ProductConfigHelper::returnReleaseForAcronym(releaseAcronym.str());
for (const auto &device : supportedDevicesConfigs) {
if (device.release == release) {
auto config = ProductConfigHelper::parseMajorMinorRevisionValue(device.aotConfig);
expected.push_back(config);
}
}
std::vector<std::string> argv = {
"ocloc",
"ids",
releaseAcronym.str()};
std::stringstream expectedOutput;
testing::internal::CaptureStdout();
int retVal = OfflineCompiler::queryAcronymIds(argv.size(), argv, oclocArgHelperWithoutInput.get());
std::string output = testing::internal::GetCapturedStdout();
expectedOutput << "Matched ids:";
for (const auto &prefix : expected) {
expectedOutput << "\n" + prefix;
}
EXPECT_STREQ(expectedOutput.str().c_str(), output.c_str());
EXPECT_EQ(OclocErrorCode::SUCCESS, retVal);
}
}
TEST_F(OfflineCompilerTests, givenProductAcronymWhenIdsCommandIsInvokeThenSuccessAndCorrectIdsAreReturned) {
auto enabledProducts = oclocArgHelperWithoutInput->getEnabledProductAcronyms();
if (enabledProducts.empty()) {
GTEST_SKIP();
}
auto supportedDevicesConfigs = oclocArgHelperWithoutInput->getAllSupportedDeviceConfigs();
for (const auto &productAcronym : enabledProducts) {
std::vector<std::string> expected{};
auto product = ProductConfigHelper::returnProductConfigForAcronym(productAcronym.str());
for (const auto &device : supportedDevicesConfigs) {
if (device.aotConfig.ProductConfig == product) {
auto config = ProductConfigHelper::parseMajorMinorRevisionValue(device.aotConfig);
expected.push_back(config);
}
}
std::vector<std::string> argv = {
"ocloc",
"ids",
productAcronym.str()};
std::stringstream expectedOutput;
testing::internal::CaptureStdout();
int retVal = OfflineCompiler::queryAcronymIds(argv.size(), argv, oclocArgHelperWithoutInput.get());
std::string output = testing::internal::GetCapturedStdout();
expectedOutput << "Matched ids:";
for (const auto &prefix : expected) {
expectedOutput << "\n" + prefix;
}
EXPECT_STREQ(expectedOutput.str().c_str(), output.c_str());
EXPECT_EQ(OclocErrorCode::SUCCESS, retVal);
}
}
TEST_F(OfflineCompilerTests, GivenFlagsWhichRequireMoreArgsWithoutThemWhenParsingThenErrorIsReported) {
const std::array<std::string, 8> flagsToTest = {
"-file", "-output", "-device", "-options", "-internal_options", "-out_dir", "-revision_id", "-config"};