[pushed] gdb.base/commands.exp: Test loop_break and loop_continue in nested loops

Message ID 1504552886-4258-1-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi Sept. 4, 2017, 7:21 p.m. UTC
  This patch improves the loop_break and loop_continue tests to verify
that they work as expected when multiple loops are nested (they affect
the inner loop).

gdb/testsuite/ChangeLog:

	* gdb.base/commands.exp (loop_break_test, loop_continue_test):
	Test with nested loops.
---
 gdb/testsuite/ChangeLog             |  5 +++
 gdb/testsuite/gdb.base/commands.exp | 65 ++++++++++++++++++++++++-------------
 2 files changed, 47 insertions(+), 23 deletions(-)
  

Patch

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8a6838b..24ad99b 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@ 
 2017-09-04  Simon Marchi  <simon.marchi@ericsson.com>
 
+	* gdb.base/commands.exp (loop_break_test, loop_continue_test):
+	Test with nested loops.
+
+2017-09-04  Simon Marchi  <simon.marchi@ericsson.com>
+
 	* gdb.base/commands.exp: Call the new procedures.
 	(loop_break_test, loop_continue_test): New procedures.
 
diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 49a9242..17f113c 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -1030,41 +1030,60 @@  proc define_if_without_arg_test {} {
 
 proc_with_prefix loop_break_test {} {
     gdb_test_no_output "set \$a = 0" "initialize \$a"
+    gdb_test_no_output "set \$total = 0" "initialize \$total"
 
     gdb_test \
-    [multi_line_input \
-	 "while \$a < 5" \
-	 "  if \$a == 3" \
-	 "    loop_break" \
-	 "  end" \
-	 "  set \$a = \$a + 1" \
-	 "end"] \
-    "" \
-    "run while loop"
-
-    gdb_test "print \$a" " = 3" "validate \$a"
+	[multi_line_input \
+	     "while \$a < 5" \
+	     "  if \$a == 4" \
+	     "    loop_break" \
+	     "  end" \
+	     "  set \$b = 0" \
+	     "  while \$b < 5" \
+	     "    if \$b == 2" \
+	     "      loop_break" \
+	     "    end" \
+	     "    set \$total = \$total + 1" \
+	     "    set \$b = \$b + 1" \
+	     "  end" \
+	     "  set \$a = \$a + 1" \
+	     "end"] \
+	"" \
+	"run while loop"
+
+    gdb_test "print \$a" " = 4" "validate \$a"
+    gdb_test "print \$b" " = 2" "validate \$b"
+    gdb_test "print \$total" " = 8" "validate \$total"
 }
 
 # Test the loop_continue command.
 
 proc_with_prefix loop_continue_test {} {
     gdb_test_no_output "set \$a = 0" "initialize \$a"
-    gdb_test_no_output "set \$b = 0" "initialize \$b"
+    gdb_test_no_output "set \$total = 0" "initialize \$total"
 
     gdb_test \
-    [multi_line_input \
-	 "while \$a < 5" \
-	 "  set \$a = \$a + 1" \
-	 "  if \$a % 2 == 0" \
-	 "    loop_continue" \
-	 "  end" \
-	 "  set \$b = \$b + 1" \
-	 "end"] \
-    "" \
-    "run while loop"
+	[multi_line_input \
+	     "while \$a < 5" \
+	     "  set \$a = \$a + 1" \
+	     "  set \$b = 0" \
+	     "  if \$a == 4" \
+	     "    loop_continue" \
+	     "  end" \
+	     "  while \$b < 5" \
+	     "    set \$b = \$b + 1" \
+	     "    if \$b == 2" \
+	     "      loop_continue" \
+	     "    end" \
+	     "    set \$total = \$total + 1" \
+	     "  end" \
+	     "end"] \
+	"" \
+	"run while loop"
 
     gdb_test "print \$a" " = 5" "validate \$a"
-    gdb_test "print \$b" " = 3" "validate \$b"
+    gdb_test "print \$b" " = 5" "validate \$b"
+    gdb_test "print \$total" " = 16" "validate \$total"
 }
 
 # Test an input line split with a continuation character (backslash)