You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test-no-fds-leaked-to-maintainer-scripts 5.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. testequalor2 "startup archives unpack
  49. install $PKGNAME <none> 1.0
  50. status half-installed $PKGNAME 1.0
  51. status unpacked $PKGNAME 1.0
  52. startup packages configure
  53. configure $PKGNAME 1.0 <none>
  54. status unpacked $PKGNAME 1.0
  55. status half-configured $PKGNAME 1.0
  56. status installed $PKGNAME 1.0" "startup archives unpack
  57. install $PKGNAME <none> 1.0
  58. status half-installed $PKGNAME 1.0
  59. status unpacked $PKGNAME 1.0
  60. status unpacked $PKGNAME 1.0
  61. startup packages configure
  62. configure $PKGNAME 1.0 <none>
  63. status unpacked $PKGNAME 1.0
  64. status half-configured $PKGNAME 1.0
  65. status installed $PKGNAME 1.0" cut -f 3- -d' ' rootdir/var/log/dpkg.log
  66. }
  67. checkinstall
  68. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  69. testsuccess aptget purge -y fdleaks -qq
  70. checkpurge() {
  71. checkfdleak 12
  72. cp rootdir/tmp/testsuccess.output terminal.output
  73. tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
  74. testfileequal 'terminal.log' "$(cat terminal.output)"
  75. if dpkg --compare-versions "$(dpkg_version)" 'ge' '1.18.11'; then
  76. testequalor2 "startup packages remove
  77. status installed $PKGNAME 1.0
  78. remove $PKGNAME 1.0 <none>
  79. status half-configured $PKGNAME 1.0
  80. status half-installed $PKGNAME 1.0
  81. status config-files $PKGNAME 1.0
  82. startup packages configure
  83. startup packages purge
  84. purge $PKGNAME 1.0 <none>
  85. status config-files $PKGNAME 1.0
  86. status not-installed $PKGNAME <none>
  87. startup packages configure" "startup packages remove
  88. status installed $PKGNAME 1.0
  89. remove $PKGNAME 1.0 <none>
  90. status half-configured $PKGNAME 1.0
  91. status half-installed $PKGNAME 1.0
  92. status config-files $PKGNAME 1.0
  93. status config-files $PKGNAME 1.0
  94. startup packages configure
  95. startup packages purge
  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. else
  105. testequalor2 "startup packages remove
  106. status installed $PKGNAME 1.0
  107. remove $PKGNAME 1.0 <none>
  108. status half-configured $PKGNAME 1.0
  109. status half-installed $PKGNAME 1.0
  110. status config-files $PKGNAME 1.0
  111. startup packages configure
  112. startup packages purge
  113. remove $PKGNAME 1.0 <none>
  114. purge $PKGNAME 1.0 <none>
  115. status config-files $PKGNAME 1.0
  116. status not-installed $PKGNAME <none>
  117. startup packages configure" "startup packages remove
  118. status installed $PKGNAME 1.0
  119. remove $PKGNAME 1.0 <none>
  120. status half-configured $PKGNAME 1.0
  121. status half-installed $PKGNAME 1.0
  122. status config-files $PKGNAME 1.0
  123. status config-files $PKGNAME 1.0
  124. startup packages configure
  125. startup packages purge
  126. remove $PKGNAME 1.0 <none>
  127. purge $PKGNAME 1.0 <none>
  128. status config-files $PKGNAME 1.0
  129. status config-files $PKGNAME 1.0
  130. status config-files $PKGNAME 1.0
  131. status config-files $PKGNAME 1.0
  132. status config-files $PKGNAME 1.0
  133. status not-installed $PKGNAME <none>
  134. startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
  135. fi
  136. testequalor2 "dpkg-query: no packages found matching ${PKGNAME}" "No packages found matching ${PKGNAME}." dpkg -l "$PKGNAME"
  137. }
  138. checkpurge
  139. msgtest 'setsid provided is new enough to support' '-w'
  140. if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then
  141. msgpass
  142. else
  143. msgskip "$(command dpkg -l util-linux)"
  144. exit
  145. fi
  146. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  147. testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null
  148. checkinstall
  149. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  150. testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
  151. checkpurge
  152. touch rootdir/tmp/read_stdin
  153. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  154. for i in $(seq 1 10); do echo "$i"; done | testsuccess aptget install -y fdleaks -qq
  155. checkinstall
  156. testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log
  157. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  158. yes '' | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
  159. checkpurge
  160. testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log