From patchwork Fri Mar 6 11:49:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 38446 Received: (qmail 117625 invoked by alias); 6 Mar 2020 11:49:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 117548 invoked by uid 89); 6 Mar 2020 11:49:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=fd X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Mar 2020 11:49:28 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 875CBAD80; Fri, 6 Mar 2020 11:49:26 +0000 (UTC) Date: Fri, 6 Mar 2020 12:49:24 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH][gdb/testsuite] Fix "text file busy" errors with cc-with-tweaks.exp Message-ID: <20200306114923.GA2185@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi, When using target board cc-with-gdb-index.exp and running tests in parallel, we run into: ... gdb compile failed, gdb/contrib/gdb-add-index.sh: line 86: \ build/gdb/testsuite/gdb.sh: Text file busy ... The problem is that because of the parallel test run, gdb.sh is created for every single test-case, and eventually gdb.sh is overwritten while being executed. Fix this by creating gdb.sh only once. Tested on x86_64-linux with target board cc-with-gdb-index.exp, using both a serial and parallel -j 5 test run. OK for trunk? Thanks, - Tom [gdb/testsuite] Fix "text file busy" errors with cc-with-tweaks.exp gdb/testsuite/ChangeLog: 2020-03-06 Tom de Vries * lib/gdb.exp (tentative_rename, cached_file): New proc. * boards/cc-with-tweaks.exp: Use cached_file to create gdb.sh. --- gdb/testsuite/boards/cc-with-tweaks.exp | 6 ++--- gdb/testsuite/lib/gdb.exp | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/boards/cc-with-tweaks.exp b/gdb/testsuite/boards/cc-with-tweaks.exp index a60507a01e..8701ccd377 100644 --- a/gdb/testsuite/boards/cc-with-tweaks.exp +++ b/gdb/testsuite/boards/cc-with-tweaks.exp @@ -69,7 +69,5 @@ if ![info exists F77_FOR_TARGET] { } set F77_FOR_TARGET "$contrib_dir/cc-with-tweaks.sh $CC_WITH_TWEAKS_FLAGS $F77_FOR_TARGET" -set pwd [exec pwd -P] -exec echo $GDB $INTERNAL_GDBFLAGS $GDBFLAGS \"\$@\" > $pwd/gdb.sh -exec chmod +x gdb.sh -set env(GDB) $pwd/gdb.sh +set env(GDB) \ + [cached_file gdb.sh "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS \"\$@\"" 1] diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index f8f404ff26..55e58584c8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4929,6 +4929,48 @@ proc standard_temp_file {basename} { return [file join $dir $basename] } +# Rename file A to file B, if B does not already exists. Otherwise, leave B +# as is and delete A. Return 1 if rename happened. + +proc tentative_rename { a b } { + global errorInfo errorCode + set code [catch {file rename -- $a $b} result] + if { $code == 1 && [lindex $errorCode 0] == "POSIX" \ + && [lindex $errorCode 1] == "EEXIST" } { + file delete $a + return 0 + } + if {$code == 1} { + return -code error -errorinfo $errorInfo -errorcode $errorCode $result + } elseif {$code > 1} { + return -code $code $result + } + return 1 +} + +# Create a file with name FILENAME and contents TXT in the cache directory. +# If EXECUTABLE, mark the new file for execution. + +proc cached_file { filename txt {executable 0}} { + set filename [make_gdb_parallel_path cache $filename] + + if { [file exists $filename] } { + return $filename + } + + set tmp_filename $filename.[pid] + set fd [open $tmp_filename w] + puts $fd $txt + close $fd + + if { $executable } { + exec chmod +x $tmp_filename + } + tentative_rename $tmp_filename $filename + + return $filename +} + # Set 'testfile', 'srcfile', and 'binfile'. # # ARGS is a list of source file specifications.