extrac11.at 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Process this file with autom4te to create testsuite. -*- Autotest -*-
  2. # Test suite for GNU tar.
  3. # Copyright 2010-2023 Free Software Foundation, Inc.
  4. # This file is part of GNU tar.
  5. # GNU tar is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version.
  9. # GNU tar is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  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. # written by Paul Eggert
  16. # Check that 'tar' works even in a file-descriptor-limited environment.
  17. AT_SETUP([scarce file descriptors])
  18. AT_KEYWORDS([extract extrac11 chdir])
  19. AT_TAR_CHECK([
  20. exec </dev/null
  21. dirs='a
  22. a/b
  23. a/b/c
  24. a/b/c/d
  25. a/b/c/d/e
  26. a/b/c/d/e/f
  27. a/b/c/d/e/f/g
  28. a/b/c/d/e/f/g/h
  29. a/b/c/d/e/f/g/h/i
  30. a/b/c/d/e/f/g/h/i/j
  31. a/b/c/d/e/f/g/h/i/j/k
  32. '
  33. files=
  34. mkdir $dirs dest1 dest2 dest3 || exit
  35. for dir in $dirs; do
  36. for file in X Y Z; do
  37. echo $file >$dir/$file || exit
  38. files="$files $file"
  39. done
  40. done
  41. # Check that "ulimit" itself works. Close file descriptors before
  42. # invoking ulimit, to work around a bug (or a "feature") in some shells,
  43. # where they squirrel away dups of file descriptors into FD 10 and up
  44. # before closing the originals.
  45. ( (exec 3<&- 4<&- 5<&- 6<&- 7<&- 8<&- 9<&- &&
  46. ulimit -n 100 &&
  47. tar -cf archive1.tar a &&
  48. tar -xf archive1.tar -C dest1 a
  49. ) &&
  50. diff -r a dest1/a
  51. ) >/dev/null 2>&1 ||
  52. AT_SKIP_TEST
  53. # Another test that "ulimit" itself works:
  54. # tar should fail when completely starved of file descriptors.
  55. ( (exec 3<&- 4<&- 5<&- 6<&- 7<&- 8<&- 9<&- &&
  56. ulimit -n 4 &&
  57. tar -cf archive2.tar a &&
  58. tar -xf archive2.tar -C dest2 a
  59. ) &&
  60. diff -r a dest2/a
  61. ) >/dev/null 2>&1 &&
  62. AT_SKIP_TEST
  63. # Test if it is possible to limit the number of file descriptors to 10.
  64. ( ulimit -n 10 ) >/dev/null 2>&1 || AT_SKIP_TEST
  65. # Tar should work when there are few, but enough, file descriptors.
  66. ( (exec 3<&- 4<&- 5<&- 6<&- 7<&- 8<&- 9<&- &&
  67. ulimit -n 10 &&
  68. tar -cf archive3.tar a &&
  69. tar -xf archive3.tar -C dest3 a
  70. ) &&
  71. diff -r a dest3/a >/dev/null 2>&1
  72. ) || { diff -r a dest3/a; exit 1; }
  73. ],
  74. [0],[],[],[],[],[gnu])
  75. AT_CLEANUP