#include "cpu-arm-linux.h"
#include <string.h>
#include <gtest/gtest.h>
TEST(ARMLinuxTest, CPUInfo) {
struct CPUInfoTest {
const char *cpuinfo;
unsigned long hwcap;
unsigned long hwcap2;
bool broken_neon;
} kTests[] = {
{
"Processor: ARMv7 Processory rev 0 (v71)\n"
"processor: 0\n"
"BogoMIPS: 13.50\n"
"\n"
"Processor: 1\n"
"BogoMIPS: 13.50\n"
"\n"
"Features: swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 "
"idiva idivt\n"
"CPU implementer : 0x51\n"
"CPU architecture: 7\n"
"CPU variant: 0x1\n"
"CPU part: 0x04d\n"
"CPU revision: 0\n"
"\n"
"Hardware: SAMSUNG M2\n"
"Revision: 0010\n"
"Serial: 00001e030000354e\n",
HWCAP_NEON,
0,
true,
},
{
"Processor : ARMv7 Processor rev 0 (v7l)\n"
"processor : 0\n"
"BogoMIPS : 13.53\n"
"\n"
"Features : swp half thumb fastmult vfp edsp neon vfpv3 tls "
"vfpv4\n"
"CPU implementer : 0x51\n"
"CPU architecture: 7\n"
"CPU variant : 0x1\n"
"CPU part : 0x04d\n"
"CPU revision : 0\n"
"\n"
"Hardware : SAMSUNG M2_ATT\n"
"Revision : 0010\n"
"Serial : 0000df0c00004d4c\n",
HWCAP_NEON,
0,
true,
},
{
"Processor : ARMv7 Processor rev 2 (v7l)\n"
"processor : 0\n"
"BogoMIPS : 13.53\n"
"\n"
"processor : 1\n"
"BogoMIPS : 13.53\n"
"\n"
"processor : 2\n"
"BogoMIPS : 13.53\n"
"\n"
"processor : 3\n"
"BogoMIPS : 13.53\n"
"\n"
"Features : swp half thumb fastmult vfp edsp neon vfpv3 tls "
"vfpv4 \n"
"CPU implementer : 0x51\n"
"CPU architecture: 7\n"
"CPU variant : 0x0\n"
"CPU part : 0x06f\n"
"CPU revision : 2\n"
"\n"
"Hardware : QCT APQ8064 MAKO\n"
"Revision : 000b\n"
"Serial : 0000000000000000\n",
HWCAP_NEON,
0,
false,
},
{
"Processor : ARMv7 Processor rev 4 (v7l)\n"
"processor : 0\n"
"BogoMIPS : 13.53\n"
"\n"
"Features : swp half thumb fastmult vfp edsp neon vfpv3 tls "
"vfpv4\n"
"CPU implementer : 0x51\n"
"CPU architecture: 7\n"
"CPU variant : 0x1\n"
"CPU part : 0x04d\n"
"CPU revision : 4\n"
"\n"
"Hardware : msm8960dt\n"
"Revision : 82a0\n"
"Serial : 0001000201fe37a5\n",
HWCAP_NEON,
0,
false,
},
{
"Processor : AArch64 Processor rev 1 (aarch64)\n"
"processor : 0\n"
"BogoMIPS : 38.00\n"
"Features : fp asimd evtstrm aes pmull sha1 sha2 crc32\n"
"CPU implementer : 0x51\n"
"CPU architecture: 8\n"
"CPU variant : 0xa\n"
"CPU part : 0x801\n"
"CPU revision : 4\n"
"\n"
"processor : 1\n"
"BogoMIPS : 38.00\n"
"Features : fp asimd evtstrm aes pmull sha1 sha2 crc32\n"
"CPU implementer : 0x51\n"
"CPU architecture: 8\n"
"CPU variant : 0xa\n"
"CPU part : 0x801\n"
"CPU revision : 4\n"
"\n"
"processor : 2\n"
"BogoMIPS : 38.00\n"
"Features : fp asimd evtstrm aes pmull sha1 sha2 crc32\n"
"CPU implementer : 0x51\n"
"CPU architecture: 8\n"
"CPU variant : 0xa\n"
"CPU part : 0x801\n"
"CPU revision : 4\n"
"\n"
"processor : 3\n"
"BogoMIPS : 38.00\n"
"Features : fp asimd evtstrm aes pmull sha1 sha2 crc32\n"
"CPU implementer : 0x51\n"
"CPU architecture: 8\n"
"CPU variant : 0xa\n"
"CPU part : 0x801\n"
"CPU revision : 4\n"
"\n"
"Hardware : Qualcomm Technologies, Inc MSM8998\n",
HWCAP_NEON, HWCAP2_AES | HWCAP2_PMULL | HWCAP2_SHA1 | HWCAP2_SHA2,
false,
},
{
"Blah blah blah this is definitely an ARM CPU",
0,
0,
false,
},
{
"Features : aes pmull sha1 sha2\n"
"CPU architecture: 8\n",
HWCAP_NEON,
HWCAP2_AES | HWCAP2_PMULL | HWCAP2_SHA1 | HWCAP2_SHA2,
false,
},
{
"Features : aes sha1 sha2\n"
"CPU architecture: 8\n",
HWCAP_NEON,
HWCAP2_AES | HWCAP2_SHA1 | HWCAP2_SHA2,
false,
},
{
"Features : pmull sha2\n"
"CPU architecture: 8\n",
HWCAP_NEON,
HWCAP2_PMULL | HWCAP2_SHA2,
false,
},
{
"Features : aes aes aes not_aes aes aes \n"
"CPU architecture: 8\n",
HWCAP_NEON,
HWCAP2_AES,
false,
},
{
"Features : \n"
"CPU architecture: 8\n",
HWCAP_NEON,
0,
false,
},
{
"Features : nothing\n"
"CPU architecture: 8\n",
HWCAP_NEON,
0,
false,
},
{
"",
0,
0,
false,
},
};
for (const auto &t : kTests) {
SCOPED_TRACE(t.cpuinfo);
STRING_PIECE sp = {t.cpuinfo, strlen(t.cpuinfo)};
EXPECT_EQ(t.hwcap, crypto_get_arm_hwcap_from_cpuinfo(&sp));
EXPECT_EQ(t.hwcap2, crypto_get_arm_hwcap2_from_cpuinfo(&sp));
EXPECT_EQ(t.broken_neon ? 1 : 0, crypto_cpuinfo_has_broken_neon(&sp));
}
}