Sha256: 9586d7eee739f1c6313b79c916561426aa2322d8e0ecc76d0322239bca1e534f

Contents?: true

Size: 1.73 KB

Versions: 4

Compression:

Stored size: 1.73 KB

Contents

module Roby
    # Fault injection plugin for Roby
    #
    # Roby::FaultInjection::Application#fault_models defines a set of
    # probabilistic models of emission for task events. It maps task model
    # events to emission models, and during execution will randomly emit
    # events.
    #
    # Fault injection applies only on tasks which are running and interruptible.
    module FaultInjection
	# This module gets included in Roby::Application when the plugin is activated
	module Application
	    # The set of fault models defined for this application. More specifically,
	    # the emission model for an event +ev+ of a task model +model+ is given by
	    #
	    #   emission_model = Roby.app.fault_models[model][ev]
	    #
	    # where +ev+ is a symbol.
	    attribute(:fault_models) do
		Hash.new { |h, k| h[k] = Hash.new }
	    end

	    # call-seq:
	    #   Roby.app.fault_model task_model, emission_model, ev1, ev2, ...
	    #
	    # Defines +emission_model+ as the emission model for the listed
	    # events of task +task_model+. +ev1+, +ev2+ are symbols.
	    #
	    # Emission models are objects which must respond to #fault?(task).
	    # If this predicate returns true for the running task +task+, then
	    # the emission of the tested event will be simulated. The emission
	    # models are tested every one second.
	    #
	    # See Roby::FaultInjection::Rate for an example.
	    def add_fault_model(task_model, *args)
		fault_model = args.pop
		args.each do |ev|
		    fault_models[task_model][ev.to_sym] = fault_model
		end
	    end
	end
    end

    Application.register_plugin('fault_injection', Roby::FaultInjection::Application) do
	require 'fault_injection'
	Roby.every(1) do
	    FaultInjection.apply(Roby.app.fault_models)
	end
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roby-0.7.2 plugins/fault_injection/app.rb
roby-0.7.1 plugins/fault_injection/app.rb
roby-0.7 plugins/fault_injection/app.rb
roby-0.7.3 plugins/fault_injection/app.rb