import time from classes.Logging import Logging from threading import Thread from random import uniform import common_parameters as cp # All common parameters will bet at common_parameters module import os,signal import sys """ Signal the app to stop so GDB can execute the script to flip a value """ class SignalApp(Thread): def __init__(self, signal_cmd, max_wait_time, log_path, unique_id, signals_to_send, init_sleep, syncro,waitfinish): global hang hang=False super(SignalApp, self).__init__() self.__signal_cmd = signal_cmd os.system("rm -f {}".format(log_path)) self.__log = Logging(log_file=log_path, unique_id=unique_id) # Most of the benchmarks we cannot wait until the end of the processing # Considering most of 90% of the time #self.__init_wait_time = uniform(init_sleep, max_wait_time * cp.MAX_SIGNAL_BEFORE_ENDING) self.__init_wait_time = uniform(0, max_wait_time * cp.MAX_SIGNAL_BEFORE_ENDING) self.__signals_to_send = signals_to_send self.__time_to_sleep = (max_wait_time - self.__init_wait_time) / self.__signals_to_send # self.__time_to_sleep = (max_wait_time) / self.__signals_to_send self._syncro=syncro self._waitfinish=waitfinish def run(self): # Send a series of signal to make sure gdb will flip a value in one of the interrupt signals log_string = "Sending a signal using command: {} after {}s and each {}s.".format(self.__signal_cmd, self.__init_wait_time,self.__time_to_sleep) if cp.DEBUG: self.__log.info(log_string) # Sleep for a random time # time.sleep(self.__init_wait_time) #a=[ uniform.randint(1,1000) for _ in range(self.__signals_to_send))] #a.sort() #os.system(self.__signal_cmd) #for line in os.popen(self.__signal_cmd): # pid=int(line) #os.kill(int(self.__signal_cmd),signal.SIGINT) self.__log.info(log_string) try: (self._syncro).wait() #except threading.BrokenBarrierError: except: (self._syncro).abort() self.__log.info("Breakpoint inicial fuera de tiempo") #(self._waitfinish).wait() (self._syncro).reset() hang=True self.__log.info("Timeout syncron of breakpoint\n") pid = (os.popen(self.__signal_cmd)).read() pid=int(pid.split('\n')[0]) #print("Comando {} y resultado {} de tipo {}".format(self.__signal_cmd,pid, type (pid)) ) # Time random #print ("INIT:"+str(self.__init_wait_time)+"sleep"+str()) time.sleep(self.__init_wait_time) for signals in range(0, self.__signals_to_send): #os.system("{} > /dev/null 2>/dev/null".format(self.__signal_cmd)) try: os.kill(pid,signal.SIGINT) except: self.__log.info("Process is dead") break self.__log.info("sending signal {}".format(signals)) try: (self._syncro).wait() except: (self._syncro).abort() break #print("Breakpoint fuera de tiempo") (self._syncro).reset() time.sleep(self.__time_to_sleep) #(self._syncro).reset() try: (self._waitfinish).wait() #except threading.BrokenBarrierError: except: (self._waitfinish).abort() self.__log.info("Hang timeout execution") hang=True self.__log.info("Timeout execution programa") (self._waitfinish).reset() def ishang (self): return hang def get_int_wait_time(self): return self.__init_wait_time