public static void Cleanup() { if (PerformanceCounterTest.manifestPath != null) { TestCounterManifest.Uninstall(PerformanceCounterTest.manifestPath); } }
public static void Initialize(TestContext context) { PerformanceCounterTest.performanceProviderPath = Path.Combine(context.TestDeploymentDir, "TestPerformanceProvider.exe"); PerformanceCounterTest.manifestPath = TestCounterManifest.Create( context.TestDeploymentDir, Directory.GetCurrentDirectory(), typeof(PerformanceCounterTest).Name, PerformanceCounterTest.performanceProviderPath ); try { // if a previous test run aborted the manifest may still be loaded TestCounterManifest.Uninstall(PerformanceCounterTest.manifestPath); } catch { // ignore uninstall errors, logged by Uninstall } try { TestCounterManifest.Install(PerformanceCounterTest.manifestPath); } catch { // set it to null so we don't try to clean it up later PerformanceCounterTest.manifestPath = null; throw; } }
public static string Create(string sourceDirectory, string outputDirectory, string testName, string performanceProvider) { var sourceManifest = Path.Combine(sourceDirectory, TestCounterManifest.ManifestName); Assert.IsTrue(File.Exists(sourceManifest), "Manifest file not found: {0}", sourceManifest); var path = Path.Combine( outputDirectory, testName, TestCounterManifest.ManifestName); var targetDir = Path.GetDirectoryName(path); if (Directory.Exists(targetDir)) { // delete leftovers from previous runs Directory.Delete(targetDir, true); } Directory.CreateDirectory(targetDir); LogHelper.Log("Load manifest from {0}", sourceManifest); XmlDocument manifest = new XmlDocument { XmlResolver = null }; var settings = new XmlReaderSettings { XmlResolver = null, DtdProcessing = System.Xml.DtdProcessing.Prohibit }; var reader = XmlTextReader.Create(sourceManifest, settings); manifest.Load(reader); var manNs = "http://schemas.microsoft.com/win/2004/08/events"; var counterNs = "http://schemas.microsoft.com/win/2005/12/counters"; XmlNamespaceManager mgr = new XmlNamespaceManager(manifest.NameTable); mgr.AddNamespace("man", manNs); mgr.AddNamespace("ctr", counterNs); var provider = manifest.SelectSingleNode("/man:instrumentationManifest/man:instrumentation/ctr:counters/ctr:provider", mgr) as XmlElement; var providerApplication = Path.Combine(targetDir, Path.GetFileName(performanceProvider)); provider.SetAttribute("applicationIdentity", providerApplication); LogHelper.Log("Save manifest to {0}", path); manifest.Save(path); TestCounterManifest.DeployProviderAndResources(performanceProvider, providerApplication); Assert.IsTrue(File.Exists(providerApplication), "Check that test performance provider application has been created during build."); return(path); }