private void ExploreOrRun(Type driverType, object[] driverArguments, string assemblyPath, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { Assembly assembly = LoadAssembly(assemblyPath); using (var queuedMessageSink = new QueuedMessageSink(messageSink)) { var testDriver = (DotNetTestDriver)Activator.CreateInstance(driverType, driverArguments); if (testExecutionOptions == null) { testDriver.ExploreAssembly(assembly, testExplorationOptions, queuedMessageSink, progressMonitor); } else { testDriver.RunAssembly(assembly, testExplorationOptions, testExecutionOptions, queuedMessageSink, progressMonitor); } } }
private static void ExploreOrRun(TestPackage testPackage, ScriptRuntimeSetup scriptRuntimeSetup, string testDriverScriptPath, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, ILogger logger) { using (BufferedLogWriter outputWriter = new BufferedLogWriter(logger, LogSeverity.Info, Encoding.Default), errorWriter = new BufferedLogWriter(logger, LogSeverity.Error, Encoding.Default)) { using (var queuedMessageSink = new QueuedMessageSink(messageSink)) { using (new ConsoleRedirection(outputWriter, errorWriter)) { var scriptRuntime = new ScriptRuntime(scriptRuntimeSetup); scriptRuntime.IO.SetInput(Stream.Null, TextReader.Null, Encoding.Default); scriptRuntime.IO.SetOutput(new TextWriterStream(outputWriter), outputWriter); scriptRuntime.IO.SetErrorOutput(new TextWriterStream(errorWriter), errorWriter); try { var scriptParameters = new Dictionary <string, object>(); scriptParameters.Add("Verb", testExecutionOptions != null ? "Run" : "Explore"); scriptParameters.Add("TestPackage", testPackage); scriptParameters.Add("TestExplorationOptions", testExplorationOptions); scriptParameters.Add("TestExecutionOptions", testExecutionOptions); scriptParameters.Add("MessageSink", queuedMessageSink); scriptParameters.Add("ProgressMonitor", progressMonitor); scriptParameters.Add("Logger", logger); scriptRuntime.Globals.SetVariable(ScriptParametersVariableName, scriptParameters); RunScript(scriptRuntime, testDriverScriptPath); } finally { scriptRuntime.Shutdown(); } } } } }
/// <summary> /// Called automatically when isolation task is ready to run. /// </summary> protected override object RunImpl(object[] args) { file_ = (FileInfo)args[0]; architecture_ = (string)args[1]; configuration_ = (string)args[2]; testExecutionOptions_ = (TestExecutionOptions)args[3]; logger_ = (ILogger)args[4]; progressMonitor_ = (IProgressMonitor)args[5]; using (QueuedMessageSink sink = new QueuedMessageSink((IMessageSink)args[6])) { messageSink_ = sink; testModel_ = new TestModel(); currentTest_ = testModel_.RootTest; currentTestSuite_ = testModel_.RootTest; using (progressMonitor_.BeginTask("Processing " + file_.Name, 100)) { // Expect native DLL to be reachable in subdirectory relative to the current assembly path. string assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string suffix = Path.Combine(architecture_, configuration_); // Make sure we can find the right version of Boost.Test DLL. if (!SetDllDirectory(Path.Combine(assemblyDir, suffix))) { Logger.Log( LogSeverity.Error, String.Format( "Failed to adjust DLL directory search path: {0}", new Win32Exception(Marshal.GetLastWin32Error()).Message ) ); return null; } // Try loading native bridge DLL. IntPtr hModule = LoadLibrary(Path.Combine(assemblyDir, Path.Combine(suffix, NativeDllName))); if (hModule == IntPtr.Zero) { Logger.Log( LogSeverity.Error, String.Format( "Failed to load native DLL to communicate with Boost.Test: {0}", new Win32Exception(Marshal.GetLastWin32Error()).Message ) ); return null; } try { // Make sure we allow loading additional DLLs // from the same folder our testable DLL is located in. if (!SetDllDirectory(File.DirectoryName)) { Logger.Log( LogSeverity.Error, String.Format( "Failed to adjust DLL directory search path: {0}", new Win32Exception(Marshal.GetLastWin32Error()).Message ) ); return null; } progressMonitor_.Worked(14); // Retrieve pointer to function in native bridge DLL that is required to // perform our task. IntPtr bridgeFunc = GetProcAddress(hModule, BridgeFunctionName); if (bridgeFunc == IntPtr.Zero) { Logger.Log( LogSeverity.Error, String.Format( "Failed to retrieve entry point {0} in Boost.Test interface: {1}", BridgeFunctionName, new Win32Exception(Marshal.GetLastWin32Error()).Message ) ); return null; } progressMonitor_.Worked(1); // Perform the task. Execute(bridgeFunc, progressMonitor_.CreateSubProgressMonitor(80)); } finally { FreeLibrary(hModule); progressMonitor_.Worked(5); } } } return null; }