Revise MI protocol events parsing.
authorMikhail Kurinnoi <m.kurinnoi@samsung.net>
Wed, 9 Oct 2019 14:41:44 +0000 (17:41 +0300)
committerAlexander Soldatov/Staff Engineer/AI Compiler Lab /SRR/Samsung Electronics <soldatov.a@samsung.com>
Thu, 10 Oct 2019 14:58:13 +0000 (17:58 +0300)
18 files changed:
test-suite/MIExampleTest/Program.cs
test-suite/MITestBreakpoint/Program.cs
test-suite/MITestEnv/Program.cs
test-suite/MITestException/Program.cs
test-suite/MITestExceptionBreakpoint/Program.cs
test-suite/MITestExecAbort/Program.cs
test-suite/MITestExecFinish/Program.cs
test-suite/MITestExecInt/Program.cs
test-suite/MITestExpression/Program.cs
test-suite/MITestGDB/Program.cs
test-suite/MITestHandshake/Program.cs
test-suite/MITestLambda/Program.cs
test-suite/MITestSetValue/Program.cs
test-suite/MITestStepping/Program.cs
test-suite/MITestTarget/Program.cs
test-suite/MITestVarObject/Program.cs
test-suite/NetcoreDbgTest/MI/MIDebugger.cs
test-suite/NetcoreDbgTest/MI/MIParser.cs

