예제 #1
0
 internal static void AttachDebugger(VisualStudioProxy app, ProcessOutput proc, PythonDebugMode debugMode, string debugSecret, int debugPort)
 {
     if (debugMode == PythonDebugMode.PythonOnly)
     {
         string qualifierUri = string.Format("tcp://{0}@localhost:{1}", debugSecret, debugPort);
         while (!app.AttachToProcess(proc, PythonRemoteDebugPortSupplierUnsecuredId, qualifierUri))
         {
             if (proc.Wait(TimeSpan.FromMilliseconds(500)))
             {
                 break;
             }
         }
     }
     else if (debugMode == PythonDebugMode.PythonAndNative)
     {
         var engines = new[] { PythonDebugEngineGuid, NativeDebugEngineGuid };
         while (!app.AttachToProcess(proc, engines))
         {
             if (proc.Wait(TimeSpan.FromMilliseconds(500)))
             {
                 break;
             }
         }
     }
 }
예제 #2
0
        public void FromCommandLineArgsRaceCondition()
        {
            // https://pytools.codeplex.com/workitem/1429

            var mre   = new ManualResetEvent(false);
            var tasks = new Task <bool> [100];

            try {
                for (int i = 0; i < tasks.Length; i += 1)
                {
                    tasks[i] = Task.Run(() => {
                        mre.WaitOne();
                        using (var arg = VisualStudioProxy.FromProcessId(123)) {
                            return(arg is VisualStudioProxy);
                        }
                    });
                }
                mre.Set();
                Assert.IsTrue(Task.WaitAll(tasks, TimeSpan.FromSeconds(30.0)));
                Assert.IsTrue(tasks.All(t => t.Result));
            } finally {
                mre.Dispose();
                Task.WaitAll(tasks, TimeSpan.FromSeconds(30.0));
            }
        }
예제 #3
0
        internal static void GetDebugSettings(VisualStudioProxy app, IRunContext runContext, PythonProjectSettings projectSettings, out PythonDebugMode debugMode, out string debugSecret, out int debugPort)
        {
            debugMode   = PythonDebugMode.None;
            debugSecret = "";
            debugPort   = 0;

            if (runContext.IsBeingDebugged && app != null)
            {
                debugMode = projectSettings.EnableNativeCodeDebugging ? PythonDebugMode.PythonAndNative : PythonDebugMode.PythonOnly;
            }

            if (debugMode == PythonDebugMode.PythonOnly)
            {
                if (projectSettings.UseLegacyDebugger)
                {
                    var secretBuffer = new byte[24];
                    RandomNumberGenerator.Create().GetNonZeroBytes(secretBuffer);
                    debugSecret = Convert.ToBase64String(secretBuffer)
                                  .Replace('+', '-')
                                  .Replace('/', '_')
                                  .TrimEnd('=');
                }

                SocketUtils.GetRandomPortListener(IPAddress.Loopback, out debugPort).Stop();
            }
        }
예제 #4
0
            public TestRunner(
                IFrameworkHandle frameworkHandle,
                IRunContext runContext,
                IEnumerable <TestCase> tests,
                string codeCoverageFile,
                PythonProjectSettings settings,
                VisualStudioProxy app,
                ManualResetEvent cancelRequested)
            {
                _frameworkHandle  = frameworkHandle;
                _context          = runContext;
                _tests            = tests.ToArray();
                _codeCoverageFile = codeCoverageFile;
                _settings         = settings;
                _app             = app;
                _cancelRequested = cancelRequested;
                _dryRun          = ExecutorService.IsDryRun(runContext.RunSettings);
                _showConsole     = ExecutorService.ShouldShowConsole(runContext.RunSettings);

                _env = new Dictionary <string, string>();

                _searchPaths = GetSearchPaths(tests, settings);

                ExecutorService.GetDebugSettings(_app, _context, _settings, out _debugMode, out _debugSecret, out _debugPort);

                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                _socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
                _socket.Listen(0);
                _socket.BeginAccept(AcceptConnection, _socket);
            }
예제 #5
0
        internal static void DetachFromSillyManagedProcess(VisualStudioProxy app, PythonDebugMode debugMode)
        {
            var dte = app?.GetDTE();

            if (dte != null && debugMode != PythonDebugMode.None)
            {
                dte.Debugger.DetachAll();
            }
        }
