-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaultInjection_package.cpp
129 lines (115 loc) · 4.23 KB
/
faultInjection_package.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
#include "systemc.h"
#include <string>
#include <iostream>
using namespace std;
#ifndef __FIM.h_H__
#define __FIM.h_H__
enum Faults { SA0, SA1, BitFlip, NoFault };
SC_MODULE(SC_MODULE_FAULTABLE) {
public:
sc_signal <bool> faultInjected;
SC_MODULE_FAULTABLE() {}
};
class faultProperty{
private:
int moduleId;
int faultId;
int objId;
Faults faultType;
bool enable;
public:
faultProperty(){};
faultProperty(int moduleId, int objId, int faultId, Faults faultType) :moduleId{ moduleId }, objId{ objId }, faultId{ faultId }, faultType{ faultType }, enable(0) {}
void setFaultProperty(int moduleId, int objId, int faultId, Faults faultType){
this->moduleId = moduleId;
this->objId = objId;
this->faultId = faultId;
this->faultType = faultType;
this->enable = 0;
}
int getModuleId(){ return moduleId; }
int getObjId(){return objId;}
int getFaultId(){return faultId;}
Faults getFaultType(){return faultType;}
bool getEnable(){return enable;}
void enableFault(){enable=1;}
void disableFault(){enable=0;}
};
class faultRegistry {
private:
vector <SC_MODULE_FAULTABLE*> moduleVector;
vector <int> moduleIdVector;
vector <faultProperty*> faultVector;
public:
int registerModule(SC_MODULE_FAULTABLE* regModule);
void registerFault(faultProperty* regFault);
void saboteurOn(int moduleId, int objId, int faultId); //search, find, enable
void saboteurOff(int moduleId, int objId, int faultId); //search, find, disable
Faults getFaultType(int moduleId, int objId, int faultId); //search, find, getFaultType
Faults getObjectFaultType(int moduleId, int objId); //search, find, if enabled getFaultType
void infFaults();
void infStuckAt();
};
int faultRegistry::registerModule(SC_MODULE_FAULTABLE* regModule) {
moduleVector.push_back(regModule);
int moduleId = moduleVector.size()-1;
moduleIdVector.push_back(moduleId);
return moduleId;
}
void faultRegistry::registerFault(faultProperty* regFault) {
faultVector.push_back(regFault);
}
void faultRegistry::infFaults(){
for(int i=0; i<faultVector.size(); i++)
cout << "moduleId:" << faultVector[i]->getModuleId()
<< " objId:" << faultVector[i]->getObjId()
<< " faultId:" << faultVector[i]->getFaultId()
<< " type:" << faultVector[i]->getFaultType()
<< " enable:" << faultVector[i]->getEnable()
<< 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::saboteurOn(int moduleId, int objId, int faultId){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) && (faultVector[i]->getFaultId() == faultId)){
faultVector[i]->enableFault(); //Activate fault
// int mId = faultVector[i]-> getModuleId();
moduleVector[moduleId]->faultInjected.write(true); // Inject fault
}
}
}
void faultRegistry::saboteurOff(int moduleId, int objId, int faultId){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) && (faultVector[i]->getFaultId() == faultId)){
faultVector[i]->disableFault();
// int mId = faultVector[i]-> getModuleId();
moduleVector[moduleId]->faultInjected.write(false);
}
}
}
Faults faultRegistry::getFaultType(int moduleId, int objId, int faultId){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) && (faultVector[i]->getFaultId() == faultId))
return faultVector[i]->getFaultType();
}
return NoFault;
}
Faults faultRegistry::getObjectFaultType(int moduleId, int objId){
for(int i=0; i<faultVector.size(); i++){
if((faultVector[i]->getModuleId() == moduleId) && (faultVector[i]->getObjId() == objId) &&(faultVector[i]->getEnable() == true))
return faultVector[i]->getFaultType();
}
return NoFault;
}
#endif