[TF port] Disable tests for GetCurrentCpu() on iOS/OS X because MacOS has a __cpuid bug.
PiperOrigin-RevId: 226125575
This commit is contained in:
parent
4e57040e94
commit
1fc046c3a8
@ -35,10 +35,11 @@ TEST(Port, AlignedMalloc) {
|
|||||||
|
|
||||||
TEST(Port, GetCurrentCPU) {
|
TEST(Port, GetCurrentCPU) {
|
||||||
const int cpu = GetCurrentCPU();
|
const int cpu = GetCurrentCPU();
|
||||||
// TODO(b/120919972): Re-enable this EXPECT_GE after fixing MacOS Kokoro
|
#if !defined(__APPLE__)
|
||||||
// failures.
|
// GetCurrentCPU does not currently work on MacOS.
|
||||||
// EXPECT_GE(cpu, 0);
|
EXPECT_GE(cpu, 0);
|
||||||
EXPECT_LT(cpu, NumTotalCPUs());
|
EXPECT_LT(cpu, NumTotalCPUs());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConditionVariable, WaitForMilliseconds_Timeout) {
|
TEST(ConditionVariable, WaitForMilliseconds_Timeout) {
|
||||||
|
@ -29,7 +29,7 @@ limitations under the License.
|
|||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__APPLE__) && (__x86_64__ || __i386__)
|
#if (__x86_64__ || __i386__)
|
||||||
#include <cpuid.h>
|
#include <cpuid.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -78,20 +78,24 @@ int NumSchedulableCPUs() {
|
|||||||
|
|
||||||
int NumTotalCPUs() {
|
int NumTotalCPUs() {
|
||||||
int count = absl::base_internal::NumCPUs();
|
int count = absl::base_internal::NumCPUs();
|
||||||
return (count == 0) ? kUnknownCPU : count;
|
return (count <= 0) ? kUnknownCPU : count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCurrentCPU() {
|
int GetCurrentCPU() {
|
||||||
#if defined(__linux__) && !defined(__ANDROID__)
|
#if defined(__linux__) && !defined(__ANDROID__)
|
||||||
return sched_getcpu();
|
return sched_getcpu();
|
||||||
#elif defined(__cpuid_count)
|
|
||||||
// Attempt to use cpuid on all other platforms. If that fails, perform a
|
// Attempt to use cpuid on all other platforms. If that fails, perform a
|
||||||
// syscall.
|
// syscall.
|
||||||
uint32_t eax, ebx, ecx, edx;
|
#elif defined(__cpuid) && !defined(__APPLE__)
|
||||||
__cpuid_count(/*leaf=*/1, /*subleaf=*/0, eax, ebx, ecx, edx);
|
// TODO(b/120919972): __cpuid returns invalid APIC ids on OS X.
|
||||||
if ((edx & (1 << 9)) != 0) {
|
uint32_t eax = 0;
|
||||||
|
uint32_t ebx = 0;
|
||||||
|
uint32_t ecx = 0;
|
||||||
|
uint32_t edx = 0;
|
||||||
|
__cpuid(/*level=*/1, eax, ebx, ecx, edx);
|
||||||
|
if ((edx & /*bit_APIC=*/(1 << 9)) != 0) {
|
||||||
// EBX bits 24-31 are APIC ID
|
// EBX bits 24-31 are APIC ID
|
||||||
return static_cast<unsigned int>(ebx >> 24);
|
return (ebx & 0xFF) >> 24;
|
||||||
}
|
}
|
||||||
#elif defined(__NR_getcpu)
|
#elif defined(__NR_getcpu)
|
||||||
unsigned int cpu;
|
unsigned int cpu;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user