File: cpuinfo_tests.cpp

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (171 lines) | stat: -rw-r--r-- 7,957 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 * Copyright (C) 2017-2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/utilities/cpu_info.h"

#include "gtest/gtest.h"

using namespace NEO;

void mockCpuidEnableAll(int cpuInfo[4], int functionId) {
    cpuInfo[0] = -1;
    cpuInfo[1] = -1;
    cpuInfo[2] = -1;
    cpuInfo[3] = -1;
}

void mockCpuidFunctionAvailableDisableAll(int cpuInfo[4], int functionId) {
    cpuInfo[0] = -1;
    cpuInfo[1] = 0;
    cpuInfo[2] = 0;
    cpuInfo[3] = 0;
}

void mockCpuidFunctionNotAvailableDisableAll(int cpuInfo[4], int functionId) {
    cpuInfo[0] = 0;
    cpuInfo[1] = 0;
    cpuInfo[2] = 0;
    cpuInfo[3] = 0;
}

void mockCpuidReport36BitVirtualAddressSize(int cpuInfo[4], int functionId) {
    if (static_cast<uint32_t>(functionId) == 0x80000008) {
        cpuInfo[0] = 36 << 8;
        cpuInfo[1] = 0;
        cpuInfo[2] = 0;
        cpuInfo[3] = 0;
    } else {
        mockCpuidEnableAll(cpuInfo, functionId);
    }
}

TEST(CpuInfoTest, giveFunctionIsNotAvailableWhenFeatureIsNotSupportedThenMaskBitIsOff) {
    void (*defaultCpuidFunc)(int[4], int) = CpuInfo::cpuidFunc;
    CpuInfo::cpuidFunc = mockCpuidFunctionNotAvailableDisableAll;

    CpuInfo testCpuInfo;

    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureFpu));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureCmov));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureMmx));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureFxsave));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSse));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE2));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE3));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSssE3));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE41));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE42));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureMovbe));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featurePopcnt));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featurePclmulqdq));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAes));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureF16C));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvx));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdrnd));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureFma));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureBmi));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureLzcnt));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureHle));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRtm));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureTsc));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdtscp));

    CpuInfo::cpuidFunc = defaultCpuidFunc;
}

TEST(CpuInfoTest, giveFunctionIsAvailableWhenFeatureIsNotSupportedThenMaskBitIsOff) {
    void (*defaultCpuidFunc)(int[4], int) = CpuInfo::cpuidFunc;
    CpuInfo::cpuidFunc = mockCpuidFunctionAvailableDisableAll;

    CpuInfo testCpuInfo;

    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureFpu));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureCmov));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureMmx));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureFxsave));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSse));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE2));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE3));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSssE3));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE41));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE42));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureMovbe));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featurePopcnt));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featurePclmulqdq));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAes));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureF16C));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvx));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdrnd));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureFma));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureBmi));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureLzcnt));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureHle));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRtm));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureTsc));
    EXPECT_FALSE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdtscp));

    CpuInfo::cpuidFunc = defaultCpuidFunc;
}

TEST(CpuInfoTest, whenFeatureIsSupportedThenMaskBitIsOn) {
    void (*defaultCpuidFunc)(int[4], int) = CpuInfo::cpuidFunc;
    CpuInfo::cpuidFunc = mockCpuidEnableAll;

    CpuInfo testCpuInfo;

    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureFpu));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureCmov));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureMmx));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureFxsave));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureSse));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE2));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE3));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureSssE3));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE41));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureSsE42));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureMovbe));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featurePopcnt));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featurePclmulqdq));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureAes));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureF16C));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvx));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdrnd));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureFma));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureBmi));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureLzcnt));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureHle));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureRtm));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureAvX2));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureClflush));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureTsc));
    EXPECT_TRUE(testCpuInfo.isFeatureSupported(CpuInfo::featureRdtscp));

    CpuInfo::cpuidFunc = defaultCpuidFunc;
}

TEST(CpuInfoTest, WhenGettingVirtualAddressSizeThenCorrectResultIsReturned) {
    void (*defaultCpuidFunc)(int[4], int) = CpuInfo::cpuidFunc;
    CpuInfo::cpuidFunc = mockCpuidReport36BitVirtualAddressSize;

    CpuInfo testCpuInfo;

    EXPECT_EQ(36u, testCpuInfo.getVirtualAddressSize());

    CpuInfo::cpuidFunc = defaultCpuidFunc;
}

TEST(CpuInfo, WhenGettingCpuidexThenOperationSucceeds) {
    const CpuInfo &cpuInfo = CpuInfo::getInstance();

    uint32_t cpuRegsInfo[4];
    uint32_t subleaf = 0;
    cpuInfo.cpuidex(cpuRegsInfo, 4, subleaf);
}