[RFAv5,2/3] Test the convenience functions $_gdb_setting and $_gdb_int_setting.

Message ID 20190915185314.19875-3-philippe.waroquiers@skynet.be
State Superseded
Headers show
Series
  • Convenience functions $_gdb_setting/$_gdb_setting_str
Related show

Commit Message

Philippe Waroquiers Sept. 15, 2019, 6:53 p.m.
gdb/testsuite/ChangeLog
2019-09-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/setshow.exp: Test $_gdb_setting and $_gdb_setting_str.
	* gdb.base/settings.exp: Test all settings types using
	$_gdb_maint_setting and $_gdb_maint_setting_str in proc_show_setting,
	that now verifies that the value of "maint show" is the same as
	returned by the settings functions.  Test the type of the
	maintenance settings.
	* gdb.base/default.exp: Update show_conv_list.
---
 gdb/testsuite/gdb.base/default.exp  |  4 ++
 gdb/testsuite/gdb.base/setshow.exp  | 74 ++++++++++++++++++++++-
 gdb/testsuite/gdb.base/settings.exp | 94 ++++++++++++++++++++++++++---
 3 files changed, 162 insertions(+), 10 deletions(-)

-- 
2.20.1

Comments

Pedro Alves Oct. 30, 2019, 7:44 p.m. | #1
The subject is stale -- it's $_gdb_setting / $_gdb_setting_str nowadays.

> +# Verifies that $_gdb_setting (SETTING) gives a value whose ptype matches EXPECTED.

> +proc check_type {setting expected} {

> +    with_test_prefix "check_type $setting $expected" {

> +	gdb_test "print \$_gdb_maint_setting(\"$setting\")"

> +	gdb_test "ptype $" "$expected"

> +    }

>  }

>  


I think it would still be good to add here:

 	gdb_test "ptype \$_gdb_maint_setting(\"$setting\")" \
            "type = int"

This is so if someone changes ptype of convenience
functions, maybe making it work for this case, the testcase makes
sure this case is inspected.

Otherwise this version LGTM.

Thanks,
Pedro Alves

Patch

diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index 0325b8045d..114831f2fc 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -604,6 +604,10 @@  set show_conv_list \
 	{$_cimag = <internal function _cimag>} \
 	{$_creal = <internal function _creal>} \
 	{$_isvoid = <internal function _isvoid>} \
+	{$_gdb_maint_setting_str = <internal function _gdb_maint_setting_str>} \
+	{$_gdb_maint_setting = <internal function _gdb_maint_setting>} \
+	{$_gdb_setting_str = <internal function _gdb_setting_str>} \
+	{$_gdb_setting = <internal function _gdb_setting>} \
 	{$_gdb_major = 8} \
 	{$_gdb_minor = 4} \
 	{$_shell_exitsignal = void} \
diff --git a/gdb/testsuite/gdb.base/setshow.exp b/gdb/testsuite/gdb.base/setshow.exp
index d807d75a66..5316b48509 100644
--- a/gdb/testsuite/gdb.base/setshow.exp
+++ b/gdb/testsuite/gdb.base/setshow.exp
@@ -84,6 +84,9 @@  gdb_test "show annotate" "Annotation_level is 0..*"  "show annotate (0)"
 #test annotation_level 0
 gdb_test "info line 1" "Line 1 of .* is at address .* but contains no code.*"  "annotation_level 0" 
 
+gdb_test "show args" "Argument list to give program being debugged when it is started is \"\"\."
+gdb_test "p \$_gdb_setting_str(\"args\")" " = \"\""
+
 gdb_test_no_output "set args ~"
 gdb_test "show args" "Argument list to give program being debugged when it is started is \"~\"..*" \
     "show args ~"
@@ -91,6 +94,9 @@  gdb_test "show args" "Argument list to give program being debugged when it is st
 gdb_test_no_output "set args foo bar blup baz bubble" "set args" 
 #test show args
 gdb_test "show args" "Argument list to give program being debugged when it is started is \"foo bar blup baz bubble\"..*" "show args"
