From be6992c7d3d838e278e6c74808f9d0ba01cd17e6 Mon Sep 17 00:00:00 2001 From: Hafiz Abid Qadeer Date: Wed, 26 Nov 2014 16:37:51 +0000 Subject: [PATCH] Improve lldb-mi tests. summary of changes: Cleanup: Use "line_number" API instead of hardcoded source lines Combine child.sendline with previous child.send command. test_lldbmi_tokens: Add test for MI tokens. test_lldbmi_badpathexe: Remove check for prompt so test for bad path can be enabled. Patch from dawn@burble.org. llvm-svn: 222838 --- lldb/test/tools/lldb-mi/TestMiBreakpoint.py | 70 ++++++++++--------------- lldb/test/tools/lldb-mi/TestMiEvaluate.py | 78 ++++++++++------------------ lldb/test/tools/lldb-mi/TestMiInterrupt.py | 44 ++++++---------- lldb/test/tools/lldb-mi/TestMiLaunch.py | 49 ++++++----------- lldb/test/tools/lldb-mi/TestMiProgramArgs.py | 33 +++++------- lldb/test/tools/lldb-mi/loop.c | 2 +- 6 files changed, 98 insertions(+), 178 deletions(-) diff --git a/lldb/test/tools/lldb-mi/TestMiBreakpoint.py b/lldb/test/tools/lldb-mi/TestMiBreakpoint.py index a45ec5a..a6a8204 100644 --- a/lldb/test/tools/lldb-mi/TestMiBreakpoint.py +++ b/lldb/test/tools/lldb-mi/TestMiBreakpoint.py @@ -41,29 +41,23 @@ class MiBreakpointTestCase(TestBase): child.logfile_send = f_send child.logfile_read = f_read - child.send("-file-exec-and-symbols " + self.myexe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + self.myexe) child.expect("\^done") - child.send("-break-insert -f a_MyFunction") - child.sendline('') + child.sendline("-break-insert -f a_MyFunction") child.expect("\^done,bkpt={number=\"1\"") - child.send("-exec-run") - child.sendline('') # FIXME: lldb-mi hangs here, so the extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") # FIXME: lldb-mi hangs here, so extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. @@ -102,29 +96,26 @@ class MiBreakpointTestCase(TestBase): child.logfile_send = f_send child.logfile_read = f_read - child.send("-file-exec-and-symbols " + self.myexe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + self.myexe) child.expect("\^done") - child.send("-break-insert -f main.c:22") - child.sendline('') + # Find the line number to break inside main() and set + # pending BP. + self.line = line_number('main.c', '//BP_source') + child.sendline("-break-insert -f main.c:%d" % self.line) child.expect("\^done,bkpt={number=\"1\"") - child.send("-exec-run") - child.sendline('') # FIXME: lldb-mi hangs here, so the extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") # FIXME: lldb-mi hangs here, so extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. @@ -163,50 +154,41 @@ class MiBreakpointTestCase(TestBase): child.logfile_send = f_send child.logfile_read = f_read - child.send("-file-exec-and-symbols " + self.myexe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + self.myexe) child.expect("\^done") - child.send("-break-insert -f main") - child.sendline('') + child.sendline("-break-insert -f main") child.expect("\^done,bkpt={number=\"1\"") - child.send("-exec-run") - child.sendline('') # FIXME: lldb-mi hangs here, so the extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") # FIXME: lldb-mi hangs here, so extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") #break on symbol - child.send("-break-insert a_MyFunction") - child.sendline('') + child.sendline("-break-insert a_MyFunction") child.expect("\^done,bkpt={number=\"2\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") #break on source - child.send("-break-insert main.c:29") - child.sendline('') + self.line = line_number('main.c', '//BP_source') + child.sendline("-break-insert main.c:%d" % self.line) child.expect("\^done,bkpt={number=\"3\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") #run to exit - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. diff --git a/lldb/test/tools/lldb-mi/TestMiEvaluate.py b/lldb/test/tools/lldb-mi/TestMiEvaluate.py index 87b2da08..6d5be43 100644 --- a/lldb/test/tools/lldb-mi/TestMiEvaluate.py +++ b/lldb/test/tools/lldb-mi/TestMiEvaluate.py @@ -41,103 +41,79 @@ class MiEvaluateTestCase(TestBase): child.logfile_send = f_send child.logfile_read = f_read - child.send("-file-exec-and-symbols " + self.myexe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + self.myexe) child.expect("\^done") #run to main - child.send("-break-insert -f main") - child.sendline('') + child.sendline("-break-insert -f main") child.expect("\^done,bkpt={number=\"1\"") - child.send("-exec-run") - child.sendline('') #FIXME: hangs here; extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") #FIXME: hangs here; extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") - #run to program return - child.send("-break-insert main.c:30") #BP_source - child.sendline('') + #run to program return (marked BP_source) + self.line = line_number('main.c', '//BP_source') + child.sendline("-break-insert main.c:%d" % self.line) child.expect("\^done,bkpt={number=\"2\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") #print non-existant variable - #child.send("-var-create var1 --thread 1 --frame 0 * undef") - #child.sendline('') #FIXME: shows undef as {...} + #child.sendline("-var-create var1 --thread 1 --frame 0 * undef") #FIXME: shows undef as {...} #child.expect("error") - #child.send("-data-evaluate-expression undef") - #child.sendline('') #FIXME: gets value="undef" + #child.sendline("-data-evaluate-expression undef") #FIXME: gets value="undef" #child.expect("error") #print global "g_MyVar" - child.send("-var-create var1 --thread 1 --frame 0 * g_MyVar") - child.sendline('') #FIXME: shows name=" + child.sendline("-var-create var1 --thread 1 --frame 0 * g_MyVar") #FIXME: shows name=" child.expect("value=\"3\",type=\"int\"") - #child.send("-var-evaluate-expression var1") - #child.sendline('') #FIXME: gets var1 does not exist - child.send("-var-show-attributes var1") - child.sendline('') + #child.sendline("-var-evaluate-expression var1") #FIXME: gets var1 does not exist + child.sendline("-var-show-attributes var1") child.expect("status=\"editable\"") - child.send("-var-delete var1") - child.sendline('') + child.sendline("-var-delete var1") child.expect("\^done") - child.send("-var-create var1 --thread 1 --frame 0 * g_MyVar") - child.sendline('') + child.sendline("-var-create var1 --thread 1 --frame 0 * g_MyVar") child.expect("value=\"3\",type=\"int\"") #print static "s_MyVar" and modify - child.send("-data-evaluate-expression s_MyVar") - child.sendline('') + child.sendline("-data-evaluate-expression s_MyVar") child.expect("value=\"30\"") - child.send("-var-create var3 --thread 1 --frame 0 * \"s_MyVar=3\"") - child.sendline('') + child.sendline("-var-create var3 --thread 1 --frame 0 * \"s_MyVar=3\"") child.expect("value=\"3\",type=\"int\"") - child.send("-data-evaluate-expression \"s_MyVar=30\"") - child.sendline('') + child.sendline("-data-evaluate-expression \"s_MyVar=30\"") child.expect("value=\"30\"") #print local "b" and modify - child.send("-data-evaluate-expression b") - child.sendline('') + child.sendline("-data-evaluate-expression b") child.expect("value=\"20\"") - child.send("-var-create var3 --thread 1 --frame 0 * \"b=3\"") - child.sendline('') + child.sendline("-var-create var3 --thread 1 --frame 0 * \"b=3\"") child.expect("value=\"3\",type=\"int\"") - child.send("-data-evaluate-expression \"b=20\"") - child.sendline('') + child.sendline("-data-evaluate-expression \"b=20\"") child.expect("value=\"20\"") #print "a + b" - child.send("-data-evaluate-expression \"a + b\"") - child.sendline('') + child.sendline("-data-evaluate-expression \"a + b\"") child.expect("value=\"30\"") - child.send("-var-create var3 --thread 1 --frame 0 * \"a + b\"") - child.sendline('') + child.sendline("-var-create var3 --thread 1 --frame 0 * \"a + b\"") child.expect("value=\"30\",type=\"int\"") #print "argv[0]" - child.send("-data-evaluate-expression \"argv[0]\"") - child.sendline('') + child.sendline("-data-evaluate-expression \"argv[0]\"") child.expect("value=\"0x") - child.send("-var-create var3 --thread 1 --frame 0 * \"argv[0]\"") - child.sendline('') + child.sendline("-var-create var3 --thread 1 --frame 0 * \"argv[0]\"") child.expect("numchild=\"1\",value=\"0x.*\",type=\"const char \*\"") #run to exit - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. diff --git a/lldb/test/tools/lldb-mi/TestMiInterrupt.py b/lldb/test/tools/lldb-mi/TestMiInterrupt.py index e86111a..1c016b1 100644 --- a/lldb/test/tools/lldb-mi/TestMiInterrupt.py +++ b/lldb/test/tools/lldb-mi/TestMiInterrupt.py @@ -42,55 +42,43 @@ class MiInterruptTestCase(TestBase): child.logfile_send = f_send child.logfile_read = f_read - child.send("-file-exec-and-symbols " + self.myexe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + self.myexe) child.expect("\^done") #run to main - child.send("-break-insert -f main") - child.sendline('') + child.sendline("-break-insert -f main") child.expect("\^done,bkpt={number=\"1\"") - child.send("-exec-run") - child.sendline('') #FIXME: hangs here; extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") #FIXME: hangs here; extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") #set doloop=1 and run (to loop forever) - child.send("-data-evaluate-expression \"doloop=1\"") - child.sendline('') + child.sendline("-data-evaluate-expression \"doloop=1\"") child.expect("value=\"1\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") - #issue interrupt, set a bp, and resume - child.send("-exec-interrupt") - child.sendline('') + #issue interrupt, set BP in loop (marked BP_loop), and resume + child.sendline("-exec-interrupt") child.expect("\*stopped,reason=\"signal-received\"") - child.send("-break-insert loop.c:11") - child.sendline('') + self.line = line_number('loop.c', '//BP_loop') + child.sendline("-break-insert loop.c:%d" % self.line) child.expect("\^done,bkpt={number=\"2\"") - #child.send("-exec-resume") - #child.sendline('') #FIXME: command not recognized - child.send("-exec-continue") - child.sendline('') + #child.sendline("-exec-resume") #FIXME: command not recognized + child.sendline("-exec-continue") child.expect("\*stopped,reason=\"breakpoint-hit\"") - #we should be sitting at loop.c:12 + #we should have hit BP #set loop=-1 so we'll exit the loop - child.send("-data-evaluate-expression \"loop=-1\"") - child.sendline('') + child.sendline("-data-evaluate-expression \"loop=-1\"") child.expect("value=\"-1\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. diff --git a/lldb/test/tools/lldb-mi/TestMiLaunch.py b/lldb/test/tools/lldb-mi/TestMiLaunch.py index 90470b0..dc0a4da 100644 --- a/lldb/test/tools/lldb-mi/TestMiLaunch.py +++ b/lldb/test/tools/lldb-mi/TestMiLaunch.py @@ -42,20 +42,16 @@ class MiLaunchTestCase(TestBase): child.logfile_read = f_read #use no path - child.send("-file-exec-and-symbols " + self.myexe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + self.myexe) child.expect("\^done") - child.send("-exec-run") - child.sendline('') # FIXME: lldb-mi hangs here, so the extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") # FIXME: lldb-mi hangs here, so extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. @@ -93,20 +89,16 @@ class MiLaunchTestCase(TestBase): #use full path exe = os.path.join(os.getcwd(), "a.out") - child.send("-file-exec-and-symbols " + exe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + exe) child.expect("\^done") - child.send("-exec-run") - child.sendline('') # FIXME: lldb-mi hangs here, so the extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") # FIXME: lldb-mi hangs here, so extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. @@ -144,20 +136,16 @@ class MiLaunchTestCase(TestBase): #use relative path exe = "../../" + self.mydir + "/" + self.myexe - child.send("-file-exec-and-symbols " + exe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + exe) child.expect("\^done") - child.send("-exec-run") - child.sendline('') # FIXME: lldb-mi hangs here, so the extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") # FIXME: lldb-mi hangs here, so extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"exited-normally\"") child.expect_exact(prompt) - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. @@ -174,7 +162,6 @@ class MiLaunchTestCase(TestBase): print "\n\nContents of child_read.txt:" print from_child - @unittest2.skip("lldb-mi badpath hang") @lldbmi_test def test_lldbmi_badpathexe(self): """Test that 'lldb-mi --interpreter' works for -file-exec-and-symbols badpath/exe.""" @@ -194,17 +181,13 @@ class MiLaunchTestCase(TestBase): child.logfile_send = f_send child.logfile_read = f_read - #use relative path + #use non-existant path exe = "badpath/" + self.myexe - #print ("-file-exec-and-symbols " + exe) - child.send("-file-exec-and-symbols " + exe) - child.sendline('') #FIXME: non-existant directory caused hang + child.sendline("-file-exec-and-symbols " + exe) child.expect("\^error") + #child.expect_exact(prompt) #FIXME: no prompt after error - child.expect_exact(prompt) - - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. diff --git a/lldb/test/tools/lldb-mi/TestMiProgramArgs.py b/lldb/test/tools/lldb-mi/TestMiProgramArgs.py index 4927429..b7d5f1a 100644 --- a/lldb/test/tools/lldb-mi/TestMiProgramArgs.py +++ b/lldb/test/tools/lldb-mi/TestMiProgramArgs.py @@ -42,42 +42,33 @@ class MiProgramArgsTestCase(TestBase): child.logfile_send = f_send child.logfile_read = f_read - child.send("-file-exec-and-symbols " + self.myexe) - child.sendline('') + child.sendline("-file-exec-and-symbols " + self.myexe) child.expect("\^done") - #child.send("-exec-arguments l") - #child.sendline('') #FIXME: not recognized and hung lldb-mi - child.send("settings set target.run-args l") - child.sendline('') #FIXME: args not passed + child.sendline("settings set target.run-args l") #FIXME: args not passed + #child.sendline("-exec-arguments l") #FIXME: not recognized and hung lldb-mi #run to main - child.send("-break-insert -f main") - child.sendline('') + child.sendline("-break-insert -f main") child.expect("\^done,bkpt={number=\"1\"") - child.send("-exec-run") - child.sendline('') #FIXME: hangs here; extra return below is needed - child.send("") - child.sendline('') + child.sendline("-exec-run") + child.sendline("") #FIXME: hangs here; extra return is needed child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") #check argc to see if arg passed - child.send("-data-evaluate-expression argc") - child.sendline('') + child.sendline("-data-evaluate-expression argc") child.expect("value=\"2\"") - #set BP on code which is only executed if "l" was passed correctly - child.send("-break-insert main.c:27") #BP_argtest - child.sendline('') + #set BP on code which is only executed if "l" was passed correctly (marked BP_argtest) + self.line = line_number('main.c', '//BP_argtest') + child.sendline("-break-insert main.c:%d" % self.line) child.expect("\^done,bkpt={number=\"2\"") - child.send("-exec-continue") - child.sendline('') + child.sendline("-exec-continue") child.expect("\^running") child.expect("\*stopped,reason=\"breakpoint-hit\"") - child.send("quit") - child.sendline('') + child.sendline("quit") # Now that the necessary logging is done, restore logfile to None to # stop further logging. diff --git a/lldb/test/tools/lldb-mi/loop.c b/lldb/test/tools/lldb-mi/loop.c index c868fdb..ef54c71 100644 --- a/lldb/test/tools/lldb-mi/loop.c +++ b/lldb/test/tools/lldb-mi/loop.c @@ -8,7 +8,7 @@ infloop () sleep(1); loop = 1; } - loop++; // Set break point at this line. + loop++; //BP_loop } return loop; } -- 2.7.4