Blame test/hydra/exit_status.rb

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