public void GenerateSuite(int seed, string suiteName, string outputPath, string[] testPaths, string[] searchPatterns, string[] hintPaths, LoadSuiteConfig config, string cachePath = null, bool legacyProject = false, string globalPackageConfig = null) { Random rand = new Random(seed); int suiteTestCount = 0; _unitTestSelector = new UnitTestSelector(); _unitTestSelector.Initialize(seed, testPaths, searchPatterns, hintPaths, cachePath); for (int iConfig = 0; iConfig < config.LoadTestConfigs.Count; iConfig++) { var loadTestConfig = config.LoadTestConfigs[iConfig]; for (int i = 0; i < loadTestConfig.TestCount; i++) { var loadTestInfo = new LoadTestInfo(globalPackageConfig) { TestName = suiteName + "_" + suiteTestCount.ToString("X4"), Duration = loadTestConfig.Duration, LoadPatternType = typeof(StaticLoadPattern), //Type.GetType(loadTestConfig.LoadPattern), TestPatternType = typeof(RandomTestPattern), //Type.GetType(loadTestConfig.TestPattern), WorkerStrategyType = typeof(DedicatedThreadWorkerStrategy), //Type.GetType(loadTestConfig.WorkerStrategy), WorkerCount = loadTestConfig.NumWorkers, SelfDestruct = loadTestConfig.SelfDestruct, EnvironmentVariables = loadTestConfig.EnvironmentVariables, SuiteConfig = config, Seed = rand.Next(), }; loadTestInfo.SourceDirectory = Path.Combine(outputPath, iConfig.ToString("00") + "_" + loadTestInfo.Duration.TotalHours.ToString("00.##") + "hr", loadTestInfo.TestName); loadTestInfo.UnitTests = _unitTestSelector.NextUnitTests(loadTestConfig.NumTests).ToArray(); //build a list of all the sources files to generate for the load test var generators = new List <ISourceFileGenerator>() { new LoadTestSourceFileGenerator(), new ProgramSourceFileGenerator(), new ExecutionFileGeneratorWindows(), new ExecutionFileGeneratorLinux(), }; //if we want to generate a legacy project file (i.e. ToF project file) use HelixToFProjectFileGenerator otherwise use LoadTestProjectFileGenerator var projectFileGenerator = legacyProject ? (ISourceFileGenerator) new HelixToFProjectFileGenerator() : (ISourceFileGenerator) new LoadTestProjectFileGenerator(); if (!legacyProject) { generators.Add(new LoadTestProjectJsonFileGenerator()); } //I believe the project file generator must be last, becuase it depends on discovering all the other source files //however the ordering beyond that should not matter generators.Add(projectFileGenerator); this.GenerateTestSources(loadTestInfo, generators); CodeGenOutput.Info($"Generated Load Test: {loadTestInfo.TestName}"); suiteTestCount++; } } }
public void GenerateSuite(int seed, string suiteName, string outputPath, string[] testPaths, string[] searchPatterns, string[] hintPaths, LoadSuiteConfig config, string cachePath = null) { int suiteTestCount = 0; _unitTestSelector = new UnitTestSelector(); _unitTestSelector.Initialize(seed, testPaths, searchPatterns, hintPaths, cachePath); for (int iConfig = 0; iConfig < config.LoadTestConfigs.Count; iConfig++) { var loadTestConfig = config.LoadTestConfigs[iConfig]; for (int i = 0; i < loadTestConfig.TestCount; i++) { var loadTestInfo = new LoadTestInfo() { TestName = suiteName + "_" + suiteTestCount.ToString("X4"), Duration = loadTestConfig.Duration, LoadPatternType = typeof(StaticLoadPattern), //Type.GetType(loadTestConfig.LoadPattern), TestPatternType = typeof(RandomTestPattern), //Type.GetType(loadTestConfig.TestPattern), WorkerStrategyType = typeof(DedicatedThreadWorkerStrategy), //Type.GetType(loadTestConfig.WorkerStrategy), WorkerCount = loadTestConfig.NumWorkers, EnvironmentVariables = loadTestConfig.EnvironmentVariables, SuiteConfig = config, }; loadTestInfo.SourceDirectory = Path.Combine(outputPath, iConfig.ToString("00") + "_" + loadTestInfo.Duration.TotalHours.ToString("00.##") + "hr", loadTestInfo.TestName); loadTestInfo.UnitTests = _unitTestSelector.NextUnitTests(loadTestConfig.NumTests).ToArray(); this.GenerateTestSources(loadTestInfo); CodeGenOutput.Info($"Generated Load Test: {loadTestInfo.TestName}"); suiteTestCount++; } } }
private UnitTestInfo[] GetTests(string path, string[] hintPaths) { List <UnitTestInfo> cachedTests; if (_candidateCache != null && _candidateCache.TryGetValue(path, out cachedTests)) { CodeGenOutput.Info($"{path}: {cachedTests.Count} tests discovered from cache"); return(cachedTests.ToArray()); } else { return(JsonConvert.DeserializeObject <UnitTestInfo[]>(FindTests(path, hintPaths))); } }
public void Initialize(int seed, string[] paths, string[] patterns, string[] hintPaths, string cachePath = null) { _rand = new Random(seed); if (cachePath != null) { _candidateCache = LoadCacheFromFile(cachePath); } _candidates = this.FindAllTests(paths, patterns, hintPaths).ToArray(); if (cachePath != null) { WriteCacheToFile(cachePath); } CodeGenOutput.Info($"Discovered {_candidates.Length} unit tests, across {_candidates.Select(t => t.AssemblyPath).Distinct().Count()} assemblies."); }
private UnitTestInfo[] FindTests(string path, string[] hintPaths) { var codeGenDllPath = Assembly.GetExecutingAssembly().Location; var codegenDir = Path.GetDirectoryName(codeGenDllPath); AppDomain loaderDomain = AppDomain.CreateDomain(path, AppDomain.CurrentDomain.Evidence, new AppDomainSetup() { ApplicationBase = codegenDir }); var loader = (TestAssemblyLoader)loaderDomain.CreateInstanceFromAndUnwrap(codeGenDllPath, typeof(TestAssemblyLoader).FullName); loader.InitializeLifetimeService(); HashSet <string> hints = new HashSet <string>(hintPaths) { Path.GetDirectoryName(path) }; loader.Load(path, hints.ToArray()); UnitTestInfo[] tests = loader.GetTests <XUnitTestDiscoverer>(); //if no xunit tests were discovered and the assembly is an exe treat as a standalone exe test if ((tests == null || tests.Length == 0) && Path.GetExtension(path).ToLowerInvariant() == ".exe") { tests = loader.GetTests <StandAloneTestDiscoverer>(); } AppDomain.Unload(loaderDomain); if (tests.Length > 0) { CodeGenOutput.Info($"{path}: {tests.Length} tests discovered from assembly"); } return(tests); }
public string GetTests <TDiscoverer>() where TDiscoverer : ITestDiscoverer, new() { try { var discoverer = new TDiscoverer(); var tests = discoverer.GetTests(_assembly); if (tests.Length > 0) { CodeGenOutput.Info($"{_assembly.Assembly.FullName}: {tests.Length} tests discovered from assembly"); } return(JsonConvert.SerializeObject(tests)); } catch (Exception e) { this.LoadError = (this.LoadError ?? string.Empty) + e.ToString(); } return(JsonConvert.SerializeObject(new UnitTestInfo[] { })); }