//public void DestroyAgent( ITestAgent agent ) //{ // AgentRecord r = agentData[agent.Id]; // if ( r != null ) // { // if( !r.Process.HasExited ) // r.Agent.Stop(); // agentData[r.Id] = null; // } //} #endregion #region Helper Methods private Guid LaunchAgentProcess(RuntimeFramework targetRuntime, bool enableDebug) { string agentExePath = NUnitConfiguration.GetTestAgentExePath(targetRuntime.ClrVersion); if (agentExePath == null) { throw new ArgumentException( string.Format("NUnit components for version {0} of the CLR are not installed", targetRuntime.ClrVersion.ToString()), "targetRuntime"); } log.Debug("Using nunit-agent at " + agentExePath); Process p = new Process(); p.StartInfo.UseShellExecute = false; Guid agentId = Guid.NewGuid(); string arglist = agentId.ToString() + " " + ServerUrl; if (enableDebug) { arglist += " --pause"; } switch (targetRuntime.Runtime) { case RuntimeType.Mono: p.StartInfo.FileName = NUnitConfiguration.MonoExePath; if (enableDebug) { p.StartInfo.Arguments = string.Format("--debug \"{0}\" {1}", agentExePath, arglist); } else { p.StartInfo.Arguments = string.Format("\"{0}\" {1}", agentExePath, arglist); } break; case RuntimeType.Net: p.StartInfo.FileName = agentExePath; if (targetRuntime.ClrVersion.Build < 0) { targetRuntime = RuntimeFramework.GetBestAvailableFramework(targetRuntime); } string envVar = "v" + targetRuntime.ClrVersion.ToString(3); p.StartInfo.EnvironmentVariables["COMPLUS_Version"] = envVar; p.StartInfo.Arguments = arglist; break; default: p.StartInfo.FileName = agentExePath; p.StartInfo.Arguments = arglist; break; } //p.Exited += new EventHandler(OnProcessExit); p.Start(); log.Info("Launched Agent process {0} - see nunit-agent_{0}.log", p.Id); log.Info("Command line: \"{0}\" {1}", p.StartInfo.FileName, p.StartInfo.Arguments); agentData.Add(new AgentRecord(agentId, p, null, AgentStatus.Starting)); return(agentId); }
//public void DestroyAgent( ITestAgent agent ) //{ // AgentRecord r = agentData[agent.Id]; // if ( r != null ) // { // if( !r.Process.HasExited ) // r.Agent.Stop(); // agentData[r.Id] = null; // } //} #endregion #region Helper Methods private Guid LaunchAgentProcess(RuntimeFramework targetRuntime) { string agentExePath = NUnitConfiguration.GetTestAgentExePath(targetRuntime.Version); if (agentExePath == null) { throw new ArgumentException( string.Format("NUnit components for version {0} of the CLR are not installed", targetRuntime.Version.ToString(3)), "targetRuntime"); } // TODO: Replace adhoc code //if (targetRuntime.Version.Major == 1 && RuntimeFramework.CurrentFramework.Version.Major == 2) //{ // agentExePath = agentExePath // .Replace("2.0", "1.1") // .Replace("vs2008", "vs2003") // .Replace("vs2005", "vs2003"); //} //else if (targetRuntime.Version.Major == 2 && RuntimeFramework.CurrentFramework.Version.Major == 1) //{ // agentExePath = agentExePath // .Replace("1.1", "2.0") // .Replace("1.0", "2.0") // .Replace("vs2003", "vs2008"); //} log.Debug("Using nunit-agent at " + agentExePath); Process p = new Process(); p.StartInfo.UseShellExecute = false; Guid agentId = Guid.NewGuid(); string arglist = agentId.ToString() + " " + ServerUtilities.MakeUrl(this.uri, this.port); switch (targetRuntime.Runtime) { case RuntimeType.Mono: // TODO: Replace hard-coded path p.StartInfo.FileName = NUnitConfiguration.MonoExePath; p.StartInfo.Arguments = string.Format("\"{0}\" {1}", agentExePath, arglist); break; case RuntimeType.Net: p.StartInfo.FileName = agentExePath; if (targetRuntime.Version == new Version("1.0.3705")) { p.StartInfo.EnvironmentVariables["COMPLUS_Version"] = "v1.0.3705"; } p.StartInfo.Arguments = arglist; break; default: p.StartInfo.FileName = agentExePath; p.StartInfo.Arguments = arglist; break; } //p.Exited += new EventHandler(OnProcessExit); p.Start(); log.Info("Launched Agent process {0} - see nunit-agent_{0}.log", p.Id); log.Info("Command line: \"{0}\" {1}", p.StartInfo.FileName, p.StartInfo.Arguments); agentData.Add(new AgentRecord(agentId, p, null, AgentStatus.Starting)); return(agentId); }
/// <summary> /// Selects a target runtime framework for a TestPackage based on /// the settings in the package and the assemblies themselves. /// The package RuntimeFramework setting may be updated as a /// result and the selected runtime is returned. /// </summary> /// <param name="package">A TestPackage</param> /// <returns>The selected RuntimeFramework</returns> public RuntimeFramework SelectRuntimeFramework(TestPackage package) { RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework; RuntimeFramework requestedFramework = package.Settings["RuntimeFramework"] as RuntimeFramework; log.Debug("Current framework is {0}", currentFramework); if (requestedFramework == null) { log.Debug("No specific framework requested"); } else { log.Debug("Requested framework is {0}", requestedFramework); } RuntimeType targetRuntime = requestedFramework == null ? RuntimeType.Any : requestedFramework.Runtime; Version targetVersion = requestedFramework == null ? RuntimeFramework.DefaultVersion : requestedFramework.FrameworkVersion; if (targetRuntime == RuntimeType.Any) { targetRuntime = currentFramework.Runtime; } if (targetVersion == RuntimeFramework.DefaultVersion) { foreach (string assembly in package.Assemblies) { using (AssemblyReader reader = new AssemblyReader(assembly)) { Version v = new Version(reader.ImageRuntimeVersion.Substring(1)); log.Debug("Assembly {0} uses version {1}", assembly, v); if (v > targetVersion) { targetVersion = v; } } } RuntimeFramework checkFramework = new RuntimeFramework(targetRuntime, targetVersion); if (!checkFramework.IsAvailable || NUnitConfiguration.GetTestAgentExePath(targetVersion) == null) { log.Debug("Preferred version {0} is not installed or this NUnit installation does not support it", targetVersion); if (targetVersion < currentFramework.FrameworkVersion) { targetVersion = currentFramework.FrameworkVersion; } } } RuntimeFramework targetFramework = new RuntimeFramework(targetRuntime, targetVersion); package.Settings["RuntimeFramework"] = targetFramework; log.Debug("Test will use {0} framework", targetFramework); return(targetFramework); }