From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/7] [gdb/testsuite] Factor out proc with_lock
Date: Mon, 15 Apr 2024 17:56:23 +0200 [thread overview]
Message-ID: <20240415155627.22108-3-tdevries@suse.de> (raw)
In-Reply-To: <20240415155627.22108-1-tdevries@suse.de>
Factor out proc with_lock from with_rocm_gpu_lock, and move required procs
lock_file_acquire and lock_file_release to lib/gdb-utils.exp.
Tested on aarch64-linux.
---
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}.exp"
+ 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}.exp"
+
+ 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 == 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
-# 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}.exp"
- 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}.exp"
-
- 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.
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
# 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 == 1} {
- global errorInfo errorCode
- return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
- } else {
- return -code $code $result
- }
}
# Return true if all the devices support debugging multiple processes
--
2.35.3
next prev parent reply other threads:[~2024-04-15 15:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 15:56 [PATCH 1/7] [gdb/testsuite] Factor out proc get_portnum Tom de Vries
2024-04-15 15:56 ` [PATCH 2/7] [gdb/testsuite] Make portnum a persistent global Tom de Vries
2024-05-03 20:20 ` Tom Tromey
2024-04-15 15:56 ` Tom de Vries [this message]
2024-05-03 20:22 ` [PATCH 3/7] [gdb/testsuite] Factor out proc with_lock Tom Tromey
2024-04-15 15:56 ` [PATCH 4/7] [gdb/testsuite] Factor out proc lock_dir Tom de Vries
2024-05-03 20:23 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 5/7] [gdb/testsuite] Move gpu-parallel.lock to cache dir Tom de Vries
2024-05-03 20:25 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 6/7] [gdb/testsuite] Use unique portnum in parallel testing Tom de Vries
2024-05-03 20:27 ` Tom Tromey
2024-04-15 15:56 ` [PATCH 7/7] [gdb/testsuite] Use unique portnum in parallel testing (check//% case) Tom de Vries
2024-05-03 20:30 ` Tom Tromey
2024-05-04 7:48 ` Tom de Vries
2024-05-03 20:19 ` [PATCH 1/7] [gdb/testsuite] Factor out proc get_portnum Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240415155627.22108-3-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).