forked from nvmecompliance/tnvme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
236 lines (199 loc) · 7.76 KB
/
test.cpp
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright (c) 2011, Intel Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "tnvme.h"
#include "test.h"
#include "globals.h"
#include "./Utils/kernelAPI.h"
Test::Test(string grpName, string testName, SpecRev specRev)
{
mSpecRev = specRev;
mGrpName = grpName;
mTestName = testName;
mResult = TR_SUCCESS;
}
Test::~Test()
{
///////////////////////////////////////////////////////////////////////////
// Allocations taken from the heap and not under the control of the
// RsrcMngr need to be freed/deleted here.
///////////////////////////////////////////////////////////////////////////
}
Test::Test(const Test &other) :
mSpecRev(other.mSpecRev), mGrpName(other.mGrpName),
mTestName(other.mTestName), mTestDesc(other.mTestDesc),
mResult(other.mResult)
{
///////////////////////////////////////////////////////////////////////////
// All pointers in this object must be NULL, never allow shallow or deep
// copies, see Test::Clone() header comment.
///////////////////////////////////////////////////////////////////////////
}
Test &
Test::operator=(const Test &other)
{
///////////////////////////////////////////////////////////////////////////
// All pointers in this object must be NULL, never allow shallow or deep
// copies, see Test::Clone() header comment.
///////////////////////////////////////////////////////////////////////////
mSpecRev = other.mSpecRev;
mGrpName = other.mGrpName;
mTestName = other.mTestName;
mTestDesc = other.mTestDesc;
mResult = other.mResult;
return *this;
}
TestResult
Test::Run()
{
try {
ResetStatusRegErrors();
KernelAPI::DumpKernelMetrics(FileSystem::PrepDumpFile(mGrpName,
mTestName, "kmetrics", "preTestRun"));
RunCoreTest(); // Throws upon errors, returns upon success
// What do the PCI registers say about errors that may have occurred?
if (GetStatusRegErrors() == false)
return TR_FAIL;
} catch (FrmwkEx &ex) {
return TR_FAIL;
} catch (...) {
// If this exception is thrown from some library which tnvme links
// with then there is nothing that can be done about this. However,
// If the source of this exception is source within the compliance
// suite, then remove it, see class note in file Exception/frmwkEx.h
LOG_ERR("******************************************************");
LOG_ERR("******************************************************");
LOG_ERR("* Unsupp'd exception, replace with \"throw FrmwkEx\" *");
LOG_ERR("* see class note in file Exception/frmwkEx.h *");
LOG_ERR("******************************************************");
LOG_ERR("******************************************************");
return TR_FAIL;
}
return mResult;
}
Test::RunType
Test::Runnable(bool preserve)
{
try {
return RunnableCoreTest(preserve); // Throws upon errors
} catch (FrmwkEx &ex) {
return RUN_FAIL;
} catch (...) {
// If this exception is thrown from some library which tnvme links
// with then there is nothing that can be done about this. However,
// If the source of this exception is source within the compliance
// suite, then remove it, see class note in file Exception/frmwkEx.h
LOG_ERR("******************************************************");
LOG_ERR("******************************************************");
LOG_ERR("* Unsupp'd exception, replace with \"throw FrmwkEx\" *");
LOG_ERR("* see class note in file Exception/frmwkEx.h *");
LOG_ERR("******************************************************");
LOG_ERR("******************************************************");
return RUN_FAIL;
}
}
void
Test::ResetStatusRegErrors()
{
const vector<PciCapabilities> *cap = gRegisters->GetPciCapabilities();
// The following algo is taking advantage of the fact that writing
// RO register bits have no effect, but will have effect on RWC bits
LOG_NRM("Resetting sticky PCI errors");
gRegisters->Write(PCISPC_STS, 0xffff);
for (uint16_t i = 0; i < cap->size(); i++) {
if (cap->at(i) == PCICAP_PXCAP)
gRegisters->Write(PCISPC_PXDS, 0xffff);
else if (cap->at(i) == PCICAP_AERCAP)
gRegisters->Write(PCISPC_AERUCES, 0xffffffff);
}
}
bool
Test::GetStatusRegErrors()
{
uint64_t value = 0;
uint64_t expectedValue = 0;
const PciSpcType *pciMetrics = gRegisters->GetPciMetrics();
const CtlSpcType *ctlMetrics = gRegisters->GetCtlMetrics();
const vector<PciCapabilities> *cap = gRegisters->GetPciCapabilities();
// PCI STS register may indicate some error
if (gRegisters->Read(PCISPC_STS, value) == false)
return false;
expectedValue = (value & ~((uint64_t)gCmdLine.errRegs.sts));
if (value != expectedValue) {
LOG_ERR("%s error bit #%d indicates test failure",
pciMetrics[PCISPC_STS].desc,
ReportOffendingBitPos(value, expectedValue));
return false;
}
// Other optional PCI errors
for (uint16_t i = 0; i < cap->size(); i++) {
if (cap->at(i) == PCICAP_PXCAP) {
if (gRegisters->Read(PCISPC_PXDS, value) == false)
return false;
expectedValue = (value & ~((uint64_t)gCmdLine.errRegs.pxds));
if (value != expectedValue) {
LOG_ERR("%s error bit #%d indicates test failure",
pciMetrics[PCISPC_PXDS].desc,
ReportOffendingBitPos(value, expectedValue));
return false;
}
} else if (cap->at(i) == PCICAP_AERCAP) {
if (gRegisters->Read(PCISPC_AERUCES, value) == false)
return false;
expectedValue = (value & ~((uint64_t)gCmdLine.errRegs.aeruces));
if (value != expectedValue) {
LOG_ERR("%s error bit #%d indicates test failure",
pciMetrics[PCISPC_PXDS].desc,
ReportOffendingBitPos(value, expectedValue));
return false;
}
}
}
// Ctrl'r STS register may indicate some error
if (gRegisters->Read(CTLSPC_CSTS, value) == false)
return false;
expectedValue = (value & ~((uint64_t)gCmdLine.errRegs.csts));
if (value != expectedValue) {
LOG_ERR("%s error bit #%d indicates test failure",
ctlMetrics[CTLSPC_CSTS].desc,
ReportOffendingBitPos(value, expectedValue));
return false;
}
return true;
}
int
Test::ReportOffendingBitPos(uint64_t val, uint64_t expectedVal)
{
uint64_t bitMask;
for (int i = 0; i < (int)(sizeof(uint64_t)*8); i++) {
bitMask = (1 << i);
if ((val & bitMask) != (expectedVal & bitMask)) {
LOG_NRM("Reg val(0x%016lX) expect val(0x%016lX)", val, expectedVal);
return i;
}
}
return INT_MAX; // there is no mismatch
}
void
Test::RunCoreTest()
{
throw FrmwkEx(HERE, "Children must over ride to provide functionality");
}
Test::RunType
Test::RunnableCoreTest(bool preserve)
{
preserve = preserve; // Suppress compiler error/warning
throw FrmwkEx(HERE, "Children must over ride to provide functionality");
}