Add Xunit tests support.
authorMikhail Kurinnoi <m.kurinnoi@samsung.net>
Mon, 23 Sep 2019 09:57:21 +0000 (12:57 +0300)
committerAlexander Soldatov/AI Compiler Lab /SRR/Staff Engineer/삼성전자 <soldatov.a@samsung.com>
Mon, 23 Sep 2019 10:21:28 +0000 (13:21 +0300)
test-suite/README.md
test-suite/XunitTests/LocalTest.cs [new file with mode: 0644]
test-suite/XunitTests/XunitTests.csproj [new file with mode: 0644]

index 0919f9c7740c21690f47fc03ab86e997fd0e8ead..7f515596226e75514bdb2eeb16ea9ce6f060e3a3 100644 (file)
@@ -85,6 +85,13 @@ to make all necessary steps.
     $ powershell.exe -executionpolicy bypass -File run_tests.ps1 <test-name> [<test-name>]
 ```
 
+- Xunit tests:
+```
+    $ cd XunitTests
+    $ dotnet test
+```
+
+
 # How to add new test
 
 - move to test-suite directory;
@@ -106,4 +113,12 @@ to make all necessary steps.
 
 - add test name into ALL_TEST_NAMES list in "run_tests.sh", "run_tests.ps1", "sdb_run_tests.sh" and "sdb_run_tests.ps1" scripts;
 
+- add reference to NewTest project in Xunit tests:
+```
+    $ cd XunitTests
+    $ dotnet add reference ../NewTest/NewTest.csproj
+```
+
+- add attribute `[InlineData("NewTest")]` in xunit test class before method `Run()`;
+
 - in MIExampleTest implemented small scenario of NetCoreDbgTest library using.
diff --git a/test-suite/XunitTests/LocalTest.cs b/test-suite/XunitTests/LocalTest.cs
new file mode 100644 (file)
index 0000000..a33fa75
--- /dev/null
@@ -0,0 +1,107 @@
+using System;
+using System.IO;
+using Xunit;
+
+using LocalDebugger;
+using NetcoreDbgTestCore;
+using NetcoreDbgTestCore.MI;
+using NetcoreDbgTestCore.VSCode;
+
+namespace XUnitTests
+{
+    public class LocalTest : IDisposable
+    {
+        public LocalTest()
+        {
+            DebuggerClient = null;
+            LocalDebugger = null;
+        }
+
+        [Theory]
+        [InlineData("MIExampleTest", "Program.cs;Program_second_source.cs")]
+        [InlineData("MITestBreakpoint", "Program.cs")]
+        [InlineData("MITestExpression", "Program.cs")]
+        [InlineData("MITestSetValue", "Program.cs")]
+        [InlineData("MITestStepping", "Program.cs")]
+        [InlineData("MITestVarObject", "Program.cs")]
+        [InlineData("MITestException", "Program.cs")]
+        [InlineData("MITestLambda", "Program.cs")]
+        [InlineData("MITestEnv", "Program.cs")]
+        [InlineData("MITestGDB", "Program.cs")]
+        [InlineData("MITestExecFinish", "Program.cs")]
+        [InlineData("MITestExecAbort", "Program.cs")]
+        [InlineData("MITestExecInt", "Program.cs")]
+        [InlineData("MITestHandshake", "Program.cs")]
+        [InlineData("MITestTarget", "Program.cs")]
+        [InlineData("VSCodeExampleTest", "Program.cs")]
+        [InlineData("VSCodeTestBreakpoint", "Program.cs")]
+        [InlineData("VSCodeTestFuncBreak", "Program.cs")]
+        [InlineData("VSCodeTestAttach", "Program.cs")]
+        [InlineData("VSCodeTestPause", "Program.cs")]
+        [InlineData("VSCodeTestDisconnect", "Program.cs")]
+        [InlineData("VSCodeTestThreads", "Program.cs")]
+        [InlineData("VSCodeTestVariables", "Program.cs")]
+        [InlineData("VSCodeTestEvaluate", "Program.cs")]
+        [InlineData("VSCodeTestStepping", "Program.cs")]
+        public void Run(string testCaseName, string testCourceList)
+        {
+            string testSuiteRoot = Path.GetFullPath(
+                Path.Combine(Directory.GetCurrentDirectory(), "../../../..")
+            );
+
+            var Env = new NetcoreDbgTestCore.Environment();
+            Env.TestName = testCaseName;
+
+            string[] testFileArray = testCourceList.Split(";");
+            foreach (var FileName in testFileArray) {
+                Env.SourceFilesPath += Path.Combine(testSuiteRoot, testCaseName, FileName + ";");
+            }
+            Env.SourceFilesPath = Env.SourceFilesPath.Remove(Env.SourceFilesPath.Length - 1);
+
+            Env.TargetAssemblyPath = Path.Combine(testSuiteRoot,
+                testCaseName + "/bin/Debug/netcoreapp2.1/",
+                testCaseName + ".dll");
+            string fullDebuggerPath = Path.GetFullPath(Path.Combine(testSuiteRoot, DebuggerPath));
+
+            if (testCaseName.StartsWith("MI")) {
+                LocalDebugger = new LocalDebuggerProcess(fullDebuggerPath, @" --interpreter=mi");
+                LocalDebugger.Start();
+                DebuggerClient = new MILocalDebuggerClient(LocalDebugger.Input,
+                                                           LocalDebugger.Output);
+            } else if (testCaseName.StartsWith("VSCode")) {
+                LocalDebugger = new LocalDebuggerProcess(fullDebuggerPath, @" --interpreter=vscode");
+                LocalDebugger.Start();
+                DebuggerClient = new VSCodeLocalDebuggerClient(LocalDebugger.Input,
+                                                               LocalDebugger.Output);
+            } else {
+                throw new System.Exception();
+            }
+
+            Xunit.Assert.True(DebuggerClient.DoHandshake(200));
+
+            var Script = new DebuggeeScript(Env.SourceFilesPath, DebuggerClient.Protocol);
+
+            Debuggee.Run(Script, DebuggerClient, Env);
+        }
+
+        public void Dispose()
+        {
+            if (DebuggerClient != null) {
+                DebuggerClient.Close();
+            }
+            if (LocalDebugger != null) {
+                // we may exit debugger by "gdb-exit" call in command script
+                try
+                {
+                    LocalDebugger.Close();
+                }
+                // "No such process" exception at System.Diagnostics.Process.Kill()
+                catch (System.ComponentModel.Win32Exception) {}
+            }
+        }
+
+        private LocalDebuggerProcess LocalDebugger;
+        private DebuggerClient DebuggerClient;
+        private static string DebuggerPath = "../bin/netcoredbg";
+    }
+}
diff --git a/test-suite/XunitTests/XunitTests.csproj b/test-suite/XunitTests/XunitTests.csproj
new file mode 100644 (file)
index 0000000..d3fa62e
--- /dev/null
@@ -0,0 +1,46 @@
+<Project Sdk="Microsoft.NET.Sdk">\r
+\r
+  <PropertyGroup>\r
+    <TargetFramework>netcoreapp2.1</TargetFramework>\r
+\r
+    <IsPackable>false</IsPackable>\r
+  </PropertyGroup>\r
+\r
+  <ItemGroup>\r
+    <PackageReference Include="Microsoft.CodeAnalysis" Version="2.10.0" />\r
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />\r
+    <PackageReference Include="xunit" Version="2.4.1" />\r
+    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />\r
+  </ItemGroup>\r
+\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\LocalDebugger\LocalDebugger.csproj" />\r
+    <ProjectReference Include="..\NetcoreDbgTest\NetcoreDbgTest.csproj" />\r
+    <ProjectReference Include="..\MIExampleTest\MIExampleTest.csproj" />\r
+    <ProjectReference Include="..\MITestStepping\MITestStepping.csproj" />\r
+    <ProjectReference Include="..\MITestException\MITestException.csproj" />\r
+    <ProjectReference Include="..\MITestExpression\MITestExpression.csproj" />\r
+    <ProjectReference Include="..\MITestLambda\MITestLambda.csproj" />\r
+    <ProjectReference Include="..\MITestSetValue\MITestSetValue.csproj" />\r
+    <ProjectReference Include="..\MITestVarObject\MITestVarObject.csproj" />\r
+    <ProjectReference Include="..\MITestBreakpoint\MITestBreakpoint.csproj" />\r
+    <ProjectReference Include="..\MITestEnv\MITestEnv.csproj" />\r
+    <ProjectReference Include="..\MITestGDB\MITestGDB.csproj" />\r
+    <ProjectReference Include="..\MITestExecFinish\MITestExecFinish.csproj" />\r
+    <ProjectReference Include="..\MITestExecAbort\MITestExecAbort.csproj" />\r
+    <ProjectReference Include="..\MITestExecInt\MITestExecInt.csproj" />\r
+    <ProjectReference Include="..\MITestHandshake\MITestHandshake.csproj" />\r
+    <ProjectReference Include="..\MITestTarget\MITestTarget.csproj" />\r
+    <ProjectReference Include="..\VSCodeExampleTest\VSCodeExampleTest.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestBreakpoint\VSCodeTestBreakpoint.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestFuncBreak\VSCodeTestFuncBreak.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestAttach\VSCodeTestAttach.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestPause\VSCodeTestPause.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestDisconnect\VSCodeTestDisconnect.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestThreads\VSCodeTestThreads.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestVariables\VSCodeTestVariables.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestEvaluate\VSCodeTestEvaluate.csproj" />\r
+    <ProjectReference Include="..\VSCodeTestStepping\VSCodeTestStepping.csproj" />\r
+  </ItemGroup>\r
+\r
+</Project>\r