/********************* Tests go above **************************************************** * */ public void RunAsimoWithChecks(string testDataFile, params string[] testRuleFileNames) { try { var assemblyResolver = new AssemblyResolver(TestContext.TestDeploymentDir, @"%OTOOLS%\bin\lsbuild6.0"); assemblyResolver.Init(); var inputCfg = CreateTestConfig(TestContext, testDataFile, testRuleFileNames); var engine = new OSLEBotEngine(inputCfg); var engineRan = engine.StartRun(); if (engineRan) { Console.WriteLine("OSLEBotExec is waiting for engine activity to complete..."); engine.CoProcessingDone.WaitOne(); // block this thread until the engine is done, since we have nothing else to do and this is the main thread. engine.AllOutputFinished.WaitOne(); //wait for output to finish engine.Cleanup(); } Assert.IsFalse(engine.EngineLoggedErrors, "Engine reported some execution errors."); //Attach results from OSLEBot to the test results. var fileInfo = new FileInfo(string.Format("{0}_OSLEBotOutput.xml", testDataFile)); if (fileInfo.Exists) { TestContext.WriteLine("Adding Asimo results file ({0}) to test results.", fileInfo.Name); TestContext.AddResultFile(fileInfo.Name); TestContext.AddResultFile(fileInfo.FullName); } } catch (OperationCanceledException ex) //Thrown when Data source providers were not specified. //Thrown when Property providers were not specified //Thrown when Data adapters were not specified //Thrown when Data Source packages list is null. { if (ex.InnerException != null) { TestContext.WriteLine("InnerException: {0}", ex.InnerException.Message); if (ex.InnerException.InnerException != null) { TestContext.WriteLine("InnerException.Inner: {0}", ex.InnerException.InnerException.Message); } } Assert.Fail("OSLEBot engine failed because {0}", ex.Message); } catch (OSLEBotEngineInitializationException ex)//Thrown when there are no rules to run on the input set. { if (ex.InnerException != null) { TestContext.WriteLine("InnerException: {0}", ex.InnerException.Message); if (ex.InnerException.InnerException != null) { TestContext.WriteLine("InnerException.Inner: {0}", ex.InnerException.InnerException.Message); } } Assert.Fail("OSLEBot engine failed because {0}", ex.Message); } }
/// <summary> /// Runs Asimo (a.k.a. OSLEBot) on the specified input files. /// </summary> /// <param name="fileSet">Set of files to run Asimo on.</param> /// <param name="languageFilter">Collection of languages to filter enlistment by. If empty, no filtering is applied.</param> /// <param name="projectFilter">Collection of projects to filter enlistment by. If empty, no filtering is applied.</param> public override void Run(IEnumerable <ConfigItem> fileSet, IEnumerable <string> languageFilter, IEnumerable <string> projectFilter) { if (fileSet == null) { throw new ArgumentNullException("fileSet"); } if (languageFilter == null) { throw new ArgumentNullException("languageFilter"); } if (projectFilter == null) { throw new ArgumentNullException("projectFilter"); } var assemblyResolver = new AssemblyResolver(new[] { Enlistment.LSBuildToolsPath, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) }); assemblyResolver.Init(); //Apply language and project filters fileSet = ApplyFilters(fileSet, languageFilter, projectFilter); //Split executions per language per locgroup to allow finite time of execution var distinctLanguages = GetDistinctLanguages(fileSet); var distinctProjects = GetDistinctProjects(fileSet); var distinctLocgroups = GetDistinctLocgroups(fileSet); //Additional validation for incorrect filter values (e.g. misspelled language or project name) ValidateFilterAgainstData(languageFilter, distinctLanguages, "language"); ValidateFilterAgainstData(projectFilter, distinctProjects, "project"); var checks = GetCheckFileLocations(); LoggerSAP.Log("One OSLEBot instance will be run against each locgroup."); foreach (var language in distinctLanguages) { foreach (var project in distinctProjects) { foreach (var locgroup in distinctLocgroups) { try { var inputCfg = CreateAsimoConfig(fileSet, checks, language, project, locgroup); if (inputCfg.DataSourcePkgs == null || inputCfg.DataSourcePkgs.Count == 0) { //LoggerSAP.Log("No data sources for {0}, {1}, {2}. Skipping.", language, project, locgroup); continue; } var engine = new OSLEBotEngine(inputCfg); var engineRan = engine.StartRun(); if (engineRan) { LoggerSAP.Trace("Cerberus is waiting for engine activity to complete..."); engine.WaitForJobFinish(); //Wait for complete stop of activity. engine.Cleanup(); } if (engine.EngineLoggedErrors) { LoggerSAP.Error("Engine reported some execution errors."); } } catch (OperationCanceledException ex) { LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message); } catch (OSLEBotEngineInitializationException ex) //Thrown when there are no rules to run on the input set. { LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message); } } } } }
/// <summary> /// Runs Asimo (a.k.a. OSLEBot) on the specified input files and database information to control which checks /// are enabled for which {languages, projects} /// </summary> /// <param name="fileSet">Set of files to run Asimo on.</param> /// <param name="languageFilter">Collection of languages to filter enlistment by. If empty, no filtering is applied.</param> /// <param name="projectFilter">Collection of projects to filter enlistment by. If empty, no filtering is applied.</param> public override void Run(IEnumerable <ConfigItem> fileSet, IEnumerable <string> languageFilter, IEnumerable <string> projectFilter) { var readOnlyDB = new CheckConfiguration(); LoadDataFromDatabase(readOnlyDB); if (fileSet == null) { throw new ArgumentNullException("fileSet"); } if (languageFilter == null) { throw new ArgumentNullException("languageFilter"); } if (projectFilter == null) { throw new ArgumentNullException("projectFilter"); } var assemblyResolver = new AssemblyResolver(new[] { Enlistment.LSBuildToolsPath, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) }); assemblyResolver.Init(); //Apply language and project filters fileSet = ApplyFilters(fileSet, languageFilter, projectFilter); //Split executions per language per locgroup to allow finite time of execution var distinctLanguages = GetDistinctLanguages(fileSet); var distinctProjects = GetDistinctProjects(fileSet); //Additional validation for incorrect filter values (e.g. misspelled language or project name) ValidateFilterAgainstData(languageFilter, distinctLanguages, "language"); ValidateFilterAgainstData(projectFilter, distinctProjects, "project"); var physicalChecks = GetCheckFileLocations(); LoggerSAP.Log("One OSLEBot instance will be run against each project."); foreach (var language in distinctLanguages) { foreach (var project in distinctProjects) { try { var checksEnabledForThisLanguageProject = readOnlyDB.GetEnabledChecks(language, project); var availableEnabledChecks = physicalChecks.Select(c => Path.GetFileNameWithoutExtension(c)) .Intersect(checksEnabledForThisLanguageProject); var phycicalCheckPathsToRun = physicalChecks .Where(c => availableEnabledChecks .Any(cc => Path.GetFileNameWithoutExtension(c).Equals(cc))); if (availableEnabledChecks.Count() == 0) { LoggerSAP.Trace(@"No checks are enabled for [{0}, {1}]. Skipping.", language, project); continue; } var inputCfg = CreateAsimoConfig(fileSet, phycicalCheckPathsToRun, language, project); if (inputCfg.DataSourcePkgs == null || inputCfg.DataSourcePkgs.Count == 0) { //Skip the execution when there is 0 file matches for the specified {language, project} pair. continue; } var engine = new OSLEBotEngine(inputCfg); var engineRan = engine.StartRun(); if (engineRan) { LoggerSAP.Trace("Cerberus is waiting for engine activity to complete..."); engine.WaitForJobFinish(); //Wait for complete stop of activity. engine.Cleanup(); } if (engine.EngineLoggedErrors) { LoggerSAP.Error("Engine reported some execution errors."); } } catch (OperationCanceledException ex) { LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message); } catch (OSLEBotEngineInitializationException ex) //Thrown when there are no rules to run on the input set. { LoggerSAP.Error("OSLEBot engine failed ({0}) because {1}", ex.GetType().Name, ex.Message); } } } }
/// <summary> /// Runs OSLEBot on a set of files. The set of files specified in response file is cross-joined with data in configuration file /// to produce an input configuration for OSLEBot engine. /// </summary> /// <param name="responseFilePath">A list of references to LCX files for OSLEBot processing. Includes additional metadata about project and locgroup.</param> /// <param name="cerberusConfigPath">A Cerberus configuration database which defines the checks that are to be applied by OSLEBot.</param> /// <param name="cerberusOutputPath">A path to be used by Cerberus to create merged output.</param> public OSLEBotResult Run(string responseFilePath, string cerberusConfigPath, string cerberusOutputPath, string oslebotEngineLogPath) { OSLEBotResult result = OSLEBotResult.Success; if (responseFilePath == null) { throw new ArgumentNullException("responseFilePath"); } if (cerberusConfigPath == null) { throw new ArgumentNullException("cerberusConfigPath"); } if (cerberusOutputPath == null) { throw new ArgumentNullException("ceberusOutputPath"); } if (oslebotEngineLogPath == null) { throw new ArgumentNullException("oslebotEngineLogPath"); } IList <InputFileItem> fileList = null; try { fileList = LoadResponseFile(responseFilePath); } catch (Exception e) { throw; } var readOnlyDB = new CheckConfiguration(); LoadDataFromDatabase(readOnlyDB, cerberusConfigPath); //initialize configuration helper. WARNING: thread unsafe if multiple configurations are ever to be used. ConfigurationHelper.Initialize(readOnlyDB); var checkConfigs = ReadCheckConfigsFromDatabase(readOnlyDB); var inputCfg = CreateConfig(fileList, checkConfigs, cerberusOutputPath, oslebotEngineLogPath); try { if (inputCfg.DataSourcePkgs == null || inputCfg.DataSourcePkgs.Count == 0) { //Skip the execution when there is 0 file matches for the specified {language, project} pair. } var engine = new OSLEBotEngine(inputCfg); var engineRan = engine.StartRun(); if (engineRan) { LoggerSAP.Trace("Cerberus is waiting for engine activity to complete..."); engine.WaitForJobFinish(); //Wait for complete stop of activity. engine.Cleanup(); } if (engine.EngineLoggedErrors) { LoggerSAP.Error("Engine reported some execution errors."); result = OSLEBotResult.HandledExceptions; } } // catch and log any exception that was not handled by OSLEBot engine catch (Exception e) { LoggerSAP.Error("OSLEBot engine failed with the following exception:\n{0}", e.GetExceptionDetails(true)); result = OSLEBotResult.HandledExceptions; } return(result); }