From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 2BEF83844767; Sat, 4 May 2024 08:40:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BEF83844767 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1714812059; bh=iaNnX7WhekKaSx26QS176I5czcM7VIYBmQRZkoHj8Xg=; h=From:To:Subject:Date:From; b=arROLjxiaLmG+3KZKtusk601wry7FYe3GMVZfV4a35xib9goGPUmMNOGV03f/Eguf ygVepjepL7ym823oapgJDVxl0g6E5L4+jX1WJ8TI8AoFi+kJr01MMtq/SXHtXWZRDd ABC4C2GbkdKGgF4dXQFRU/0yz0OhZCyedRiNasws= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Factor out proc with_lock X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: c42c12f9bf93b5f10f3d6dc10f45d9484a7f9faa X-Git-Newrev: fbb0edfe60edf4ca01884151e6d9b1353aaa0a7e Message-Id: <20240504084059.2BEF83844767@sourceware.org> Date: Sat, 4 May 2024 08:40:59 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfbb0edfe60ed= f4ca01884151e6d9b1353aaa0a7e commit fbb0edfe60edf4ca01884151e6d9b1353aaa0a7e Author: Tom de Vries Date: Sat May 4 10:41:09 2024 +0200 [gdb/testsuite] Factor out proc with_lock =20 Factor out proc with_lock from with_rocm_gpu_lock, and move required pr= ocs lock_file_acquire and lock_file_release to lib/gdb-utils.exp. =20 Tested on aarch64-linux. =20 Approved-By: Tom Tromey Diff: --- gdb/testsuite/lib/gdb-utils.exp | 59 +++++++++++++++++++++++++++++++++++++= ++++ gdb/testsuite/lib/rocm.exp | 55 +------------------------------------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.= exp index 34752081b60..4205f8d1a22 100644 --- a/gdb/testsuite/lib/gdb-utils.exp +++ b/gdb/testsuite/lib/gdb-utils.exp @@ -138,3 +138,62 @@ proc version_compare { l1 op l2 } { } return 1 } + +# Acquire lock file LOCKFILE. Tries forever until the lock file is +# successfully created. + +proc lock_file_acquire {lockfile} { + verbose -log "acquiring lock file: $::subdir/${::gdb_test_file_name}.e= xp" + while {true} { + if {![catch {open $lockfile {WRONLY CREAT EXCL}} rc]} { + set msg "locked by $::subdir/${::gdb_test_file_name}.exp" + verbose -log "lock file: $msg" + # For debugging, put info in the lockfile about who owns + # it. + puts $rc $msg + flush $rc + return [list $rc $lockfile] + } + after 10 + } +} + +# Release a lock file. + +proc lock_file_release {info} { + verbose -log "releasing lock file: $::subdir/${::gdb_test_file_name}.e= xp" + + if {![catch {fconfigure [lindex $info 0]}]} { + if {![catch { + close [lindex $info 0] + file delete -force [lindex $info 1] + } rc]} { + return "" + } else { + return -code error "Error releasing lockfile: '$rc'" + } + } else { + error "invalid lock" + } +} + +# Run body under lock LOCK_FILE. + +proc with_lock { lock_file body } { + if {[info exists ::GDB_PARALLEL]} { + set lock_rc [lock_file_acquire $lock_file] + } + + set code [catch {uplevel 1 $body} result] + + if {[info exists ::GDB_PARALLEL]} { + lock_file_release $lock_rc + } + + if {$code =3D=3D 1} { + global errorInfo errorCode + return -code $code -errorinfo $errorInfo -errorcode $errorCode $result + } else { + return -code $code $result + } +} diff --git a/gdb/testsuite/lib/rocm.exp b/gdb/testsuite/lib/rocm.exp index ab21db6685c..7dd7ef3f3b5 100644 --- a/gdb/testsuite/lib/rocm.exp +++ b/gdb/testsuite/lib/rocm.exp @@ -108,68 +108,15 @@ gdb_caching_proc allow_hipcc_tests {} { # at a time. set gpu_lock_filename $objdir/gpu-parallel.lock =20 -# Acquire lock file LOCKFILE. Tries forever until the lock file is -# successfully created. - -proc lock_file_acquire {lockfile} { - verbose -log "acquiring lock file: $::subdir/${::gdb_test_file_name}.e= xp" - while {true} { - if {![catch {open $lockfile {WRONLY CREAT EXCL}} rc]} { - set msg "locked by $::subdir/${::gdb_test_file_name}.exp" - verbose -log "lock file: $msg" - # For debugging, put info in the lockfile about who owns - # it. - puts $rc $msg - flush $rc - return [list $rc $lockfile] - } - after 10 - } -} - -# Release a lock file. - -proc lock_file_release {info} { - verbose -log "releasing lock file: $::subdir/${::gdb_test_file_name}.e= xp" - - if {![catch {fconfigure [lindex $info 0]}]} { - if {![catch { - close [lindex $info 0] - file delete -force [lindex $info 1] - } rc]} { - return "" - } else { - return -code error "Error releasing lockfile: '$rc'" - } - } else { - error "invalid lock" - } -} - # Run body under the GPU lock. Also calls gdb_exit before releasing # the GPU lock. =20 proc with_rocm_gpu_lock { body } { - if {[info exists ::GDB_PARALLEL]} { - set lock_rc [lock_file_acquire $::gpu_lock_filename] - } - - set code [catch {uplevel 1 $body} result] + with_lock $::gpu_lock_filename $body =20 # In case BODY returned early due to some testcase failing, and # left GDB running, debugging the GPU. gdb_exit - - if {[info exists ::GDB_PARALLEL]} { - lock_file_release $lock_rc - } - - if {$code =3D=3D 1} { - global errorInfo errorCode - return -code $code -errorinfo $errorInfo -errorcode $errorCode $result - } else { - return -code $code $result - } } =20 # Return true if all the devices support debugging multiple processes