--- /dev/null
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+using NetcoreDbgTest;
+using NetcoreDbgTest.VSCode;
+using NetcoreDbgTest.Script;
+
+using Xunit;
+using Newtonsoft.Json;
+
+namespace NetcoreDbgTest.Script
+{
+ // Context includes methods and constants which
+ // will be move to debugger API
+ class Context
+ {
+ public static void PrepareStart()
+ {
+ InitializeRequest initializeRequest = new InitializeRequest();
+ initializeRequest.arguments.clientID = "vscode";
+ initializeRequest.arguments.clientName = "Visual Studio Code";
+ initializeRequest.arguments.adapterID = "coreclr";
+ initializeRequest.arguments.pathFormat = "path";
+ initializeRequest.arguments.linesStartAt1 = true;
+ initializeRequest.arguments.columnsStartAt1 = true;
+ initializeRequest.arguments.supportsVariableType = true;
+ initializeRequest.arguments.supportsVariablePaging = true;
+ initializeRequest.arguments.supportsRunInTerminalRequest = true;
+ initializeRequest.arguments.locale = "en-us";
+ Assert.True(VSCodeDebugger.Request(initializeRequest).Success);
+
+ LaunchRequest launchRequest = new LaunchRequest();
+ launchRequest.arguments.name = ".NET Core Launch (console) with pipeline";
+ launchRequest.arguments.type = "coreclr";
+ launchRequest.arguments.preLaunchTask = "build";
+ launchRequest.arguments.program = DebuggeeInfo.TargetAssemblyPath;
+ launchRequest.arguments.cwd = "";
+ launchRequest.arguments.console = "internalConsole";
+ launchRequest.arguments.stopAtEntry = true;
+ launchRequest.arguments.internalConsoleOptions = "openOnSessionStart";
+ launchRequest.arguments.__sessionId = Guid.NewGuid().ToString();
+ Assert.True(VSCodeDebugger.Request(launchRequest).Success);
+ }
+
+ public static void PrepareEnd()
+ {
+ ConfigurationDoneRequest configurationDoneRequest = new ConfigurationDoneRequest();
+ Assert.True(VSCodeDebugger.Request(configurationDoneRequest).Success);
+ }
+
+ public static void WasEntryPointHit()
+ {
+ Func<string, bool> filter = (resJSON) => {
+ if (VSCodeDebugger.isResponseContainProperty(resJSON, "event", "stopped")
+ && VSCodeDebugger.isResponseContainProperty(resJSON, "reason", "entry")) {
+ threadId = Convert.ToInt32(VSCodeDebugger.GetResponsePropertyValue(resJSON, "threadId"));
+ return true;
+ }
+ return false;
+ };
+
+ if (!VSCodeDebugger.IsEventReceived(filter))
+ throw new NetcoreDbgTestCore.ResultNotSuccessException();
+ }
+
+ public static void WasExit()
+ {
+ bool wasExited = false;
+ int ?exitCode = null;
+ bool wasTerminated = false;
+
+ Func<string, bool> filter = (resJSON) => {
+ if (VSCodeDebugger.isResponseContainProperty(resJSON, "event", "exited")) {
+ wasExited = true;
+ ExitedEvent exitedEvent = JsonConvert.DeserializeObject<ExitedEvent>(resJSON);
+ exitCode = exitedEvent.body.exitCode;
+ }
+ if (VSCodeDebugger.isResponseContainProperty(resJSON, "event", "terminated")) {
+ wasTerminated = true;
+ }
+ if (wasExited && exitCode == 0 && wasTerminated)
+ return true;
+
+ return false;
+ };
+
+ if (!VSCodeDebugger.IsEventReceived(filter))
+ throw new NetcoreDbgTestCore.ResultNotSuccessException();
+ }
+
+ public static void DebuggerExit()
+ {
+ DisconnectRequest disconnectRequest = new DisconnectRequest();
+ disconnectRequest.arguments = new DisconnectArguments();
+ disconnectRequest.arguments.restart = false;
+ Assert.True(VSCodeDebugger.Request(disconnectRequest).Success);
+ }
+
+ public static void AddBreakpoint(string bpName, string Condition = null)
+ {
+ Breakpoint bp = DebuggeeInfo.Breakpoints[bpName];
+ Assert.Equal(BreakpointType.Line, bp.Type);
+ var lbp = (LineBreakpoint)bp;
+
+ BreakpointSourceName = lbp.FileName;
+ BreakpointList.Add(new SourceBreakpoint(lbp.NumLine, Condition));
+ BreakpointLines.Add(lbp.NumLine);
+ }
+
+ public static void SetBreakpoints()
+ {
+ SetBreakpointsRequest setBreakpointsRequest = new SetBreakpointsRequest();
+ setBreakpointsRequest.arguments.source.name = BreakpointSourceName;
+ // NOTE this code works only with one source file
+ setBreakpointsRequest.arguments.source.path = DebuggeeInfo.SourceFilesPath;
+ setBreakpointsRequest.arguments.lines.AddRange(BreakpointLines);
+ setBreakpointsRequest.arguments.breakpoints.AddRange(BreakpointList);
+ setBreakpointsRequest.arguments.sourceModified = false;
+ Assert.True(VSCodeDebugger.Request(setBreakpointsRequest).Success);
+ }
+
+ public static void WasBreakpointHit(Breakpoint breakpoint)
+ {
+ Func<string, bool> filter = (resJSON) => {
+ if (VSCodeDebugger.isResponseContainProperty(resJSON, "event", "stopped")
+ && VSCodeDebugger.isResponseContainProperty(resJSON, "reason", "breakpoint")) {
+ threadId = Convert.ToInt32(VSCodeDebugger.GetResponsePropertyValue(resJSON, "threadId"));
+ return true;
+ }
+ return false;
+ };
+
+ if (!VSCodeDebugger.IsEventReceived(filter))
+ throw new NetcoreDbgTestCore.ResultNotSuccessException();
+
+ StackTraceRequest stackTraceRequest = new StackTraceRequest();
+ stackTraceRequest.arguments.threadId = threadId;
+ stackTraceRequest.arguments.startFrame = 0;
+ stackTraceRequest.arguments.levels = 20;
+ var ret = VSCodeDebugger.Request(stackTraceRequest);
+ Assert.True(ret.Success);
+
+ Assert.Equal(BreakpointType.Line, breakpoint.Type);
+ var lbp = (LineBreakpoint)breakpoint;
+
+ StackTraceResponse stackTraceResponse =
+ JsonConvert.DeserializeObject<StackTraceResponse>(ret.ResponseStr);
+
+ foreach (var Frame in stackTraceResponse.body.stackFrames) {
+ if (Frame.line == lbp.NumLine
+ && Frame.source.name == lbp.FileName
+ // NOTE this code works only with one source file
+ && Frame.source.path == DebuggeeInfo.SourceFilesPath)
+ return;
+ }
+
+ throw new NetcoreDbgTestCore.ResultNotSuccessException();
+ }
+
+ public static void Continue()
+ {
+ ContinueRequest continueRequest = new ContinueRequest();
+ continueRequest.arguments.threadId = threadId;
+ Assert.True(VSCodeDebugger.Request(continueRequest).Success);
+ }
+
+ static VSCodeDebugger VSCodeDebugger = new VSCodeDebugger();
+ static int threadId = -1;
+ public static string BreakpointSourceName;
+ public static List<SourceBreakpoint> BreakpointList = new List<SourceBreakpoint>();
+ public static List<int> BreakpointLines = new List<int>();
+ }
+}
+
+namespace VSCodeTest297killNCD
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ // first checkpoint (initialization) must provide "init" as id
+ Label.Checkpoint("init", "bp_test", () => {
+ Context.PrepareStart();
+ Context.AddBreakpoint("bp");
+ Context.SetBreakpoints();
+ Context.PrepareEnd();
+ Context.WasEntryPointHit();
+ Context.Continue();
+ });
+
+ Console.WriteLine("Pre delay");
+ System.Threading.Thread.Sleep(25000);
+ Console.WriteLine("Sleep done. A breakpoint \"bp\" is here"); Label.Breakpoint("bp");
+
+ Label.Checkpoint("bp_test", "finish", () => {
+ Context.WasBreakpointHit(DebuggeeInfo.Breakpoints["bp"]);
+ Context.Continue();
+ });
+
+ // last checkpoint must provide "finish" as id or empty string ("") as next checkpoint id
+ Label.Checkpoint("finish", "", () => {
+ Context.WasExit();
+ Context.DebuggerExit();
+ });
+ }
+ }
+}