1
0
mirror of https://github.com/google/cpu_features.git synced 2025-04-29 07:53:37 +02:00

Fix tests & fix missing GetHardwareCapabilities() change

This commit is contained in:
Arvid Gerstmann 2018-05-03 17:07:07 +02:00
parent a1ffdcbe70
commit fd4839032c
6 changed files with 61 additions and 61 deletions

View File

@ -145,7 +145,7 @@ static uint32_t GetHardwareCapabilitiesFor(uint32_t type) {
return hwcaps; return hwcaps;
} }
HardwareCapabilities GetHardwareCapabilities(void) { HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
HardwareCapabilities capabilities; HardwareCapabilities capabilities;
capabilities.hwcaps = GetHardwareCapabilitiesFor(AT_HWCAP); capabilities.hwcaps = GetHardwareCapabilitiesFor(AT_HWCAP);
capabilities.hwcaps2 = GetHardwareCapabilitiesFor(AT_HWCAP2); capabilities.hwcaps2 = GetHardwareCapabilitiesFor(AT_HWCAP2);

View File

@ -81,7 +81,7 @@ FakeFilesystem& GetEmptyFilesystem() {
return *kFilesystem; return *kFilesystem;
} }
extern "C" int OpenFile(const char* filename) { extern "C" int CpuFeatures_OpenFile(const char* filename) {
auto* const file = kFilesystem->FindFileOrNull(filename); auto* const file = kFilesystem->FindFileOrNull(filename);
if (file) { if (file) {
file->Open(); file->Open();
@ -90,11 +90,11 @@ extern "C" int OpenFile(const char* filename) {
return -1; return -1;
} }
extern "C" void CloseFile(int file_descriptor) { extern "C" void CpuFeatures_CloseFile(int file_descriptor) {
kFilesystem->FindFileOrDie(file_descriptor)->Close(); kFilesystem->FindFileOrDie(file_descriptor)->Close();
} }
extern "C" int ReadFile(int file_descriptor, void* buf, size_t count) { extern "C" int CpuFeatures_ReadFile(int file_descriptor, void* buf, size_t count) {
return kFilesystem->FindFileOrDie(file_descriptor) return kFilesystem->FindFileOrDie(file_descriptor)
->Read(file_descriptor, buf, count); ->Read(file_descriptor, buf, count);
} }

View File

@ -25,7 +25,7 @@ void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) {
g_hardware_capabilities->hwcaps2 = hwcaps2; g_hardware_capabilities->hwcaps2 = hwcaps2;
} }
HardwareCapabilities GetHardwareCapabilities(void) { HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
return *g_hardware_capabilities; return *g_hardware_capabilities;
} }

View File

