assert.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh
  2. # Test for assertion failure in "test".
  3. # Copyright (C) 1999-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  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. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. # This test fails with tail from textutils-2.0.
  15. # It would get something like this:
  16. # tail: tail.c:718: recheck: Assertion 'valid_file_spec (f)' failed.
  17. # Aborted
  18. # due to a race condition in which a dev/inode pair is reused.
  19. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  20. print_ver_ tail
  21. check_tail_output()
  22. {
  23. local delay="$1"
  24. grep "$tail_re" out ||
  25. { sleep $delay; return 1; }
  26. }
  27. # Terminate any background tail process
  28. cleanup_() { kill $pid 2>/dev/null && wait $pid; }
  29. # Speedup the non inotify case
  30. fastpoll='-s.1 --max-unchanged-stats=1'
  31. for mode in '' '---disable-inotify'; do
  32. rm -f a foo out
  33. touch a foo || framework_failure_
  34. tail $mode --follow=name $fastpoll a foo > out 2>&1 & pid=$!
  35. # Wait up to 12.7s for tail to start.
  36. echo x > a || framework_failure_
  37. tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
  38. { cat out; fail=1; break; }
  39. # Wait 12.7s for this diagnostic:
  40. # tail: foo: No such file or directory
  41. rm foo || framework_failure_
  42. tail_re='No such file' retry_delay_ check_tail_output .1 7 ||
  43. { cat out; fail=1; break; }
  44. # Wait up to 12.7s for tail to notice new foo file
  45. ok='ok ok ok'
  46. echo "$ok" > foo || framework_failure_
  47. tail_re="^$ok$" retry_delay_ check_tail_output .1 7 ||
  48. { echo "$0: foo: unexpected delay?"; cat out; fail=1; break; }
  49. cleanup_
  50. done
  51. Exit $fail