From: Simon Marchi <simon.marchi@polymtl.ca>
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 [thread overview]
Message-ID: <20210714045520.1623120-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20210714045520.1623120-1-simon.marchi@polymtl.ca>
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
next prev parent reply other threads:[~2021-07-14 4:55 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 4:55 [PATCH 00/16] Bunch of commands related cleanups Simon Marchi
2021-07-14 4:55 ` Simon Marchi [this message]
2021-07-14 4:55 ` [PATCH 02/16] gdb.base/setshow.exp: use save_vars to save/restore gdb_prompt Simon Marchi
2021-07-14 4:55 ` [PATCH 03/16] gdb.base/setshow.exp: split in procs Simon Marchi
2021-07-14 4:55 ` [PATCH 04/16] gdb.base/setshow.exp: fix duplicate test name Simon Marchi
2021-07-14 4:55 ` [PATCH 05/16] gdb: un-share set_inferior_cwd declaration Simon Marchi
2021-07-14 4:55 ` [PATCH 06/16] gdb: remove inferior::{argc,argv} Simon Marchi
2021-07-14 4:55 ` [PATCH 07/16] gdb: add setter/getter for inferior arguments Simon Marchi
2021-07-14 4:55 ` [PATCH 08/16] gdb: add setter/getter for inferior cwd Simon Marchi
2021-07-14 4:55 ` [PATCH 09/16] gdb: make inferior::m_args an std::string Simon Marchi
2021-07-14 4:55 ` [PATCH 10/16] gdb: make inferior::m_cwd " Simon Marchi
2021-07-14 4:55 ` [PATCH 11/16] gdb: make inferior::m_terminal " Simon Marchi
2021-07-14 4:55 ` [PATCH 12/16] gdb: rename cfunc to simple_func Simon Marchi
2021-07-14 4:55 ` [PATCH 13/16] gdb: remove cmd_list_element::function::sfunc Simon Marchi
2021-07-28 19:10 ` Tom Tromey
2021-07-28 21:17 ` Simon Marchi
2021-07-29 17:33 ` Tom Tromey
2021-07-14 4:55 ` [PATCH 14/16] gdb/testsuite: test get/set value of unregistered Guile parameter Simon Marchi
2021-07-23 19:42 ` Simon Marchi
2021-07-14 4:55 ` [PATCH 15/16] gdb: make cmd_list_element var an optional union Simon Marchi
2021-07-14 12:08 ` Lancelot SIX
2021-07-14 17:12 ` Lancelot SIX
2021-07-14 19:22 ` Simon Marchi
2021-07-14 23:22 ` Lancelot SIX
2021-07-19 14:32 ` Simon Marchi
2021-07-19 19:52 ` Simon Marchi
2021-07-20 23:03 ` Lancelot SIX
2021-07-23 19:56 ` Simon Marchi
2021-07-23 20:46 ` Lancelot SIX
2021-07-23 21:15 ` Simon Marchi
2021-07-23 22:55 ` Lancelot SIX
2021-07-24 2:04 ` Simon Marchi
2021-07-28 20:13 ` Tom Tromey
2021-07-28 20:45 ` Lancelot SIX
2021-07-29 17:47 ` Tom Tromey
2021-07-29 20:12 ` Lancelot SIX
2021-07-30 2:09 ` Simon Marchi
2021-07-30 17:47 ` Lancelot SIX
2021-07-18 15:44 ` Lancelot SIX
2021-07-19 14:19 ` Simon Marchi
2021-07-19 20:58 ` Lancelot SIX
2021-07-28 19:47 ` Tom Tromey
2021-07-28 20:59 ` Simon Marchi
2021-07-29 17:41 ` Tom Tromey
2021-07-29 17:44 ` Simon Marchi
2021-07-29 17:49 ` Tom Tromey
2021-07-29 18:00 ` Simon Marchi
2021-07-14 4:55 ` [PATCH 16/16] gdb: make string-like set show commands use std::string variable Simon Marchi
2021-07-28 20:27 ` Tom Tromey
2021-07-28 21:03 ` Simon Marchi
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=20210714045520.1623120-2-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/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).