@ -42,7 +42,7 @@ class LinuxFeatureAggregatorTest : public testing::Test {
TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) { TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
Features features; Features features;
SetFromFlags(kConfigs.size(), kConfigs.data(), str(""), &features); CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str(""), &features);
EXPECT_FALSE(features.a); EXPECT_FALSE(features.a);
EXPECT_FALSE(features.b); EXPECT_FALSE(features.b);
EXPECT_FALSE(features.c); EXPECT_FALSE(features.c);
@ -50,7 +50,7 @@ TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) { TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
Features features; Features features;
SetFromFlags(kConfigs.size(), kConfigs.data(), str("a c b"), &features); CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a c b"), &features);
EXPECT_TRUE(features.a); EXPECT_TRUE(features.a);
EXPECT_TRUE(features.b); EXPECT_TRUE(features.b);
EXPECT_TRUE(features.c); EXPECT_TRUE(features.c);
@ -58,7 +58,7 @@ TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
TEST_F(LinuxFeatureAggregatorTest, FromFlagsOnlyA) { TEST_F(LinuxFeatureAggregatorTest, FromFlagsOnlyA) {
Features features; Features features;
SetFromFlags(kConfigs.size(), kConfigs.data(), str("a"), &features); CpuFeatures_SetFromFlags(kConfigs.size(), kConfigs.data(), str("a"), &features);
EXPECT_TRUE(features.a); EXPECT_TRUE(features.a);
EXPECT_FALSE(features.b); EXPECT_FALSE(features.b);
EXPECT_FALSE(features.c); EXPECT_FALSE(features.c);
@ -69,7 +69,7 @@ TEST_F(LinuxFeatureAggregatorTest, FromHwcapsNone) {
capability.hwcaps = 0; // matches none capability.hwcaps = 0; // matches none
capability.hwcaps2 = 0; // matches none capability.hwcaps2 = 0; // matches none
Features features; Features features;
OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability, &features); CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability, &features);
EXPECT_FALSE(features.a); EXPECT_FALSE(features.a);
EXPECT_FALSE(features.b); EXPECT_FALSE(features.b);
EXPECT_FALSE(features.c); EXPECT_FALSE(features.c);
@ -80,7 +80,7 @@ TEST_F(LinuxFeatureAggregatorTest, FromHwcapsSet) {
capability.hwcaps = 0b0010; // matches b but not a capability.hwcaps = 0b0010; // matches b but not a
capability.hwcaps2 = 0b1111; // matches c capability.hwcaps2 = 0b1111; // matches c
Features features; Features features;
OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability, &features); CpuFeatures_OverrideFromHwCaps(kConfigs.size(), kConfigs.data(), capability, &features);
EXPECT_FALSE(features.a); EXPECT_FALSE(features.a);
EXPECT_TRUE(features.b); EXPECT_TRUE(features.b);
EXPECT_TRUE(features.c); EXPECT_TRUE(features.c);

View File

@ -20,7 +20,7 @@
namespace cpu_features { namespace cpu_features {
bool operator==(const StringView& a, const StringView& b) { bool operator==(const StringView& a, const StringView& b) {
return IsEquals(a, b); return CpuFeatures_StringView_IsEquals(a, b);
} }
namespace { namespace {

View File

@ -19,7 +19,7 @@
namespace cpu_features { namespace cpu_features {
bool operator==(const StringView& a, const StringView& b) { bool operator==(const StringView& a, const StringView& b) {
return IsEquals(a, b); return CpuFeatures_StringView_IsEquals(a, b);
} }
namespace { namespace {
@ -35,95 +35,95 @@ TEST(StringViewTest, Build) {
EXPECT_EQ(view.size, 4); EXPECT_EQ(view.size, 4);
} }
TEST(StringViewTest, IndexOfChar) { TEST(StringViewTest, CpuFeatures_StringView_IndexOfChar) {
// Found. // Found.
EXPECT_EQ(IndexOfChar(str("test"), 'e'), 1); EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(str("test"), 'e'), 1);
// Not found. // Not found.
EXPECT_EQ(IndexOfChar(str("test"), 'z'), -1); EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(str("test"), 'z'), -1);
// Empty. // Empty.
EXPECT_EQ(IndexOfChar(kEmptyStringView, 'z'), -1); EXPECT_EQ(CpuFeatures_StringView_IndexOfChar(kEmptyStringView, 'z'), -1);
} }
TEST(StringViewTest, IndexOf) { TEST(StringViewTest, CpuFeatures_StringView_IndexOf) {
// Found. // Found.
EXPECT_EQ(IndexOf(str("test"), str("es")), 1); EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("test"), str("es")), 1);
// Not found. // Not found.
EXPECT_EQ(IndexOf(str("test"), str("aa")), -1); EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("test"), str("aa")), -1);
// Empty. // Empty.
EXPECT_EQ(IndexOf(kEmptyStringView, str("aa")), -1); EXPECT_EQ(CpuFeatures_StringView_IndexOf(kEmptyStringView, str("aa")), -1);
EXPECT_EQ(IndexOf(str("aa"), kEmptyStringView), -1); EXPECT_EQ(CpuFeatures_StringView_IndexOf(str("aa"), kEmptyStringView), -1);
} }
TEST(StringViewTest, StartsWith) { TEST(StringViewTest, CpuFeatures_StringView_StartsWith) {
EXPECT_TRUE(StartsWith(str("test"), str("te"))); EXPECT_TRUE(CpuFeatures_StringView_StartsWith(str("test"), str("te")));
EXPECT_FALSE(StartsWith(str("test"), str(""))); EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), str("")));
EXPECT_FALSE(StartsWith(str("test"), kEmptyStringView)); EXPECT_FALSE(CpuFeatures_StringView_StartsWith(str("test"), kEmptyStringView));
EXPECT_FALSE(StartsWith(kEmptyStringView, str("test"))); EXPECT_FALSE(CpuFeatures_StringView_StartsWith(kEmptyStringView, str("test")));
} }
TEST(StringViewTest, IsEquals) { TEST(StringViewTest, CpuFeatures_StringView_IsEquals) {
EXPECT_TRUE(IsEquals(kEmptyStringView, kEmptyStringView)); EXPECT_TRUE(CpuFeatures_StringView_IsEquals(kEmptyStringView, kEmptyStringView));
EXPECT_TRUE(IsEquals(kEmptyStringView, str(""))); EXPECT_TRUE(CpuFeatures_StringView_IsEquals(kEmptyStringView, str("")));
EXPECT_TRUE(IsEquals(str(""), kEmptyStringView)); EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str(""), kEmptyStringView));
EXPECT_TRUE(IsEquals(str("a"), str("a"))); EXPECT_TRUE(CpuFeatures_StringView_IsEquals(str("a"), str("a")));
EXPECT_FALSE(IsEquals(str("a"), str("b"))); EXPECT_FALSE(CpuFeatures_StringView_IsEquals(str("a"), str("b")));
EXPECT_FALSE(IsEquals(str("a"), kEmptyStringView)); EXPECT_FALSE(CpuFeatures_StringView_IsEquals(str("a"), kEmptyStringView));
EXPECT_FALSE(IsEquals(kEmptyStringView, str("a"))); EXPECT_FALSE(CpuFeatures_StringView_IsEquals(kEmptyStringView, str("a")));
} }
TEST(StringViewTest, PopFront) { TEST(StringViewTest, CpuFeatures_StringView_PopFront) {
EXPECT_EQ(PopFront(str("test"), 2), str("st")); EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 2), str("st"));
EXPECT_EQ(PopFront(str("test"), 0), str("test")); EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 0), str("test"));
EXPECT_EQ(PopFront(str("test"), 4), str("")); EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 4), str(""));
EXPECT_EQ(PopFront(str("test"), 100), str("")); EXPECT_EQ(CpuFeatures_StringView_PopFront(str("test"), 100), str(""));
} }
TEST(StringViewTest, ParsePositiveNumber) { TEST(StringViewTest, CpuFeatures_StringView_ParsePositiveNumber) {
EXPECT_EQ(ParsePositiveNumber(str("42")), 42); EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("42")), 42);
EXPECT_EQ(ParsePositiveNumber(str("0x2a")), 42); EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("0x2a")), 42);
EXPECT_EQ(ParsePositiveNumber(str("0x2A")), 42); EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("0x2A")), 42);
EXPECT_EQ(ParsePositiveNumber(str("-0x2A")), -1); EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("-0x2A")), -1);
EXPECT_EQ(ParsePositiveNumber(str("abc")), -1); EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("abc")), -1);
EXPECT_EQ(ParsePositiveNumber(str("")), -1); EXPECT_EQ(CpuFeatures_StringView_ParsePositiveNumber(str("")), -1);
} }
TEST(StringViewTest, CopyString) { TEST(StringViewTest, CpuFeatures_StringView_CopyString) {
char buf[4]; char buf[4];
buf[0] = 'X'; buf[0] = 'X';
// Empty // Empty
CopyString(str(""), buf, sizeof(buf)); CpuFeatures_StringView_CopyString(str(""), buf, sizeof(buf));
EXPECT_STREQ(buf, ""); EXPECT_STREQ(buf, "");
// Less // Less
CopyString(str("a"), buf, sizeof(buf)); CpuFeatures_StringView_CopyString(str("a"), buf, sizeof(buf));
EXPECT_STREQ(buf, "a"); EXPECT_STREQ(buf, "a");
// exact // exact
CopyString(str("abc"), buf, sizeof(buf)); CpuFeatures_StringView_CopyString(str("abc"), buf, sizeof(buf));
EXPECT_STREQ(buf, "abc"); EXPECT_STREQ(buf, "abc");
// More // More
CopyString(str("abcd"), buf, sizeof(buf)); CpuFeatures_StringView_CopyString(str("abcd"), buf, sizeof(buf));
EXPECT_STREQ(buf, "abc"); EXPECT_STREQ(buf, "abc");
} }
TEST(StringViewTest, HasWord) { TEST(StringViewTest, CpuFeatures_StringView_HasWord) {
// Find flags at beginning, middle and end. // Find flags at beginning, middle and end.
EXPECT_TRUE(HasWord(str("first middle last"), "first")); EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "first"));
EXPECT_TRUE(HasWord(str("first middle last"), "middle")); EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "middle"));
EXPECT_TRUE(HasWord(str("first middle last"), "last")); EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "last"));
// Do not match partial flags // Do not match partial flags
EXPECT_FALSE(HasWord(str("first middle last"), "irst")); EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "irst"));
EXPECT_FALSE(HasWord(str("first middle last"), "mid")); EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "mid"));
EXPECT_FALSE(HasWord(str("first middle last"), "las")); EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "las"));
} }
TEST(StringViewTest, GetAttributeKeyValue) { TEST(StringViewTest, CpuFeatures_StringView_GetAttributeKeyValue) {
const StringView line = str(" key : first middle last "); const StringView line = str(" key : first middle last ");
StringView key, value; StringView key, value;
EXPECT_TRUE(GetAttributeKeyValue(line, &key, &value)); EXPECT_TRUE(CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value));
EXPECT_EQ(key, str("key")); EXPECT_EQ(key, str("key"));
EXPECT_EQ(value, str("first middle last")); EXPECT_EQ(value, str("first middle last"));
} }
@ -131,7 +131,7 @@ TEST(StringViewTest, GetAttributeKeyValue) {
TEST(StringViewTest, FailingGetAttributeKeyValue) { TEST(StringViewTest, FailingGetAttributeKeyValue) {
const StringView line = str("key first middle last"); const StringView line = str("key first middle last");
StringView key, value; StringView key, value;
EXPECT_FALSE(GetAttributeKeyValue(line, &key, &value)); EXPECT_FALSE(CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value));
} }
} // namespace } // namespace