• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 
3 #include <stdint.h>
4 #include <string.h>
5 
6 #include <string>
7 
8 #define CPUINFO_HARDWARE_VALUE_MAX 64
9 #define CPUINFO_BUILD_PROP_VALUE_MAX 92
10 #define CPUINFO_ARM_CHIPSET_NAME_MAX 48
11 
12 extern "C" void cpuinfo_arm_android_parse_chipset_properties(
13 	const char proc_cpuinfo_hardware[CPUINFO_HARDWARE_VALUE_MAX],
14 	const char ro_product_board[CPUINFO_BUILD_PROP_VALUE_MAX],
15 	const char ro_board_platform[CPUINFO_BUILD_PROP_VALUE_MAX],
16 	const char ro_mediatek_platform[CPUINFO_BUILD_PROP_VALUE_MAX],
17 	const char ro_arch[CPUINFO_HARDWARE_VALUE_MAX],
18 	const char ro_chipname[CPUINFO_BUILD_PROP_VALUE_MAX],
19 	uint32_t cores,
20 	uint32_t max_cpu_freq_max,
21 	char chipset_name[CPUINFO_ARM_CHIPSET_NAME_MAX]);
22 
parse_chipset(std::string hardware,std::string product_board,std::string board_platform,std::string mediatek_platform,std::string arch,std::string chipname,uint32_t cores=1,uint32_t max_cpu_freq_max=0)23 inline std::string parse_chipset(
24 	std::string hardware,
25 	std::string product_board,
26 	std::string board_platform,
27 	std::string mediatek_platform,
28 	std::string arch,
29 	std::string chipname,
30 	uint32_t cores=1,
31 	uint32_t max_cpu_freq_max=0)
32 {
33 	char chipset_name[CPUINFO_ARM_CHIPSET_NAME_MAX];
34 	cpuinfo_arm_android_parse_chipset_properties(
35 		hardware.c_str(), product_board.c_str(), board_platform.c_str(), mediatek_platform.c_str(), arch.c_str(), chipname.c_str(),
36 		cores, max_cpu_freq_max, chipset_name);
37 	return std::string(chipset_name, strnlen(chipset_name, CPUINFO_ARM_CHIPSET_NAME_MAX));
38 }
39 
TEST(ANDROID_PROPERTIES,disambiguate_chipset)40 TEST(ANDROID_PROPERTIES, disambiguate_chipset) {
41 #if CPUINFO_ARCH_ARM
42 	EXPECT_EQ("Amlogic S812",
43 		parse_chipset("Amlogic Meson8", "n200C", "meson8", "", "", ""));
44 	EXPECT_EQ("HiSilicon Kirin 925",
45 		parse_chipset("Kirin925", "MT7-L09", "hi3630", "", "", ""));
46 #endif /* CPUINFO_ARCH_ARM */
47 	EXPECT_EQ("HiSilicon Kirin 955",
48 		parse_chipset("Hisilicon Kirin 955", "EVA-L09", "hi3650", "", "", ""));
49 #if CPUINFO_ARCH_ARM
50 	EXPECT_EQ("Marvell PXA986",
51 		parse_chipset("PXA988", "PXA986", "mrvl", "", "", ""));
52 	EXPECT_EQ("Marvell PXA986",
53 		parse_chipset("PXA988", "PXA986", "mrvl", "", "", "PXA986"));
54 #endif /* CPUINFO_ARCH_ARM */
55 	EXPECT_EQ("MediaTek MT6735P",
56 		parse_chipset("MT6735P", "MT6735P", "mt6735m", "MT6735", "", ""));
57 	EXPECT_EQ("MediaTek MT8382",
58 		parse_chipset("MT8382", "MT8382", "", "MT6582", "", ""));
59 	EXPECT_EQ("MediaTek MT6735P",
60 		parse_chipset("MT6735P", "unknown", "mt6735m", "MT6735", "", ""));
61 	EXPECT_EQ("MediaTek MT8382",
62 		parse_chipset("MT8382", "LenovoTAB2A7-30HC", "", "MT6582", "", ""));
63 	EXPECT_EQ("Qualcomm MSM8926",
64 		parse_chipset("Qualcomm MSM 8226 (Flattened Device Tree)", "MSM8226", "msm8226", "", "", "MSM8926"));
65 	EXPECT_EQ("Qualcomm MSM8926",
66 		parse_chipset("Qualcomm MSM8926", "draconis", "msm8226", "", "", ""));
67 	EXPECT_EQ("Qualcomm MSM8930AB",
68 		parse_chipset("SAMSUNG SERRANO", "MSM8960", "msm8960", "", "", "MSM8930AB", 2));
69 	EXPECT_EQ("Qualcomm MSM8940",
70 		parse_chipset("Qualcomm Technologies, Inc MSM8940", "msm8937_32", "msm8937", "", "", "", 8));
71 	EXPECT_EQ("Spreadtrum SC6815AS",
72 		parse_chipset("scx15", "SC6815AS", "scx15", "", "", "SC6815AS"));
73 	EXPECT_EQ("Spreadtrum SC7727S",
74 		parse_chipset("sc8830", "SC7727S", "sc8830", "", "", "SC7727S"));
75 	EXPECT_EQ("Spreadtrum SC7731",
76 		parse_chipset("sc7731", "SC7731", "sc8830", "", "", ""));
77 	EXPECT_EQ("Spreadtrum SC7731C",
78 		parse_chipset("sc7731c", "sp7731cea", "sc8830", "", "", ""));
79 }
80 
TEST(ANDROID_PROPERTIES,ambiguous_vendors)81 TEST(ANDROID_PROPERTIES, ambiguous_vendors) {
82 	EXPECT_EQ("",
83 		parse_chipset("MTK6580", "sp7731ceb", "sc8830", "", "", ""));
84 	EXPECT_EQ("",
85 		parse_chipset("", "universal5410", "msm8974", "", "", ""));
86 	EXPECT_EQ("",
87 		parse_chipset("MT6580", "universal8895", "mt6580", "MT6580", "", ""));
88 #if CPUINFO_ARCH_ARM
89 	EXPECT_EQ("",
90 		parse_chipset("", "smdk4x12", "msm8974", "", "", "", 2));
91 #endif /* CPUINFO_ARCH_ARM */
92 }
93 
TEST(ANDROID_PROPERTIES,unambiguous_chipset)94 TEST(ANDROID_PROPERTIES, unambiguous_chipset) {
95 	EXPECT_EQ("Samsung Exynos 3470",
96 		parse_chipset("UNIVERSAL_GARDA", "universal_garda", "exynos3", "", "exynos3470", "exynos3470"));
97 	EXPECT_EQ("MediaTek MT6582",
98 		parse_chipset("APPLE A8", "APPLE A8", "", "MT6582", "", ""));
99 #if CPUINFO_ARCH_ARM
100 	EXPECT_EQ("NovaThor U8500",
101 		parse_chipset("SAMSUNG GOLDEN", "DB8520H", "montblanc", "", "", ""));
102 #endif /* CPUINFO_ARCH_ARM */
103 	EXPECT_EQ("MediaTek MT6580",
104 		parse_chipset("Qualcomm", "unknown", "mt6580", "MT6580", "", ""));
105 	EXPECT_EQ("HiSilicon Kirin 650",
106 		parse_chipset("", "hi6250", "", "", "", ""));
107 	EXPECT_EQ("Samsung Exynos 8890",
108 		parse_chipset("", "universal8890", "exynos5", "", "exynos8890", "exynos8890"));
109 	EXPECT_EQ("MediaTek MT6582",
110 		parse_chipset("", "MT6582", "", "MT6582", "", ""));
111 	EXPECT_EQ("Qualcomm MSM8994",
112 		parse_chipset("", "msm8994", "msm8994", "", "", ""));
113 	EXPECT_EQ("Qualcomm APQ8064",
114 		parse_chipset("SAMSUNG JF", "MSM8960", "msm8960", "", "", "apq8064", 4));
115 	EXPECT_EQ("MediaTek MT6795",
116 		parse_chipset("", "mt6795", "mt6795", "MT6795", "", ""));
117 #if CPUINFO_ARCH_ARM
118 	EXPECT_EQ("Marvell PXA1908",
119 		parse_chipset("PXA1908", "PXA19xx", "mrvl", "", "", "PXA19xx"));
120 #endif /* CPUINFO_ARCH_ARM */
121 	EXPECT_EQ("Spreadtrum SC7715A",
122 		parse_chipset("scx15", "SM-G928G", "scx15", "", "", "SC7715A"));
123 	EXPECT_EQ("MediaTek MT6592",
124 		parse_chipset("MT6592", "lcsh92_cwet_htc_kk", "", "MT6592", "", ""));
125 	EXPECT_EQ("HiSilicon Kirin 620",
126 		parse_chipset("hi6210sft", "BalongV8R1SFT", "hi6210sft", "", "", ""));
127 	EXPECT_EQ("Qualcomm APQ8064",
128 		parse_chipset("PANTECH APQ8064 EF52L", "VEGA", "msm8960", "", "", "apq8064", 4));
129 	EXPECT_EQ("MediaTek MT6580M",
130 		parse_chipset("MT6580M", "unknown", "mt6580", "MT6580", "", ""));
131 #if CPUINFO_ARCH_ARM
132 	EXPECT_EQ("Samsung Exynos 4412",
133 		parse_chipset("SMDK4x12", "smdk4x12", "exynos4", "", "", "smdk4x12", 4));
134 #endif /* CPUINFO_ARCH_ARM */
135 	EXPECT_EQ("Samsung Exynos 7420",
136 		parse_chipset("SAMSUNG Exynos7420", "universal7420", "exynos5", "", "exynos7420", "exynos7420"));
137 	EXPECT_EQ("MediaTek MT6582",
138 		parse_chipset("MT6582", "MT6582", "", "MT6582", "", ""));
139 	EXPECT_EQ("Qualcomm MSM8916",
140 		parse_chipset("Qualcomm Technologies, Inc MSM8916", "msm8916", "msm8916", "", "", "", 4));
141 	EXPECT_EQ("Qualcomm MSM8916",
142 		parse_chipset("Qualcomm Technologies, Inc MSM8916", "MSM8916", "msm8916", "", "", "MSM8916", 4));
143 	EXPECT_EQ("MediaTek MT6735",
144 		parse_chipset("MT6735", "mt6735", "mt6735", "MT6735", "", ""));
145 	EXPECT_EQ("MediaTek MT6737T",
146 		parse_chipset("Samsung GrandPrimePlus LTE CIS rev04 board based on MT6737T", "MT6737T", "mt6737t", "MT6737T", "", "MT6737T"));
147 }
148