Class: Evilution::Isolation::Fork Private

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/isolation/fork.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

GRACE_PERIOD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

2
REAP_DEADLINE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1.0

Instance Method Summary collapse

Constructor Details

#initialize(hooks: nil) ⇒ Fork

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Fork.



16
17
18
19
20
21
22
# File 'lib/evilution/isolation/fork.rb', line 16

def initialize(hooks: nil)
  @hooks = hooks
  # EV-3aw3 / EV-5rrh step 2: the supervisor owns this path's lifecycle --
  # spawn + process-group isolation, the TERM/grace/KILL ladder, and reap +
  # sandbox removal. fork.rb keeps only the marshal-pipe read protocol.
  @supervisor = Evilution::ProcessSupervisor.new
end

Instance Method Details

#call(mutation:, test_command:, timeout:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/evilution/isolation/fork.rb', line 24

def call(mutation:, test_command:, timeout:)
  handle = nil
  sandbox_dir = Dir.mktmpdir("evilution-run")
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  parent_rss = Evilution::Memory.rss_kb
  read_io, write_io = binary_pipe
  handle = spawn_child(read_io, write_io, sandbox_dir, mutation, test_command)
  write_io.close
  result = wait_for_result(handle, read_io, timeout)
  duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
  build_mutation_result(mutation, result, duration, parent_rss)
ensure
  cleanup_resources(read_io, write_io, handle, sandbox_dir)
end