Пример #1
0
from respkernel import get_namespace
controller = get_namespace()['controller']
import sc_controller_wrapper

""" Commodity module to handle callbacks and breakpoints via Python """

global breaks
breaks = []

class GenericBreakpoint( sc_controller_wrapper.DeltaCallback ):
    """ A generic breakpoint class: it stops simulation when a certain condition occurs """

    def __init__(self, object, attribute, checker):
        sc_controller_wrapper.DeltaCallback.__init__(self)
        self.object = object
        self.attribute = attribute
        self.checker = checker

    def __call__(self):
        value = getattr(self.object, self.attribute)
        if self.checker(value):
            controller.pause_simulation()

#
# Commodity checker classes
#
class equals:
    def __init__(self,y):
        self.y = y

    def __call__(self, x):
Пример #2
0
    def executeSingleFault(self, num):
        """Executes a fault simulation"""
        self.__currExpNum = num
        self.timeout = False
        import respkernel
        try:
            resp_ns = respkernel.get_namespace()
            controller = resp_ns['controller']
        except:
            import respkernel
            controller = respkernel.controller

        #import of required modules
        import attributeWrapper

        if controller.interactive == True:
            raise exceptions.Exception('It is not possible to run executeSingleFault function in the interactive mode')
        
        if not isinstance(num,int) and not isinstance(num,long):
            raise exceptions.Exception('Not compatible parameter received by the executeSingleFault function')
        if not num >= 0 and num < self.__currentFaultList:
            raise exceptions.Exception('Not compatible parameter received by the executeSingleFault function')            
        command = self.__currentFaultList[num]
        
        times = command.keys()
        if not (len(times) > 0):
            raise exceptions.Exception('Empty fault list: the simulation cannot be executed')
        
        #compute time deltas to be run
        times.sort()
        delta = {}
        delta[times[0]] = times[0]
        for i in range(1,len(times)):
            delta[times[i]] = times[i] - times[i-1]
        #print times
        for t in times: #execute all delta and inject
            #run for a delta time  
            controller.run_simulation(delta[t])                        
            #print controller.get_simulated_time()
            #inject fault
            if not t == times[len(times)-1]: #after the last delta time no injection is performed
                injections = command[t]
                #inject all the faults
                for fault in injections:
                    #get the reference to the class of the mask function
                    maskFunctionName = fault['mask_function']
                    if dir(resp_ns).count(maskFunctionName) != 0:
                        maskFunction = resp_ns[maskFunctionName]()
                    elif dir(attributeWrapper).count(maskFunctionName) != 0:#maskFunctions.count(maskFunctionName) != 0:
                        maskFunction = getattr(attributeWrapper,maskFunctionName)()
                    else:
                        raise exceptions.Exception( str(maskFunctionName) + ' is not a valid mask function')
                    
                    #get the reference to the class of the attribute wrapper
                    wrapperClassName = fault['wrapper']
                    if dir(resp_ns).count(wrapperClassName) != 0:
                        wrapperClass = resp_ns[wrapperClassName]
                    elif dir(attributeWrapper).count(wrapperClassName) != 0:
                        wrapperClass = getattr(attributeWrapper,wrapperClassName)
                    else:
                        raise exceptions.Exception( str(wrapperClassName) + ' is not a valid wrapper class')
                    
                    wrapper = wrapperClass(resp_ns['manager'].getCompInstance(fault['component']), fault['attribute'], maskFunction, fault['line'])
                    wrapper.applyMask(fault['mask'])                    

            #check if simulation is finished
            if controller.is_finished(): 
                break
        if not controller.is_finished():
            self.timeout = True
            controller.stop_simulation()