public override bool Load(TestPackage package) { log.Info("Loading " + package.Name); Unload(); runtimeFramework = package.Settings["RuntimeFramework"] as RuntimeFramework; if ( runtimeFramework == null ) runtimeFramework = RuntimeFramework.CurrentFramework; bool loaded = false; try { if (this.agent == null) { this.agent = Services.TestAgency.GetAgent( runtimeFramework, 30000); if (this.agent == null) return false; } if ( this.TestRunner == null ) this.TestRunner = agent.CreateRunner(this.runnerID); loaded = base.Load (package); return loaded; } finally { // Clean up if the load failed if ( !loaded ) Unload(); } }
private void AppendProcessInfo( int pid, string moduleName, RuntimeFramework framework ) { AppendBoldText(string.Format("{0} ( {1} )\r\n", moduleName, pid)); TextBox.AppendText(string.Format( " CLR Version: {0} ( {1} )\r\n", framework.Version.ToString(), framework.DisplayName)); }
/// <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) { if (Services.UserSettings.GetSetting("Options.TestLoader.RuntimeSelectionEnabled", true)) foreach (string assembly in package.Assemblies) { using (AssemblyReader reader = new AssemblyReader(assembly)) { string vString = reader.ImageRuntimeVersion; if (vString.Length > 1) // Make sure it's a valid dot net assembly { Version v = new Version(vString.Substring(1)); log.Debug("Assembly {0} uses version {1}", assembly, v); if (v > targetVersion) targetVersion = v; } } } else targetVersion = RuntimeFramework.CurrentFramework.ClrVersion; RuntimeFramework checkFramework = new RuntimeFramework(targetRuntime, targetVersion); if (!checkFramework.IsAvailable || !Services.TestAgency.IsRuntimeVersionSupported(targetVersion)) { 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; }
public void RequestForSpecificVersionIsHonored(RuntimeFramework requestedFramework) { Assume.That(requestedFramework.Runtime, Is.EqualTo(RuntimeType.Any)); RuntimeFrameworkSelector selector = new RuntimeFrameworkSelector(); package.Settings["RuntimeFramework"] = requestedFramework; RuntimeFramework selectedFramework = selector.SelectRuntimeFramework(package); Assert.That(selectedFramework.Runtime, Is.EqualTo(RuntimeFramework.CurrentFramework.Runtime)); Assert.That(selectedFramework.ClrVersion, Is.EqualTo(requestedFramework.ClrVersion)); }
/// <summary> /// Constructs a TestAssemblyInfo /// </summary> /// <param name="assemblyName">The name of the assembly</param> /// <param name="imageRuntimeVersion">The version of the runtime for which the assembly was built</param> /// <param name="runnerRuntimeFramework">The runtime framework under which the assembly is loaded</param> /// <param name="testFrameworks">A list of test framework useds by the assembly</param> public TestAssemblyInfo( string assemblyName, Version imageRuntimeVersion, RuntimeFramework runnerRuntimeFramework, IList testFrameworks ) { this.assemblyName = assemblyName; this.imageRuntimeVersion = imageRuntimeVersion; this.runnerRuntimeFramework = runnerRuntimeFramework; this.testFrameworks = testFrameworks; Process p = Process.GetCurrentProcess(); this.processId = p.Id; this.moduleName = p.MainModule.ModuleName; this.domainName = AppDomain.CurrentDomain.FriendlyName; this.appBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; this.configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; this.binPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath; }
/// <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; }
/// <summary> /// Returns a test runner based on the settings in a TestPackage. /// Any setting that is "consumed" by the factory is removed, so /// that downstream runners using the factory will not repeatedly /// create the same type of runner. /// </summary> /// <param name="package">The TestPackage to be loaded and run</param> /// <returns>A TestRunner</returns> public static TestRunner MakeTestRunner(TestPackage package) { RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework; RuntimeFramework targetFramework = package.Settings["RuntimeFramework"] as RuntimeFramework; if (targetFramework == null) targetFramework = currentFramework; else if (targetFramework.Runtime == RuntimeType.Any) { targetFramework = new RuntimeFramework(currentFramework.Runtime, targetFramework.Version); package.Settings["RuntimeFramework"] = targetFramework; } log.Debug("Test requires {0} framework", targetFramework); ProcessModel processModel = (ProcessModel)package.GetSetting("ProcessModel", ProcessModel.Default); if ( processModel == ProcessModel.Default ) if ( !targetFramework.Matches( currentFramework ) ) processModel = ProcessModel.Separate; switch (processModel) { case ProcessModel.Multiple: package.Settings.Remove("ProcessModel"); return new MultipleTestProcessRunner(); case ProcessModel.Separate: package.Settings.Remove("ProcessModel"); return new ProcessRunner(); default: DomainUsage domainUsage = (DomainUsage)package.GetSetting("DomainUsage", DomainUsage.Default); if (domainUsage == DomainUsage.Multiple) { package.Settings.Remove("DomainUsage"); return new MultipleTestDomainRunner(); } else return new TestDomain(); } }
/// <summary> /// Returns true if a particular target runtime is available. /// </summary> /// <param name="framework">The framework being sought</param> /// <returns>True if it's available, false if not</returns> public static bool IsAvailable(RuntimeFramework framework) { switch (framework.Runtime) { case RuntimeType.Mono: return IsMonoInstalled(); case RuntimeType.Net: return CurrentFramework.Matches( framework ) || IsDotNetInstalled(framework.Version); default: return false; } }
private bool IsRuntimeSupported(RuntimeType runtime, string versionSpecification) { Version version = versionSpecification == null ? RuntimeFramework.DefaultVersion : new Version(versionSpecification); RuntimeFramework target = new RuntimeFramework(runtime, version); return rt.Supports(target); }
public TestAgent GetAgent(RuntimeFramework framework, int waitTime, bool enableDebug) { log.Info("Getting agent for use under {0}", framework); if (!framework.IsAvailable) throw new ArgumentException( string.Format("The {0} framework is not available", framework), "framework"); // TODO: Decide if we should reuse agents //AgentRecord r = FindAvailableRemoteAgent(type); //if ( r == null ) // r = CreateRemoteAgent(type, framework, waitTime); return CreateRemoteAgent(framework, waitTime, enableDebug); }
public TestAgent GetAgent(RuntimeFramework framework, int waitTime) { return GetAgent(framework, waitTime, false); }
/// <summary> /// Default constructor uses the operating system and /// common language runtime of the system. /// </summary> public PlatformHelper() { this.os = Environment.OSVersion; this.rt = RuntimeFramework.CurrentFramework; }
/// <summary> /// Default constructor uses the operating system and /// common language runtime of the system. /// </summary> public PlatformHelper() { this.os = OSPlatform.CurrentPlatform; this.rt = RuntimeFramework.CurrentFramework; }
public void LoadTest( string testName ) { log.Info("Loading tests for " + Path.GetFileName(TestFileName)); long startTime = DateTime.Now.Ticks; try { events.FireTestLoading( TestFileName ); TestPackage package = MakeTestPackage(testName); testRunner = TestRunnerFactory.MakeTestRunner(package); bool loaded = testRunner.Load(package); loadedTest = testRunner.Test; loadedTestName = testName; testResult = null; reloadPending = false; if ( Services.UserSettings.GetSetting( "Options.TestLoader.ReloadOnChange", true ) ) InstallWatcher( ); if (loaded) { this.currentFramework = package.Settings.Contains("RuntimeFramework") ? package.Settings["RuntimeFramework"] as RuntimeFramework : RuntimeFramework.CurrentFramework; testProject.HasChangesRequiringReload = false; events.FireTestLoaded(TestFileName, loadedTest); } else { lastException = new ApplicationException(string.Format("Unable to find test {0} in assembly", testName)); events.FireTestLoadFailed(TestFileName, lastException); } } catch( FileNotFoundException exception ) { log.Error("File not found", exception); lastException = exception; foreach( string assembly in TestProject.ActiveConfig.Assemblies ) { if ( Path.GetFileNameWithoutExtension( assembly ) == exception.FileName && !PathUtils.SamePathOrUnder( testProject.ActiveConfig.BasePath, assembly ) ) { lastException = new ApplicationException( string.Format( "Unable to load {0} because it is not located under the AppBase", exception.FileName ), exception ); break; } } events.FireTestLoadFailed( TestFileName, lastException ); double loadTime = (double)(DateTime.Now.Ticks - startTime) / (double)TimeSpan.TicksPerSecond; log.Info("Load completed in {0} seconds", loadTime); } catch( Exception exception ) { log.Error("Failed to load test", exception); lastException = exception; events.FireTestLoadFailed( TestFileName, exception ); } }
/// <summary> /// Reload the current test on command /// </summary> public void ReloadTest(RuntimeFramework framework) { log.Info("Reloading tests for " + Path.GetFileName(TestFileName)); try { events.FireTestReloading( TestFileName ); TestPackage package = MakeTestPackage(loadedTestName); if (framework != null) package.Settings["RuntimeFramework"] = framework; RemoveWatcher(); testRunner.Unload(); if (!factory.CanReuse(testRunner, package)) { testRunner.Dispose(); testRunner = factory.MakeTestRunner(package); } if (testRunner.Load(package)) this.currentFramework = package.Settings.Contains("RuntimeFramework") ? package.Settings["RuntimeFramework"] as RuntimeFramework : RuntimeFramework.CurrentFramework; loadedTest = testRunner.Test; currentRuntime = framework; reloadPending = false; if (ServicesArxNet.UserSettings.GetSetting("Options.TestLoader.ReloadOnChange", true)) InstallWatcher(); testProject.HasChangesRequiringReload = false; events.FireTestReloaded(TestFileName, loadedTest); log.Info("Reload complete"); } catch( Exception exception ) { log.Error("Reload failed", exception); lastException = exception; events.FireTestReloadFailed( TestFileName, exception ); } }
/// <summary> /// Contruct a PlatformHelper for a particular operating /// system and common language runtime. Used in testing. /// </summary> /// <param name="os">OperatingSystem to be used</param> public PlatformHelper(OSPlatform os, RuntimeFramework rt) { this.os = os; this.rt = rt; }
/// <summary> /// Return true if the current project can be reloaded under /// the specified CLR version. /// </summary> /*public bool CanReloadUnderRuntimeVersion(Version version) { if (!ServicesArxNet.TestAgency.IsRuntimeVersionSupported(version)) return false; foreach (TestAssemblyInfo info in AssemblyInfo) if (info.ImageRuntimeVersion > version) return false; return true; }*/ /// <summary> /// Reload the current test on command /// </summary> //在CAD环境下重载的测试须是单线程、异步 public new void ReloadTest(RuntimeFramework framework) { log.Info("Reloading tests for " + Path.GetFileName(TestFileName)); object value; TestEventDispatcher events; string loadedTestName; TestRunner testRunner; ITestRunnerFactory factory; RuntimeFramework currentFramework; ITest loadedTest; bool reloadPending; NUnitProject testProject; Exception lastException; try { //private TestEventDispatcher events; //events.FireTestReloading(TestFileName); events = null; value = GetBaseNoPublicField("events"); if (value != null) events = (TestEventDispatcher)value; if (events != null) events.FireTestReloading(TestFileName); //private string loadedTestName = null; //TestPackage package = MakeTestPackage(loadedTestName); loadedTestName = null; value = GetBaseNoPublicField("loadedTestName"); if (value != null) loadedTestName = (string)value; TestPackage package = MakeTestPackage(loadedTestName); if (framework != null) package.Settings["RuntimeFramework"] = framework; RemoveWatcher();//调用新方法 //private TestRunner testRunner = null; //testRunner.Unload(); testRunner = null; value = GetBaseNoPublicField("testRunner"); if (value != null) testRunner = (TestRunner)value; if (testRunner != null) testRunner.Unload(); //private ITestRunnerFactory factory; //if (!factory.CanReuse(testRunner, package)) factory = null; value = GetBaseNoPublicField("factory"); if (value != null) factory = (ITestRunnerFactory)value; if (factory != null) { if (!factory.CanReuse(testRunner, package)) { testRunner.Dispose(); //private TestRunner testRunner = null; //testRunner = factory.MakeTestRunner(package); testRunner = factory.MakeTestRunner(package); SetBaseNoPublicField("testRunner", testRunner); } } //private TestRunner testRunner = null; //if (testRunner.Load(package)) testRunner = null; value = GetBaseNoPublicField("testRunner"); if (value != null) testRunner = (TestRunner)value; if (testRunner != null) { if (testRunner.Load(package)) { //private RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework; /*this.currentFramework = package.Settings.Contains("RuntimeFramework") ? package.Settings["RuntimeFramework"] as RuntimeFramework : RuntimeFramework.CurrentFramework;*/ currentFramework = package.Settings.Contains("RuntimeFramework") ? package.Settings["RuntimeFramework"] as RuntimeFramework : RuntimeFramework.CurrentFramework; SetBaseNoPublicField("currentFramework", currentFramework); } } //private ITest loadedTest = null; //loadedTest = testRunner.Test; testRunner = null; value = GetBaseNoPublicField("testRunner"); if (value != null) testRunner = (TestRunner)value; if (testRunner != null) { loadedTest = testRunner.Test; SetBaseNoPublicField("loadedTest", loadedTest); } //private RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework; //currentRuntime = framework; currentFramework = framework; SetBaseNoPublicField("currentFramework", currentFramework); //private bool reloadPending = false; //reloadPending = false; reloadPending = false; SetBaseNoPublicField("reloadPending", reloadPending); if (ServicesArxNet.UserSettings.GetSetting("Options.TestLoader.ReloadOnChange", true)) { InstallWatcher();//调用新方法 } //private NUnitProject testProject = null; //testProject.HasChangesRequiringReload = false; testProject = null; value = GetBaseNoPublicField("testProject"); if (value != null) testProject = (NUnitProject)value; if (testProject != null) testProject.HasChangesRequiringReload = false; //private ITest loadedTest = null; //events.FireTestReloaded(TestFileName, loadedTest); loadedTest = null; value = GetBaseNoPublicField("loadedTest"); if (loadedTest != null) loadedTest = (ITest)value; //private TestEventDispatcher events; //events.FireTestReloaded(TestFileName, loadedTest); events = null; value = GetBaseNoPublicField("events"); if (value != null) events = (TestEventDispatcher)value; if (events != null) events.FireTestReloaded(TestFileName, loadedTest); log.Info("Reload complete"); } catch (Exception exception) { log.Error("Reload failed", exception); //private Exception lastException = null; //lastException = exception; lastException = exception; SetBaseNoPublicField("lastException", lastException); //private TestEventDispatcher events; //events.FireTestReloadFailed(TestFileName, exception); events = null; value = GetBaseNoPublicField("events"); if (value != null) events = (TestEventDispatcher)value; if (events != null) events.FireTestReloadFailed(TestFileName, exception); } }
/// <summary> /// Returns an array of all available frameworks of a given type, /// for example, all mono or all .NET frameworks. /// </summary> public static RuntimeFramework[] GetAvailableFrameworks(RuntimeType rt) { ArrayList frameworks = new ArrayList(); if (rt == RuntimeType.Net) { RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\.NETFramework\policy"); if (key != null) { foreach (string name in key.GetSubKeyNames()) { if (name.StartsWith("v")) { RegistryKey key2 = key.OpenSubKey(name); foreach (string build in key2.GetValueNames()) frameworks.Add( new RuntimeFramework(rt, new Version(name.Substring(1) + "." + build))); } } } } else if (rt == RuntimeType.Mono && IsMonoInstalled()) { RuntimeFramework framework = new RuntimeFramework(rt, new Version(1,1,4322)); framework.displayName = "Mono 1.0 Profile"; frameworks.Add( framework ); framework = new RuntimeFramework(rt, new Version(2, 0, 50727)); framework.displayName = "Mono 2.0 Profile"; frameworks.Add( framework ); } // Code to list various versions of Mono - currently not used //else if (rt == RuntimeType.Mono) //{ // RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Novell\Mono"); // if (key != null) // { // foreach (string name in key.GetSubKeyNames()) // { // RuntimeFramework framework = new RuntimeFramework(rt, new Version(1, 0)); // framework.displayName = "Mono " + name + " - 1.0 Profile"; // frameworks.Add(framework); // framework = new RuntimeFramework(rt, new Version(2, 0)); // framework.displayName = "Mono " + name + " - 2.0 Profile"; // frameworks.Add(framework); // } // } //} return (RuntimeFramework[])frameworks.ToArray(typeof(RuntimeFramework)); }
private static void AppendMonoFrameworks(FrameworkCollection frameworks) { #if true string monoPrefix = null; string version = null; if (Environment.OSVersion.Platform == PlatformID.Win32NT) { RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Novell\Mono"); if (key != null) { version = key.GetValue("DefaultCLR") as string; if (version != null && version != "") { key = key.OpenSubKey(version); if (key != null) { monoPrefix = key.GetValue("SdkInstallRoot") as string; } } } } else // Assuming we're currently running Mono - change if more runtimes are added { string libMonoDir = Path.GetDirectoryName(typeof(object).Assembly.Location); monoPrefix = Path.GetDirectoryName(Path.GetDirectoryName(libMonoDir)); } if (monoPrefix != null) { string displayFmt = version != null ? "Mono " + version + " - {0} Profile" : "Mono {0} Profile"; RuntimeFramework framework = new RuntimeFramework(RuntimeType.Mono, new Version(1, 1, 4322)); framework.displayName = string.Format(displayFmt, "1.0"); frameworks.Add(framework); framework = new RuntimeFramework(RuntimeType.Mono, new Version(2, 0, 50727)); framework.displayName = string.Format(displayFmt, "2.0"); frameworks.Add(framework); if (File.Exists(Path.Combine(monoPrefix, "lib/Mono/4.0/mscorlib.dll"))) { framework = new RuntimeFramework(RuntimeType.Mono, new Version(4, 0, 30319)); framework.displayName = string.Format(displayFmt, "4.0"); frameworks.Add(framework); } } #else // Code to list various versions of Mono - currently not used // because it only works on Windows RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Novell\Mono"); if (key == null) { return; } foreach (string name in key.GetSubKeyNames()) { RuntimeFramework framework = new RuntimeFramework(RuntimeType.Mono, new Version(1, 0)); framework.displayName = "Mono " + name + " - 1.0 Profile"; frameworks.Add(framework); framework = new RuntimeFramework(RuntimeType.Mono, new Version(2, 0)); framework.displayName = "Mono " + name + " - 2.0 Profile"; frameworks.Add(framework); } #endif }
/// <summary> /// Returns true if the current framework matches the /// one supplied as an argument. Two frameworks match /// if their runtime types are the same or either one /// is RuntimeType.Any and all specified version components /// are equal. Negative (i.e. unspecified) version /// components are ignored. /// </summary> /// <param name="other">The RuntimeFramework to be matched.</param> /// <returns>True on match, otherwise false</returns> public bool Matches(RuntimeFramework other) { return ( this.Runtime == RuntimeType.Any || other.Runtime == RuntimeType.Any || this.Runtime == other.Runtime ) && this.Version.Major == other.Version.Major && this.Version.Minor == other.Version.Minor && ( this.Version.Build < 0 || other.Version.Build < 0 || this.Version.Build == other.Version.Build ) && ( this.Version.Revision < 0 || other.Version.Revision < 0 || this.Version.Revision == other.Version.Revision ); }
private TestAgent CreateRemoteAgent(RuntimeFramework framework, int waitTime, bool enableDebug) { Guid agentId = LaunchAgentProcess(framework, enableDebug); log.Debug( "Waiting for agent {0} to register", agentId.ToString("B") ); int pollTime = 200; bool infinite = waitTime == Timeout.Infinite; while( infinite || waitTime > 0 ) { Thread.Sleep( pollTime ); if ( !infinite ) waitTime -= pollTime; TestAgent agent = agentData[agentId].Agent; if ( agent != null ) { log.Debug( "Returning new agent {0}", agentId.ToString("B") ); return agent; } } return null; }
/// <summary> /// Contruct a PlatformHelper for a particular operating /// system and common language runtime. Used in testing. /// </summary> /// <param name="os">OperatingSystem to be used</param> public PlatformHelper( OSPlatform os, RuntimeFramework rt ) { this.os = os; this.rt = rt; }
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; }
/// <summary> /// Contruct a PlatformHelper for a particular operating /// system and common language runtime. Used in testing. /// </summary> /// <param name="os">OperatingSystem to be used</param> public PlatformHelper( OperatingSystem os, RuntimeFramework rt ) { this.os = os; this.rt = rt; }
/// <summary> /// Contruct a PlatformHelper for a particular operating /// system and common language runtime. Used in testing. /// </summary> /// <param name="os">OperatingSystem to be used</param> public PlatformHelper(OperatingSystem os, RuntimeFramework rt) { this.os = os; this.rt = rt; }
/// <summary> /// Reload the current test on command /// </summary> public void ReloadTest(RuntimeFramework framework) { log.Info("Reloading tests for " + Path.GetFileName(TestFileName)); try { events.FireTestReloading( TestFileName ); TestPackage package = MakeTestPackage(loadedTestName); if (framework != null) package.Settings["RuntimeFramework"] = framework; testRunner.Unload(); testRunner = TestRunnerFactory.MakeTestRunner(package); if (testRunner.Load(package)) this.currentFramework = package.Settings.Contains("RuntimeFramework") ? package.Settings["RuntimeFramework"] as RuntimeFramework : RuntimeFramework.CurrentFramework; loadedTest = testRunner.Test; reloadPending = false; testProject.HasChangesRequiringReload = false; events.FireTestReloaded(TestFileName, loadedTest); log.Info("Reload complete"); } catch( Exception exception ) { log.Error("Reload failed", exception); lastException = exception; events.FireTestReloadFailed( TestFileName, exception ); } }
//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; }