forked from youtube/cobalt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu_features_get_test.cc
137 lines (121 loc) · 5.1 KB
/
cpu_features_get_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2019 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstring>
#include "starboard/cpu_features.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace starboard {
namespace nplb {
namespace {
constexpr int kFeatureValueInvalid = -1;
void ExpectArmInvalid(const SbCPUFeatures& features) {
EXPECT_EQ(kFeatureValueInvalid, features.arm.implementer);
EXPECT_EQ(kFeatureValueInvalid, features.arm.variant);
EXPECT_EQ(kFeatureValueInvalid, features.arm.revision);
EXPECT_EQ(kFeatureValueInvalid, features.arm.architecture_generation);
EXPECT_EQ(kFeatureValueInvalid, features.arm.part);
EXPECT_EQ(false, features.arm.has_neon);
EXPECT_EQ(false, features.arm.has_thumb2);
EXPECT_EQ(false, features.arm.has_vfp);
EXPECT_EQ(false, features.arm.has_vfp3);
EXPECT_EQ(false, features.arm.has_vfp4);
EXPECT_EQ(false, features.arm.has_vfp3_d32);
EXPECT_EQ(false, features.arm.has_idiva);
EXPECT_EQ(false, features.arm.has_aes);
EXPECT_EQ(false, features.arm.has_crc32);
EXPECT_EQ(false, features.arm.has_sha1);
EXPECT_EQ(false, features.arm.has_sha2);
EXPECT_EQ(false, features.arm.has_pmull);
}
void ExpectMipsInvalid(const SbCPUFeatures& features) {
EXPECT_EQ(false, features.mips_arch.has_msa);
}
void ExpectX86Invalid(const SbCPUFeatures& features) {
EXPECT_NE(nullptr, features.x86.vendor);
EXPECT_EQ(0, strlen(features.x86.vendor));
EXPECT_EQ(kFeatureValueInvalid, features.x86.family);
EXPECT_EQ(kFeatureValueInvalid, features.x86.ext_family);
EXPECT_EQ(kFeatureValueInvalid, features.x86.model);
EXPECT_EQ(kFeatureValueInvalid, features.x86.ext_model);
EXPECT_EQ(kFeatureValueInvalid, features.x86.stepping);
EXPECT_EQ(kFeatureValueInvalid, features.x86.type);
EXPECT_EQ(kFeatureValueInvalid, features.x86.signature);
EXPECT_EQ(false, features.x86.has_cmov);
EXPECT_EQ(false, features.x86.has_mmx);
EXPECT_EQ(false, features.x86.has_sse);
EXPECT_EQ(false, features.x86.has_sse2);
EXPECT_EQ(false, features.x86.has_tsc);
EXPECT_EQ(false, features.x86.has_sse3);
EXPECT_EQ(false, features.x86.has_pclmulqdq);
EXPECT_EQ(false, features.x86.has_ssse3);
EXPECT_EQ(false, features.x86.has_sse41);
EXPECT_EQ(false, features.x86.has_sse42);
EXPECT_EQ(false, features.x86.has_movbe);
EXPECT_EQ(false, features.x86.has_popcnt);
EXPECT_EQ(false, features.x86.has_osxsave);
EXPECT_EQ(false, features.x86.has_avx);
EXPECT_EQ(false, features.x86.has_f16c);
EXPECT_EQ(false, features.x86.has_fma3);
EXPECT_EQ(false, features.x86.has_aesni);
EXPECT_EQ(false, features.x86.has_avx2);
EXPECT_EQ(false, features.x86.has_avx512f);
EXPECT_EQ(false, features.x86.has_avx512dq);
EXPECT_EQ(false, features.x86.has_avx512ifma);
EXPECT_EQ(false, features.x86.has_avx512pf);
EXPECT_EQ(false, features.x86.has_avx512er);
EXPECT_EQ(false, features.x86.has_avx512cd);
EXPECT_EQ(false, features.x86.has_avx512bw);
EXPECT_EQ(false, features.x86.has_avx512vl);
EXPECT_EQ(false, features.x86.has_bmi1);
EXPECT_EQ(false, features.x86.has_bmi2);
EXPECT_EQ(false, features.x86.has_lzcnt);
EXPECT_EQ(false, features.x86.has_sahf);
}
TEST(SbCPUFeaturesGetTest, SunnyDay) {
SbCPUFeatures features;
bool result = SbCPUFeaturesGet(&features);
if (!result) {
EXPECT_EQ(kSbCPUFeaturesArchitectureUnknown, features.architecture);
EXPECT_NE(nullptr, features.brand);
EXPECT_EQ(0, strlen(features.brand));
EXPECT_EQ(kFeatureValueInvalid, features.icache_line_size);
EXPECT_EQ(kFeatureValueInvalid, features.dcache_line_size);
EXPECT_FALSE(features.has_fpu);
EXPECT_EQ(0, features.hwcap);
EXPECT_EQ(0, features.hwcap2);
ExpectArmInvalid(features);
ExpectMipsInvalid(features);
ExpectX86Invalid(features);
return;
} else {
// If the architecture is unknown, SbCPUFeaturesGet() must return
// false.
EXPECT_NE(kSbCPUFeaturesArchitectureUnknown, features.architecture);
#if SB_IS(ARCH_ARM) || SB_IS(ARCH_ARM64)
EXPECT_TRUE(features.architecture == kSbCPUFeaturesArchitectureArm ||
features.architecture == kSbCPUFeaturesArchitectureArm64);
#else // !SB_IS(ARCH_ARM) && !SB_IS(ARCH_ARM64)
ExpectArmInvalid(features);
#endif // SB_IS(ARCH_ARM) || SB_IS(ARCH_ARM64)
#if SB_IS(ARCH_X86) || SB_IS(ARCH_X64)
EXPECT_TRUE(features.architecture == kSbCPUFeaturesArchitectureX86 ||
features.architecture == kSbCPUFeaturesArchitectureX86_64);
#else // !SB_IS(ARCH_X86) && !SB_IS(ARCH_X64)
ExpectX86Invalid(features);
#endif // SB_IS(ARCH_X86) || SB_IS(ARCH_X64)
ExpectMipsInvalid(features);
}
}
} // namespace
} // namespace nplb
} // namespace starboard