Timeout-test.inc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2014, 2015 Free Software Foundation, Inc.
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3, or (at your option)
  6. # any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # Shell script snippet. Wait for program to finish.
  16. # Not timed out yet
  17. TIMED_OUT=
  18. # Attempt to test if "read -t" works. Under Solaris 10, read -t below
  19. # should exit the subshell with an error exit status. Under some other
  20. # shells the subshell will not exit but the "read -t" will have an exit
  21. # status of 2, representing a syntax error.
  22. status=0
  23. (read -t 0 ; test $? != 2 ; exit $?)
  24. if test $? != 0; then
  25. # skip test below
  26. status=2
  27. fi
  28. # If that succeeded, now check that "read -t 0" has no output, which could
  29. # be an error message.
  30. if test $status != 2; then
  31. (read -t 0 2>&1 ) | grep .
  32. test $? = 0 && status=2
  33. fi
  34. # This last test was needed under OpenBSD 5.5, where
  35. # "read -t 0" has an exit status of 1, not 2
  36. if test $status != 2; then
  37. read -t 3 FINISHED <$FINISHEDFIFO
  38. status=$?
  39. fi
  40. RETVAL=0
  41. if test $status = 1; then
  42. echo 'read -t failed - probably end-of-file' >&2
  43. RETVAL=1
  44. elif test $status != 0 -a $status -le 128 ; then
  45. # Exit status of 'read' should be 0 on a successful read, or
  46. # greater than 128 if it timed out.
  47. rm -f $FINISHEDFIFO
  48. echo 'read -t not supported - test skipped' >&2
  49. RETVAL=77
  50. cleanup
  51. elif test "$FINISHED" = failure; then
  52. echo 'Program exited unsuccessfully' >&2
  53. RETVAL=1
  54. elif test "$FINISHED" != finished; then
  55. # Kill ginfo if we have its PID. Failing this, it will probably exit
  56. # with an I/O error when pseudotty is killed in Cleanup.inc.
  57. test "$GINFO_PID" != unknown && kill $GINFO_PID
  58. echo 'Program timed out after 3 seconds' >&2
  59. TIMED_OUT=1
  60. fi
  61. # Subshell is gone, so avoid trying to kill it in cleanup
  62. SUBSHELL=0
  63. rm -f $FINISHEDFIFO