public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/5] Refactor py-inferior.exp
Date: Fri, 7 Jul 2023 19:12:41 +0100	[thread overview]
Message-ID: <2f182acf-ee4b-c3ff-61ed-c589fc1b0c3a@palves.net> (raw)
In-Reply-To: <20230707-py-inf-fixes-30615-v1-2-7792ab559530@adacore.com>

On 2023-07-07 16:07, Tom Tromey via Gdb-patches wrote:
> This changes py-inferior.exp to make it a bit more robust when adding
> new inferiors during the course of the test.

Ah, this fixes the "There's also:" case I pointed out in patch #1 anyhow.

Approved-By: Pedro Alves <pedro@palves.net>

Pedro Alves

> ---
>  gdb/testsuite/gdb.python/py-inferior.exp | 43 +++++++++++++++++++++-----------
>  1 file changed, 29 insertions(+), 14 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
> index 33bc27ee86d..a29624f4fd5 100644
> --- a/gdb/testsuite/gdb.python/py-inferior.exp
> +++ b/gdb/testsuite/gdb.python/py-inferior.exp
> @@ -40,6 +40,20 @@ if {![runto_main]} {
>      return 0
>  }
>  
> +# The most recently added inferior.
> +set most_recent_inf 1
> +
> +# A helper function that adds a new inferior.  It returns the expected
> +# number of the new inferior.  ARG is a string to pass to
> +# add-inferior.
> +proc add_inferior {{arg ""}} {
> +    global most_recent_inf
> +    incr most_recent_inf
> +    gdb_test "add-inferior $arg" "Added inferior $most_recent_inf.*" \
> +	"add inferior $most_recent_inf"
> +    return $most_recent_inf
> +}
> +
>  # Test basic gdb.Inferior attributes and methods.
>  
>  gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1
> @@ -234,7 +248,7 @@ with_test_prefix "is_valid" {
>  	"gdb.events.inferior_deleted.connect(del_inf_handler)" "" \
>  	"end" ""
>  
> -    gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
> +    set num [add_inferior]
>      gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
>      gdb_test "python print (len(inf_list))" "2" "get inferior list length 2"
>      gdb_test "python print (inf_list\[0\].is_valid())" "True" \
> @@ -246,7 +260,7 @@ with_test_prefix "is_valid" {
>      gdb_test "python print (inf_list\[1\].is_valid())" "True" \
>  	"check inferior validity 3"
>  
> -    gdb_test_no_output "remove-inferiors 2" "remove-inferiors 2"
> +    gdb_test_no_output "remove-inferiors $num" "remove-inferiors $num"
>      gdb_test "python print (inf_list\[0\].is_valid())" "True" \
>  	"check inferior validity 4"
>  
> @@ -287,15 +301,16 @@ with_test_prefix "selected_inferior" {
>      # Figure out if inf 1 has a native target.
>      set inf_1_is_native [gdb_is_target_native]
>  
> -    gdb_test "add-inferior -no-connection" "Added inferior 3" "create new inferior"
> -    gdb_test "inferior 3" ".*" "switch to third inferior"
> -    gdb_test "py print (gdb.selected_inferior().num)" "3" "third inferior selected"
> +    set num [add_inferior "-no-connection"]
> +    gdb_test "inferior $num" ".*" "switch to inferior $num"
> +    gdb_test "py print (gdb.selected_inferior().num)" "$num" \
> +	"inferior $num selected"
>      gdb_test "py print (gdb.selected_inferior().connection_num)" "None" \
> -	"third inferior's None connection number"
> +	"inferior $num's None connection number"
>      gdb_test "py print (gdb.selected_inferior().connection)" "None" \
> -	"third inferior's None connection"
> +	"inferior $num's None connection"
>      gdb_test "target native" "Done.  Use the \"run\" command to start a process." \
> -	"target for the third inferior"
> +	"target for inferior $num"
>  
>      # If inf 1 has a native target, inf 3's target is shared with 1's.
>      # Otherwise, it must have created a new target with a new number.
> @@ -306,10 +321,10 @@ with_test_prefix "selected_inferior" {
>      }
>      gdb_test "py print (gdb.selected_inferior().connection_num)" \
>  	"$expected_connection_num" \
> -	"third inferior's native connection number"
> +	"inferior $num's native connection number"
>      gdb_test "py print (gdb.selected_inferior().connection.num)" \
>  	"$expected_connection_num" \
> -	"third inferior's native connection number, though connection object"
> +	"inferior $num's native connection number, though connection object"
>  
>      # Test printing of gdb.TargetConnection object.
>      gdb_test "py print (gdb.selected_inferior().connection)" \
> @@ -317,18 +332,18 @@ with_test_prefix "selected_inferior" {
>  	"print a connection object"
>  
>      gdb_test "inferior 1" ".*" "switch back to first inferior"
> -    gdb_test_no_output "remove-inferiors 3" "remove second inferior"
> +    gdb_test_no_output "remove-inferiors $num" "remove inferior $num"
>  }
>  
>  # Test repr()/str()
>  with_test_prefix "__repr__" {
> -    gdb_test "add-inferior" "Added inferior 4 on connection .*" "add inferior 4"
> +    set num [add_inferior]
>      gdb_py_test_silent_cmd "python infs = gdb.inferiors()" "get inferior list" 1
>      gdb_test "python print (infs\[0\])" "<gdb.Inferior num=1, pid=$decimal>"
>      gdb_test "python print (infs)" \
> -	"\\\(<gdb.Inferior num=1, pid=$decimal>, <gdb.Inferior num=4, pid=$decimal>\\\)" \
> +	"\\\(<gdb.Inferior num=1, pid=$decimal>, <gdb.Inferior num=$num, pid=$decimal>\\\)" \
>  	"print all inferiors 1"
> -    gdb_test_no_output "remove-inferiors 4"
> +    gdb_test_no_output "remove-inferiors $num"
>      gdb_test "python print (infs)" \
>  	"\\\(<gdb.Inferior num=1, pid=$decimal>, <gdb.Inferior \\\(invalid\\\)>\\\)" \
>  	"print all inferiors 2"
> 


  reply	other threads:[~2023-07-07 18:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 15:07 [PATCH 0/5] Fix some Python Inferior methods Tom Tromey
2023-07-07 15:07 ` [PATCH 1/5] Minor cleanups in py-inferior.exp Tom Tromey
2023-07-07 18:06   ` Pedro Alves
2023-07-11 15:05     ` Tom Tromey
2023-07-07 15:07 ` [PATCH 2/5] Refactor py-inferior.exp Tom Tromey
2023-07-07 18:12   ` Pedro Alves [this message]
2023-07-07 15:07 ` [PATCH 3/5] Rename Python variable in py-inferior.exp Tom Tromey
2023-07-07 18:14   ` Pedro Alves
2023-07-11 15:19     ` Tom Tromey
2023-07-07 15:08 ` [PATCH 4/5] Remove obsolete comment from gdbthread.h Tom Tromey
2023-07-07 18:15   ` Pedro Alves
2023-07-07 15:08 ` [PATCH 5/5] Use correct inferior in Inferior.read_memory et al Tom Tromey
2023-07-07 18:26   ` Pedro Alves
2023-07-07 18:27     ` Pedro Alves

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=2f182acf-ee4b-c3ff-61ed-c589fc1b0c3a@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /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).