[2/3] Add testcases for display function

Message ID 1446620987-4140-3-git-send-email-feij.fnst@cn.fujitsu.com
State New, archived
Headers

Commit Message

Fei Jie Nov. 4, 2015, 7:09 a.m. UTC
  add testcases to test display under different conditions
---
 gdb/testsuite/gdb.base/display.c       |  5 +++++
 gdb/testsuite/gdb.base/testdisplay.exp | 35 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/testdisplay.exp
  

Comments

Joel Brobecker Nov. 4, 2015, 9:39 p.m. UTC | #1
>     add testcases to test display under different conditions

Same kind of procedural issues as before, so I'm not going to comment
on those again.

> --- a/gdb/testsuite/gdb.base/display.c
> +++ b/gdb/testsuite/gdb.base/display.c
> @@ -4,6 +4,11 @@
>  #define LOOP 10
>  
>  int sum = 0;
> +int int_array[2]={0,1};

The formatting does not follow the GCS:
  - spaces around binary operators;
  - space after comma.
Thus:

int int_array[2] = {0, 1};

> +struct {
> +	char name;
> +	int age;
> +} human;

GCS issues:
  - the opening curly braces should be on the next line. 
  - the indentation level should be 2 characters.
Thus:

struct
  {
    char name;
    int age;
  } human;

> +set bp_location [gdb_get_line_number "set breakpoint 1 here"]
> +send_gdb "break $bp_location\n"
> +send_gdb "run\n"

Do not use send_gdb unless you absolutely have no other choice.
Take a look at the gdb testsuite cookbook for how to insert breakpoints
and run to them.

Also, this might no longer become relevant, but it's better to never
test the "run" command directly, since there are targets where this
is not the appropriate thing to do (Eg: when using gdbserver, we do
"set target remote ..." followed by "continue" instead).

But why not enhance display.exp instead of creating a new one?
  

Patch

diff --git a/gdb/testsuite/gdb.base/display.c b/gdb/testsuite/gdb.base/display.c
index cd833e2..6db289c 100644
--- a/gdb/testsuite/gdb.base/display.c
+++ b/gdb/testsuite/gdb.base/display.c
@@ -4,6 +4,11 @@ 
 #define LOOP 10
 
 int sum = 0;
+int int_array[2]={0,1};
+struct {
+	char name;
+	int age;
+} human;
 
 /* Call to force a variable onto the stack so we can see its address.  */
 void force_mem (int *arg) { }
diff --git a/gdb/testsuite/gdb.base/testdisplay.exp b/gdb/testsuite/gdb.base/testdisplay.exp
new file mode 100644
index 0000000..984465e2
--- /dev/null
+++ b/gdb/testsuite/gdb.base/testdisplay.exp
@@ -0,0 +1,35 @@ 
+set srcfile display.c
+
+if { [prepare_for_testing testdisplay.exp "testdisplay" display.c {debug nowarnings}] } {
+	untest testdisplay.exp
+	return -1
+}
+
+set bp_location [gdb_get_line_number "set breakpoint 1 here"]
+send_gdb "break $bp_location\n"
+send_gdb "run\n"
+
+#Test disp(display)
+gdb_test "display f" "1: f = 3.1415"
+gdb_test "display/x f" "2: /x f = 0x3"
+gdb_test "display/d f" "3: /d f = 3"
+gdb_test "display/u f" "4: /u f = 3"
+gdb_test "display/o f" "5: /o f = 03"
+gdb_test "display/t f" "6: /t f = 11"
+gdb_test "display/a f" "7: /a f = 0x3"
+gdb_test "display/c f" "8: /c f = 3\ \'\\\\003\'"
+gdb_test "display/f f" "9: /f f = 3.1415"
+
+gdb_test "display int_array" \
+	"10: int_array = \\{0, 1\\}"
+gdb_test "display human" \
+	"11: human = {name = 0 '\\\\000', age = 0}"
+
+#Test disable/enable display
+gdb_test "disable display 999" \
+	"No display number 999\."
+gdb_test_no_output "disable display 9"
+gdb_test_no_output "enable display 9"
+
+gdb_exit
+return 0