>From 1027613d0f224a3d2cb4f9e0f7f7407ea3807ff2 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Wed, 9 Jan 2019 00:24:34 +0100 Subject: [PATCH 07/12] tests: migrate 'execdir-fd-leak' to the new testsuite * find/testsuite/sv-34976-execdir-fd-leak.sh: Move to ... * tests/find/execdir-fd-leak.sh: ... this, and apply the above. Simplify, and make more robust. * find/testsuite/Makefile.am (tests_shell_progs): Remove the reference to this test ... * tests/local.mk (all_tests): .. and add it here. --- find/testsuite/Makefile.am | 1 - .../find/execdir-fd-leak.sh | 64 ++++++++----------- tests/local.mk | 1 + 3 files changed, 26 insertions(+), 40 deletions(-) rename find/testsuite/sv-34976-execdir-fd-leak.sh => tests/find/execdir-fd-leak.sh (67%) diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am index 1a78eeac..d476ede7 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -253,7 +253,6 @@ find.posix/user-missing.exp test_shell_progs = \ test_type-list.sh \ -sv-34976-execdir-fd-leak.sh \ sv-48030-exec-plus-bug.sh \ sv-48180-refuse-noop.sh \ sv-52220.sh diff --git a/find/testsuite/sv-34976-execdir-fd-leak.sh b/tests/find/execdir-fd-leak.sh similarity index 67% rename from find/testsuite/sv-34976-execdir-fd-leak.sh rename to tests/find/execdir-fd-leak.sh index bd92bf74..ef9b404c 100755 --- a/find/testsuite/sv-34976-execdir-fd-leak.sh +++ b/tests/find/execdir-fd-leak.sh @@ -1,26 +1,25 @@ -#! /bin/sh +#!/bin/sh +# This test verifies that find does not leak a file descriptor for the working +# directory specified by the -execdir option. +# See Savannah bug #34976. + # Copyright (C) 2013-2019 Free Software Foundation, Inc. -# + # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# + # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# + # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# - -# This test verifies that find does not leak a file descriptor for the working -# directory specified by the -execdir option [Savannah bug #34976]. -testname="$(basename $0)" - -. "${srcdir}"/binary_locations.sh +. "${srcdir=.}/tests/init.sh" +print_ver_ find oldfind # seq is not required by POSIX, so we have manual lists of number here instead. three_to_thirty_five="3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35" @@ -37,44 +36,31 @@ test_ulimit() { done | sh -x ; ) 2>/dev/null } -# Opening 33 files with a limit of 50 should work. +# Opening 33 files with a limit of 40 should work. test_ulimit 40 || { echo "SKIP: ulimit does not work (case 1)" >&2; exit 0 ; } # Opening 33 files with a limit of 20 should fail. test_ulimit 20 && { echo "SKIP: ulimit does not work (case 2)" >&2; exit 0 ; } -die() { - echo "$@" >&2 - exit 1 -} - # Create test files, each 98 in the directories ".", "one" and "two". make_test_data() { - d="$1" - ( - cd "$1" || exit 1 - mkdir one two || exit 1 - for i in ${three_to_hundred} ; do - # We don't quote the RHS here because we actually want to create 3 files. - touch $(printf './%03d one/%03d two/%03d ' $i $i $i) || exit 1 - done - ) \ - || die "failed to set up the test in ${outdir}" + mkdir one two || return 1 + for i in ${three_to_hundred} ; do + # We don't quote the RHS here because we actually want to create 3 files. + touch $(printf './%03d one/%03d two/%03d ' $i $i $i) \ + || return 1 + done } -outdir="$(mktemp -d)" || die "FAIL: could not create a test files." - # Create some test files. -make_test_data "${outdir}" || die "FAIL: failed to set up the test in ${outdir}" +make_test_data \ + || framework_failure_ "failed to set up the test" -fail=0 -for exe in "${ftsfind}" "${oldfind}"; do +for exe in find oldfind; do ( ulimit -n 30 && \ - ${exe} "${outdir}" -type f -execdir cat '{}' \; >/dev/null; ) \ - || { \ - echo "Option -execdir of ${exe} leaks file descriptors" >&2 ; \ - fail=1 ; \ - } + ${exe} . -type f -execdir cat '{}' \; >/dev/null; \ + ) \ + || { echo "Option -execdir of ${exe} leaks file descriptors" >&2 ; \ + fail=1 ; } done -rm -rf "${outdir}" || exit 1 -exit $fail +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 0dcabab4..3e01c6c3 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -109,6 +109,7 @@ all_tests = \ tests/find/printf_escapechars.sh \ tests/find/printf_escape_c.sh \ tests/find/printf_inode.sh \ + tests/find/execdir-fd-leak.sh \ $(all_root_tests) $(TEST_LOGS): $(PROGRAMS) -- 2.20.1