diff options
author | Ankit Jain <radical@gmail.com> | 2020-02-25 19:38:37 +0300 |
---|---|---|
committer | Ankit Jain <radical@gmail.com> | 2020-02-25 19:38:37 +0300 |
commit | f6bef135d5188d1dfedac5722b93ef81bbd428cf (patch) | |
tree | bf79cfdf077c36675476506a92f6d80d9c444910 /sdks | |
parent | c2f8fd8bc79d08bd9869a5e682e91399fab66a22 (diff) |
[wasm][debugger][tests] Update tests to track test api changes
Diffstat (limited to 'sdks')
-rw-r--r-- | sdks/wasm/DebuggerTestSuite/Tests.cs | 355 |
1 files changed, 139 insertions, 216 deletions
diff --git a/sdks/wasm/DebuggerTestSuite/Tests.cs b/sdks/wasm/DebuggerTestSuite/Tests.cs index 9e5bbc7913d..5954ab03e4f 100644 --- a/sdks/wasm/DebuggerTestSuite/Tests.cs +++ b/sdks/wasm/DebuggerTestSuite/Tests.cs @@ -16,6 +16,7 @@ namespace DebuggerTests { public class SourceList : DebuggerTestBase { + DebugTestContext ctx; Dictionary<string, string> dicScriptsIdToUrl; Dictionary<string, string> dicFileToUrl; Dictionary<string, string> SubscribeToScripts (Inspector insp) { @@ -72,14 +73,10 @@ namespace DebuggerTests await Ready (); await insp.Ready (async (cli, token) => { - var bp1_req = JObject.FromObject(new { - lineNumber = 5, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }); + ctx = new DebugTestContext (cli, insp, token, scripts); + + var bp1_res = await SetBreakpoint ("dotnet://debugger-test.dll/debugger-test.cs", 5, 2, ctx); - var bp1_res = await cli.SendCommand ("Debugger.setBreakpointByUrl", bp1_req, token); - Assert.True (bp1_res.IsOk); Assert.Equal ("dotnet:0", bp1_res.Value ["breakpointId"]); Assert.Equal (1, bp1_res.Value ["locations"]?.Value<JArray> ()?.Count); @@ -124,44 +121,41 @@ namespace DebuggerTests await Ready (); await insp.Ready (async (cli, token) => { - var bp1_req = JObject.FromObject(new { - lineNumber = 5, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }); + ctx = new DebugTestContext (cli, insp, token, scripts); - var bp1_res = await cli.SendCommand ("Debugger.setBreakpointByUrl", bp1_req, token); - Assert.True (bp1_res.IsOk); + await SetBreakpoint ("dotnet://debugger-test.dll/debugger-test.cs", 5, 2, ctx); var eval_req = JObject.FromObject(new { expression = "window.setTimeout(function() { invoke_add(); }, 1);", }); - var eval_res = await cli.SendCommand ("Runtime.evaluate", eval_req, token); - Assert.True (eval_res.IsOk); - - var pause_location = await insp.WaitFor(Inspector.PAUSE); - - Assert.Equal ("other", pause_location ["reason"]?.Value<string> ()); - Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); - - var top_frame = pause_location ["callFrames"][0]; - - Assert.Equal ("IntAdd", top_frame ["functionName"].Value<string>()); - Assert.Contains ("debugger-test.cs", top_frame ["url"].Value<string> ()); - - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame["functionLocation"]); - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 5, 2, scripts, top_frame["location"]); - - //now check the scope - var scope = top_frame ["scopeChain"][0]; - Assert.Equal ("local", scope ["type"]); - Assert.Equal ("IntAdd", scope ["name"]); + await EvaluateAndCheck ( + "window.setTimeout(function() { invoke_add(); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", 5, 2, + "IntAdd", ctx, + wait_for_event_fn: (pause_location) => { + Assert.Equal ("other", pause_location ["reason"]?.Value<string> ()); + Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); + + var top_frame = pause_location ["callFrames"][0]; + Assert.Equal ("IntAdd", top_frame ["functionName"].Value<string>()); + Assert.Contains ("debugger-test.cs", top_frame ["url"].Value<string> ()); + + CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame["functionLocation"]); + + //now check the scope + var scope = top_frame ["scopeChain"][0]; + Assert.Equal ("local", scope ["type"]); + Assert.Equal ("IntAdd", scope ["name"]); + + Assert.Equal ("object", scope ["object"]["type"]); + Assert.Equal ("dotnet:scope:0", scope ["object"]["objectId"]); + CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, scope["startLocation"]); + CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 9, 1, scripts, scope["endLocation"]); + return Task.CompletedTask; + } + ); - Assert.Equal ("object", scope ["object"]["type"]); - Assert.Equal ("dotnet:scope:0", scope ["object"]["objectId"]); - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, scope["startLocation"]); - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 9, 1, scripts, scope["endLocation"]); }); } @@ -193,14 +187,9 @@ namespace DebuggerTests await Ready (); await insp.Ready (async (cli, token) => { - var bp1_req = JObject.FromObject(new { - lineNumber = 27, - columnNumber = 2, - url = dicFileToUrl["/debugger-driver.html"], - }); + ctx = new DebugTestContext (cli, insp, token, scripts); - var bp1_res = await cli.SendCommand ("Debugger.setBreakpointByUrl", bp1_req, token); - Assert.True (bp1_res.IsOk); + await SetBreakpoint ("/debugger-driver.html", 27, 2, ctx); var eval_req = JObject.FromObject(new { expression = "window.setTimeout(function() { invoke_bad_js_test(); }, 1);", @@ -293,14 +282,8 @@ namespace DebuggerTests [Fact] public async Task InspectLocalsAtBreakpointSite () => await CheckInspectLocalsAtBreakpointSite ( - bp_req_fn: () => JObject.FromObject(new { - lineNumber = 5, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }), - eval_req_fn: () => JObject.FromObject(new { - expression = "window.setTimeout(function() { invoke_add(); }, 1);", - }), + "dotnet://debugger-test.dll/debugger-test.cs", 5, 2, "x", + "window.setTimeout(function() { invoke_add(); }, 1);", test_fn: (locals) => { CheckNumber (locals, "a", 10); CheckNumber (locals, "b", 20); @@ -313,14 +296,8 @@ namespace DebuggerTests [Fact] public async Task InspectLocalsWithDelegatesAtBreakpointSite () => await CheckInspectLocalsAtBreakpointSite ( - bp_req_fn: () => JObject.FromObject(new { - lineNumber = 41, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }), - eval_req_fn: () => JObject.FromObject(new { - expression = "window.setTimeout(function() { invoke_delegates_test (); }, 1);", - }), + "dotnet://debugger-test.dll/debugger-test.cs", 41, 2, "x", + "window.setTimeout(function() { invoke_delegates_test (); }, 1);", test_fn: (locals) => { CheckObject (locals, "fn_func", "System.Func<Math, bool>"); CheckObject (locals, "fn_func_null", "System.Func<Math, bool>", subtype: "null"); @@ -343,14 +320,8 @@ namespace DebuggerTests [Fact] public async Task InspectLocalsWithGenericTypesAtBreakpointSite () => await CheckInspectLocalsAtBreakpointSite ( - bp_req_fn: () => JObject.FromObject(new { - lineNumber = 62, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }), - eval_req_fn: () => JObject.FromObject(new { - expression = "window.setTimeout(function() { invoke_generic_types_test (); }, 1);", - }), + "dotnet://debugger-test.dll/debugger-test.cs", 62, 2, "x", + "window.setTimeout(function() { invoke_generic_types_test (); }, 1);", test_fn: (locals) => { CheckObject (locals, "list", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>"); CheckObject (locals, "list_null", "System.Collections.Generic.Dictionary<Math[], Math.IsMathNull>", subtype: "null"); @@ -367,48 +338,35 @@ namespace DebuggerTests } ); - async Task CheckInspectLocalsAtBreakpointSite (Func<JObject> bp_req_fn, Func<JObject> eval_req_fn, Action<JToken> test_fn) { + async Task CheckInspectLocalsAtBreakpointSite (string url_key, int line, int column, string function_name, string eval_expression, Action<JToken> test_fn) { var insp = new Inspector (); //Collect events var scripts = SubscribeToScripts(insp); await Ready (); await insp.Ready (async (cli, token) => { - var bp_req = bp_req_fn (); - System.Console.WriteLine("InspectLocalsAtBreakpointSite-1"); - var bp_res = await cli.SendCommand ("Debugger.setBreakpointByUrl", bp_req, token); - System.Console.WriteLine("InspectLocalsAtBreakpointSite-2"); - Assert.True (bp_res.IsOk); - System.Console.WriteLine("InspectLocalsAtBreakpointSite-3"); - var eval_req = eval_req_fn (); - System.Console.WriteLine("InspectLocalsAtBreakpointSite-4"); - var eval_res = await cli.SendCommand ("Runtime.evaluate", eval_req, token); - System.Console.WriteLine("InspectLocalsAtBreakpointSite-5"); - Assert.True (eval_res.IsOk); - System.Console.WriteLine("InspectLocalsAtBreakpointSite-6"); - var pause_location = await insp.WaitFor(Inspector.PAUSE); - System.Console.WriteLine("InspectLocalsAtBreakpointSite-7"); - //make sure we're on the right bp - Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); - - var top_frame = pause_location ["callFrames"][0]; + var ctx = new DebugTestContext (cli, insp, token, scripts); - var scope = top_frame ["scopeChain"][0]; - Assert.Equal ("dotnet:scope:0", scope ["object"]["objectId"]); + await SetBreakpoint (url_key, line, column, ctx); - //ok, what's on that scope? - var get_prop_req = JObject.FromObject(new { - objectId = "dotnet:scope:0", - }); + await EvaluateAndCheck ( + eval_expression, url_key, line, column, + function_name, ctx, + wait_for_event_fn: (pause_location) => { + //make sure we're on the right bp + Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); - var frame_props = await cli.SendCommand ("Runtime.getProperties", get_prop_req, token); - if (frame_props.IsErr) - Console.WriteLine ($"frame_props: {frame_props.Error.ToString ()}"); - Assert.True (frame_props.IsOk); + var top_frame = pause_location ["callFrames"][0]; - var locals = frame_props.Value ["result"]; - if (test_fn != null) - test_fn (locals); + var scope = top_frame ["scopeChain"][0]; + Assert.Equal ("dotnet:scope:0", scope ["object"]["objectId"]); + return Task.CompletedTask; + }, + locals_fn: (locals) => { + if (test_fn != null) + test_fn (locals); + } + ); }); } @@ -420,36 +378,32 @@ namespace DebuggerTests await Ready (); await insp.Ready (async (cli, token) => { - var bp_req = JObject.FromObject(new { - lineNumber = 41, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }); + var ctx = new DebugTestContext (cli, insp, token, scripts); - var bp_res = await cli.SendCommand ("Debugger.setBreakpointByUrl", bp_req, token); - Assert.True (bp_res.IsOk); - var eval_req = JObject.FromObject(new { - expression = "window.setTimeout(function() { invoke_delegates_test (); }, 1);", - }); - var eval_res = await cli.SendCommand ("Runtime.evaluate", eval_req, token); - Assert.True (eval_res.IsOk); - var pause_location = await insp.WaitFor(Inspector.PAUSE); + await SetBreakpoint ("dotnet://debugger-test.dll/debugger-test.cs", 41, 2, ctx); - //make sure we're on the right bp - Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); + await EvaluateAndCheck ( + "window.setTimeout(function() { invoke_delegates_test (); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", 41, 2, + "IntAdd", ctx, + wait_for_event_fn: async (pause_location) => { + //make sure we're on the right bp + Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); - var top_frame = pause_location ["callFrames"][0]; + var top_frame = pause_location ["callFrames"][0]; - var scope = top_frame ["scopeChain"][0]; - Assert.Equal ("dotnet:scope:0", scope ["object"]["objectId"]); + var scope = top_frame ["scopeChain"][0]; + Assert.Equal ("dotnet:scope:0", scope ["object"]["objectId"]); - // Try to get an invalid scope! - var get_prop_req = JObject.FromObject(new { - objectId = "dotnet:scope:23490871", - }); + // Try to get an invalid scope! + var get_prop_req = JObject.FromObject(new { + objectId = "dotnet:scope:23490871", + }); - var frame_props = await cli.SendCommand ("Runtime.getProperties", get_prop_req, token); - Assert.True (frame_props.IsErr); + var frame_props = await cli.SendCommand ("Runtime.getProperties", get_prop_req, token); + Assert.True (frame_props.IsErr); + } + ); }); } @@ -461,42 +415,31 @@ namespace DebuggerTests await Ready (); await insp.Ready (async (cli, token) => { - var bp1_req = JObject.FromObject(new { - lineNumber = 5, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }); + ctx = new DebugTestContext (cli, insp, token, scripts); - var bp1_res = await cli.SendCommand ("Debugger.setBreakpointByUrl", bp1_req, token); - Assert.True (bp1_res.IsOk); + await SetBreakpoint ("dotnet://debugger-test.dll/debugger-test.cs", 5, 2, ctx); - var eval_req = JObject.FromObject(new { - expression = "window.setTimeout(function() { invoke_add(); }, 1);", - }); + await EvaluateAndCheck ( + "window.setTimeout(function() { invoke_add(); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", 5, 2, + "IntAdd", ctx, + wait_for_event_fn: (pause_location) => { + //make sure we're on the right bp + Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); - var eval_res = await cli.SendCommand ("Runtime.evaluate", eval_req, token); - Assert.True (eval_res.IsOk); + var top_frame = pause_location ["callFrames"][0]; + CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame["functionLocation"]); + return Task.CompletedTask; + } + ); - var pause_location = await insp.WaitFor(Inspector.PAUSE); - //make sure we're on the right bp - Assert.Equal ("dotnet:0", pause_location ["hitBreakpoints"]?[0]?.Value<string> ()); - var top_frame = pause_location ["callFrames"][0]; - System.Console.WriteLine("TrivalStepping1"); - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame["functionLocation"]); - System.Console.WriteLine("TrivalStepping2"); - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 5, 2, scripts, top_frame["location"]); - System.Console.WriteLine("TrivalStepping3"); - var step_res = await cli.SendCommand ("Debugger.stepOver", null, token); - Assert.True (step_res.IsOk); - System.Console.WriteLine("TrivalStepping4"); - var pause_location2 = await insp.WaitFor(Inspector.PAUSE); - System.Console.WriteLine("TrivalStepping5"); - var top_frame2 = pause_location2 ["callFrames"][0]; - System.Console.WriteLine("TrivalStepping6"); - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame2["functionLocation"]); - System.Console.WriteLine("TrivalStepping7"); - CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 6, 2, scripts, top_frame2["location"]); //it moved one line! - System.Console.WriteLine("TrivalStepping8"); + await StepAndCheck (StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 6, 2, "IntAdd", ctx, + wait_for_event_fn: (pause_location) => { + var top_frame = pause_location ["callFrames"][0]; + CheckLocation ("dotnet://debugger-test.dll/debugger-test.cs", 3, 41, scripts, top_frame["functionLocation"]); + return Task.CompletedTask; + } + ); }); } @@ -508,65 +451,43 @@ namespace DebuggerTests await Ready(); await insp.Ready (async (cli, token) => { - var bp1_req = JObject.FromObject(new { - lineNumber = 4, - columnNumber = 2, - url = dicFileToUrl["dotnet://debugger-test.dll/debugger-test.cs"], - }); - - var bp1_res = await cli.SendCommand ("Debugger.setBreakpointByUrl", bp1_req, token); - Assert.True (bp1_res.IsOk); + ctx = new DebugTestContext (cli, insp, token, scripts); - var eval_req = JObject.FromObject(new { - expression = "window.setTimeout(function() { invoke_add(); }, 1);", - }); - - var eval_res = await cli.SendCommand ("Runtime.evaluate", eval_req, token); - Assert.True (eval_res.IsOk); - - var pause_location = await insp.WaitFor(Inspector.PAUSE); - - //ok, what's on that scope? - var get_prop_req = JObject.FromObject(new { - objectId = "dotnet:scope:0", - }); + var debugger_test_loc = "dotnet://debugger-test.dll/debugger-test.cs"; + await SetBreakpoint (debugger_test_loc, 4, 2, ctx); - var frame_props = await cli.SendCommand ("Runtime.getProperties", get_prop_req, token); - Assert.True (frame_props.IsOk); - var locals = frame_props.Value ["result"]; - CheckNumber (locals, "a", 10); - CheckNumber (locals, "b", 20); - CheckNumber (locals, "c", 0); - CheckNumber (locals, "d", 0); - CheckNumber (locals, "e", 0); + await EvaluateAndCheck ( + "window.setTimeout(function() { invoke_add(); }, 1);", + debugger_test_loc, 4, 2, "IntAdd", ctx, + locals_fn: (locals) => { + CheckNumber (locals, "a", 10); + CheckNumber (locals, "b", 20); + CheckNumber (locals, "c", 0); + CheckNumber (locals, "d", 0); + CheckNumber (locals, "e", 0); + } + ); - //step and get locals - var step_res = await cli.SendCommand ("Debugger.stepOver", null, token); - Assert.True (step_res.IsOk); - pause_location = await insp.WaitFor(Inspector.PAUSE); - frame_props = await cli.SendCommand ("Runtime.getProperties", get_prop_req, token); - Assert.True (frame_props.IsOk); - - locals = frame_props.Value ["result"]; - CheckNumber (locals, "a", 10); - CheckNumber (locals, "b", 20); - CheckNumber (locals, "c", 30); - CheckNumber (locals, "d", 0); - CheckNumber (locals, "e", 0); + await StepAndCheck (StepKind.Over, debugger_test_loc, 5, 2, "IntAdd", ctx, + locals_fn: (locals) => { + CheckNumber (locals, "a", 10); + CheckNumber (locals, "b", 20); + CheckNumber (locals, "c", 30); + CheckNumber (locals, "d", 0); + CheckNumber (locals, "e", 0); + } + ); //step and get locals - step_res = await cli.SendCommand ("Debugger.stepOver", null, token); - Assert.True (step_res.IsOk); - pause_location = await insp.WaitFor(Inspector.PAUSE); - frame_props = await cli.SendCommand ("Runtime.getProperties", get_prop_req, token); - Assert.True (frame_props.IsOk); - - locals = frame_props.Value ["result"]; - CheckNumber (locals, "a", 10); - CheckNumber (locals, "b", 20); - CheckNumber (locals, "c", 30); - CheckNumber (locals, "d", 50); - CheckNumber (locals, "e", 0); + await StepAndCheck (StepKind.Over, debugger_test_loc, 6, 2, "IntAdd", ctx, + locals_fn: (locals) => { + CheckNumber (locals, "a", 10); + CheckNumber (locals, "b", 20); + CheckNumber (locals, "c", 30); + CheckNumber (locals, "d", 50); + CheckNumber (locals, "e", 0); + } + ); }); } @@ -578,7 +499,7 @@ namespace DebuggerTests await Ready(); await insp.Ready (async (cli, token) => { - var ctx = new DebugTestContext (cli, insp, token, scripts); + ctx = new DebugTestContext (cli, insp, token, scripts); var dep_cs_loc = "dotnet://Simple.Dependency.dll/dependency.cs"; await SetBreakpoint (dep_cs_loc, 24, 2, ctx); @@ -636,7 +557,7 @@ namespace DebuggerTests await Ready(); await insp.Ready (async (cli, token) => { - var ctx = new DebugTestContext (cli, insp, token, scripts); + ctx = new DebugTestContext (cli, insp, token, scripts); var debugger_test_loc = "dotnet://debugger-test.dll/debugger-test.cs"; await SetBreakpoint (debugger_test_loc, 100, 3, ctx); @@ -726,7 +647,7 @@ namespace DebuggerTests await Ready(); await insp.Ready (async (cli, token) => { - var ctx = new DebugTestContext (cli, insp, token, scripts); + ctx = new DebugTestContext (cli, insp, token, scripts); await SetBreakpoint ("dotnet://debugger-test.dll/debugger-test.cs", 75, 2, ctx); @@ -858,7 +779,7 @@ namespace DebuggerTests } } - async Task SetBreakpoint (string url_key, int line, int column, DebugTestContext ctx) + async Task<Result> SetBreakpoint (string url_key, int line, int column, DebugTestContext ctx, bool expect_ok=true) { var bp1_req = JObject.FromObject(new { lineNumber = line, @@ -867,7 +788,9 @@ namespace DebuggerTests }); var bp1_res = await ctx.cli.SendCommand ("Debugger.setBreakpointByUrl", bp1_req, ctx.token); - Assert.True (bp1_res.IsOk); + Assert.True (expect_ok ? bp1_res.IsOk : bp1_res.IsErr); + + return bp1_res; } //TODO add tests covering basic stepping behavior as step in/out/over |