logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

timeout.sh (916B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. plans=10
  5. WD="$(dirname "$0")/../"
  6. target="${WD}/cmd/timeout"
  7. . "${WD}/test-cmd/tap.sh"
  8. time_fmt() {
  9. out=$(mktemp time_fmt.XXXXXX)
  10. "$@" 2> "$out"
  11. err=$?
  12. cut -f1 -d '.' <"$out"
  13. rm -f "$out"
  14. return $err
  15. }
  16. t_args --exit=124 longer_sleep '' 0.5 sleep 10
  17. t_args shorter_sleep '' 0.5 sleep 0.2
  18. t_args true '' 0.5 true
  19. t_args --exit=1 false '' 0.5 false
  20. t_args --exit=124 kill_longer_sleep '' -s KILL 0.5 sleep 10
  21. t_args --exit=124 sigkill_longer_sleep '' -s SIGKILL 0.5 sleep 10
  22. t_args --exit=124 sig9_longer_sleep '' -s 9 0.5 sleep 10
  23. t_cmd --exit=124 time_longer_sleep_nokill '' time_fmt "$target" -f 0.5 "${WD}/cmd/time" -p sleep 1
  24. t_cmd --exit=124 time_longer_sleep '' time_fmt "$target" 0.5 "${WD}/cmd/time" -p sleep 1
  25. t_args preserve_status '' -p 0.5 sleep 10
  26. wait