test-no-fds-leaked-to-maintainer-scripts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64' 'i386'
  7. configdpkgnoopchroot
  8. setupsimplenativepackage "fdleaks" 'all' '1.0' 'unstable'
  9. BUILDDIR="incoming/fdleaks-1.0"
  10. for script in 'preinst' 'postinst' 'prerm' 'postrm'; do
  11. cat > ${BUILDDIR}/debian/$script << EOF
  12. #!/bin/sh
  13. if [ -e '$(pwd)/rootdir/tmp/read_stdin' ]; then
  14. read line;
  15. echo "STDIN: -\$line-"
  16. fi
  17. ls -l /proc/self/fd/
  18. EOF
  19. done
  20. buildpackage "$BUILDDIR" 'unstable' 'main' 'native'
  21. rm -rf "$BUILDDIR"
  22. PKGNAME='fdleaks:all'
  23. if ! dpkg-checkbuilddeps -d 'dpkg (>= 1.16.2)' /dev/null >/dev/null 2>&1; then
  24. PKGNAME='fdleaks'
  25. fi
  26. setupaptarchive
  27. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  28. testsuccess aptget install -y fdleaks -qq < /dev/null
  29. checkfdleak() {
  30. msgtest 'Check if fds were not' 'leaked'
  31. if [ "$(grep 'root root' rootdir/tmp/testsuccess.output | wc -l)" = "$1" ]; then
  32. msgpass
  33. else
  34. echo
  35. cat rootdir/tmp/testsuccess.output
  36. msgfail
  37. fi
  38. }
  39. checkinstall() {
  40. checkfdleak 8
  41. cp rootdir/tmp/testsuccess.output terminal.output
  42. tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
  43. testfileequal 'terminal.log' "$(cat terminal.output)"
  44. testequal "startup archives unpack
  45. install $PKGNAME <none> 1.0
  46. status half-installed $PKGNAME 1.0
  47. status unpacked $PKGNAME 1.0
  48. status unpacked $PKGNAME 1.0
  49. startup packages configure
  50. configure $PKGNAME 1.0 <none>
  51. status unpacked $PKGNAME 1.0
  52. status half-configured $PKGNAME 1.0
  53. status installed $PKGNAME 1.0
  54. startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
  55. }
  56. checkinstall
  57. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  58. testsuccess aptget purge -y fdleaks -qq
  59. checkpurge() {
  60. checkfdleak 12
  61. cp rootdir/tmp/testsuccess.output terminal.output
  62. tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
  63. testfileequal 'terminal.log' "$(cat terminal.output)"
  64. testequal "startup packages purge
  65. status installed $PKGNAME 1.0
  66. remove $PKGNAME 1.0 <none>
  67. status half-configured $PKGNAME 1.0
  68. status half-installed $PKGNAME 1.0
  69. status config-files $PKGNAME 1.0
  70. purge $PKGNAME 1.0 <none>
  71. status config-files $PKGNAME 1.0
  72. status config-files $PKGNAME 1.0
  73. status config-files $PKGNAME 1.0
  74. status config-files $PKGNAME 1.0
  75. status config-files $PKGNAME 1.0
  76. status not-installed $PKGNAME <none>
  77. startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
  78. }
  79. checkpurge
  80. msgtest 'setsid provided is new enough to support' '-w'
  81. if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then
  82. msgpass
  83. else
  84. msgskip "$(command dpkg -l util-linux)"
  85. exit
  86. fi
  87. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  88. testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null
  89. checkinstall
  90. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  91. testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
  92. checkpurge
  93. touch rootdir/tmp/read_stdin
  94. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  95. for i in $(seq 1 10); do echo "$i"; done | testsuccess aptget install -y fdleaks -qq
  96. checkinstall
  97. testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log
  98. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  99. yes '' | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
  100. checkpurge
  101. testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log