Example #1
0
        public void Run(string testCaseName, string testCourceList)
        {
            // Explicit encoding setup, since system console encoding could be not utf8 (Windows OS).
            // Note, netcoredbg aimed to interact with utf8 encoding usage only for all protocols.
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.InputEncoding  = System.Text.Encoding.UTF8;

            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/netcoreapp3.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(5000));

            var Script = new DebuggeeScript(Env.SourceFilesPath, DebuggerClient.Protocol);

            Debuggee.Run(Script, DebuggerClient, Env);
        }
Example #2
0
        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/netcoreapp3.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);
        }
Example #3
0
        public static int Main(string[] args)
        {
            var                  cli           = new CLInterface(args);
            DebuggerClient       debugger      = null;
            DebuggeeScript       script        = null;
            LocalDebuggerProcess localDebugger = null;

            if (cli.NeedHelp)
            {
                cli.PrintHelp();
                return(1);
            }

            if (cli.ClientInfo == null)
            {
                Console.Error.WriteLine("Please define client type");
                return(1);
            }

            try {
                switch (cli.Protocol)
                {
                case ProtocolType.MI:
                    switch (cli.ClientInfo.Type)
                    {
                    case ClientType.Local:
                        var localClientInfo = (LocalClientInfo)cli.ClientInfo;
                        localDebugger = new LocalDebuggerProcess(
                            localClientInfo.DebuggerPath, @" --interpreter=mi");
                        localDebugger.Start();

                        debugger = new MILocalDebuggerClient(localDebugger.Input,
                                                             localDebugger.Output);
                        break;

                    case ClientType.Tcp:
                        var tcpClientInfo = (TcpClientInfo)cli.ClientInfo;
                        debugger = new MITcpDebuggerClient(tcpClientInfo.Addr,
                                                           tcpClientInfo.Port);
                        break;

                    default:
                        Console.Error.WriteLine("Only tcp and local debuggers are supported now");
                        return(1);
                    }

                    break;

                case ProtocolType.VSCode:
                    switch (cli.ClientInfo.Type)
                    {
                    case ClientType.Local:
                        var localClientInfo = (LocalClientInfo)cli.ClientInfo;
                        localDebugger = new LocalDebuggerProcess(
                            localClientInfo.DebuggerPath, @" --interpreter=vscode");
                        localDebugger.Start();

                        debugger = new VSCodeLocalDebuggerClient(localDebugger.Input,
                                                                 localDebugger.Output);
                        break;

                    case ClientType.Tcp:
                        var tcpClientInfo = (TcpClientInfo)cli.ClientInfo;
                        debugger = new VSCodeTcpDebuggerClient(tcpClientInfo.Addr,
                                                               tcpClientInfo.Port);
                        break;

                    default:
                        Console.Error.WriteLine("Only tcp and local debuggers are supported now");
                        return(1);
                    }

                    break;

                default:
                    Console.Error.WriteLine("Only GDB/MI and VSCode protocols is supported now");
                    return(1);
                }
            }
            catch {
                Console.Error.WriteLine("Can't create debugger client");
                return(1);
            }

            if (!debugger.DoHandshake(200))
            {
                Console.Error.WriteLine("Handshake is failed");
                if (localDebugger != null)
                {
                    localDebugger.Close();
                }
                return(1);
            }

            try {
                script = new DebuggeeScript(cli.Environment.SourceFilesPath, debugger.Protocol);
            }
            catch (ScriptNotBuiltException e) {
                Console.Error.WriteLine("Script is not built:");
                Console.Error.WriteLine(e.ToString());
                debugger.Close();
                if (localDebugger != null)
                {
                    localDebugger.Close();
                }
                return(1);
            }

            try {
                Debuggee.Run(script, debugger, cli.Environment);
                Console.WriteLine("Success: Test case \"{0}\" is passed!!!",
                                  cli.Environment.TestName);
            }
            catch (System.Exception e) {
                Console.Error.WriteLine("Script running is failed. Got exception:\n" + e.ToString());
                return(1);
            }

            debugger.Close();
            return(0);
        }