summaryrefslogtreecommitdiff
path: root/tests/support/util.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'tests/support/util.tcl')
-rw-r--r--tests/support/util.tcl15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/support/util.tcl b/tests/support/util.tcl
index c5a6853b3..3804f253b 100644
--- a/tests/support/util.tcl
+++ b/tests/support/util.tcl
@@ -312,3 +312,18 @@ proc csvstring s {
proc roundFloat f {
format "%.10g" $f
}
+
+proc find_available_port start {
+ for {set j $start} {$j < $start+1024} {incr j} {
+ if {[catch {
+ set fd [socket 127.0.0.1 $j]
+ }]} {
+ return $j
+ } else {
+ close $fd
+ }
+ }
+ if {$j == $start+1024} {
+ error "Can't find a non busy port in the $start-[expr {$start+1023}] range."
+ }
+}