Skip to content

[llvm][unittests] Put human-readable names on TargetParserTests. NFC #80749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions llvm/unittests/TargetParser/TargetParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ template <typename T> struct ARMCPUTestParams {
return os;
}

/// Print a gtest-compatible facsimile of the CPUName, to make the test's name
/// human-readable.
///
/// https://github.com/google/googletest/blob/main/docs/advanced.md#specifying-names-for-value-parameterized-test-parameters
static std::string
PrintToStringParamName(const testing::TestParamInfo<ARMCPUTestParams<T>>& Info) {
std::string Name = Info.param.CPUName.str();
for (char &C : Name)
if (!std::isalnum(C))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this ever happen? Are there CPU names that have weird chars in it? If yes, why can't we just print them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it can't print "cortex-whatever", it needs to replace "-" with "_"?

How strange...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of them have -s in them, and it is a requirement that gtest test names only have alphanumeric characters in them: https://github.com/google/googletest/blob/main/docs/advanced.md#specifying-names-for-value-parameterized-test-parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it has to do with simplifying command-line argument parsing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a comment mentioning the requirement from the suite

C = '_';
return Name;
}

StringRef CPUName;
StringRef ExpectedArch;
StringRef ExpectedFPU;
Expand Down Expand Up @@ -263,7 +276,8 @@ INSTANTIATE_TEST_SUITE_P(
ARM::AEK_SEC | ARM::AEK_VIRT | ARM::AEK_DSP,
"7-A"),
ARMCPUTestParams<uint64_t>("cortex-a8", "armv7-a", "neon",
ARM::AEK_SEC | ARM::AEK_DSP, "7-A")));
ARM::AEK_SEC | ARM::AEK_DSP, "7-A")),
ARMCPUTestParams<uint64_t>::PrintToStringParamName);

// gtest in llvm has a limit of 50 test cases when using ::Values so we split
// them into 2 blocks
Expand Down Expand Up @@ -483,7 +497,8 @@ INSTANTIATE_TEST_SUITE_P(
ARMCPUTestParams<uint64_t>("xscale", "xscale", "none", ARM::AEK_NONE, "xscale"),
ARMCPUTestParams<uint64_t>("swift", "armv7s", "neon-vfpv4",
ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
"7-S")));
"7-S")),
ARMCPUTestParams<uint64_t>::PrintToStringParamName);

static constexpr unsigned NumARMCPUArchs = 90;

Expand Down Expand Up @@ -1660,7 +1675,8 @@ INSTANTIATE_TEST_SUITE_P(
{AArch64::AEK_CRC, AArch64::AEK_AES, AArch64::AEK_SHA2,
AArch64::AEK_FP, AArch64::AEK_SIMD, AArch64::AEK_FP16,
AArch64::AEK_RAS, AArch64::AEK_LSE, AArch64::AEK_RDM})),
"8.2-A")));
"8.2-A")),
ARMCPUTestParams<AArch64::ExtensionBitset>::PrintToStringParamName);

// Note: number of CPUs includes aliases.
static constexpr unsigned NumAArch64CPUArchs = 68;
Expand Down