예제 #6
0
        public ExecutorService(PythonProjectSettings projectSettings, IFrameworkHandle frameworkHandle, IRunContext runContext)
        {
            _projectSettings = projectSettings;
            _frameworkHandle = frameworkHandle;
            _runContext      = runContext;
            _app             = VisualStudioProxy.FromEnvironmentVariable(PythonConstants.PythonToolsProcessIdEnvironmentVariable);

            GetDebugSettings(_app, _runContext, _projectSettings, out _debugMode, out _debugSecret, out _debugPort);
        }
예제 #7
0
            public TestRunner(
                IFrameworkHandle frameworkHandle,
                IRunContext runContext,
                IEnumerable <TestCase> tests,
                string codeCoverageFile,
                PythonProjectSettings settings,
                VisualStudioProxy app,
                ManualResetEvent cancelRequested)
            {
                _frameworkHandle  = frameworkHandle;
                _context          = runContext;
                _tests            = tests.ToArray();
                _codeCoverageFile = codeCoverageFile;
                _settings         = settings;
                _app             = app;
                _cancelRequested = cancelRequested;
                _dryRun          = IsDryRun(runContext.RunSettings);
                _showConsole     = ShouldShowConsole(runContext.RunSettings);

                _env = new Dictionary <string, string>();

                _debugMode = PythonDebugMode.None;
                if (runContext.IsBeingDebugged && _app != null)
                {
                    _debugMode = settings.EnableNativeCodeDebugging ? PythonDebugMode.PythonAndNative : PythonDebugMode.PythonOnly;
                }

                _searchPaths = GetSearchPaths(tests, settings);

                if (_debugMode == PythonDebugMode.PythonOnly)
                {
                    if (_settings.UseLegacyDebugger)
                    {
                        var secretBuffer = new byte[24];
                        RandomNumberGenerator.Create().GetNonZeroBytes(secretBuffer);
                        _debugSecret = Convert.ToBase64String(secretBuffer)
                                       .Replace('+', '-')
                                       .Replace('/', '_')
                                       .TrimEnd('=');
                    }
                    else
                    {
                        _debugSecret = "";
                    }

                    SocketUtils.GetRandomPortListener(IPAddress.Loopback, out _debugPort).Stop();
                }
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                _socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
                _socket.Listen(0);
                _socket.BeginAccept(AcceptConnection, _socket);
            }
예제 #8
0
 internal ExecutorService(
     ITestConfiguration config,
     PythonProjectSettings projectSettings,
     IFrameworkHandle frameworkHandle,
     IRunContext runContext
     )
 {
     _testConfig      = config ?? throw new ArgumentNullException(nameof(config));
     _projectSettings = projectSettings ?? throw new ArgumentNullException(nameof(projectSettings));
     _frameworkHandle = frameworkHandle ?? throw new ArgumentNullException(nameof(frameworkHandle));
     _runContext      = runContext ?? throw new ArgumentNullException(nameof(runContext));;
     _app             = VisualStudioProxy.FromEnvironmentVariable(PythonConstants.PythonToolsProcessIdEnvironmentVariable);
     GetDebugSettings(_app, _runContext, _projectSettings, out _debugMode, out _debugSecret, out _debugPort);
 }
예제 #9
0
 public PytestTestExecutor()
 {
     _app = VisualStudioProxy.FromEnvironmentVariable(PythonConstants.PythonToolsProcessIdEnvironmentVariable);
 }
예제 #10
0
 public static VisualStudioProxy FromProcessId(int processId)
 {
     VisualStudioProxy inst;
     lock (_knownInstances) {
         if (!_knownInstances.TryGetValue(processId, out inst)) {
             _knownInstances[processId] = inst = new VisualStudioProxy(processId);
         }
     }
     return inst;
 }
예제 #11
0
 public TestExecutor()
 {
     _app                = VisualStudioProxy.FromEnvironmentVariable(PythonConstants.PythonToolsProcessIdEnvironmentVariable);
     _container          = InterpreterCatalog.CreateContainer(typeof(IInterpreterRegistryService), typeof(IInterpreterOptionsService), typeof(TestExecutorProjectContext));
     _interpreterService = _container.GetExportedValue <IInterpreterOptionsService>();
 }
예제 #12
0
        private static CompositionContainer CreateCompositionContainer()
        {
            var app = VisualStudioProxy.FromEnvironmentVariable(PythonConstants.PythonToolsProcessIdEnvironmentVariable);

            return(InterpreterCatalog.CreateContainer(typeof(IInterpreterRegistryService), typeof(IInterpreterOptionsService), typeof(TestDiscoverer)));
        }