1
0
mirror of https://github.com/google/cpu_features.git synced 2025-07-01 13:21:13 +02:00

Use a getter function to avoid manual work for future to-be-added cpu features

This commit is contained in:
Patrick Siegl
2019-12-14 11:58:36 +00:00
committed by Guillaume Chatelet
parent 73a121b1ae
commit 3d71a964f5
7 changed files with 260 additions and 442 deletions

View File

@ -43,6 +43,12 @@ TEST(CpuinfoArmTest, FromHardwareCap) {
EXPECT_FALSE(info.features.pmull);
EXPECT_FALSE(info.features.sha1);
EXPECT_FALSE(info.features.sha2);
// check some random features with EnumValue():
EXPECT_TRUE(GetArmFeaturesEnumValue(&info.features, ARM_VFP));
EXPECT_FALSE(GetArmFeaturesEnumValue(&info.features, ARM_VFPV4));
// out of bound EnumValue() check
EXPECT_FALSE(GetArmFeaturesEnumValue(&info.features, (ArmFeaturesEnum)~0x0));
}
TEST(CpuinfoArmTest, ODroidFromCpuInfo) {

View File

@ -28,16 +28,23 @@ struct Features {
bool c = false;
};
DECLARE_SETTER(Features, a)
DECLARE_SETTER(Features, b)
DECLARE_SETTER(Features, c)
enum eFeatures {
TEST_a,
TEST_b,
TEST_c
};
DECLARE_SETTER_AND_GETTER(Features, a)
DECLARE_SETTER_AND_GETTER(Features, b)
DECLARE_SETTER_AND_GETTER(Features, c)
class LinuxFeatureAggregatorTest : public testing::Test {
public:
const std::array<CapabilityConfig, 3> kConfigs = {
{{{0b0001, 0b0000}, "a", &set_a},
{{0b0010, 0b0000}, "b", &set_b},
{{0b0000, 0b1100}, "c", &set_c}}};
const std::array<CapabilityConfig, 3> kConfigs = {{
{{0b0001, 0b0000}, "a", &set_a, &get_a},
{{0b0010, 0b0000}, "b", &set_b, &get_b},
{{0b0000, 0b1100}, "c", &set_c, &get_c}
}};
};
TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
@ -47,6 +54,8 @@ TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {
EXPECT_FALSE(features.a);
EXPECT_FALSE(features.b);
EXPECT_FALSE(features.c);
EXPECT_FALSE(kConfigs[TEST_a].get_bit(&features));
}
TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
@ -56,6 +65,8 @@ TEST_F(LinuxFeatureAggregatorTest, FromFlagsAllSet) {
EXPECT_TRUE(features.a);
EXPECT_TRUE(features.b);
EXPECT_TRUE(features.c);
EXPECT_TRUE(kConfigs[TEST_a].get_bit(&features));
}
TEST_F(LinuxFeatureAggregatorTest, FromFlagsOnlyA) {
@ -65,6 +76,10 @@ TEST_F(LinuxFeatureAggregatorTest, FromFlagsOnlyA) {
EXPECT_TRUE(features.a);
EXPECT_FALSE(features.b);
EXPECT_FALSE(features.c);
EXPECT_TRUE(kConfigs[TEST_a].get_bit(&features));
EXPECT_FALSE(kConfigs[TEST_b].get_bit(&features));
EXPECT_FALSE(kConfigs[TEST_c].get_bit(&features));
}
TEST_F(LinuxFeatureAggregatorTest, FromHwcapsNone) {