Added conveniece API to ease debugger scripting (and testing)
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sun, 08 Mar 2015 07:37:59 +0000
changeset 63 29a7a3b4532b
parent 62 e1e763c6ac19
child 64 ed6b45e838b7
Added conveniece API to ease debugger scripting (and testing) Added generic method #do:andWaitFor:withTimeoutMs: and variants. This is to simplify scripting use of GDBDebugger object when acript runs sequentially. Heavily used in tests.
tests/GDBDebuggerTestCase.st
tests/GDBDebuggerTestsR.st
tests/GDBDebuggerTestsS.st
--- a/tests/GDBDebuggerTestCase.st	Sun Mar 08 06:01:49 2015 +0000
+++ b/tests/GDBDebuggerTestCase.st	Sun Mar 08 07:37:59 2015 +0000
@@ -19,96 +19,3 @@
     ^ self == GDBDebuggerTestCase.
 ! !
 
-!GDBDebuggerTestCase methodsFor:'utilities'!
-
-do: block thenWaitFor: announcementClass1
-    ^ self with: debugger do: block thenWaitFor: announcementClass1
-
-    "Created: / 27-02-2015 / 11:44:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-with: debugger do: block thenWaitFor: announcementClass1
-    | announcements |
-
-    announcements := self with: debugger do: block thenWaitForSequence: { announcementClass1 }.
-    announcements notNil ifTrue:[ 
-        self assert: announcements size == 1.
-        ^ announcements last.
-    ].
-    ^ nil
-
-    "Created: / 01-08-2014 / 12:58:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-with: debugger do: block thenWaitFor: announcementClass1 thenWaitFor: announcementClass2
-    | announcements |
-
-    announcements := self with: debugger do: block thenWaitForSequence: { announcementClass1 . announcementClass2 }.
-    announcements notNil ifTrue:[ 
-        self assert: announcements size == 2.
-        ^ announcements last.
-    ].
-    ^ nil
-
-    "Created: / 01-08-2014 / 12:58:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-with: debugger do: block thenWaitFor: announcementClass1 thenWaitFor: announcementClass2  thenWaitFor: announcementClass3
-    | announcements |
-
-    announcements := self with: debugger do: block thenWaitForSequence: { announcementClass1 . announcementClass2 . announcementClass3 }.
-    announcements notNil ifTrue:[ 
-        self assert: announcements size == 3.
-        ^ announcements last.
-    ].
-    ^ nil
-
-    "Created: / 01-08-2014 / 12:59:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-with: debugger do: block thenWaitForSequence: announcementClasses
-    "Blocks the caller until  given announcement (or its subclass)
-     is announced until timeout. Returns the annoucement or nil if call
-     timeouted."
-
-    | handlers blocker announcements timeout |
-
-    blocker := Semaphore new.
-
-    handlers        := Array new: announcementClasses size.
-    announcements   := Array new: announcementClasses size.
-
-    announcementClasses withIndexDo:[ :announcementClass :announcementClassIndex |
-        handlers at: announcementClassIndex put: [ :arg | 
-            (announcementClassIndex == 1 or:[ (announcements at: announcementClassIndex - 1) notNil ]) ifTrue:[ 
-                "Previous announcement arrived, so record announcement and unregister"
-                announcements at: announcementClassIndex put: arg.
-                debugger announcer unsubscribe: (handlers at: announcementClassIndex).
-                handlers at: announcementClassIndex put: nil.
-                announcementClassIndex == handlers size ifTrue:[ 
-                    blocker signal
-                ].
-            ].
-        ].
-        debugger announcer when: announcementClass do: (handlers at: announcementClassIndex).
-    ].
-    block value.
-
-    timeout := DefaultWaitForTimeout.
-    (blocker waitWithTimeoutMs: timeout) isNil ifTrue:[
-        announcements := nil.
-    ].
-
-    handlers do:[:handler | handler notNil ifTrue:[debugger announcer unsubscribe: handler] ].
-    announcements isNil ifTrue:[
-        Logger trace: 'Wait for event(s) timed out'.
-        TimeoutError newException
-            parameter: timeout;
-            raise.
-    ].
-    ^ announcements
-
-    "Created: / 01-08-2014 / 12:57:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 27-02-2015 / 11:43:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
--- a/tests/GDBDebuggerTestsR.st	Sun Mar 08 06:01:49 2015 +0000
+++ b/tests/GDBDebuggerTestsR.st	Sun Mar 08 07:37:59 2015 +0000
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'jv:libgdbs/tests' }"
 
 "{ NameSpace: Smalltalk }"
@@ -46,9 +48,7 @@
     debugger executable: GDBDebuggeesResource current binaryFactorial.
     debugger send: 'b factorial'.
 
-    self 
-        do:[ debugger send: 'r' ] 
-        thenWaitFor: GDBStoppedEvent.
+    debugger send: 'r' andWaitFor: GDBStoppedEvent.
 
     self assert: debugger inferiors size == 1.
     inferior1 := debugger inferiors anElement.
@@ -66,11 +66,11 @@
     self assert: frame2 variables third name = 'i'.
     self assert: frame2 variables fourth name = 'f'.
 
-    self 
-        do:[ debugger send: 'd'; send: 'c' ]
-        thenWaitFor: GDBThreadGroupExitedEvent.
+    debugger send: 'd'.
+    debugger send: 'c' andWaitFor: GDBThreadGroupExitedEvent.
 
     "Created: / 28-02-2015 / 00:55:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2015 / 06:10:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_basic_01
--- a/tests/GDBDebuggerTestsS.st	Sun Mar 08 06:01:49 2015 +0000
+++ b/tests/GDBDebuggerTestsS.st	Sun Mar 08 07:37:59 2015 +0000
@@ -74,8 +74,8 @@
     debugger announcer when: GDBThreadEvent do:[:ev |  
         tevent := ev.
     ].
-    debugger send: (GDBMI_file_exec_and_symbols new arguments: {'/home/jv/Private/Projects/SmalltalkX/sources/branches/jv1/build/jv/libgdbs/tests/c/factorial'}).
-    debugger send: (GDBCLICommand new value: 'b factorial').
+    debugger executable: '/home/jv/Private/Projects/SmalltalkX/sources/branches/jv1/build/jv/libgdbs/tests/c/factorial'.
+    debugger send: 'b factorial'.
 
     self assert: debugger inferiors size == 1.
     self assert: debugger inferiors anElement id = 'i1'.
@@ -83,9 +83,7 @@
     "/ emited before we register the handler above!!
     "/ self assert: debugger inferiors anElement == event threadGroup.
 
-    self 
-        do:[ debugger send: (GDBCLICommand new value: 'r') ]
-        thenWaitFor: GDBStoppedEvent.
+    debugger send: 'r' andWaitFor: GDBStoppedEvent.
 
     self assert: tgevent notNil.
     self assert: tevent notNil.
@@ -102,9 +100,7 @@
     tgevent := tevent := nil.
 
     debugger send: (GDBCLICommand new value: 'del 1').
-    tgevent := self 
-        do:[ debugger send: (GDBCLICommand new value: 'c') ]
-        thenWaitFor: GDBThreadGroupExitedEvent.
+    tgevent := debugger send:'c' andWaitFor: GDBThreadGroupExitedEvent.
 
     self assert: tgevent notNil.
     self assert: debugger inferiors size == 1.
@@ -115,7 +111,7 @@
     self assert: debugger inferiors anElement threads isEmptyOrNil.
 
     "Created: / 07-09-2014 / 13:37:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 27-02-2015 / 12:42:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2015 / 07:33:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBDebuggerTestsS class methodsFor:'documentation'!