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.
 
 
 
 
 
 

119 lines
3.4 KiB

  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: expect $1"
  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" cut -f 3- -d' ' rootdir/var/log/dpkg.log
  54. }
  55. checkinstall
  56. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  57. testsuccess aptget purge -y fdleaks -qq
  58. checkpurge() {
  59. checkfdleak 12
  60. cp rootdir/tmp/testsuccess.output terminal.output
  61. tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log
  62. testfileequal 'terminal.log' "$(cat terminal.output)"
  63. testequal "startup packages purge
  64. remove $PKGNAME 1.0 <none>
  65. status half-configured $PKGNAME 1.0
  66. status half-installed $PKGNAME 1.0
  67. status config-files $PKGNAME 1.0
  68. purge $PKGNAME 1.0 <none>
  69. status config-files $PKGNAME 1.0
  70. status config-files $PKGNAME 1.0
  71. status config-files $PKGNAME 1.0
  72. status config-files $PKGNAME 1.0
  73. status config-files $PKGNAME 1.0
  74. status not-installed $PKGNAME <none>
  75. startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log
  76. testequalor2 "dpkg-query: no packages found matching ${PKGNAME}" "No packages found matching ${PKGNAME}." dpkg -l "$PKGNAME"
  77. }
  78. checkpurge
  79. msgtest 'setsid provided is new enough to support' '-w'
  80. if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then
  81. msgpass
  82. else
  83. msgskip "$(command dpkg -l util-linux)"
  84. exit
  85. fi
  86. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  87. testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null
  88. checkinstall
  89. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  90. testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
  91. checkpurge
  92. touch rootdir/tmp/read_stdin
  93. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  94. for i in $(seq 1 10); do echo "$i"; done | testsuccess aptget install -y fdleaks -qq
  95. checkinstall
  96. testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log
  97. rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log
  98. yes '' | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq
  99. checkpurge
  100. testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log