assert-2.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # This variant of 'assert' would get a Uninit Mem Read reliably in 2.0.9.
  3. # Due to a race condition in the test, the 'assert' script would get
  4. # the UMR on Solaris only some of the time, and not at all on Linux/GNU.
  5. # Copyright (C) 2000-2018 Free Software Foundation, Inc.
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  17. print_ver_ tail
  18. check_tail_output()
  19. {
  20. local delay="$1"
  21. grep "$tail_re" out ||
  22. { sleep $delay; return 1; }
  23. }
  24. # Terminate any background tail process
  25. cleanup_() { kill $pid 2>/dev/null && wait $pid; }
  26. # Speedup the non inotify case
  27. fastpoll='-s.1 --max-unchanged-stats=1'
  28. for mode in '' '---disable-inotify'; do
  29. rm -f a foo out
  30. touch a || framework_failure_
  31. tail $mode $fastpoll -F a foo > out 2>&1 & pid=$!
  32. # Wait up to 12.7s for tail to start.
  33. echo x > a || framework_failure_
  34. tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
  35. { cat out; fail=1; break; }
  36. # Wait up to 12.7s for tail to notice new foo file
  37. ok='ok ok ok'
  38. echo "$ok" > foo || framework_failure_
  39. tail_re="^$ok$" retry_delay_ check_tail_output .1 7 ||
  40. { echo "$0: foo: unexpected delay?"; cat out; fail=1; break; }
  41. cleanup_
  42. done
  43. Exit $fail