index a1269c756faff021b660c2543ae8cce8edf09786..87d680194c3daf789e81c9a1143ce48facb05d22 100644 (file)
@@ -26,7 +26,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -44,50 +44,45 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            // TODO: Implement API for comfortable searching
-            // of out-of-band records
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
-                // Currently let's believe that all *stopped events have
-                // a reason of stopping
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasBreakpointHit(Breakpoint breakpoint)
         {
-            var records = MIDebugger.Receive();
             var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
@@ -96,39 +91,41 @@ namespace NetcoreDbgTest.Script
 
                 if (fileName.CString == bp.FileName &&
                     numLine.CString == bp.NumLine.ToString()) {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index 42224ba366a61c7f0833ceea31bbce20658a2f77..e6f1515546d40f8f0c1fce023606652224f9c385 100644 (file)
@@ -11,7 +11,7 @@ namespace NetcoreDbgTest.Script
 {
     class Context
     {
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -29,45 +29,45 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
+
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasBreakpointHit(Breakpoint breakpoint, string id)
         {
-            var records = MIDebugger.Receive();
             var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
@@ -76,27 +76,28 @@ namespace NetcoreDbgTest.Script
 
                 if (numLine == bp.NumLine.ToString() &&
                     bkptno == id) {
-                    return;
-                }
-            }
+                    return true;
+                 }
+
+                return false;
+            };
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasFuncBreakpointHit(string func_name, string id)
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
@@ -105,39 +106,41 @@ namespace NetcoreDbgTest.Script
 
                 if (funcName.EndsWith(func_name) &&
                     bkptno == id) {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index d7c75a7dffe6f82934a2a9f07c26eccb76fbe2fb..f9f7ef2962ec61ff2a6984eab574be764406087d 100644 (file)
@@ -14,32 +14,32 @@ namespace NetcoreDbgTest.Script
     {
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -57,30 +57,29 @@ namespace NetcoreDbgTest.Script
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index c9be6a863a33b8b49b8d5656a093380e50e51657..6036302e5dfafdd4de86c0726367fc224e141a27 100644 (file)
@@ -13,27 +13,29 @@ namespace NetcoreDbgTest.Script
     {
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
+
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static bool IsValidFrame(MIResult frame, string bpName, int level)
@@ -53,17 +55,15 @@ namespace NetcoreDbgTest.Script
 
         public static bool WasStep(LineBreakpoint lbp)
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
                 if (reason.CString != "end-stepping-range") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)output["frame"];
@@ -71,37 +71,38 @@ namespace NetcoreDbgTest.Script
                 if (lbp.NumLine == line) {
                     return true;
                 }
-            }
 
-            return false;
+                return false;
+            };
+
+            return MIDebugger.IsEventReceived(filter);
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
@@ -109,7 +110,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Exit, Context.MIDebugger.Request("-gdb-exit").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -187,7 +188,7 @@ namespace MITestException
             Label.Checkpoint("test_steps", "try_catch", () => {
                 Assert.True(Context.DoStepTo("STEP1"));
                 Assert.True(Context.DoStepTo("TRY1"));
-                Assert.True(Context.DoStepTo("TRY1"));
+                Assert.True(Context.DoStepTo("TRY2"));
                 Assert.True(Context.DoStepTo("TRY3"));
                 Assert.True(Context.DoStepTo("CATCH1"));
                 Assert.True(Context.DoStepTo("CATCH2"));
index c740aedcc5e19edb7b4d596102fd7fb3585afa4c..319304022658d61340ba29e30e6bbada9fd1d77d 100644 (file)
@@ -26,27 +26,29 @@ namespace NetcoreDbgTest.Script
 \r
         public static void WasEntryPointHit()\r
         {\r
-            var records = MIDebugger.Receive();\r
-\r
-            foreach (MIOutOfBandRecord record in records) {\r
+            Func<MIOutOfBandRecord, bool> filter = (record) => {\r
                 if (!IsStoppedEvent(record)) {\r
-                    continue;\r
+                    return false;\r
                 }\r
 \r
                 var output = ((MIAsyncRecord)record).Output;\r
                 var reason = (MIConst)output["reason"];\r
+\r
                 if (reason.CString != "entry-point-hit") {\r
-                    continue;\r
+                    return false;\r
                 }\r
 \r
                 var frame = (MITuple)(output["frame"]);\r
                 var func = (MIConst)(frame["func"]);\r
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {\r
-                    return;\r
+                    return true;\r
                 }\r
-            }\r
 \r
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+                return false;\r
+            };\r
+\r
+            if (!MIDebugger.IsEventReceived(filter))\r
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
         }\r
 \r
         public static void EnableBreakpoint(string bpName)\r
@@ -64,19 +66,18 @@ namespace NetcoreDbgTest.Script
 \r
         public static void WasBreakpointHit(Breakpoint breakpoint)\r
         {\r
-            var records = MIDebugger.Receive();\r
             var bp = (LineBreakpoint)breakpoint;\r
 \r
-            foreach (MIOutOfBandRecord record in records) {\r
+            Func<MIOutOfBandRecord, bool> filter = (record) => {\r
                 if (!IsStoppedEvent(record)) {\r
-                    continue;\r
+                    return false;\r
                 }\r
 \r
                 var output = ((MIAsyncRecord)record).Output;\r
                 var reason = (MIConst)output["reason"];\r
 \r
                 if (reason.CString != "breakpoint-hit") {\r
-                    continue;\r
+                    return false;\r
                 }\r
 \r
                 var frame = (MITuple)(output["frame"]);\r
@@ -85,69 +86,73 @@ namespace NetcoreDbgTest.Script
 \r
                 if (fileName.CString == bp.FileName &&\r
                     numLine.CString == bp.NumLine.ToString()) {\r
-                    return;\r
+                    return true;\r
                 }\r
-            }\r
 \r
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+                return false;\r
+            };\r
+\r
+            if (!MIDebugger.IsEventReceived(filter))\r
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
         }\r
 \r
         public static void WasExceptionBreakpointHit(Breakpoint breakpoint)\r
         {\r
-            var records = MIDebugger.Receive();\r
             var bp = (LineBreakpoint)breakpoint;\r
-            // should check only the last one event\r
-            MIOutOfBandRecord record = records[records.Length - 1];\r
 \r
-            if (!IsStoppedEvent(record)) {\r
-                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
-            }\r
+            Func<MIOutOfBandRecord, bool> filter = (record) => {\r
+                if (!IsStoppedEvent(record)) {\r
+                    return false;\r
+                }\r
 \r
-            var output = ((MIAsyncRecord)record).Output;\r
-            var reason = (MIConst)output["reason"];\r
+                var output = ((MIAsyncRecord)record).Output;\r
+                var reason = (MIConst)output["reason"];\r
 \r
-            if (reason.CString != "exception-received") {\r
-                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
-            }\r
+                if (reason.CString != "exception-received") {\r
+                    return false;\r
+                }\r
 \r
-            var frame = (MITuple)(output["frame"]);\r
-            var fileName = (MIConst)(frame["file"]);\r
-            var numLine = (MIConst)(frame["line"]);\r
+                var frame = (MITuple)(output["frame"]);\r
+                var fileName = (MIConst)(frame["file"]);\r
+                var numLine = (MIConst)(frame["line"]);\r
 \r
-            if (fileName.CString == bp.FileName &&\r
-                numLine.CString == bp.NumLine.ToString()) {\r
-                return;\r
-            }\r
+                if (fileName.CString == bp.FileName &&\r
+                    numLine.CString == bp.NumLine.ToString()) {\r
+                    return true;\r
+                }\r
 \r
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+                return false;\r
+            };\r
+\r
+            if (!MIDebugger.IsEventReceived(filter))\r
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
         }\r
 \r
         public static void WasExit()\r
         {\r
-            var records = MIDebugger.Receive();\r
-\r
-            foreach (MIOutOfBandRecord record in records) {\r
+            Func<MIOutOfBandRecord, bool> filter = (record) => {\r
                 if (!IsStoppedEvent(record)) {\r
-                    continue;\r
+                    return false;\r
                 }\r
 \r
                 var output = ((MIAsyncRecord)record).Output;\r
                 var reason = (MIConst)output["reason"];\r
 \r
                 if (reason.CString != "exited") {\r
-                    continue;\r
+                    return false;\r
                 }\r
 \r
                 var exitCode = (MIConst)output["exit-code"];\r
 \r
                 if (exitCode.CString == "0") {\r
-                    return;\r
-                } else {\r
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+                    return true;\r
                 }\r
-            }\r
 \r
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
+                return false;\r
+            };\r
+\r
+            if (!MIDebugger.IsEventReceived(filter))\r
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();\r
         }\r
 \r
         public static void DebuggerExit()\r
@@ -155,7 +160,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Exit, Context.MIDebugger.Request("-gdb-exit").Class);\r
         }\r
 \r
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)\r
+        static bool IsStoppedEvent(MIOutOfBandRecord record)\r
         {\r
             if (record.Type != MIOutOfBandRecordType.Async) {\r
                 return false;\r
index c11597c92f12dcc6cf6f99144a3aee25c444db4e..c32c33628a837182927487fe6e18c171857373e4 100644 (file)
@@ -25,7 +25,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -43,29 +43,29 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index 936e4a822dd403923df8055c34822014d66b63f9..e5db6493d2d38331018c765bb80f022f5a091b0e 100644 (file)
@@ -24,7 +24,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -42,46 +42,45 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasBreakpointHit(Breakpoint breakpoint)
         {
-            var records = MIDebugger.Receive();
             var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
@@ -90,39 +89,41 @@ namespace NetcoreDbgTest.Script
 
                 if (fileName.CString == bp.FileName &&
                     numLine.CString == bp.NumLine.ToString()) {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
@@ -145,28 +146,30 @@ namespace NetcoreDbgTest.Script
 
         public static void WasStep(Breakpoint breakpoint)
         {
-            var records = MIDebugger.Receive();
             var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
                 if (reason.CString != "end-stepping-range") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)output["frame"];
                 var line = ((MIConst)frame["line"]).Int;
                 if (bp.NumLine == line) {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
         
         public static void Continue()
index e9b78734416cd8a6146130ff73fcb0907415051b..7478d062debbeb45f362b1f733cf25891c43aace 100644 (file)
@@ -25,7 +25,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -43,29 +43,29 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index 36604b9d1d37e5cbf6ae9e50e920c7de5b5f820c..545254caa00f358f1f6ed495593ca8224ef1a791 100644 (file)
@@ -39,82 +39,88 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
+
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static string GetBreakpointHitId(Breakpoint bp)
         {
-            var records = MIDebugger.Receive();
+            string Result = "-1";
             var bpLine = ((LineBreakpoint)bp).NumLine.ToString();
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var line = (MIConst)(frame["line"]);
 
                 if (bpLine == line.CString) {
-                    return ((MIConst)output["bkptno"]).CString;
+                    Result = ((MIConst)output["bkptno"]).CString;
+                    return true;
                 }
-            }
 
-            return "-1";
+                return false;
+            };
+
+            MIDebugger.IsEventReceived(filter);
+
+            return Result;
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
@@ -122,7 +128,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Exit, Context.MIDebugger.Request("-gdb-exit").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
index 4a2a7ad306386fdf8c8a93fc0a4cf79c718ed506..48a853a2aa332583079124dbca58ff85c07db6c9 100644 (file)
@@ -25,7 +25,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -43,57 +43,56 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void Continue()
index 2a0e0b2945e976f51d9a0cbbe4296b2bb7d14a7b..1d7da99563ebdc70b8a6257105485bad91c1fa96 100644 (file)
@@ -24,7 +24,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -42,57 +42,56 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index 3d2bf10d8a00712b264cde292fd74518a1344c27..90fe3d673c90a2569eae5c541bc91c9906249a0b 100644 (file)
@@ -13,44 +13,45 @@ namespace NetcoreDbgTest.Script
     {
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
+
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasBreakpointHit(Breakpoint breakpoint)
         {
-            var records = MIDebugger.Receive();
             var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
@@ -59,39 +60,41 @@ namespace NetcoreDbgTest.Script
 
                 if (fileName.CString == bp.FileName &&
                     numLine.CString == bp.NumLine.ToString()) {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index 2f3d787608c027c2d6a269eaaabcfd9a7daa3be6..c95876ad23c9b19ec07d69c5e0106711b9d1a114 100644 (file)
@@ -58,82 +58,88 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
+
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
-        public static void WasBreakpointHit(Breakpoint bp)
+        public static void WasBreakpointHit(Breakpoint breakpoint)
         {
-            var records = MIDebugger.Receive();
-            var bpLine = ((LineBreakpoint)bp).NumLine.ToString();
+            var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
+
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
-                var line = (MIConst)(frame["line"]);
+                var fileName = (MIConst)(frame["file"]);
+                var numLine = (MIConst)(frame["line"]);
 
-                if (bpLine == line.CString) {
-                    return;
+                if (fileName.CString == bp.FileName &&
+                    numLine.CString == bp.NumLine.ToString()) {
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
@@ -141,7 +147,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Exit, Context.MIDebugger.Request("-gdb-exit").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
index 522bacd4155e1ebf80b6e715cb501b7924de8002..ba291d8785f6562df6426afeeb6f0c5ca85cad37 100644 (file)
@@ -28,89 +28,90 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            // TODO: Implement API for comfortable searching
-            // of out-of-band records
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
-                // Currently let's believe that all *stopped events have
-                // a reason of stopping
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static MIConst WasStep(string stepName)
         {
-            var records = MIDebugger.Receive();
+            MIConst Result = new MIConst("-1");
             var bp = (LineBreakpoint)DebuggeeInfo.Breakpoints[stepName];
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "end-stepping-range") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var numLine = (MIConst)(frame["line"]);
 
                 if (numLine.CString == bp.NumLine.ToString()) {
-                    return (MIConst)output["thread-id"];
+                    Result = (MIConst)output["thread-id"];
+                    return true;
                 }
-            }
+
+                return false;
+            };
+
+            if (MIDebugger.IsEventReceived(filter))
+                return Result;
 
             throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
@@ -118,7 +119,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Exit, Context.MIDebugger.Request("-gdb-exit").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
index 8ce2292cbb7467605923b68948e66827f378dfab..3997c683c006f82aa180e97db62bfcdb71c25745 100644 (file)
@@ -13,7 +13,7 @@ namespace NetcoreDbgTest.Script
 {
     class Context
     {
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -31,19 +31,18 @@ namespace NetcoreDbgTest.Script
 
         public static void WasBreakpointHit(Breakpoint breakpoint)
         {
-            var records = MIDebugger.Receive();
             var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
@@ -52,11 +51,14 @@ namespace NetcoreDbgTest.Script
 
                 if (fileName.CString == bp.FileName &&
                     numLine.CString == bp.NumLine.ToString()) {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void EnableBreakpoint(string bpName)
index 9da1ed7d4130becaa400d586be505b5e0840734a..48d8c9a45e57e9f3e4256d93b53689d33c299bff 100644 (file)
@@ -24,7 +24,7 @@ namespace NetcoreDbgTest.Script
             Assert.Equal(MIResultClass.Running, MIDebugger.Request("-exec-run").Class);
         }
 
-        public static bool IsStoppedEvent(MIOutOfBandRecord record)
+        static bool IsStoppedEvent(MIOutOfBandRecord record)
         {
             if (record.Type != MIOutOfBandRecordType.Async) {
                 return false;
@@ -42,45 +42,45 @@ namespace NetcoreDbgTest.Script
 
         public static void WasEntryPointHit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
-
                 var reason = (MIConst)output["reason"];
+
                 if (reason.CString != "entry-point-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
                 var func = (MIConst)(frame["func"]);
                 if (func.CString == DebuggeeInfo.TestName + ".Program.Main()") {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasBreakpointHit(Breakpoint breakpoint)
         {
-            var records = MIDebugger.Receive();
             var bp = (LineBreakpoint)breakpoint;
 
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "breakpoint-hit") {
-                    continue;
+                    return false;
                 }
 
                 var frame = (MITuple)(output["frame"]);
@@ -89,39 +89,41 @@ namespace NetcoreDbgTest.Script
 
                 if (fileName.CString == bp.FileName &&
                     numLine.CString == bp.NumLine.ToString()) {
-                    return;
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void WasExit()
         {
-            var records = MIDebugger.Receive();
-
-            foreach (MIOutOfBandRecord record in records) {
+            Func<MIOutOfBandRecord, bool> filter = (record) => {
                 if (!IsStoppedEvent(record)) {
-                    continue;
+                    return false;
                 }
 
                 var output = ((MIAsyncRecord)record).Output;
                 var reason = (MIConst)output["reason"];
 
                 if (reason.CString != "exited") {
-                    continue;
+                    return false;
                 }
 
                 var exitCode = (MIConst)output["exit-code"];
 
                 if (exitCode.CString == "0") {
-                    return;
-                } else {
-                    throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                    return true;
                 }
-            }
 
-            throw new NetcoreDbgTestCore.ResultNotSuccessException();
+                return false;
+            };
+
+            if (!MIDebugger.IsEventReceived(filter))
+                throw new NetcoreDbgTestCore.ResultNotSuccessException();
         }
 
         public static void DebuggerExit()
index d91b48244ff693ac4f3dcd4c5d7443b027fe88e6..8fb3741ac527994983d59580439b9cd5f22f051d 100644 (file)
@@ -1,3 +1,4 @@
+using System;
 using System.Collections.Generic;
 using NetcoreDbgTestCore;
 using NetcoreDbgTestCore.MI;
@@ -9,7 +10,6 @@ namespace NetcoreDbgTest.MI
         public MIResultRecord Request(string command, int timeout = -1)
         {
             MIResultRecord resultRecord = null;
-            EventsAddedOnLastRequest = false;
 
             Logger.LogLine("> " + command);
 
@@ -28,27 +28,28 @@ namespace NetcoreDbgTest.MI
                     Logger.LogLine("< " + line);
                 }
 
+                // we could get async record, in this case we could have two "(gdb)" prompts one by one
+                // NOTE in this case we have only one line response, that contain prompt only
+                if (MIParser.IsEnd(response[0]))
+                    continue;
+
                 MIOutput output = MIParser.ParseOutput(response);
 
                 if (output.ResultRecord != null) {
                     resultRecord = output.ResultRecord;
                     break;
                 } else {
-                    OutOfBandRecords.AddRange(output.OutOfBandRecords);
-                    EventsAddedOnLastRequest = true;
+                    foreach (var record in output.OutOfBandRecords) {
+                        EventQueue.Enqueue(record);
+                    }
                 }
             }
 
             return resultRecord;
         }
 
-        public MIOutOfBandRecord[] Receive(int timeout = -1)
+        void ReceiveEvents(int timeout = -1)
         {
-            if (EventsAddedOnLastRequest) {
-                EventsAddedOnLastRequest = false;
-                return OutOfBandRecords.ToArray();
-            }
-
             string[] response = Debuggee.DebuggerClient.Receive(timeout);
 
             if (response == null) {
@@ -66,13 +67,30 @@ namespace NetcoreDbgTest.MI
                 throw new MIParserException();
             }
 
-            OutOfBandRecords.AddRange(output.OutOfBandRecords);
+            foreach (var record in output.OutOfBandRecords) {
+                EventQueue.Enqueue(record);
+            }
+        }
+
+        public bool IsEventReceived(Func<MIOutOfBandRecord, bool> filter)
+        {
+            // check previously received events first
+            while (EventQueue.Count > 0) {
+                if (filter(EventQueue.Dequeue()))
+                    return true;
+            }
+
+            // receive new events and check them
+            ReceiveEvents();
+            while (EventQueue.Count > 0) {
+                if (filter(EventQueue.Dequeue()))
+                    return true;
+            }
 
-            return OutOfBandRecords.ToArray();
+            return false;
         }
 
-        List<MIOutOfBandRecord> OutOfBandRecords = new List<MIOutOfBandRecord>();
+        Queue<MIOutOfBandRecord> EventQueue = new Queue<MIOutOfBandRecord>();
         MIParser MIParser = new MIParser();
-        bool EventsAddedOnLastRequest = false;
     }
 }
index b51c8b4a0f2f058a979566a06aa970681e7c8042..6b050ab32b196c85d079c64a88c1f59e198f25e7 100644 (file)
@@ -351,7 +351,7 @@ namespace NetcoreDbgTestCore.MI
             return response[i] == '^';
         }
 
-        private bool IsEnd(string response)
+        public bool IsEnd(string response)
         {
             return response == "(gdb)";
         }