ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Action.cpp
Go to the documentation of this file.
1 /*
2 
3  @copyright
4 
5  <pre>
6 
7  Copyright 2018 Infineon Technologies AG
8 
9  This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10 
11  The initial version of this software has been created with the funding support by the German Federal
12  Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13 
14  Redistribution and use in source and binary forms, with or without modification, are permitted
15  provided that the following conditions are met:
16 
17  1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18  the following disclaimer.
19 
20  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21  and the following disclaimer in the documentation and/or other materials provided with the distribution.
22 
23  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24  or promote products derived from this software without specific prior written permission.
25 
26  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  POSSIBILITY OF SUCH DAMAGE.
34 
35  </pre>
36 
37  @author Chair of Electronic Design Automation, TUM
38 
39  @version 0.1
40 
41 */
42 
43 #ifndef NO_ETISS
44 #include "etiss/fault/Action.h"
45 #else
46 #include "fault/Action.h"
47 #endif
48 
49 #include <sstream>
50 
51 namespace etiss
52 {
53 namespace fault
54 {
55 
57 {
58  if (type_ != t)
59  throw "wrong action type";
60 }
61 
62 Action::Action() : type_(NOP)
63 {
64  etiss::log(etiss::VERBOSE, std::string("etiss::fault::Action::Action() called. "));
65 }
66 
67 Action::Action(const InjectorAddress &inj, const std::string &command) : type_(COMMAND), inj_(inj), command_(command)
68 {
69  etiss::log(etiss::VERBOSE, std::string("etiss::fault::Action::Action(InjectorAddress &=") + inj.getInjectorPath() +
70  std::string(", command=") + command + std::string(") called. "));
71 }
72 
73 Action::Action(const InjectorAddress &inj, const std::string &field, unsigned bit)
74  : type_(BITFLIP), inj_(inj), field_(field), bit_(bit)
75 {
76  etiss::log(etiss::VERBOSE, std::string("etiss::fault::Action::Action(InjectorAddress &=") + inj.getInjectorPath() +
77  std::string(", field=") + field + std::string(", bit=") + std::to_string(bit) +
78  std::string(") called. "));
79 }
80 
81 Action::Action(const Fault &fault) : type_(INJECTION)
82 {
84  std::string("etiss::fault::Action::Action(Fault &=") + fault.toString() + std::string(") called. "));
85  fault_.push_back(fault);
86 }
87 
89 {
90  return type_;
91 }
92 
94 {
95  return inj_;
96 }
97 
99 const std::string &Action::getCommand() const
100 {
101  return command_;
102 }
103 
105 const std::string &Action::getTargetField() const
106 {
107  return field_;
108 }
109 
111 unsigned Action::getTargetBit() const
112 {
113  return bit_;
114 }
115 
116 const Fault &Action::getFault() const
117 {
118  if (type_ != INJECTION)
119  throw "Action doesn't have the type INJECTION: cannot call getFault()";
120  return fault_.front();
121 }
122 
123 std::string Action::toString() const
124 {
125  pugi::xml_document doc;
126  doc.load("<?xml version=\"1.0\"?>");
127 
128  etiss::fault::xml::Diagnostics diag;
129 
130  etiss::fault::xml::write<etiss::fault::Action>(doc.append_child("action"), *this, diag);
131 
132  std::stringstream ss;
133 
134  doc.save(ss);
135 
136  return ss.str();
137 }
138 
139 #if ETISS_FAULT_XML
140 namespace xml
141 {
142 template <>
143 bool parse<etiss::fault::Action>(pugi::xml_node node, etiss::fault::Action &f, Diagnostics &diag)
144 {
145  etiss::log(etiss::VERBOSE, std::string("etiss::fault::parse<etiss::fault::Action>(node, Action") +
146  std::string(", Diagnostics) called. "));
147 
148  std::string type;
149  if (!parse_attr(node, "type", type, diag))
150  {
151  diag.unexpectedNode(node, "Failed to parse type of action");
152  return false;
153  }
154 
155  if (type == "NOP")
156  {
157  f = Action();
158  return true;
159  }
160  else if (type == "BITFLIP")
161  {
163  if (!etiss::cfg().get<bool>("faultInjection::allowBitFlip", true))
164  return true;
165  if (!parse<etiss::fault::InjectorAddress>(findSingleNode(node, "injector", diag), inj, diag))
166  {
167  diag.unexpectedNode(node, "Failed to parse target injector");
168  return false;
169  }
170  std::string field;
171  if (!parse<std::string>(findSingleNode(node, "field", diag), field, diag))
172  {
173  diag.unexpectedNode(node, "Failed to parse target field");
174  return false;
175  }
176  setCoreName(field);
177  unsigned bit;
178  if (!parse<unsigned>(findSingleNode(node, "bit", diag), bit, diag))
179  {
180  diag.unexpectedNode(node, "Failed to parse target bit");
181  return false;
182  }
183  f = Action(inj, field, bit);
184  return true;
185  }
186  else if (type == "COMMAND")
187  {
189  if (!parse<etiss::fault::InjectorAddress>(findSingleNode(node, "injector", diag), inj, diag))
190  {
191  diag.unexpectedNode(node, "Failed to parse target injector");
192  return false;
193  }
194  std::string command;
195  if (!parse<std::string>(findSingleNode(node, "command", diag), command, diag))
196  {
197  diag.unexpectedNode(node, "Failed to parse target command");
198  return false;
199  }
200  f = Action(inj, command);
201  return true;
202  }
203  else if (type == "INJECTION")
204  {
206  if (!parse<Fault>(findSingleNode(node, "fault", diag), inj, diag))
207  {
208  diag.unexpectedNode(node, "Failed to parse fault to inject");
209  return false;
210  }
211  f = Action(inj);
212  return true;
213  }
214  else
215  {
216  diag.unexpectedNode(node, std::string("Unknown type of action: ") + type);
217  return false;
218  }
219  return false;
220 }
221 template <>
222 bool write<etiss::fault::Action>(pugi::xml_node node, const etiss::fault::Action &f, Diagnostics &diag)
223 {
224  etiss::log(etiss::VERBOSE, std::string("etiss::fault::write<etiss::fault::Action>(node, Action&=") +
225  std::string(", Diagnostics) called. "));
226  bool ok = true;
227  switch (f.getType())
228  {
230  return write_attr<std::string>(node, "type", "NOP", diag);
231  break;
233  ok = ok & write_attr<std::string>(node, "type", "BITFLIP", diag);
234  ok = ok & write(node.append_child("injector"), f.getInjectorAddress(), diag);
235  ok = ok & write<std::string>(node.append_child("field"), f.getTargetField(), diag);
236  ok = ok & write<unsigned>(node.append_child("bit"), f.getTargetBit(), diag);
237  break;
239  ok = ok & write_attr<std::string>(node, "type", "COMMAND", diag);
240  ok = ok & write<std::string>(node.append_child("command"), f.getCommand(), diag);
241  break;
243  ok = ok & write_attr<std::string>(node, "type", "INJECTION", diag);
244  ok = ok & write<Fault>(node.append_child("fault"), f.getFault(), diag);
245  break;
246  }
247  return false;
248 }
249 
250 } // namespace xml
251 #endif
252 
253 } // namespace fault
254 
255 } // namespace etiss
contains an action class that describes actions associated with a fault
std::vector< Fault > fault_
for other injections
Definition: Action.h:140
InjectorAddress inj_
Definition: Action.h:136
const InjectorAddress & getInjectorAddress() const
Definition: Action.cpp:93
@ BITFLIP
applies a bit flip to a bit in a specified field
Definition: Action.h:83
@ INJECTION
an action that injects a fault definition (trigger + actions)
Definition: Action.h:90
@ NOP
NO Operation. used by default constructor.
Definition: Action.h:88
@ COMMAND
commands are targetet at Injectors, not fields.
Definition: Action.h:86
unsigned bit_
concerning Bit (for fault injection)
Definition: Action.h:139
std::string toString() const
operator<< can be used.
Definition: Action.cpp:123
std::string command_
command e.g. for booting OR1KVCPU
Definition: Action.h:137
Type getType() const
Definition: Action.cpp:88
const std::string & getCommand() const
COMMAND only.
Definition: Action.cpp:99
const std::string & getTargetField() const
BITFLIP only.
Definition: Action.cpp:105
Type type_
type of the Attribute
Definition: Action.h:135
std::string field_
concerning Field (for fault injection)
Definition: Action.h:138
const Fault & getFault() const
INJECTION only.
Definition: Action.cpp:116
unsigned getTargetBit() const
BITFLIP only.
Definition: Action.cpp:111
void ensure(Type)
Definition: Action.cpp:56
std::string toString() const
operator<< can be used.
Definition: Fault.cpp:213
const std::string & getInjectorPath() const
xml_parse_result load(std::basic_istream< char, std::char_traits< char > > &stream, unsigned int options=parse_default, xml_encoding encoding=encoding_auto)
void save(xml_writer &writer, const char_t *indent=PUGIXML_TEXT("\t"), unsigned int flags=format_default, xml_encoding encoding=encoding_auto) const
Definition: pugixml.cpp:6125
xml_node append_child(xml_node_type type=node_element)
Definition: pugixml.cpp:4983
void setCoreName(std::string &str)
Definition: XML.cpp:62
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
@ VERBOSE
Definition: Misc.h:130
Configuration & cfg(const std::string &cfgName)
Get reference of the global ETISS configuration object.
Definition: Misc.cpp:560
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition: Misc.cpp:125