2013-01-15 17:46:05 -05:00
|
|
|
module Mutant
|
|
|
|
class Killer
|
|
|
|
|
|
|
|
# Killer that executes other killer in forked environment
|
|
|
|
class Forked < self
|
|
|
|
|
|
|
|
# Initialize object
|
|
|
|
#
|
|
|
|
# @param [Killer] killer
|
|
|
|
# @param [Strategy] strategy
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(killer, strategy, mutation)
|
|
|
|
@killer = killer
|
|
|
|
super(strategy, mutation)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Run killer
|
|
|
|
#
|
2013-04-17 23:31:21 -04:00
|
|
|
# @return [true]
|
2013-01-15 17:46:05 -05:00
|
|
|
# if mutant was killed
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run
|
2013-06-23 19:43:03 -04:00
|
|
|
pid = fork do
|
2013-06-23 16:22:35 -04:00
|
|
|
killer = @killer.new(strategy, mutation)
|
2013-07-04 18:20:45 -04:00
|
|
|
exit(killer.killed? ? CLI::EXIT_SUCCESS : CLI::EXIT_FAILURE)
|
2013-01-15 17:46:05 -05:00
|
|
|
end
|
|
|
|
|
2013-06-23 19:43:03 -04:00
|
|
|
status = Process.wait2(pid).last
|
2013-06-23 20:27:45 -04:00
|
|
|
status.exited? && status.success?
|
2013-01-15 17:46:05 -05:00
|
|
|
end
|
|
|
|
|
2013-06-14 14:54:02 -04:00
|
|
|
end # Forked
|
|
|
|
end # Killer
|
|
|
|
end # Mutant
|