From patchwork Thu Jul 13 14:05:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 72650 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 E495F385DC22 for ; Thu, 13 Jul 2023 14:06:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E495F385DC22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1689257164; 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=tn8zp/GzZ6PvoWK/gdbtSc3yyw1iuKnFO0KVIAlv0K+BKZ5P3DE3ReRzVflLCR2pU A5kNsVeiwyhmUdburj2MkofiVYV/G7ihx5rQyMG9EcQ24at8kxchnxWrtsckXFkLTk TuHCk9goD349yg3gb7cXZY0ReeEbCDqABYiUt+20= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 962703858CDB for ; Thu, 13 Jul 2023 14:05:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 962703858CDB Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-78360f61ba0so27235939f.1 for ; Thu, 13 Jul 2023 07:05:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689257132; x=1691849132; 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=ELglwVMLGy3FhF+gZCLpleUpSpW11rz1NGkpJScUFxGMwY2+T2esOnj8gvPQVlpw7/ FYgKsQtGmdUOdIGLXS4LI7gsZAD14U8Z/AlEYrWnbkU1UnIjpQwndBNMjQVEjtcNDHjb JfMoroJpa2xWSdRvLoGXRQOxdcP8aatWbVW2jR+MjiXMjrjnew3EDMho5dmw0E56J/LC adEMjWmmRsnpblnq7ph0enKuhpCL0v69zg/DLHbm+FM+vKi+FrQFJIWc0n/gkFcKO8vT 2p6OrYJH2vwuoRga0vF3EO2fkVOHSX/2kALfyC831UMpAIZv9N9qbifI+Q+t1QdrY+8d VGwg== X-Gm-Message-State: ABy/qLZ0OQS0KcW0GecwANUgXsiM4LvkdkusS7p/LOOcV+QR23DWSv/A fQm62I/3Eh4IJEESdlveEZ92vWgi7CcGBhHF15Losw== X-Google-Smtp-Source: APBJJlGPFKKBMShElxNmQNY+2TtfIAiYExXnUPlzpkWHvq3KXBdPinoaZiHAUHwCLbSL2SsRPuaoxQ== X-Received: by 2002:a5d:938f:0:b0:787:1990:d2de with SMTP id c15-20020a5d938f000000b007871990d2demr1852794iol.5.1689257131512; Thu, 13 Jul 2023 07:05:31 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id n13-20020a02a90d000000b0042b7b76b29fsm1841336jam.174.2023.07.13.07.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 07:05:31 -0700 (PDT) Date: Thu, 13 Jul 2023 08:05:27 -0600 Subject: [PATCH v3 2/6] Refactor py-inferior.exp MIME-Version: 1.0 Message-Id: <20230713-py-inf-fixes-30615-v3-2-26a024f30553@adacore.com> References: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@adacore.com> In-Reply-To: <20230713-py-inf-fixes-30615-v3-0-26a024f30553@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"