-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIM.cpp
324 lines (264 loc) · 12 KB
/
FIM.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include "FIM.h"
using namespace std;
const vector<string> getModuleName(SC_MODULE_FAULTABLE* regModule){
string full_name;
vector<string> name;
full_name = regModule->name();
// convert string to stringstream to use stream properties (here getline)
stringstream sstream(full_name);
string tempString;
while(getline(sstream, tempString, '.')){
name.push_back(tempString);
}
// std::cout << "+++ Module name: ----" << std::endl;
// for(vector<string>::iterator it = name.begin(); it != name.end(); it++){
// std::cout << (*it) << std::endl;
// }
// std::cout << "+++ getmodule name ends: ----" << std::endl;
return name;
}
void faultRegistry::registerModule(SC_MODULE_FAULTABLE* regModule) {
moduleVector.push_back(regModule);
string hierarchical_name = regModule->testbenchId + "." + regModule->designId + "." + regModule->hardwareObjectId;
std::cout << "++ Registered Module: " << hierarchical_name << std::endl;
moduleIdVector.push_back(hierarchical_name);
}
void faultRegistry::registerFault(faultProperty* regFault) {
faultVector.push_back(regFault);
}
vector<vector<string>> faultRegistry::readFaultList(ifstream& faultList){
vector<vector<string>> complete_flist;
while(faultList){
string line;
getline(faultList, line);
// create vector of string to save each token
vector<string> fault_prop;
// convert strin to stringstream to use stream properties (here getline)
stringstream sstream(line);
string tempString;
while(getline(sstream, tempString, '/')){
fault_prop.push_back(tempString);
}
// on the last round, right before EOF break the loop (otherwise raises seg. fault)
if(!faultList){
break;
}
// convert "one" char to string
string str2c(1, fault_prop.back().back());
fault_prop.push_back(str2c);
// remove two last char (fault value + white space)
fault_prop[fault_prop.size() - 2].pop_back();
fault_prop[fault_prop.size() - 2].pop_back();
complete_flist.push_back(fault_prop);
}
return complete_flist;
}
void faultRegistry::saboteurOn(string testbenchId, string designId, string moduleId, string objId, Faults faultType){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getTestbenchId() == testbenchId) && (faultVector[i]->getDesignId() == designId) &&
(faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) &&
(faultVector[i]->getFaultType() == faultType)){
faultVector[i]->enableFault(); //Activate fault
// std::cout << "faultVector of " << std::endl;
// std::cout << faultVector[i]->getTestbenchId() << " = " << testbenchId << std::endl;
// std::cout << faultVector[i]->getDesignId() << " = " << designId << std::endl;
// std::cout << faultVector[i]->getModuleId() << " = " << moduleId << std::endl;
// std::cout << faultVector[i]->getObjId() << " = " << objId << std::endl;
// std::cout << faultVector[i]->getFaultType() << " = " << faultType << std::endl;
// std::cout << "enabled ----------------------- " << std::endl;
}
}
string hierarchical_name = testbenchId + "." + designId + "." + moduleId;
for (int j=0; j<moduleIdVector.size(); j++){
if(moduleIdVector[j] == hierarchical_name){
std::cout << "## enable faultInjected signal on module:: ";
moduleVector[j]->faultInjected.write(true); // Inject fault
// std::cout << hierarchical_name << std::endl;
std::cout << moduleIdVector[j] << std::endl;
// std::cout << moduleVector[j]->hardwareObjectId << std::endl;
}
}
}
void faultRegistry::saboteurOff(string testbenchId, string designId, string moduleId, string objId, Faults faultType){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getTestbenchId() == testbenchId) && (faultVector[i]->getDesignId() == designId) &&
(faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) &&
(faultVector[i]->getFaultType() == faultType)){
faultVector[i]->disableFault();
}
}
string hierarchical_name = testbenchId + "." + designId + "." + moduleId;
for (int j=0; j<moduleIdVector.size(); j++){
if(moduleIdVector[j] == hierarchical_name)
moduleVector[j]->faultInjected.write(false); // deactivate fault
}
}
void faultRegistry::injectFaultList(const vector<vector<string>>& faultList, int faultNumber){
// { testbench, dut, module, obj, fault_type }
string fault_properties[5];
const string fault_p_title[] = {
"testbench | ",
"dut | ",
"module | ",
"obj | ",
"faultType | "
};
if(faultNumber <= faultList.size()){
std::cout << "Fault to be Injected: " << std::endl;
std::cout << "----------|-------------- " << std::endl;
if(faultNumber == 0){ // if (fualtNumber == 0) inject all faults
// traverse each line (fault)
for(int i=0; i < faultList.size(); i++){
// traverse fault properties
for(int j=0; j < faultList[i].size(); j++){
fault_properties[j] = faultList[i][j];
std::cout << fault_p_title[j] << fault_properties[j] << std::endl;
}
if(fault_properties[4] == "0")
this->saboteurOn(fault_properties[0], fault_properties[1], fault_properties[2], fault_properties[3],SA0);
if(fault_properties[4] == "1")
this->saboteurOn(fault_properties[0], fault_properties[1], fault_properties[2], fault_properties[3],SA1);
}
} else { // if ( 0 < faultNumber < faultList.size() ) inject one specific fault
// traverse fault properties
for(int j=0; j < faultList[faultNumber - 1].size(); j++){
fault_properties[j] = faultList[faultNumber - 1][j];
std::cout << fault_p_title[j] << fault_properties[j] << std::endl;
}
if(fault_properties[4] == "0")
this->saboteurOn(fault_properties[0], fault_properties[1], fault_properties[2], fault_properties[3],SA0);
if(fault_properties[4] == "1")
this->saboteurOn(fault_properties[0], fault_properties[1], fault_properties[2], fault_properties[3],SA1);
}
} else { // if fault number is greater than fault list range
std::cout << "OUT OF RANGE ERROR: number exceeds range of fault list" << std::endl;
}
}
void faultRegistry::removeFaultList(const vector<vector<string>>& faultList, int faultNumber){
// { testbench, dut, module, obj, fault_type }
string fault_properties[5];
const string fault_p_title[] = {
"testbench | ",
"dut | ",
"module | ",
"obj | ",
"faultType | "
};
if(faultNumber <= faultList.size()){
std::cout << "Fault to be removed: " << std::endl;
std::cout << "----------|-------------- " << std::endl;
if(faultNumber == 0){ // if (fualtNumber == 0) inject all faults
// traverse each line (fault)
for(int i=0; i < faultList.size(); i++){
// traverse fault properties
for(int j=0; j < faultList[i].size(); j++){
fault_properties[j] = faultList[i][j];
std::cout << fault_p_title[j] << fault_properties[j] << std::endl;
}
if(fault_properties[4] == "0")
this->saboteurOff(fault_properties[0], fault_properties[1], fault_properties[2],fault_properties[3],SA0);
if(fault_properties[4] == "1")
this->saboteurOff(fault_properties[0], fault_properties[1], fault_properties[2],fault_properties[3],SA1);
}
} else { // if ( 0 < faultNumber < faultList.size() ) inject one specific fault
// traverse fault properties
for(int j=0; j < faultList[faultNumber - 1].size(); j++){
fault_properties[j] = faultList[faultNumber - 1][j];
std::cout << fault_p_title[j] << fault_properties[j] << std::endl;
}
if(fault_properties[4] == "0")
this->saboteurOff(fault_properties[0], fault_properties[1], fault_properties[2],fault_properties[3],SA0);
if(fault_properties[4] == "1")
this->saboteurOff(fault_properties[0], fault_properties[1], fault_properties[2],fault_properties[3],SA1);
}
} else { // if fault number is greater than fault list range
std::cout << "OUT OF RANGE ERROR: number exceeds range of fault list" << std::endl;
}
}
bool faultRegistry::is_module_faulty(string testbenchId, string designId, string moduleId){
bool fault_enable = false;
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getTestbenchId() == testbenchId) && (faultVector[i]->getDesignId() == designId) &&
(faultVector[i]->getModuleId() == moduleId)){
fault_enable = fault_enable || faultVector[i]->getEnable();
}
}
return fault_enable;
}
bool faultRegistry::is_object_faulty(string testbenchId, string designId, string moduleId, string objId){
bool fault_enable = false;
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getTestbenchId() == testbenchId) && (faultVector[i]->getDesignId() == designId) &&
(faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId)){
fault_enable = fault_enable || faultVector[i]->getEnable();
}
}
return fault_enable;
}
int faultRegistry::getFaultId(string testbenchId, string designId, string moduleId, string objId, Faults faultType){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getTestbenchId() == testbenchId) && (faultVector[i]->getDesignId() == designId) &&
(faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) &&
(faultVector[i]->getFaultType() == faultType)){
return faultVector[i]->getFaultId();
}
}
return NoFault;
}
Faults faultRegistry::getObjectFaultType(string testbenchId, string designId, string moduleId, string objId){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getTestbenchId() == testbenchId) && (faultVector[i]->getDesignId() == designId) &&
(faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) && (faultVector[i]->getEnable() == true)){
return faultVector[i]->getFaultType();
}
}
return NoFault;
}
void faultRegistry::infFaults(){
std::cout << std::endl;
std::cout << "Registered fualt objects" << std::endl;
std::cout << "Total number of faultable objects: " << faultVector.size() << std::endl;
std::cout << "+++----+++----+++----+++----+++" << std::endl;
for(int i=0; i<faultVector.size(); i++){
std::cout << "Faulty object ==== Nubmer: " << i << std::endl;
std::cout << "-------------------------------" << std::endl;
std::cout << "getTestbenchId | " << faultVector[i]->getTestbenchId() << std::endl
<< "getDesignId | " << faultVector[i]->getDesignId() << std::endl
<< "moduleId | " << faultVector[i]->getModuleId() << std::endl
<< "objId | " << faultVector[i]->getObjId() << std::endl
<< "faultId | " << faultVector[i]->getFaultId() << std::endl
<< "type | " << faultVector[i]->getFaultType() << std::endl
<< "enable | " << faultVector[i]->getEnable() << std::endl;
std::cout << std::endl;
}
std::cout << "-----------------------------" << std::endl;
}
void faultRegistry::infStuckAt(){
for (int i = 0; i < faultVector.size(); i++){
if (faultVector[i]->getFaultType() == SA0 || faultVector[i]->getFaultType() == SA1){
cout << "moduleId:" << faultVector[i]->getModuleId()
<< " objId:" << faultVector[i]->getObjId()
<< " faultId:" << faultVector[i]->getFaultId()
<< " type:" << faultVector[i]->getFaultType()
<< " enable:" << faultVector[i]->getEnable()
<< endl;
}
}
}
void faultRegistry::disp_faultList(vector<vector<string>>& faultList){
for(int i = 0; i < faultList.size(); i++){
std::cout << "On line " << i << " of fault list there is fault with description below: " << std::endl;
int j = 0;
const string prop_name[] = {
"@ testbench: ",
"@ design under test: ",
"@ module name: ",
"@ port name: ",
"@ stuck at value: "
};
for(vector<string>::iterator it = faultList[i].begin(); it != faultList[i].end(); it++){
std::cout << prop_name[j] << (*it) << std::endl;
j++;
}
}
}