From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 5D0F73857C4F for ; Wed, 14 Jul 2021 04:55:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D0F73857C4F X-ASG-Debug-ID: 1626238521-0c856e67e219ef210001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 53pCwTdetjuc1Sc8 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Jul 2021 00:55:21 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 16F9C441D64; Wed, 14 Jul 2021 00:55:21 -0400 (EDT) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH 01/16] gdb/testsuite: split gdb.python/py-parameter.exp in procs Date: Wed, 14 Jul 2021 00:55:05 -0400 X-ASG-Orig-Subj: [PATCH 01/16] gdb/testsuite: split gdb.python/py-parameter.exp in procs Message-Id: <20210714045520.1623120-2-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210714045520.1623120-1-simon.marchi@polymtl.ca> References: <20210714045520.1623120-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1626238521 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 12268 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.91193 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, 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: Wed, 14 Jul 2021 04:55:25 -0000 Split the file into multiple independent test procs, where each proc starts with a fresh GDB. I find it easier to understand what a test is doing when each part of the test is isolated and self-contained. It makes it easier to comment out some parts of the test while working / debugging a specific part. It also makes it easier to add new things (which a subsequent patch will do) without fear of impacting another part of the test. Change-Id: I8b4d52ac82b1492d79b679e13914ed177d8a836d --- gdb/testsuite/gdb.python/py-parameter.exp | 237 +++++++++++++--------- 1 file changed, 137 insertions(+), 100 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp index 84ad70ee20ef..7a51eeb640fc 100644 --- a/gdb/testsuite/gdb.python/py-parameter.exp +++ b/gdb/testsuite/gdb.python/py-parameter.exp @@ -19,78 +19,84 @@ load_lib gdb-python.exp # Start with a fresh gdb. -gdb_exit -gdb_start -gdb_reinitialize_dir $srcdir/$subdir +clean_restart # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } -# We use "." here instead of ":" so that this works on win32 too. -if { [is_remote host] } { - # Don't match $srcdir/$subdir because proc gdb_reinitialize_dir - # doesn't set search directories on remote host. - set directories ".*\\\$cdir.\\\$cwd" -} else { - set escaped_directory [string_to_regexp "$srcdir/$subdir"] - set directories "$escaped_directory.\\\$cdir.\\\$cwd" -} -gdb_test "python print (gdb.parameter ('directories'))" $directories - -# Check we can correctly read the data-directory parameter. First, -# grab the value as read directly from the GDB CLI. -set dd "" -gdb_test_multiple "show data-directory" \ - "find the initial data-directory value" { - -re -wrap "GDB's data directory is \"(\[^\r\n\]+)\"\\." { - set dd $expect_out(1,string) - pass $gdb_test_name - } +proc_with_prefix test_directories { } { + # We use "." here instead of ":" so that this works on win32 too. + if { [is_remote host] } { + # Don't match $srcdir/$subdir because proc gdb_reinitialize_dir + # doesn't set search directories on remote host. + set directories ".*\\\$cdir.\\\$cwd" + } else { + set escaped_directory [string_to_regexp "$::srcdir/$::subdir"] + set directories "$escaped_directory.\\\$cdir.\\\$cwd" } + gdb_test "python print (gdb.parameter ('directories'))" $directories +} -# Now print the data-directory from Python. -gdb_test "python print (gdb.parameter ('data-directory'))" $dd - -# Next change the data-directory to a relative path. Internally GDB -# will resolve this to an absolute path, which Python should then see. -# -# GDB is currently running in '...../build/gdb/testsuite/' and the -# test output is being written to: -# ...../build/gdb/testsuite/outputs/gdb.python/py-parameter/ -# -# So create the relative path './outputs/gdb.python/py-parameter/' and -# set the data-directory to that, we should then see the absolute path. - -set abs_path_to_output_dir [standard_output_file ""] -set abs_path_to_cwd $objdir -set rel_path_to_output_dir \ - [file join "." [string replace ${abs_path_to_output_dir} 0 \ - [string length ${abs_path_to_cwd}] ""]] -gdb_test_no_output "set data-directory ${rel_path_to_output_dir}" - -gdb_test "python print (gdb.parameter ('data-directory'))" \ - ${abs_path_to_output_dir} \ - "python sees absolute version of data-directory path" - -# While we're here, check we see the correct path at GDB's CLI. -gdb_test "show data-directory" \ - "GDB's data directory is \"${abs_path_to_output_dir}\"\\." \ - "check modified data-directory at the CLI" - -# Now lets set the data-directory back to what it was initially. -gdb_test_no_output "set data-directory ${dd}" \ - "set data-directory back to its original value" - -# And check we see the restored value at CLI and from Python. -gdb_test "show data-directory" \ - "GDB's data directory is \"${dd}\"\\." \ - "check original data-directory was restored at the CLI" +proc_with_prefix test_data_directory { } { + clean_restart + + # Check we can correctly read the data-directory parameter. First, + # grab the value as read directly from the GDB CLI. + set dd "" + gdb_test_multiple "show data-directory" \ + "find the initial data-directory value" { + -re -wrap "GDB's data directory is \"(\[^\r\n\]+)\"\\." { + set dd $expect_out(1,string) + pass $gdb_test_name + } + } -gdb_test "python print (gdb.parameter ('data-directory'))" ${dd} \ - "python sees restored data-directory value" + # Now print the data-directory from Python. + gdb_test "python print (gdb.parameter ('data-directory'))" $dd + + # Next change the data-directory to a relative path. Internally GDB + # will resolve this to an absolute path, which Python should then see. + # + # GDB is currently running in '...../build/gdb/testsuite/' and the + # test output is being written to: + # ...../build/gdb/testsuite/outputs/gdb.python/py-parameter/ + # + # So create the relative path './outputs/gdb.python/py-parameter/' and + # set the data-directory to that, we should then see the absolute path. + + set abs_path_to_output_dir [standard_output_file ""] + set abs_path_to_cwd $::objdir + set rel_path_to_output_dir \ + [file join "." [string replace ${abs_path_to_output_dir} 0 \ + [string length ${abs_path_to_cwd}] ""]] + gdb_test_no_output "set data-directory ${rel_path_to_output_dir}" + + gdb_test "python print (gdb.parameter ('data-directory'))" \ + ${abs_path_to_output_dir} \ + "python sees absolute version of data-directory path" + + # While we're here, check we see the correct path at GDB's CLI. + gdb_test "show data-directory" \ + "GDB's data directory is \"${abs_path_to_output_dir}\"\\." \ + "check modified data-directory at the CLI" + + # Now lets set the data-directory back to what it was initially. + gdb_test_no_output "set data-directory ${dd}" \ + "set data-directory back to its original value" + + # And check we see the restored value at CLI and from Python. + gdb_test "show data-directory" \ + "GDB's data directory is \"${dd}\"\\." \ + "check original data-directory was restored at the CLI" + + gdb_test "python print (gdb.parameter ('data-directory'))" ${dd} \ + "python sees restored data-directory value" +} # Test a simple boolean parameter. -with_test_prefix "boolean parameter" { +proc_with_prefix test_boolean_parameter { } { + clean_restart + gdb_test_multiline "Simple gdb booleanparameter" \ "python" "" \ "class TestParam (gdb.Parameter):" "" \ @@ -130,7 +136,9 @@ with_test_prefix "boolean parameter" { } # Test an enum parameter. -with_test_prefix "enum parameter" { +proc_with_prefix test_enum_parameter { } { + clean_restart + gdb_test_multiline "enum gdb parameter" \ "python" "" \ "class TestEnumParam (gdb.Parameter):" "" \ @@ -163,7 +171,9 @@ with_test_prefix "enum parameter" { } # Test a file parameter. -with_test_prefix "file parameter" { +proc_with_prefix test_file_parameter { } { + clean_restart + gdb_test_multiline "file gdb parameter" \ "python" "" \ "class TestFileParam (gdb.Parameter):" "" \ @@ -195,7 +205,9 @@ with_test_prefix "file parameter" { } # Test a parameter that is not documented. -with_test_prefix "undocumented parameter" { +proc_with_prefix test_undocumented_parameter { } { + clean_restart + gdb_test_multiline "Simple gdb booleanparameter" \ "python" "" \ "class TestUndocParam (gdb.Parameter):" "" \ @@ -230,7 +242,9 @@ with_test_prefix "undocumented parameter" { } # Test a parameter that is not documented in any way.. -with_test_prefix "really undocumented parameter" { +proc_with_prefix test_really_undocumented_parameter { } { + clean_restart + gdb_test_multiline "Simple gdb booleanparameter" \ "python" "" \ "class TestNodocParam (gdb.Parameter):" "" \ @@ -258,7 +272,9 @@ with_test_prefix "really undocumented parameter" { } # Test deprecated API. Do not use in your own implementations. -with_test_prefix "deprecated API parameter" { +proc_with_prefix test_deprecated_api_parameter { } { + clean_restart + gdb_test_multiline "Simple gdb booleanparameter" \ "python" "" \ "class TestParam (gdb.Parameter):" "" \ @@ -289,41 +305,62 @@ with_test_prefix "deprecated API parameter" { "test general help" } -foreach kind {PARAM_ZUINTEGER PARAM_ZUINTEGER_UNLIMITED} { - gdb_test_multiline "Simple gdb $kind" \ +proc_with_prefix test_integer_parameter { } { + foreach_with_prefix kind {PARAM_ZUINTEGER PARAM_ZUINTEGER_UNLIMITED} { + clean_restart + + gdb_test_multiline "create parameter" \ + "python" "" \ + "class TestNodocParam (gdb.Parameter):" "" \ + " def __init__ (self, name):" "" \ + " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.$kind)" "" \ + " self.value = 0" "" \ + "test_param_$kind = TestNodocParam ('test-$kind')" "" \ + "end" + + gdb_test "python print(gdb.parameter('test-$kind'))" "0" + + gdb_test "python test_param_$kind.value = -5" "RuntimeError: Range exceeded.*" + + if {$kind == "PARAM_ZUINTEGER"} { + gdb_test "python test_param_$kind.value = -1" "RuntimeError: Range exceeded.*" + } elseif {$kind == "PARAM_ZUINTEGER_UNLIMITED"} { + gdb_test_no_output "python test_param_$kind.value = -1" \ + "check that PARAM_ZUINTEGER value can be set to -1" + gdb_test "python print(gdb.parameter('test-$kind'))" "-1" \ + "check that PARAM_ZUINTEGER value is -1 after setting" + } else { + error "invalid kind: $kind" + } + } +} + +proc_with_prefix test_throwing_parameter { } { + clean_restart + + gdb_test_multiline "Throwing gdb parameter" \ "python" "" \ - "class TestNodocParam (gdb.Parameter):" "" \ + "class TestThrowParam (gdb.Parameter):" "" \ " def __init__ (self, name):" "" \ - " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.$kind)" "" \ - " self.value = 0" "" \ - "test_param_$kind = TestNodocParam ('test-$kind')" "" \ + " super (TestThrowParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_STRING)" "" \ + " self.value = True" "" \ + " def get_set_string (self):" "" \ + " raise gdb.GdbError('Ordinary gdb error')" "" \ + "test_throw_param = TestThrowParam ('print test-throw-param')" ""\ "end" - gdb_test "python print(gdb.parameter('test-$kind'))" "0" - - gdb_test "python test_param_$kind.value = -5" "RuntimeError: Range exceeded.*" - - if {$kind == "PARAM_ZUINTEGER"} { - gdb_test "python test_param_$kind.value = -1" "RuntimeError: Range exceeded.*" - } else { - gdb_test_no_output "python test_param_$kind.value = -1" \ - "check that PARAM_ZUINTEGER value can be set to -1" - gdb_test "python print(gdb.parameter('test-$kind'))" "-1" \ - "check that PARAM_ZUINTEGER value is -1 after setting" - } + gdb_test "set print test-throw-param whoops" \ + "Ordinary gdb error" \ + "gdb.GdbError does not show Python stack" } -gdb_test_multiline "Throwing gdb parameter" \ - "python" "" \ - "class TestThrowParam (gdb.Parameter):" "" \ - " def __init__ (self, name):" "" \ - " super (TestThrowParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_STRING)" "" \ - " self.value = True" "" \ - " def get_set_string (self):" "" \ - " raise gdb.GdbError('Ordinary gdb error')" "" \ - "test_throw_param = TestThrowParam ('print test-throw-param')" ""\ - "end" - -gdb_test "set print test-throw-param whoops" \ - "Ordinary gdb error" \ - "gdb.GdbError does not show Python stack" +test_directories +test_data_directory +test_boolean_parameter +test_enum_parameter +test_file_parameter +test_undocumented_parameter +test_really_undocumented_parameter +test_deprecated_api_parameter +test_integer_parameter +test_throwing_parameter -- 2.32.0