From patchwork Tue Jul 11 16:14:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72500 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C48C83857009 for ; Tue, 11 Jul 2023 16:14:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C48C83857009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689092079; bh=Hc43djFECLk2fRZ3M6NkUPcvg60roiXJ8CgQZLcTDUs=; h=Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Qx1MM02zpf8Q+gRL5eQ/HaM+GQGD6l42olJVdVvy5KMSt9tQohJR8rkrkuhpezCOw MDiKiYxNapDnMnpJ7Y5F8/FEmZb+S0DUP8uI19uKiBjPBiWTEyHBeGDqPmlWj6a/y3 k+XJWcT0y0djtcuzG6Gkmug0RZgW98yp6UR3lZeQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id B03A23858D28 for ; Tue, 11 Jul 2023 16:14:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B03A23858D28 Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7866189cff1so271447539f.0 for ; Tue, 11 Jul 2023 09:14:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689092049; x=1691684049; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hc43djFECLk2fRZ3M6NkUPcvg60roiXJ8CgQZLcTDUs=; b=C0dxJF2R3mTQgAljntEYVfigPUDIaA3EAttFbFC00khVHeicvQ5ACcQs/1fspis8ZZ WsF8AhxPjJ34HBYuI1FXF+RyUkBkejQx/RgyO0t+hS/pxJk2OT5OWDM2xLIV72mqfJqz hir6kPWaOu/ilARtgzN4ajwZpTAKu6slPRkgoDaVWpRAcfeUpvqd31Sb0pyTAQbq3L71 1S6xJGrimkvaCYodY6B2Cs++pwvjqPRV9fMyDf1QwWrTHzppmiXVMI6145F2GZNESoOH wxULXHl+SxqhhBxGY50yKVENLCCEQ3HRWxvFYvesmSgDsJRrf0t1BclqdpLvbjCg+vHe dlHA== X-Gm-Message-State: ABy/qLapXkK9LvbB8hJQvlNkivj++W67HF2vPxykoedMH3BJAnFCeKxK zkVswNE2QZt55kFjZbaVt1CKs9ENO6LeV7KTvDqLAw== X-Google-Smtp-Source: APBJJlE1218gRrmO1SjfIcFfQ4UUVN80437Dr7/ioEFd1wC3xP29QSuBZyIzUftb203xxQmd5ZCexw== X-Received: by 2002:a5e:8c17:0:b0:787:822:30f1 with SMTP id n23-20020a5e8c17000000b00787082230f1mr6947235ioj.1.1689092048946; Tue, 11 Jul 2023 09:14:08 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id x3-20020a6bfe03000000b0077e40979b41sm702370ioh.45.2023.07.11.09.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 09:14:08 -0700 (PDT) Date: Tue, 11 Jul 2023 10:14:02 -0600 Subject: [PATCH v2 2/6] Refactor py-inferior.exp MIME-Version: 1.0 Message-Id: <20230711-py-inf-fixes-30615-v2-2-64a2540864e6@adacore.com> References: <20230711-py-inf-fixes-30615-v2-0-64a2540864e6@adacore.com> In-Reply-To: <20230711-py-inf-fixes-30615-v2-0-64a2540864e6@adacore.com> To: gdb-patches@sourceware.org Cc: Pedro Alves X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes py-inferior.exp to make it a bit more robust when adding new inferiors during the course of the test. Approved-By: 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 576c2b716e6..723f212ecc3 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" + gdb_test_no_output "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" + gdb_test_no_output "remove-inferiors $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_test "python print (infs)" \ - "\\\(, \\\)" \ + "\\\(, \\\)" \ "print all inferiors 1" - gdb_test_no_output "remove-inferiors 4" + gdb_test_no_output "remove-inferiors $num" gdb_test "python print (infs)" \ "\\\(, \\\)" \ "print all inferiors 2"