Esempio n. 1
0
        public AgentProcess(TestAgency agency, TestPackage package, Guid agentId)
        {
            // Get target runtime
            string runtimeSetting = package.GetSetting(EnginePackageSettings.TargetRuntimeFramework, "");

            TargetRuntime = RuntimeFramework.Parse(runtimeSetting);

            // Access other package settings
            bool   runAsX86        = package.GetSetting(EnginePackageSettings.RunAsX86, false);
            bool   debugAgent      = package.GetSetting(EnginePackageSettings.DebugAgent, false);
            string traceLevel      = package.GetSetting(EnginePackageSettings.InternalTraceLevel, "Off");
            bool   loadUserProfile = package.GetSetting(EnginePackageSettings.LoadUserProfile, false);
            string workDirectory   = package.GetSetting(EnginePackageSettings.WorkDirectory, string.Empty);

            AgentArgs = new StringBuilder($"{agentId} {agency.RemotingUrl} --pid={Process.GetCurrentProcess().Id}");

            // Set options that need to be in effect before the package
            // is loaded by using the command line.
            if (traceLevel != "Off")
            {
                AgentArgs.Append(" --trace=").EscapeProcessArgument(traceLevel);
            }
            if (debugAgent)
            {
                AgentArgs.Append(" --debug-agent");
            }
            if (workDirectory != string.Empty)
            {
                AgentArgs.Append(" --work=").EscapeProcessArgument(workDirectory);
            }

            AgentExePath = GetTestAgentExePath(TargetRuntime, runAsX86);

            log.Debug("Using nunit-agent at " + AgentExePath);

            StartInfo.UseShellExecute  = false;
            StartInfo.CreateNoWindow   = true;
            StartInfo.WorkingDirectory = Environment.CurrentDirectory;
            EnableRaisingEvents        = true;

            if (TargetRuntime.Runtime == RuntimeType.Mono)
            {
                StartInfo.FileName = RuntimeFramework.MonoExePath;
                string monoOptions = "--runtime=v" + TargetRuntime.ClrVersion.ToString(3);
                monoOptions        += " --debug";
                StartInfo.Arguments = string.Format("{0} \"{1}\" {2}", monoOptions, AgentExePath, AgentArgs);
            }
            else if (TargetRuntime.Runtime == RuntimeType.Net)
            {
                StartInfo.FileName        = AgentExePath;
                StartInfo.Arguments       = AgentArgs.ToString();
                StartInfo.LoadUserProfile = loadUserProfile;
            }
            else
            {
                StartInfo.FileName  = AgentExePath;
                StartInfo.Arguments = AgentArgs.ToString();
            }
        }
Esempio n. 2
0
 public void SetUp()
 {
     _agency = Substitute.For <TestAgency>();
     _agency.ServerUrl.ReturnsForAnyArgs(REMOTING_URL);
     _package = new TestPackage("junk.dll");
     // Only required setting, some tests may change this
     _package.Settings[EnginePackageSettings.TargetRuntimeFramework] = "net-4.5";
 }
Esempio n. 3
0
 public ProcessRunner(IServiceLocator services, TestPackage package) : base(services, package) 
 {
     _agency = Services.GetService<TestAgency>();
 }
 public AgentLease(TestAgency agency, Guid id, ITestAgent remoteAgent)
 {
     _agency      = agency;
     Id           = id;
     _remoteAgent = remoteAgent;
 }
Esempio n. 5
0
 public ProcessRunner(ServiceContext services, TestPackage package) : base(services, package) 
 {
     _agency = Services.GetService<TestAgency>();
 }
Esempio n. 6
0
        public AgentProcess(TestAgency agency, TestPackage package, Guid agentId)
        {
            // Get target runtime
            string runtimeSetting = package.GetSetting(EnginePackageSettings.TargetRuntimeFramework, "");

            log.Debug($"TargetRuntime = {runtimeSetting}");
            TargetRuntime = RuntimeFramework.Parse(runtimeSetting);

            // Access other package settings
            bool   runAsX86        = package.GetSetting(EnginePackageSettings.RunAsX86, false);
            bool   debugAgent      = package.GetSetting(EnginePackageSettings.DebugAgent, false);
            string traceLevel      = package.GetSetting(EnginePackageSettings.InternalTraceLevel, "Off");
            bool   loadUserProfile = package.GetSetting(EnginePackageSettings.LoadUserProfile, false);
            string workDirectory   = package.GetSetting(EnginePackageSettings.WorkDirectory, string.Empty);

            string agencyUrl = TargetRuntime.Runtime == RuntimeType.NetCore ? agency.TcpEndPoint : agency.RemotingUrl;

            AgentArgs = new StringBuilder($"{agentId} {agencyUrl} --pid={Process.GetCurrentProcess().Id}");

            // Set options that need to be in effect before the package
            // is loaded by using the command line.
            if (traceLevel != "Off")
            {
                AgentArgs.Append(" --trace=").EscapeProcessArgument(traceLevel);
            }
            if (debugAgent)
            {
                AgentArgs.Append(" --debug-agent");
            }
            if (workDirectory != string.Empty)
            {
                AgentArgs.Append(" --work=").EscapeProcessArgument(workDirectory);
            }

            AgentExePath = GetTestAgentExePath(TargetRuntime, runAsX86);

            log.Debug("Using nunit-agent at " + AgentExePath);

            StartInfo.UseShellExecute  = false;
            StartInfo.CreateNoWindow   = true;
            StartInfo.WorkingDirectory = Environment.CurrentDirectory;
            EnableRaisingEvents        = true;

            if (TargetRuntime.Runtime == RuntimeType.Mono)
            {
                StartInfo.FileName = RuntimeFramework.MonoExePath;
                string monoOptions = "--runtime=v" + TargetRuntime.ClrVersion.ToString(3);
                monoOptions        += " --debug";
                StartInfo.Arguments = string.Format("{0} \"{1}\" {2}", monoOptions, AgentExePath, AgentArgs);
            }
            else if (TargetRuntime.Runtime == RuntimeType.Net)
            {
                StartInfo.FileName        = AgentExePath;
                StartInfo.Arguments       = AgentArgs.ToString();
                StartInfo.LoadUserProfile = loadUserProfile;
            }
            else if (TargetRuntime.Runtime == RuntimeType.NetCore)
            {
                StartInfo.FileName        = "dotnet";
                StartInfo.Arguments       = $"{AgentExePath} {AgentArgs}";
                StartInfo.LoadUserProfile = loadUserProfile;

                // TODO: Remove the windows limitation and the use of a hard-coded path.
                if (runAsX86)
                {
                    if (Path.DirectorySeparatorChar != '\\')
                    {
                        throw new Exception("Running .NET Core as X86 is currently only supported on Windows");
                    }

                    var x86_dotnet_exe = @"C:\Program Files (x86)\dotnet\dotnet.exe";
                    if (!File.Exists(x86_dotnet_exe))
                    {
                        throw new Exception("The X86 version of dotnet.exe is not installed");
                    }

                    StartInfo.FileName = x86_dotnet_exe;
                }
            }
            else
            {
                StartInfo.FileName  = AgentExePath;
                StartInfo.Arguments = AgentArgs.ToString();
            }
        }