#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/cpu.h"
#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/memory/protected_memory_buildflags.h"
#include "base/strings/string_util.h"
#include "base/test/gtest_util.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(CPU, RunExtendedInstructions) { … }
TEST(CPU, BrandAndVendorContainsNoNUL) { … }
#if defined(ARCH_CPU_X86_FAMILY)
TEST(CPU, X86FamilyAndModel) { … }
#endif
#if defined(ARCH_CPU_ARM_FAMILY) && \
(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS))
TEST(CPU, ARMImplementerAndPartNumber) {
base::CPU cpu;
const std::string& cpu_brand = cpu.cpu_brand();
EXPECT_EQ(cpu_brand, base::TrimWhitespaceASCII(cpu_brand, base::TRIM_ALL));
EXPECT_GT(cpu.implementer(), 0u);
EXPECT_GT(cpu.part_number(), 0u);
}
#endif
#if BUILDFLAG(PROTECTED_MEMORY_ENABLED)
TEST(CPUDeathTest, VerifyModifyingCPUInstanceNoAllocationCrashes) {
const base::CPU& cpu = base::CPU::GetInstanceNoAllocation();
uint8_t* const bytes =
const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&cpu));
for (size_t byte_index = 0; byte_index < sizeof(cpu); byte_index += 15) {
const size_t local_bit_index = byte_index % 8;
EXPECT_CHECK_DEATH_WITH(bytes[byte_index] ^= (0x01 << local_bit_index), "");
}
}
#endif