From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 480643858D28 for ; Tue, 30 Nov 2021 12:43:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 480643858D28 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 1AUChoYB006270 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Nov 2021 07:43:55 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 1AUChoYB006270 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 98BC31EDEE; Tue, 30 Nov 2021 07:43:50 -0500 (EST) Message-ID: <667ae19d-f63a-11f4-45e1-75fed6e0b010@polymtl.ca> Date: Tue, 30 Nov 2021 07:43:50 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH] gdb/testsuite: check the python module is available before using it Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: <20211129151940.2235813-1-aburgess@redhat.com> From: Simon Marchi In-Reply-To: <20211129151940.2235813-1-aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 30 Nov 2021 12:43:50 +0000 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 30 Nov 2021 12:43:58 -0000 On 2021-11-29 10:19, Andrew Burgess via Gdb-patches wrote: > The gdb.python/py-inferior-leak.exp test makes use of the tracemalloc > module. When running the Python tests with a GDB built against Python > 2 I ran into a test failure due to the tracemalloc module not being > available. > > This commit adds a new helper function to lib/gdb-python.exp that > checks if a named module is available. Using this we can then skip > the py-inferior-leak.exp test when the tracemalloc module is not > available. > --- > gdb/testsuite/gdb.python/py-inferior-leak.exp | 6 +++++ > gdb/testsuite/lib/gdb-python.exp | 25 +++++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/gdb/testsuite/gdb.python/py-inferior-leak.exp b/gdb/testsuite/gdb.python/py-inferior-leak.exp > index 9cd1ebf2433..15d742391de 100644 > --- a/gdb/testsuite/gdb.python/py-inferior-leak.exp > +++ b/gdb/testsuite/gdb.python/py-inferior-leak.exp > @@ -25,6 +25,12 @@ clean_restart > # Skip all tests if Python scripting is not enabled. > if { [skip_python_tests] } { continue } > > +# Skip this test if the tracemalloc module is not available. > +if { ![gdb_py_module_available "tracemalloc"] } { > + unsupported "tracemalloc module not available" > + continue > +} > + > set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] > > # Source the Python script, this runs the test (which is written > diff --git a/gdb/testsuite/lib/gdb-python.exp b/gdb/testsuite/lib/gdb-python.exp > index 13a1ab517f1..60931fec28a 100644 > --- a/gdb/testsuite/lib/gdb-python.exp > +++ b/gdb/testsuite/lib/gdb-python.exp > @@ -51,3 +51,28 @@ proc get_python_valueof { exp default {test ""} } { > } > return ${val} > } > + > +# Return true if Python module NAME is available, otherwise, return > +# false. > + > +proc gdb_py_module_available { name } { > + set available "unknown" > + gdb_test_multiple "python import ${name}" "" { > + -re -wrap "ModuleNotFoundError: No module named '${name}'.*" { > + set available false > + } > + -re -wrap "ImportError: No module named ${name}.*" { > + set available false > + } > + -re -wrap "python import ${name}" { > + set available true > + } > + } > + > + if { $available == "unknown" } { > + perror "unexpected output from python import" > + set available false > + } > + > + return ${available} > +} > LGTM. Simon