Blame test/hydra/exit_status.rb

Packit 0848f5
#!/usr/bin/env ruby
Packit 0848f5
Packit 0848f5
# This script tests that hydra gives the correct output and error codes when
Packit 0848f5
# child programs exit in various ways.  If hydra's output format ever changes
Packit 0848f5
# then this test will need to be updated.
Packit 0848f5
Packit 0848f5
require 'test/unit'
Packit 0848f5
Packit 0848f5
class TestExitStatus < Test::Unit::TestCase
Packit 0848f5
  def test_exit0
Packit 0848f5
    output = `mpiexec -n 1 sh -c 'exit 0'`
Packit 0848f5
    assert $?.exitstatus == 0
Packit 0848f5
    assert output =~ /^$/;
Packit 0848f5
  end
Packit 0848f5
Packit 0848f5
  def test_exit1
Packit 0848f5
    errcode = 1
Packit 0848f5
    output = `mpiexec -n 1 sh -c 'exit #{errcode}'`
Packit 0848f5
    assert($?.exitstatus == errcode)
Packit 0848f5
    assert(output =~ /EXIT CODE: #{errcode}$/, "actual error code (#{errcode}) not reported")
Packit 0848f5
Packit 0848f5
    # also test the exact output format in this test and assume it is OK for now
Packit 0848f5
    # in most other cases
Packit 0848f5
    expected = <<-EOS
Packit 0848f5
=====================================================================================
Packit 0848f5
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
Packit 0848f5
=   EXIT CODE: #{errcode}
Packit 0848f5
=   CLEANING UP REMAINING PROCESSES
Packit 0848f5
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
Packit 0848f5
=====================================================================================
Packit 0848f5
    EOS
Packit 0848f5
    assert(expected.strip == output.strip)
Packit 0848f5
  end
Packit 0848f5
Packit 0848f5
  def test_exit254
Packit 0848f5
    errcode = 254
Packit 0848f5
    output = `mpiexec -n 1 sh -c 'exit #{errcode}'`
Packit 0848f5
    assert($?.exitstatus == errcode)
Packit 0848f5
    assert(output =~ /EXIT CODE: #{errcode}$/, "actual error code (#{errcode}) not reported")
Packit 0848f5
  end
Packit 0848f5
Packit 0848f5
  def test_exit255
Packit 0848f5
    errcode = 255
Packit 0848f5
    output = `mpiexec -n 1 sh -c 'exit #{errcode}'`
Packit 0848f5
    assert($?.exitstatus == errcode)
Packit 0848f5
    assert(output =~ /EXIT CODE: #{errcode}$/, "actual error code (#{errcode}) not reported")
Packit 0848f5
  end
Packit 0848f5
Packit 0848f5
  def test_segfault
Packit 0848f5
    # fake a segfault by sending SIGSEGV to ourself
Packit 0848f5
    output = `mpiexec -n 1 perl -e 'kill 11, $$'`
Packit 0848f5
Packit 0848f5
    # arguably this should really be 139 (128+11) to match up with regular shell
Packit 0848f5
    # behavior, although I don't know what the clearest way is to express this
Packit 0848f5
    # to the user
Packit 0848f5
    errcode = 11
Packit 0848f5
    assert($?.exitstatus == errcode)
Packit 0848f5
    assert(output =~ /EXIT CODE: #{errcode}$/, "actual error code (#{errcode}) not reported")
Packit 0848f5
Packit 0848f5
    # the "Segmentation fault: 11" string is probably platform-specific, we
Packit 0848f5
    # should compare accordingly
Packit 0848f5
    expected = <<-EOS
Packit 0848f5
=====================================================================================
Packit 0848f5
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
Packit 0848f5
=   EXIT CODE: #{errcode}
Packit 0848f5
=   CLEANING UP REMAINING PROCESSES
Packit 0848f5
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
Packit 0848f5
=====================================================================================
Packit 0848f5
YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault: 11 (signal 11)
Packit 0848f5
This typically refers to a problem with your application.
Packit 0848f5
Please see the FAQ page for debugging suggestions
Packit 0848f5
      EOS
Packit 0848f5
    # strip whitespace to be a little less sensitive
Packit 0848f5
    assert(expected.strip == output.strip)
Packit 0848f5
  end
Packit 0848f5
Packit 0848f5
  # TODO:
Packit 0848f5
  # - libc abort()
Packit 0848f5
  # - MPI_Abort()
Packit 0848f5
  # - something with more than one process
Packit 0848f5
end
Packit 0848f5