Commit 27bf99f6 authored by German Leon's avatar German Leon
Browse files

Implementado INST_OUT

parent cc607270
......@@ -22,7 +22,7 @@ class BitFlip:
self.__fault_model = kwargs.get('fault_model')
self.__logging = kwargs.get('logging')
self.__injection_site = kwargs.get('injection_site')
self.__maxregs=kwargs.get('max_regs')
self.__maxregs=int(kwargs.get('max_regs'))
self.fault_injected = False
"""
......@@ -37,7 +37,101 @@ class BitFlip:
"""
TODO: Describe the method
"""
def asmline(self):
#Leo la linea de ejecucion
return cf.execute_command(gdb=gdb, to_execute="x/1i $pc")
def reg_asmline( self):
#Obtengo los registros de la instruccion
linea= self.asmline()
self.__assmline="ASSM_LINE:{}".format(linea[0])
#print (linea)#+"-"+str(len(linea))+"-"+linea[0])
#print ("============")
lista=re.findall(r"R(\d+)", linea[0])
setlista=set()
setlista.update(lista)
#self.__logging.info(str(len(setlista)))
return setlista
def regmod (self):
lista=self.reg_asmline()
while len(lista) == 0: #Habria que poner un limite.
#Busco una instruccion que referiencia algun registro
self.__logging.info("INSTRUCTION WITHOUT DESTINATION REGISTER")
gdb.execute("nexti")
lista=self.reg_asmline()
listareg=[" R{} ".format(x) for x in lista]
strlistareg="info registers "
for x in listareg:
strlistareg+=x;
#print (strlistareg)
self.__stringregs=strlistareg
#self.__logging.info("REFERED REGISTERS :"+strlistareg)
#Obtengo el valor de los registro referenciados
valores= cf.execute_command(gdb=gdb, to_execute=strlistareg)
return valores
def nextinstr(self):
#Obtengo el valor de los registro referenciados por la primera instruccipn
#self.__logging.info("===============================")
gdb.execute("nexti")
#self.__logging.info("==============================="+self.__stringregs)
linea= self.asmline()
#self.__logging.info("ASSM_LINE:{}".format(linea))
valores= cf.execute_command(gdb=gdb, to_execute=self.__stringregs)
return valores
def dictreg(self,valores):
#self.__logging.info("Execute dictreg")
#Almaceno en un dictionario los valores de los registros
regs={}
for x in valores:
print(x)
m = re.match(r".*R(\d+).*0x([0-9a-fA-F]+).*", x)
if m:
regs[m.group(1)]=m.group(2)
print (str(m.group(1))+":= "+str(m.group(2)))
#print(regs)
#print ("========DR")
return regs
def cmpregdst (self,valores,regs):
#Comparo los regsitros, para saber cuales he modificado.
#self.__logging.info("Execute cmpregdst------------")#+str(type(valores)))
regdst=set()
#print("==cmpregdst")
#print("Arg;..valores...")
#print(type(valores))
#print (valores)
for x in valores:
m = re.match(r".*R(\d+).*0x([0-9a-fA-F]+).*", x)
if m:
#print("El registro {} tiene {} y tenia{}".format(m.group(1),m.group(2),regs[m.group(1)]))
if (regs[m.group(1)]!=m.group(2)):
#print("Diferente")
regdst.add(m.group(1))
#self.__logging.info(str(len(regdst)))
return regdst
def __inst_generic_injector(self):
#def miinst_out():
#self.__logging.info("Comienzo")
regs=self.dictreg(self.regmod())
#self.__logging.info("Reg1")
valores=self.nextinstr()
#self.__logging.info("Ejecutado sfte instuccion")
r=self.cmpregdst(valores,regs)
#self.__logging.info("Se han modificado {}".format(len(r)))
while (len(r) ==0):
self.__logging.info("INSTRUCTION WITHOUT OPERANDS")
gdb.execute("nexti")
regs=self.dictreg( self.regmod())
valores=self.nextinstr()
r=self.cmpregdst(valores,regs)
self.__register="R{}".format(r.pop())
self.__logging.info("SELECTED_REGISTER:{}".format(self.__register))
self.__logging.info("ASSM_LINE:{}".format(self.__assmline))
# __rf_generic_injector will set fault_injected attribute
self.__rf_generic_injector()
def single_event(self):
# fault_injected attribute will be set by the methods that perform fault injection
# Focusing the thread. If focus succeed, otherwise not
......@@ -210,13 +304,14 @@ class BitFlip:
#self.__logging.info ("LIne salida:{}".format(m.group(1))
# max_num_register += 1
#self.__logging.info("LIne entrada {}--max{}".format(line,max_num_register))
self.__register = "R{}".format(random.randint(0, self.__maxregs-1))
self.__logging.info("MAX_NUM_REGISTER:{}".format(self.__maxregs))
#self.__logging.info("MAX_NUM_REGISTER:{}".format(self.__maxregs))
self.__register = "R{}".format(random.randint(0, (self.__maxregs)-1))
"""
Instruction injector
"""
def __inst_generic_injector(self):
def __inst_generic_injector_old(self):
disassemble_array = cf.execute_command(gdb=gdb, to_execute="disassemble")
# Search the line to inject
# -1 will use the next instruction after program counter
......
......@@ -47,10 +47,11 @@ class SignalApp(Thread):
(self._syncro).wait()
#except threading.BrokenBarrierError:
except:
(self._syncro).abort()
print("Breakpoint fuera de tiempo")
hang=True
self.__log.info("Timeout syncron of breakpoint\n")
(self._syncro).abort()
print("Breakpoint inicial fuera de tiempo")
(self._syncro).reset()
hang=True
self.__log.info("Timeout syncron of breakpoint\n")
# Time random
#print ("INIT:"+str(self.__init_wait_time)+"sleep"+str())
......@@ -58,6 +59,13 @@ class SignalApp(Thread):
for signals in range(0, self.__signals_to_send):
os.system("{} > /dev/null 2>/dev/null".format(self.__signal_cmd))
self.__log.info("sending signal {}".format(signals))
#try:
# (self._syncro).wait()
#except threading.BrokenBarrierError:
#except:
# (self._syncro).abort()
# print("Breakpoint fuera de tiempo")
#(self._syncro).reset()
time.sleep(self.__time_to_sleep)
(self._syncro).reset()
try:
......
......@@ -17,7 +17,9 @@ faultModel = 0
# RF -> Register File
# INST_OUT -> Instruction Output (NOT IMPLEMENTED YET)
# INST_composed -> Instruction Adress (NOT IMPLEMENTED YET)
injectionSite = RF
#injectionSite = RF
injectionSite = INST_OUT
# Max time factor to finish the app, this will be multiplied by the application running time
# For example if your app spend 2s, and the maxWaitTimes is 5, the max running time before it is
# Considered as a crash is 10s
......
......@@ -223,17 +223,22 @@ def check_sdcs_and_app_crash(logging, sdc_check_script, inj_output_path, inj_err
with open(diff_log_path, 'r') as fi:
out_lines = fi.readlines()
if len(out_lines) != 0:
# Check if NVIDIA signals on output
for line in out_lines:
if 'PASS' in line:
print("PASS=="+line+"====")
is_masked= True
break
if 'FAIL' in line:
print("FAIL=="+line+"====")
is_sdc= True
break
for carol_fi_signal in cp.SIGNALS:
for line in out_lines:
if carol_fi_signal in line:
print("FAIL=="+line+"====")
is_app_crash[0] = True
if len (is_app_crash) == 1:
is_app_crash.append(carol_fi_signal)
......@@ -300,7 +305,7 @@ def check_injection_outcome(host_thread, logging, injection_site):
# if fault was injected ASSM_LINE MUST be in the logfile
assm_line = logging.search("ASSM_LINE")
instruction = re.match(r".*:\t(\S+) .*", assm_line).group(1)
instruction = assm_line
#instruction = assm_line
except TypeError as te:
instruction = new_value = old_value = None
......@@ -333,7 +338,7 @@ def gdb_inject_fault(**kwargs):
seq_signals = kwargs.get('seq_signals')
init_sleep = kwargs.get('init_sleep')
sdc_check_script = kwargs.get('gold_check_script')
maxregs=kwargs.get('max_regs').
maxregs=kwargs.get('max_regs')
# signalCmd
signal_cmd = kwargs.get("signal_cmd")
......@@ -357,7 +362,7 @@ def gdb_inject_fault(**kwargs):
logging.info("Starting GDB script")
# Generate configuration file for specific test
gdb_env_string = "{}|{}|{}|{}|{}|{}|file {}; set args {}|{}".format(gdb_kernel,os.getpid(),max_regs,",".join(str(i) for i in bits_to_flip), fault_model,
gdb_env_string = "{}|{}|{}|{}|{}|{}|file {}; set args {}|{}".format(gdb_kernel,os.getpid(),maxregs,",".join(str(i) for i in bits_to_flip), fault_model,
flip_log_file, benchmark_binary, benchmark_args,
injection_site)
......
......@@ -38,9 +38,8 @@ def set_event(event):
bp.enabled=False
gdb.execute('c')
# #os.system ("killall -2 python3")
else:
elif (isinstance(event, gdb.SignalEvent)):
try:
# Just checking if it was hit
if bit_flip.fault_injected is False:
bit_flip.single_event()
......@@ -49,7 +48,7 @@ def set_event(event):
except Exception as err:
global_logging.exception("EVENT DIFFERENT FROM STOP SIGNAL: {}".format(str(err)))
#De esta forma, si llega un event por nexti (event.stop), no realiza nada.
"""
Main function
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment