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

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