mirror of
https://github.com/google/cpu_features.git
synced 2025-04-28 07:23:37 +02:00
Avoid leaking internal headers for ppc (#164)
This commit is contained in:
parent
001faefdc3
commit
b3ef4ef49d
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "cpu_features_cache_info.h"
|
#include "cpu_features_cache_info.h"
|
||||||
#include "cpu_features_macros.h"
|
#include "cpu_features_macros.h"
|
||||||
#include "internal/hwcaps.h"
|
|
||||||
|
|
||||||
CPU_FEATURES_START_CPP_NAMESPACE
|
CPU_FEATURES_START_CPP_NAMESPACE
|
||||||
|
|
||||||
@ -74,12 +73,17 @@ typedef struct {
|
|||||||
// This function is guaranteed to be malloc, memset and memcpy free.
|
// This function is guaranteed to be malloc, memset and memcpy free.
|
||||||
PPCInfo GetPPCInfo(void);
|
PPCInfo GetPPCInfo(void);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char platform[64]; // 0 terminated string
|
||||||
|
char base_platform[64]; // 0 terminated string
|
||||||
|
} PPCPlatformTypeStrings;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char platform[64]; // 0 terminated string
|
char platform[64]; // 0 terminated string
|
||||||
char model[64]; // 0 terminated string
|
char model[64]; // 0 terminated string
|
||||||
char machine[64]; // 0 terminated string
|
char machine[64]; // 0 terminated string
|
||||||
char cpu[64]; // 0 terminated string
|
char cpu[64]; // 0 terminated string
|
||||||
PlatformType type;
|
PPCPlatformTypeStrings type;
|
||||||
} PPCPlatformStrings;
|
} PPCPlatformStrings;
|
||||||
|
|
||||||
PPCPlatformStrings GetPPCPlatformStrings(void);
|
PPCPlatformStrings GetPPCPlatformStrings(void);
|
||||||
|
@ -171,16 +171,19 @@ typedef struct {
|
|||||||
unsigned long hwcaps2;
|
unsigned long hwcaps2;
|
||||||
} HardwareCapabilities;
|
} HardwareCapabilities;
|
||||||
|
|
||||||
|
// Retrieves values from auxiliary vector for types AT_HWCAP and AT_HWCAP2.
|
||||||
|
// First tries to call getauxval(), if not available falls back to reading
|
||||||
|
// "/proc/self/auxv".
|
||||||
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
|
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
|
||||||
|
|
||||||
|
// Checks whether value for AT_HWCAP (or AT_HWCAP2) match hwcaps_mask.
|
||||||
bool CpuFeatures_IsHwCapsSet(const HardwareCapabilities hwcaps_mask,
|
bool CpuFeatures_IsHwCapsSet(const HardwareCapabilities hwcaps_mask,
|
||||||
const HardwareCapabilities hwcaps);
|
const HardwareCapabilities hwcaps);
|
||||||
|
|
||||||
typedef struct {
|
// Get pointer for the AT_PLATFORM type.
|
||||||
char platform[64]; // 0 terminated string
|
const char* CpuFeatures_GetPlatformPointer(void);
|
||||||
char base_platform[64]; // 0 terminated string
|
// Get pointer for the AT_BASE_PLATFORM type.
|
||||||
} PlatformType;
|
const char* CpuFeatures_GetBasePlatformPointer(void);
|
||||||
|
|
||||||
PlatformType CpuFeatures_GetPlatformType(void);
|
|
||||||
|
|
||||||
CPU_FEATURES_END_CPP_NAMESPACE
|
CPU_FEATURES_END_CPP_NAMESPACE
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "internal/bit_utils.h"
|
#include "internal/bit_utils.h"
|
||||||
#include "internal/filesystem.h"
|
#include "internal/filesystem.h"
|
||||||
|
#include "internal/hwcaps.h"
|
||||||
#include "internal/stack_line_reader.h"
|
#include "internal/stack_line_reader.h"
|
||||||
#include "internal/string_view.h"
|
#include "internal/string_view.h"
|
||||||
|
|
||||||
@ -133,9 +134,19 @@ static const PPCPlatformStrings kEmptyPPCPlatformStrings;
|
|||||||
|
|
||||||
PPCPlatformStrings GetPPCPlatformStrings(void) {
|
PPCPlatformStrings GetPPCPlatformStrings(void) {
|
||||||
PPCPlatformStrings strings = kEmptyPPCPlatformStrings;
|
PPCPlatformStrings strings = kEmptyPPCPlatformStrings;
|
||||||
|
const char* platform = CpuFeatures_GetPlatformPointer();
|
||||||
|
const char* base_platform = CpuFeatures_GetBasePlatformPointer();
|
||||||
|
|
||||||
FillProcCpuInfoData(&strings);
|
FillProcCpuInfoData(&strings);
|
||||||
strings.type = CpuFeatures_GetPlatformType();
|
|
||||||
|
if (platform != NULL)
|
||||||
|
CpuFeatures_StringView_CopyString(str(platform), strings.type.platform,
|
||||||
|
sizeof(strings.type.platform));
|
||||||
|
if (base_platform != NULL)
|
||||||
|
CpuFeatures_StringView_CopyString(str(base_platform),
|
||||||
|
strings.type.base_platform,
|
||||||
|
sizeof(strings.type.base_platform));
|
||||||
|
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/hwcaps.c
21
src/hwcaps.c
@ -35,7 +35,8 @@ bool CpuFeatures_IsHwCapsSet(const HardwareCapabilities hwcaps_mask,
|
|||||||
#ifdef CPU_FEATURES_TEST
|
#ifdef CPU_FEATURES_TEST
|
||||||
// In test mode, hwcaps_for_testing will define the following functions.
|
// In test mode, hwcaps_for_testing will define the following functions.
|
||||||
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
|
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
|
||||||
PlatformType CpuFeatures_GetPlatformType(void);
|
const char* CpuFeatures_GetPlatformPointer(void);
|
||||||
|
const char* CpuFeatures_GetBasePlatformPointer(void);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Debug facilities
|
// Debug facilities
|
||||||
@ -163,20 +164,12 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
|
|||||||
return capabilities;
|
return capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformType kEmptyPlatformType;
|
const char *CpuFeatures_GetPlatformPointer(void) {
|
||||||
|
return (const char *)GetHardwareCapabilitiesFor(AT_PLATFORM);
|
||||||
|
}
|
||||||
|
|
||||||
PlatformType CpuFeatures_GetPlatformType(void) {
|
const char *CpuFeatures_GetBasePlatformPointer(void) {
|
||||||
PlatformType type = kEmptyPlatformType;
|
return (const char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM);
|
||||||
char *platform = (char *)GetHardwareCapabilitiesFor(AT_PLATFORM);
|
|
||||||
char *base_platform = (char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM);
|
|
||||||
|
|
||||||
if (platform != NULL)
|
|
||||||
CpuFeatures_StringView_CopyString(str(platform), type.platform,
|
|
||||||
sizeof(type.platform));
|
|
||||||
if (base_platform != NULL)
|
|
||||||
CpuFeatures_StringView_CopyString(str(base_platform), type.base_platform,
|
|
||||||
sizeof(type.base_platform));
|
|
||||||
return type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CPU_FEATURES_TEST
|
#endif // CPU_FEATURES_TEST
|
||||||
|
@ -24,6 +24,7 @@ namespace {
|
|||||||
void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
|
void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
|
||||||
|
|
||||||
TEST(CpuinfoAarch64Test, FromHardwareCap) {
|
TEST(CpuinfoAarch64Test, FromHardwareCap) {
|
||||||
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0);
|
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0);
|
||||||
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
||||||
const auto info = GetAarch64Info();
|
const auto info = GetAarch64Info();
|
||||||
@ -62,6 +63,7 @@ TEST(CpuinfoAarch64Test, FromHardwareCap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoAarch64Test, FromHardwareCap2) {
|
TEST(CpuinfoAarch64Test, FromHardwareCap2) {
|
||||||
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(AARCH64_HWCAP_FP,
|
SetHardwareCapabilities(AARCH64_HWCAP_FP,
|
||||||
AARCH64_HWCAP2_SVE2 | AARCH64_HWCAP2_BTI);
|
AARCH64_HWCAP2_SVE2 | AARCH64_HWCAP2_BTI);
|
||||||
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
||||||
@ -90,7 +92,7 @@ TEST(CpuinfoAarch64Test, FromHardwareCap2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoAarch64Test, ARMCortexA53) {
|
TEST(CpuinfoAarch64Test, ARMCortexA53) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(Processor : AArch64 Processor rev 3 (aarch64)
|
R"(Processor : AArch64 Processor rev 3 (aarch64)
|
||||||
|
@ -21,9 +21,8 @@
|
|||||||
namespace cpu_features {
|
namespace cpu_features {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
|
|
||||||
|
|
||||||
TEST(CpuinfoArmTest, FromHardwareCap) {
|
TEST(CpuinfoArmTest, FromHardwareCap) {
|
||||||
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(ARM_HWCAP_NEON, ARM_HWCAP2_AES | ARM_HWCAP2_CRC32);
|
SetHardwareCapabilities(ARM_HWCAP_NEON, ARM_HWCAP2_AES | ARM_HWCAP2_CRC32);
|
||||||
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
||||||
const auto info = GetArmInfo();
|
const auto info = GetArmInfo();
|
||||||
@ -52,7 +51,7 @@ TEST(CpuinfoArmTest, FromHardwareCap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoArmTest, ODroidFromCpuInfo) {
|
TEST(CpuinfoArmTest, ODroidFromCpuInfo) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo", R"(processor : 0
|
fs.CreateFile("/proc/cpuinfo", R"(processor : 0
|
||||||
model name : ARMv7 Processor rev 3 (v71)
|
model name : ARMv7 Processor rev 3 (v71)
|
||||||
@ -101,7 +100,7 @@ CPU revision : 3)");
|
|||||||
|
|
||||||
// Linux test-case
|
// Linux test-case
|
||||||
TEST(CpuinfoArmTest, RaspberryPiZeroFromCpuInfo) {
|
TEST(CpuinfoArmTest, RaspberryPiZeroFromCpuInfo) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo", R"(processor : 0
|
fs.CreateFile("/proc/cpuinfo", R"(processor : 0
|
||||||
model name : ARMv6-compatible processor rev 7 (v6l)
|
model name : ARMv6-compatible processor rev 7 (v6l)
|
||||||
@ -153,7 +152,7 @@ Serial : 000000006cd946f3)");
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoArmTest, MarvellArmadaFromCpuInfo) {
|
TEST(CpuinfoArmTest, MarvellArmadaFromCpuInfo) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo", R"(processor : 0
|
fs.CreateFile("/proc/cpuinfo", R"(processor : 0
|
||||||
model name : ARMv7 Processor rev 1 (v7l)
|
model name : ARMv7 Processor rev 1 (v7l)
|
||||||
@ -217,7 +216,7 @@ Serial : 0000000000000000)");
|
|||||||
// Android test-case
|
// Android test-case
|
||||||
// http://code.google.com/p/android/issues/detail?id=10812
|
// http://code.google.com/p/android/issues/detail?id=10812
|
||||||
TEST(CpuinfoArmTest, InvalidArmv7) {
|
TEST(CpuinfoArmTest, InvalidArmv7) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(Processor : ARMv6-compatible processor rev 6 (v6l)
|
R"(Processor : ARMv6-compatible processor rev 6 (v6l)
|
||||||
@ -267,6 +266,7 @@ Serial : 33323613546d00ec )");
|
|||||||
// Android test-case
|
// Android test-case
|
||||||
// https://crbug.com/341598.
|
// https://crbug.com/341598.
|
||||||
TEST(CpuinfoArmTest, InvalidNeon) {
|
TEST(CpuinfoArmTest, InvalidNeon) {
|
||||||
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(Processor: ARMv7 Processory rev 0 (v71)
|
R"(Processor: ARMv7 Processory rev 0 (v71)
|
||||||
@ -294,7 +294,7 @@ Serial: 00001e030000354e)");
|
|||||||
// The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
|
// The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
|
||||||
// support.
|
// support.
|
||||||
TEST(CpuinfoArmTest, Nexus4_0x510006f2) {
|
TEST(CpuinfoArmTest, Nexus4_0x510006f2) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(CPU implementer : 0x51
|
R"(CPU implementer : 0x51
|
||||||
@ -312,7 +312,7 @@ CPU revision : 2)");
|
|||||||
// The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
|
// The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
|
||||||
// support.
|
// support.
|
||||||
TEST(CpuinfoArmTest, Nexus4_0x510006f3) {
|
TEST(CpuinfoArmTest, Nexus4_0x510006f3) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(CPU implementer : 0x51
|
R"(CPU implementer : 0x51
|
||||||
@ -331,7 +331,7 @@ CPU revision : 3)");
|
|||||||
// 32-bit ARM IDIV instruction. Technically, this is a feature of the virtual
|
// 32-bit ARM IDIV instruction. Technically, this is a feature of the virtual
|
||||||
// CPU implemented by the emulator.
|
// CPU implemented by the emulator.
|
||||||
TEST(CpuinfoArmTest, EmulatorSpecificIdiv) {
|
TEST(CpuinfoArmTest, EmulatorSpecificIdiv) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(Processor : ARMv7 Processor rev 0 (v7l)
|
R"(Processor : ARMv7 Processor rev 0 (v7l)
|
||||||
|
@ -24,9 +24,8 @@ namespace cpu_features {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
|
|
||||||
|
|
||||||
TEST(CpuinfoMipsTest, FromHardwareCapBoth) {
|
TEST(CpuinfoMipsTest, FromHardwareCapBoth) {
|
||||||
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(MIPS_HWCAP_MSA | MIPS_HWCAP_R6, 0);
|
SetHardwareCapabilities(MIPS_HWCAP_MSA | MIPS_HWCAP_R6, 0);
|
||||||
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
||||||
const auto info = GetMipsInfo();
|
const auto info = GetMipsInfo();
|
||||||
@ -36,6 +35,7 @@ TEST(CpuinfoMipsTest, FromHardwareCapBoth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) {
|
TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) {
|
||||||
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(MIPS_HWCAP_MSA, 0);
|
SetHardwareCapabilities(MIPS_HWCAP_MSA, 0);
|
||||||
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
||||||
const auto info = GetMipsInfo();
|
const auto info = GetMipsInfo();
|
||||||
@ -44,7 +44,7 @@ TEST(CpuinfoMipsTest, FromHardwareCapOnlyOne) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoMipsTest, Ci40) {
|
TEST(CpuinfoMipsTest, Ci40) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo", R"(system type : IMG Pistachio SoC (B0)
|
fs.CreateFile("/proc/cpuinfo", R"(system type : IMG Pistachio SoC (B0)
|
||||||
machine : IMG Marduk – Ci40 with cc2520
|
machine : IMG Marduk – Ci40 with cc2520
|
||||||
@ -72,7 +72,7 @@ VPE : 0
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoMipsTest, AR7161) {
|
TEST(CpuinfoMipsTest, AR7161) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(system type : Atheros AR7161 rev 2
|
R"(system type : Atheros AR7161 rev 2
|
||||||
@ -98,7 +98,7 @@ VCEI exceptions : not available
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpuinfoMipsTest, Goldfish) {
|
TEST(CpuinfoMipsTest, Goldfish) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo", R"(system type : MIPS-Goldfish
|
fs.CreateFile("/proc/cpuinfo", R"(system type : MIPS-Goldfish
|
||||||
Hardware : goldfish
|
Hardware : goldfish
|
||||||
|
@ -22,9 +22,8 @@
|
|||||||
namespace cpu_features {
|
namespace cpu_features {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
|
|
||||||
|
|
||||||
TEST(CpustringsPPCTest, FromHardwareCap) {
|
TEST(CpustringsPPCTest, FromHardwareCap) {
|
||||||
|
ResetHwcaps();
|
||||||
SetHardwareCapabilities(PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_VSX,
|
SetHardwareCapabilities(PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_VSX,
|
||||||
PPC_FEATURE2_ARCH_3_00);
|
PPC_FEATURE2_ARCH_3_00);
|
||||||
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
GetEmptyFilesystem(); // disabling /proc/cpuinfo
|
||||||
@ -40,7 +39,7 @@ TEST(CpustringsPPCTest, FromHardwareCap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpustringsPPCTest, Blade) {
|
TEST(CpustringsPPCTest, Blade) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(processor : 14
|
R"(processor : 14
|
||||||
@ -57,7 +56,8 @@ timebase : 512000000
|
|||||||
platform : pSeries
|
platform : pSeries
|
||||||
model : IBM,8406-70Y
|
model : IBM,8406-70Y
|
||||||
machine : CHRP IBM,8406-70Y)");
|
machine : CHRP IBM,8406-70Y)");
|
||||||
SetPlatformTypes("power7", "power8");
|
SetPlatformPointer("power7");
|
||||||
|
SetBasePlatformPointer("power8");
|
||||||
const auto strings = GetPPCPlatformStrings();
|
const auto strings = GetPPCPlatformStrings();
|
||||||
ASSERT_STREQ(strings.platform, "pSeries");
|
ASSERT_STREQ(strings.platform, "pSeries");
|
||||||
ASSERT_STREQ(strings.model, "IBM,8406-70Y");
|
ASSERT_STREQ(strings.model, "IBM,8406-70Y");
|
||||||
@ -68,7 +68,7 @@ machine : CHRP IBM,8406-70Y)");
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpustringsPPCTest, Firestone) {
|
TEST(CpustringsPPCTest, Firestone) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(processor : 126
|
R"(processor : 126
|
||||||
@ -94,7 +94,7 @@ firmware : OPAL v3)");
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CpustringsPPCTest, w8) {
|
TEST(CpustringsPPCTest, w8) {
|
||||||
DisableHardwareCapabilities();
|
ResetHwcaps();
|
||||||
auto& fs = GetEmptyFilesystem();
|
auto& fs = GetEmptyFilesystem();
|
||||||
fs.CreateFile("/proc/cpuinfo",
|
fs.CreateFile("/proc/cpuinfo",
|
||||||
R"(processor : 143
|
R"(processor : 143
|
||||||
|
@ -22,25 +22,31 @@ namespace cpu_features {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static auto* const g_hardware_capabilities = new HardwareCapabilities();
|
static auto* const g_hardware_capabilities = new HardwareCapabilities();
|
||||||
static auto* const g_platform_types = new PlatformType();
|
static const char* g_platform_pointer = nullptr;
|
||||||
|
static const char* g_base_platform_pointer = nullptr;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) {
|
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2) {
|
||||||
g_hardware_capabilities->hwcaps = hwcaps;
|
g_hardware_capabilities->hwcaps = hwcaps;
|
||||||
g_hardware_capabilities->hwcaps2 = hwcaps2;
|
g_hardware_capabilities->hwcaps2 = hwcaps2;
|
||||||
}
|
}
|
||||||
|
void SetPlatformPointer(const char* string) { g_platform_pointer = string; }
|
||||||
|
void SetBasePlatformPointer(const char* string) {
|
||||||
|
g_base_platform_pointer = string;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetHwcaps() {
|
||||||
|
SetHardwareCapabilities(0, 0);
|
||||||
|
SetPlatformPointer(nullptr);
|
||||||
|
SetBasePlatformPointer(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
|
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
|
||||||
return *g_hardware_capabilities;
|
return *g_hardware_capabilities;
|
||||||
}
|
}
|
||||||
|
const char* CpuFeatures_GetPlatformPointer(void) { return g_platform_pointer; }
|
||||||
void SetPlatformTypes(const char* platform, const char* base_platform) {
|
const char* CpuFeatures_GetBasePlatformPointer(void) {
|
||||||
CpuFeatures_StringView_CopyString(str(platform), g_platform_types->platform,
|
return g_base_platform_pointer;
|
||||||
sizeof(g_platform_types->platform));
|
|
||||||
CpuFeatures_StringView_CopyString(str(base_platform),
|
|
||||||
g_platform_types->base_platform,
|
|
||||||
sizeof(g_platform_types->base_platform));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformType CpuFeatures_GetPlatformType(void) { return *g_platform_types; }
|
|
||||||
} // namespace cpu_features
|
} // namespace cpu_features
|
||||||
|
@ -20,7 +20,11 @@
|
|||||||
namespace cpu_features {
|
namespace cpu_features {
|
||||||
|
|
||||||
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2);
|
void SetHardwareCapabilities(uint32_t hwcaps, uint32_t hwcaps2);
|
||||||
void SetPlatformTypes(const char *platform, const char *base_platform);
|
void SetPlatformPointer(const char* string);
|
||||||
|
void SetBasePlatformPointer(const char* string);
|
||||||
|
|
||||||
|
// To be called before each test.
|
||||||
|
void ResetHwcaps();
|
||||||
|
|
||||||
} // namespace cpu_features
|
} // namespace cpu_features
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user