+gdb_test "p \$_gdb_setting(\"args\")" " = \"foo bar blup baz bubble\"" \
+    "_gdb_setting args"
+
 
 # Don't test if we can't pass args or if we're using a stub.
 if { !$use_gdb_stub && ![target_info exists noargs] } {
@@ -100,32 +106,80 @@  if { !$use_gdb_stub && ![target_info exists noargs] } {
     gdb_test "run" "Starting program:.*foo bar blup baz bubble.*" "passing args"
 }
 #test set check range on
-gdb_test "set check range on" ".*" "set check range on" 
+# Note: the below might produce a warning, so match anything. 
+gdb_test "set check range on" ""
+
+gdb_test "p \$_gdb_setting(\"check range\")" " = \"on\"" \
+    "_gdb_setting check range on"
 #test show check range on
 gdb_test "show check range" "Range checking is \"on\"\..*" "show check range (on)" 
 #test set check range off with trailing space
 gdb_test_no_output "set check range off " "set check range off" 
 #test show check range off
 gdb_test "show check range" "Range checking is \"off\"\..*" "show check range (off)" 
+gdb_test "p \$_gdb_setting(\"check range\")" " = \"off\"" \
+    "_gdb_setting check range off"
 #test set check range auto
 gdb_test_no_output "set check range auto" "set check range auto" 
 #test show check range auto
 gdb_test "show check range" "Range checking is \"auto; currently .*" "show check range (auto)"
+gdb_test "p \$_gdb_setting(\"check range\")" " = \"auto\"" \
+    "_gdb_setting check range auto"
 
 # Test set check type on
-gdb_test "set check type on" ".*" "set check type on"
+gdb_test_no_output "set check type on"
 
 # Test show check type on
 gdb_test "show check type" "Strict type checking is on\..*" \
     "show check type (on)"
+gdb_test "p \$_gdb_setting_str(\"check type\")" " = \"on\"" \
+    "_gdb_setting_str check type on"
+gdb_test "p \$_gdb_setting(\"check type\")" " = 1" \
+    "_gdb_setting check type on 1"
 
 # Test set check type off with trailing space
 gdb_test_no_output "set check type off " "set check type off"
+gdb_test "p \$_gdb_setting_str(\"check type\")" " = \"off\"" \
+    "_gdb_setting_str check type off"
+gdb_test "p \$_gdb_setting(\"check type\")" " = 0" \
+    "_gdb_setting check type off 0"
 
 # Test show check type off
 gdb_test "show check type" "Strict type checking is off\..*" \
     "show check type (off)"
 
+#test set breakpoint pending
+
+#test set breakpoint pending on
+gdb_test_no_output "set breakpoint pending on"
+gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" " = \"on\"" \
+    "_gdb_setting_str breakpoint pending on"
+gdb_test "p \$_gdb_setting(\"breakpoint pending\")" " = 1" \
+    "_gdb_setting breakpoint pending 1"
+
+#test show breakpoint pending on
+gdb_test "show breakpoint pending" " is on\..*" "show breakpoint pending on"
+
+#test show breakpoint pending off
+gdb_test_no_output "set breakpoint pending off"
+gdb_test "show breakpoint pending" " is off\..*" "show breakpoint pending off"
+gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" " = \"off\"" \
+    "_gdb_setting_str breakpoint pending off"
+gdb_test "p \$_gdb_setting(\"breakpoint pending\")" " = 0" \
+    "_gdb_setting breakpoint pending 0"
+
+#test set breakpoint pending auto
+gdb_test_no_output "set breakpoint pending auto"
+
+#test show breakpoint pending auto
+gdb_test "show breakpoint pending" " is auto.*" "show breakpoint pending auto"
+gdb_test "p \$_gdb_setting_str(\"breakpoint pending\")" " = \"auto\"" \
+    "_gdb_setting_str breakpoint pending auto"
+gdb_test "p \$_gdb_setting(\"breakpoint pending\")" " = -1" \
+    "_gdb_setting breakpoint pending -1"
+
+
+
 #test set complaints 100
 gdb_test_no_output "set complaints 100" "set complaints 100" 
 #test show complaints 100
@@ -159,9 +213,17 @@  gdb_test "show environment FOOBARBAZ" "FOOBARBAZ = grbxgrbxgrbx.*"  "show enviro
 gdb_test_no_output "set height 100" "set height 100" 
 #test show height 100
 gdb_test "show height" "Number of lines gdb thinks are in a page is 100..*" "show height" 
+gdb_test "p \$_gdb_setting_str(\"height\")" " = \"100\"" \
+    "_gdb_setting_str height 100"
+gdb_test "p \$_gdb_setting(\"height\")" " = 100" \
+    "_gdb_setting height 100"
 # Back to infinite height to avoid pagers.  While at it, check that
 # literal "unlimited" works just as well as 0.
 gdb_test_no_output "set height unlimited"
+gdb_test "p \$_gdb_setting_str(\"height\")" " = \"unlimited\"" \
+    "_gdb_setting_str height unlimited"
+gdb_test "p \$_gdb_setting(\"height\")" " = 0" \
+    "_gdb_setting height unlimited"
 #test set history expansion on
 gdb_test_no_output "set history expansion on" "set history expansion on" 
 #test show history expansion on
@@ -182,6 +244,12 @@  gdb_test_no_output "set history filename ~/foobar.baz" \
 gdb_test "show history filename" \
     "The filename in which to record the command history is \"[string_to_regexp $HOME]/foobar.baz\"..*" \
     "show history filename (~/foobar.baz)"
+gdb_test "p \$_gdb_setting(\"history filename\")" \
+    " = \"[string_to_regexp $HOME]/foobar.baz\"..*" \
+    "_gdb_setting history filename"
+gdb_test "p \$_gdb_setting_str(\"history filename\")" \
+    " = \"[string_to_regexp $HOME]/foobar.baz\"..*" \
+    "_gdb_setting_str history filename"
 #get current working directory
 set PWD ""
 set test "show working directory"
@@ -209,7 +277,7 @@  gdb_test_no_output "set history size 100" "set history size 100"
 #test show history size 100
 gdb_test "show history size" "The size of the command history is 100..*" "show history size (100)" 
 #test set language asm
-gdb_test "set language asm" ".*" "set language asm" 
+gdb_test_no_output "set language asm"
 #test show language asm
 gdb_test "show language" "The current source language is \"asm\"..*" "show language (asm)" 
 #test set language rust, with a trailing space
diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp
index 53049d6b59..3cb6e63efe 100644
--- a/gdb/testsuite/gdb.base/settings.exp
+++ b/gdb/testsuite/gdb.base/settings.exp
@@ -35,11 +35,80 @@  if { ![readline_is_used] } {
 }
 
 # Test the show command SHOW_CMD.  EXPECTED_RE is the expected output.
-# This procedure exists in order to make it easier to make the test
+# Also verifies that $_gdb_maint_setting_str produces an equivalent output,
+# matching it with EXPECTED_RE.  EXPECTED_RE double quotes are escaped
+# unless EXPECTED_RE_ESCAPED is true, indicating the quotes in EXPECTED_RE
+# are already escaped.
+# The value for the setting corresponding to SHOW_CMD is then reset
+# to RESET_VALUE, then set again to the value given by $_gdb_maint_setting_str
+# and $_gdb_maint_setting.  The default value of RESET_VALUE (0) should work for
+# most settings.  Note that we do not check that RESET_VALUE differs from
+# the expected value, as we assume different values will be verified.
+# The setting value must still be the one in force before calling show_setting.
+# In other words, this verifies that
+#   maint set test-settings <some_setting> $_gdb_maint_setting_str(<some_setting>)
+#   maint set test-settings <some_setting> $_gdb_maint_setting(<some_setting>)
+# do not change the setting value.
+# This procedure makes it easier to make the test
 # name/message unique, since we test the "show" commands many times.
 # EXPECTED_RE is made part of the test name.
-proc show_setting {show_cmd expected_re} {
-    gdb_test "$show_cmd" $expected_re "$show_cmd: $expected_re"
+proc show_setting {show_cmd expected_re {expected_re_escaped 0} {reset_value 0}} {
+    global gdb_prompt
+
+    with_test_prefix "$show_cmd $expected_re" {
+	gdb_test "$show_cmd" $expected_re "show"
+
+	# Remove the first two words (such as "maint show") to have the
+	# setting name to use for $_gdb_maint_setting_str.
+	regsub "\[^ \]+ +\[^ \]+ +\(.*\)" $show_cmd "\\1" maint_setting
+	if {$expected_re_escaped} {
+	    set escaped_expected_re $expected_re
+	} else {
+	    regsub -all "\"" $expected_re "\\\\\\\"" escaped_expected_re
+	}
+	set test "print \$_gdb_maint_setting_str"
+	set setting_str_value "xxxYYYxxx"
+	gdb_test_multiple "print \$_gdb_maint_setting_str(\"$maint_setting\")" $test {
+	    -re " = \"\($escaped_expected_re\)\".*$gdb_prompt $" {
+		set setting_str_value $expect_out(1,string)
+		regsub -all "\\\\" $expect_out(1,string) "" setting_str_value
+		pass $test
+	    }
+	}
+
+	# Change the setting value to RESET_VALUE, set it back to setting_str_value
+	# and check we still have the original value.
+	gdb_test_no_output "maintenance set $maint_setting $reset_value" "str reset $reset_value"
+	gdb_test_no_output "maintenance set $maint_setting $setting_str_value" "str set again"
+	gdb_test "$show_cmd" $expected_re "str show after reset+set again"
+
+	# Same test, but with value captured from $_gdb_maint_setting.
+	set test "print \$_gdb_maint_setting"
+	set setting_value "xxxYYYxxx"
+	gdb_test_multiple "print \$_gdb_maint_setting(\"$maint_setting\")" $test {
+	    -re " = \"\(.*\)\".*$gdb_prompt $" {
+		set setting_value $expect_out(1,string)
+		regsub -all "\\\\" $expect_out(1,string) "" setting_value
+		pass $test
+	    }
+	    -re " = \(.*\)\r\n$gdb_prompt $" {
+		set setting_value $expect_out(1,string)
+		pass $test
+	    }
+	}
+
+	gdb_test_no_output "maintenance set $maint_setting $reset_value" "reset $reset_value"
+	gdb_test_no_output "maintenance set $maint_setting $setting_value" "set again"
+	gdb_test "$show_cmd" $expected_re "show after reset+set again"
+    }
+}
+
+# Verifies that $_gdb_setting (SETTING) gives a value whose ptype matches EXPECTED.
+proc check_type {setting expected} {
+    with_test_prefix "check_type $setting $expected" {
+	gdb_test "print \$_gdb_maint_setting(\"$setting\")"
+	gdb_test "ptype $" "$expected"
+    }
 }
 
 # var_Xinteger tests.  VARIANT determines which command/variant to
@@ -68,16 +137,19 @@  proc test-integer {variant} {
 	# -1 means unlimited.  Other negative values are rejected.  -1
 	# -is tested further below, along the "unlimited" tests.
 	gdb_test "$set_cmd -2" "only -1 is allowed to set as unlimited"
+	check_type "test-settings $variant" "type = int"
     } elseif {$variant == "uinteger" || $variant == "zuinteger"} {
 	# Negative values are not accepted.
 	gdb_test "$set_cmd -1" "integer -1 out of range"
 	gdb_test "$set_cmd -2" "integer -2 out of range"
+	check_type "test-settings $variant" "type = unsigned int"
     } else {
 	# Negative values are not accepted.
 	gdb_test_no_output "$set_cmd -1"
 	show_setting "$show_cmd" "-1"
 	gdb_test_no_output "$set_cmd -2"
 	show_setting "$show_cmd" "-2"
+	check_type "test-settings $variant" "type = int"
     }
 
     # Regular integer is accepted.
@@ -234,6 +306,8 @@  proc_with_prefix test-boolean {} {
 	show_setting "$show_cmd" "on"
     }
 
+    check_type "test-settings boolean" "type = int"
+
     foreach_with_prefix value {
 	"of"
 	"off"
@@ -354,6 +428,8 @@  proc_with_prefix test-auto-boolean {} {
 	show_setting "$show_cmd" "auto"
     }
 
+    check_type "test-settings auto-boolean" "type = int"
+
     # "-" is not accepted as abbreviation of "-1".
     gdb_test "$set_cmd -" \
 	"\"on\", \"off\" or \"auto\" expected\\."
@@ -409,11 +485,13 @@  proc_with_prefix test-enum {} {
     # Various valid values.  Test both full value names and
     # abbreviations.
     gdb_test_no_output "$set_cmd x"
-    show_setting "$show_cmd" "xxx"
+    show_setting "$show_cmd" "xxx" 0 "zzz"
     gdb_test_no_output "$set_cmd yy"
-    show_setting "$show_cmd" "yyy"
+    show_setting "$show_cmd" "yyy" 0 "zzz"
     gdb_test_no_output "$set_cmd zzz"
-    show_setting "$show_cmd" "zzz"
+    show_setting "$show_cmd" "zzz" 0 "yyy"
+
+    check_type "test-settings enum" "type = char \\\[3\\\]"
 
     test_gdb_complete_multiple "$set_cmd " "" "" {
 	"xxx"
@@ -458,10 +536,12 @@  proc test-string {variant} {
     gdb_test_no_output "$set_cmd hello world"
     show_setting "$show_cmd" "hello world"
 
+    check_type "test-settings $variant" "type = char \\\[\[1-9\]\[0-9\]*\\\]"
+
     # A quoted string value.
     if {$variant == "string"} {
 	gdb_test_no_output "$set_cmd \"hello world\""
-	show_setting "$show_cmd" "\\\\\"hello world\\\\\""
+	show_setting "$show_cmd" "\\\\\"hello world\\\\\"" 1
     } else {
 	gdb_test_no_output "$set_cmd \"hello world\""
 	show_setting "$show_cmd" "\"hello world\""