public static Method Unresolved(MethodIdentifier methodIdentifier, DeclaredType type) { return(new Method(methodIdentifier, type) { IsResolved = false }); }
public static Method Unresolved(MethodIdentifier methodIdentifier, DeclaredType type, MethodBase declaration, IReferencable returnType) { return(new Method(methodIdentifier, type) { IsResolved = false, declaration = declaration, ReturnType = returnType }); }
public void Test1() { var formatter = new VisualStudioCodeElementsFormatter(); MethodIdentifier methodIdentifier = formatter.CreateIdentifier(_methodName, _params); methodIdentifier.ToString().ShouldEqual(_expected); }
{//what abou tnonymous? public MethodIdentifier CreateIdentifier(string methodFullName, IList<string> parameters) { string converted = ConvertConstructorName(methodFullName); var result = new MethodIdentifier(AppendMethodParameters(converted, parameters)); Trace.WriteLine(methodFullName + " converted to " + result); return result; }
{//what abou tnonymous? public MethodIdentifier CreateIdentifier(string methodFullName, IList <string> parameters) { string converted = ConvertConstructorName(methodFullName); var result = new MethodIdentifier(AppendMethodParameters(converted, parameters)); Trace.WriteLine(methodFullName + " converted to " + result); return(result); }
public static Method Unresolved(MethodIdentifier methodIdentifier, DeclaredType type, MethodInfo representedMethod, IReferencable returnType) { return(new Method(methodIdentifier, type) { IsResolved = false, representedMethod = representedMethod, ReturnType = returnType }); }
private string ConvertConstructorName(string methodFullName) { var id = new MethodIdentifier(methodFullName); if(id.ClassSimpleName == id.MethodNameWithoutParams) { int dotIndex = methodFullName.LastIndexOf('.'); return methodFullName.Substring(0, dotIndex + 1) + ".ctor"; } return methodFullName; }
public async Task <MutationResult> ExecuteMutation(Mutant mutant, CciModuleSource moduleSource) { var type = new TypeIdentifier((INamedTypeDefinition)mutant.MutationTarget.ProcessingContext.Type.Object); var method = new MethodIdentifier((IMethodDefinition)mutant.MutationTarget.ProcessingContext.Method.Object); var filter = new MutationFilter(type.InList(), method.InList()); _log.Debug("ExecuteMutation of: " + type + " - " + method); IMutationOperator mutationOperator = mutant.MutationTarget.OperatorId == null ? new IdentityOperator() : _mutOperators.Single(m => mutant.MutationTarget.OperatorId == m.Info.Id); var cci = moduleSource; try { _log.Info("Execute mutation of " + mutant.MutationTarget + " contained in " + mutant.MutationTarget.MethodRaw + " modules. "); var mutatedModules = new List <IModuleInfo>(); var module = moduleSource.Modules.Single(); var visitorBack = new VisualCodeVisitorBack(mutant.MutationTarget.InList(), _sharedTargets.GetValues(mutationOperator, returnEmptySet: true), module.Module, mutationOperator.Info.Id); var traverser2 = new VisualCodeTraverser(_filter, visitorBack, moduleSource); traverser2.Traverse(module.Module); visitorBack.PostProcess(); var operatorCodeRewriter = mutationOperator.CreateRewriter(); var rewriter = new VisualCodeRewriter(cci.Host, visitorBack.TargetAstObjects, visitorBack.SharedAstObjects, _filter, operatorCodeRewriter, traverser2); operatorCodeRewriter.MutationTarget = new UserMutationTarget(mutant.MutationTarget.Variant.Signature, mutant.MutationTarget.Variant.AstObjects); operatorCodeRewriter.NameTable = cci.Host.NameTable; operatorCodeRewriter.Host = cci.Host; operatorCodeRewriter.Module = module.Module; operatorCodeRewriter.OperatorUtils = _operatorUtils; operatorCodeRewriter.Initialize(); var rewrittenModule = rewriter.Rewrite(module.Module); rewriter.CheckForUnfoundObjects(); mutant.MutationTarget.Variant.AstObjects = null; //TODO: avoiding leaking memory. refactor mutatedModules.Add(new ModuleInfo(rewrittenModule, "")); var result = new MutationResult(mutant, cci, null, mutant.MutationTarget.MethodMutated); mutant.MutationTarget.MethodMutated = null; //TODO: avoiding leaking memory. refactor return(result); } catch (Exception e) { throw new MutationException("CreateMutants failed on operator: {0}.".Formatted(mutationOperator.Info.Name), e); } }
public void IntegrationTestingMiscUtilLight() { string filePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"..\..\..\..\Tests\SampleTestProjectsForTestDiscoveryAndExecution\SampleLogicNunit3Tests\bin\SampleLogic.dll")); string filePathTests = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath), @"..\..\..\..\Tests\SampleTestProjectsForTestDiscoveryAndExecution\SampleLogicNunit3Tests\bin\SampleLogicNunit3Tests.dll")); var cci = new CciModuleSource(filePath); var choices = new MutationSessionChoices(); var tt = cci.Module.Module.GetAllTypes(); // var type = (NamedTypeDefinition)cci.Module.Module.GetAllTypes().Single(t => t.Name.Value == "Range"); // var method = new MethodIdentifier(type.Methods.First(m => m.Name.Value == "Contains")); MethodIdentifier method = null; choices.SelectedOperators.Add(new IdentityOperator2()); choices.Filter = method == null?MutationFilter.AllowAll() : new MutationFilter( new List <TypeIdentifier>(), method.InList()); var options = new OptionsModel(); var muexe = new MutationExecutor(options, choices, null); var mucon = new MutantsContainer(muexe, new OriginalCodebase(cci.InList()), new OptionsModel()); var nodes = mucon.InitMutantsForOperators(ProgressCounter.Inactive()); Mutant mutant = nodes.Cast <CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>()) .OfType <Mutant>().First();//.Take(4); var cciWhite = new CciModuleSource(filePath); var resu = muexe.ExecuteMutation(mutant, cciWhite).Result; using (var file = File.OpenWrite(filePath)) { resu.MutatedModules.WriteToStream(resu.MutatedModules.Modules.Single(), file, filePath); } var runContext = new NUnitTestsRunContext( options, _kernel.Get <IProcesses>(), _kernel.Get <CommonServices>(), new NUnitResultsParser(), TestProjects.NUnitConsolePath, filePathTests, new TestsSelector()); var testResult = runContext.RunTests().Result; var count = testResult.ResultMethods .GroupBy(t => t.State) .ToDictionary(t => t.Key); var countStrings = count.Select(pair => pair.Key.ToString() + ": " + pair.Value.Count()); _log.Info(string.Format("All test results: " + string.Join(" ", countStrings))); count[TestNodeState.Failure].Count().ShouldEqual(0); }
private string ConvertConstructorName(string methodFullName) { var id = new MethodIdentifier(methodFullName); if (id.ClassSimpleName == id.MethodNameWithoutParams) { int dotIndex = methodFullName.LastIndexOf('.'); return(methodFullName.Substring(0, dotIndex + 1) + ".ctor"); } return(methodFullName); }
public bool GetCurrentClassAndMethod(out MethodIdentifier methodIdentifier) { if (_parser.MethodIdentifier != "null") { methodIdentifier = new MethodIdentifier(_parser.MethodIdentifier); } else { methodIdentifier = null; } return true; }
public bool GetCurrentClassAndMethod(out MethodIdentifier methodIdentifier) { if (_parser.MethodIdentifier != "null") { methodIdentifier = new MethodIdentifier(_parser.MethodIdentifier); } else { methodIdentifier = null; } return(true); }
public void WhenMethodIdUnknownClassIdReturned() { // arrange var methodIdentifier = new MethodIdentifier(); var methodId = methodIdentifier.Record(1, "A", "B"); // act var retVal = methodIdentifier.Record(1, "C", "D"); // assert Assert.AreEqual(methodId + 1, retVal); Assert.AreEqual("C", methodIdentifier.Lookup(methodId + 1).Name); }
public async Task <IObjectRoot <SessionController> > CreateSession(MethodIdentifier methodIdentifier, List <string> testAssemblies, bool auto) { _whiteCache.Pause(true); try { AutoCreationController creationController = _autoCreationControllerFactory.Create(); var choices = await creationController.Run(methodIdentifier, testAssemblies, auto); var original = new OriginalCodebase(LoadAssemblies().Result, testAssemblies.ToEmptyIfNull().ToList()); _log.Info("Created original codebase with assemblies to mutate: " + original.ModulesToMutate.Select(m => m.Module.Name).MakeString()); return(_sessionFactory.CreateWithBindings(choices, original)); } finally { _whiteCache.Pause(false); } }
public List <TestCaseAssociationData> AssociateTestCases() { var resultList = new List <TestCaseAssociationData>(); List <AttributedMethod> attributedMethods = MethodIdentifier.GetAllAttributedMethodsInAssemblies <TestCaseIdAttribute>(); foreach (var method in attributedMethods) { TestCaseIdAttribute attribute = (TestCaseIdAttribute)Attribute.GetCustomAttribute(method.MethodInfo, typeof(TestCaseIdAttribute)); resultList.Add(new TestCaseAssociationData { AutomatedTestName = method.Type.FullName + "." + method.MethodInfo.Name, AutomatedTestStorage = method.AssemblyName, TestCaseId = attribute.TestId }); } return(resultList); }
public TraceDataCollector(IMessageProtocol messageProtocol, BufferService bufferService, ClassIdentifier classIdentifier, MethodIdentifier methodIdentifier, IErrorHandler errorHandler, ILog logger) { _messageProtocol = messageProtocol ?? throw new ArgumentNullException(nameof(messageProtocol)); _bufferService = bufferService ?? throw new ArgumentNullException(nameof(bufferService)); _classIdentifier = classIdentifier ?? throw new ArgumentNullException(nameof(classIdentifier)); _methodIdentifier = methodIdentifier ?? throw new ArgumentNullException(nameof(methodIdentifier)); _errorHandler = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _methodIdAdapter = new MethodIdAdapter(this); _task = Task.Run(() => ReadTraceMessages()); }
public bool GetCurrentClassAndMethod(out MethodIdentifier methodIdentifier) { methodIdentifier = null; //EnvDTE80.vsCMParameterKind.vsCMParameterKin CodeFunction methodAtCaret = new VisualStudioCodeSearcher().GetMethodAtCaret(_dte); if (methodAtCaret != null) { var parameters = methodAtCaret.Parameters.Cast <CodeParameter2>().ToList(); var names = parameters.Select(p => GetKindString(p) + (string.IsNullOrEmpty(p.Type.AsFullName) ? TranslateTypeName(p.Type.AsString) : p.Type.AsFullName)).ToList(); methodIdentifier = new VisualStudioCodeElementsFormatter() .CreateIdentifier(methodAtCaret.FullName, names); return(true); } return(false); }
public async Task<IObjectRoot<SessionController>> CreateSession(MethodIdentifier methodIdentifier, List<string> testAssemblies, bool auto) { _whiteCache.Pause(true); try { AutoCreationController creationController = _autoCreationControllerFactory.Create(); var choices = await creationController.Run(methodIdentifier, testAssemblies, auto); var original = new OriginalCodebase(LoadAssemblies().Result, testAssemblies.ToEmptyIfNull().ToList()); _log.Info("Created original codebase with assemblies to mutate: "+ original.ModulesToMutate.Select(m => m.Module.Name).MakeString()); return _sessionFactory.CreateWithBindings(choices, original); } finally { _whiteCache.Pause(false); } }
public void UpdateFrom(ResolveOperationBeginningMessage message) { LifetimeScope lifetimeScope; if (!_lifetimeScopes.TryGetItem(message.ResolveOperation.LifetimeScopeId, out lifetimeScope)) { throw new InvalidOperationException("Resolve operation beginning in an unknown lifetime scope."); } Thread thread; if (!_threads.TryGetItem(message.ResolveOperation.ThreadId, out thread)) { thread = new Thread(message.ResolveOperation.ThreadId); _threads.Add(thread); } ResolveOperation parent = null; if (thread.ResolveOperationStack.Count != 0) { parent = thread.ResolveOperationStack.Peek(); } MethodIdentifier callingMethod = null; if (message.ResolveOperation.CallingMethodName != null) { callingMethod = new MethodIdentifier(message.ResolveOperation.CallingMethodName, TypeIdentifier.Parse(message.ResolveOperation.CallingTypeAssemblyQualifiedName)); } var resolveOperation = new ResolveOperation(message.ResolveOperation.Id, lifetimeScope, thread, parent, callingMethod); if (parent != null) { parent.SubOperations.Add(resolveOperation); } _resolveOperations.Add(resolveOperation); thread.ResolveOperationStack.Push(resolveOperation); }
public async Task RunMutationSession(MethodIdentifier methodIdentifier = null, List <string> testAssemblies = null, bool auto = false) { //_host.Build(); _log.Info("Showing mutation session window."); var continuousConfiguration = _continuousConfigurator.GetConfiguration(); var sessionConfiguration = await Task.Run(() => continuousConfiguration.Get.CreateSessionConfiguration()); try { IObjectRoot <SessionController> sessionController = await sessionConfiguration.Get.CreateSession(methodIdentifier, testAssemblies, auto); Clean(); _sessionConfiguration = sessionConfiguration; _currentSessionController = sessionController; _viewModel.MutantDetailsViewModel = _currentSessionController.Get.MutantDetailsController.ViewModel; Subscribe(_currentSessionController.Get); try { _log.Info("Starting mutation session..."); await _currentSessionController.Get.RunMutationSession(_controlSource); } catch (TaskCanceledException) { _log.Info("Session cancelled."); } } catch (TaskCanceledException) { // cancelled by user _log.Info("Session creation cancelled."); } }
/// <summary> /// Models constructor of native object /// </summary> /// <param name="flow">FlowController</param> public void initObject(FlowController flow) { var nativeClass = NativeObjectAnalyzer.GetInstance(flow.OutSet).GetClass(ObjectName); var fields = nativeClass.Fields; var thisVariable = flow.OutSet.GetVariable(new VariableIdentifier("this")); List <Value> inputValues = new List <Value>(); foreach (var argument in getArguments(flow)) { inputValues.AddRange(argument.PossibleValues); } MethodIdentifier methodIdentifier = new MethodIdentifier(ObjectName, Method.Name.Name); if (NativeObjectAnalyzer.ReportingFunctions.ContainsKey(methodIdentifier)) { foreach (var flag in NativeObjectAnalyzer.ReportingFunctions[methodIdentifier]) { if (FlagsHandler.IsDirty(inputValues, flag)) { AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisSecurityWarning(NativeAnalyzerUtils.GetCallerScript(flow.OutSet), flow.CurrentPartial, flow.CurrentProgramPoint, flag, methodIdentifier.Name.ToString())); break; } } } foreach (FieldInfo field in fields.Values) { if (field.IsStatic == false) { MemoryEntry fieldValues = NativeAnalyzerUtils.ResolveReturnValue(field.Type, flow); fieldValues = new MemoryEntry(FlagsHandler.CopyFlags(inputValues, fieldValues.PossibleValues)); var fieldEntry = thisVariable.ReadField(flow.OutSet.Snapshot, new VariableIdentifier(field.Name.Value)); fieldEntry.WriteMemory(flow.OutSet.Snapshot, fieldValues); } } }
public async Task RunMutationSession(MethodIdentifier methodIdentifier = null, List<string> testAssemblies = null, bool auto = false) { //_host.Build(); _log.Info("Showing mutation session window."); var continuousConfiguration = _continuousConfigurator.GetConfiguration(); var sessionConfiguration = await Task.Run(() => continuousConfiguration.Get.CreateSessionConfiguration()); try { IObjectRoot<SessionController> sessionController = await sessionConfiguration.Get.CreateSession(methodIdentifier, testAssemblies, auto); Clean(); _sessionConfiguration = sessionConfiguration; _currentSessionController = sessionController; _viewModel.MutantDetailsViewModel = _currentSessionController.Get.MutantDetailsController.ViewModel; Subscribe(_currentSessionController.Get); try { _log.Info("Starting mutation session..."); await _currentSessionController.Get.RunMutationSession(_controlSource); } catch (TaskCanceledException) { _log.Info("Session cancelled."); } } catch (TaskCanceledException) { // cancelled by user _log.Info("Session creation cancelled."); } }
public MethodIdentifierAttribute(MethodIdentifier identifier, Type arg1, Type arg2, Type arg3, Type arg4) { this.argumentTypes = null; this.identifier = identifier; this.argumentTypes = new Type[] { arg1, arg2, arg3, arg4 }; }
protected bool Equals(MethodIdentifier other) { return(string.Equals(_className, other._className) && string.Equals(_methodName, other._methodName)); }
public void RetainsMethodName() { var identifier = new MethodIdentifier(CreateDefinition("SomeName", MethodAttributes.Static | MethodAttributes.Public, typeof(void))); Assert.AreEqual("SomeName", identifier.Name); }
public MethodIdentifierAttribute(MethodIdentifier identifier) { this.argumentTypes = null; this.identifier = identifier; this.argumentTypes = new Type[0]; }
public async Task<MutationSessionChoices> Run(MethodIdentifier singleMethodToMutate = null, List<string> testAssemblies = null, bool auto = false) { _sessionCreationWindowShowTime = DateTime.Now; SessionCreator sessionCreator = _sessionCreatorFactory.Create(); Task<List<CciModuleSource>> assembliesTask = _sessionConfiguration.LoadAssemblies(); // Task<List<MethodIdentifier>> coveringTask = sessionCreator.FindCoveringTests(assembliesTask, matcher); Task<TestsRootNode> testsTask = _sessionConfiguration.LoadTests(); ITestsSelectStrategy testsSelector; bool constrainedMutation = false; ICodePartsMatcher matcher; if (singleMethodToMutate != null) { matcher = new CciMethodMatcher(singleMethodToMutate); testsSelector = new CoveringTestsSelectStrategy(assembliesTask, matcher, testsTask); constrainedMutation = true; } else { testsSelector = new AllTestsSelectStrategy(testsTask); matcher = new AllMatcher(); } _log.Info("Selecting tests in assemblies: "+ testAssemblies.MakeString()); var testsSelecting = testsSelector.SelectTests(testAssemblies); var t1 = sessionCreator.GetOperators(); var t2 = sessionCreator.BuildAssemblyTree(assembliesTask, constrainedMutation, matcher); var t11 = t1.ContinueWith(task => { _viewModel.MutationsTree.MutationPackages = new ReadOnlyCollection<PackageNode>(task.Result.Packages); },CancellationToken.None, TaskContinuationOptions.NotOnFaulted, _execute.GuiScheduler); var t22 = t2.ContinueWith(task => { if (_typesManager.IsAssemblyLoadError) { _svc.Logging.ShowWarning(UserMessages.WarningAssemblyNotLoaded()); } var assembliesToMutate = task.Result.Where(a => !testAssemblies.ToEmptyIfNull().Contains(a.AssemblyPath.Path)).ToList(); //assembliesToMutate = ClassCoverage.UnmarkNotCovered(assembliesToMutate,testAssemblies); _viewModel.TypesTreeMutate.Assemblies = new ReadOnlyCollection<AssemblyNode>(assembliesToMutate); _whiteSource = assembliesTask.Result; }, CancellationToken.None, TaskContinuationOptions.NotOnFaulted, _execute.GuiScheduler); var t33 = testsSelecting.ContinueWith(task => { _viewModel.TypesTreeToTest.TestAssemblies = new ReadOnlyCollection<TestNodeAssembly>(task.Result); if (_options.UseCodeCoverage) { ClassCoverage.UnmarkNotCovered(_viewModel.TypesTreeMutate.Assemblies, _viewModel.TypesTreeToTest.TestAssemblies); } }, CancellationToken.None, TaskContinuationOptions.NotOnFaulted, _execute.GuiScheduler); try { var mainTask = Task.WhenAll(t1, t2, testsSelecting, t11, t22, t33).ContinueWith(t => { if (t.Exception != null) { ShowError(t.Exception); _viewModel.Close(); tcs.TrySetCanceled(); } }, _execute.GuiScheduler); var wrappedTask = Task.WhenAll(tcs.Task, mainTask); if (_sessionConfiguration.AssemblyLoadProblem) { new TaskFactory(_dispatcher.GuiScheduler) .StartNew(() => _svc.Logging.ShowWarning(UserMessages.WarningAssemblyNotLoaded())); } return await WaitForResult(auto, wrappedTask); } catch (Exception e) { _log.Error(e); throw; } }
public LimitedScopeStrategy(MethodIdentifier singleMethod) { _singleMethod = singleMethod; _matcher = new CciMethodMatcher(singleMethod); }
private IEnumerable <Mutant> SetupMutations(OriginalCodebase original, List <FilePathAbsolute> paths, List <string> toMutate, List <IMutationOperator> operators, MethodIdentifier method = null) { var options = new OptionsModel(); options.OtherParams = "--debugfiles true"; _kernel.Bind <IProjectClonesManager>().To <ProjectClonesManager>().InSingletonScope(); _kernel.Bind <ProjectFilesClone>().ToSelf().AndFromFactory(); _kernel.Bind <FilesManager>().ToSelf().InSingletonScope(); _kernel.Bind <TestServiceManager>().ToSelf().InSingletonScope(); _kernel.Bind <XUnitTestService>().ToSelf().InSingletonScope(); _kernel.Bind <XUnitResultsParser>().ToSelf().InSingletonScope(); _kernel.Bind <WhiteCache>().ToSelf().AndFromFactory(); _kernel.Bind <INUnitWrapper>().To <NUnitWrapper>().InSingletonScope(); _kernel.Bind <OriginalCodebase>().ToConstant(original); _kernel.Bind <ICodeDifferenceCreator>().To <CodeDifferenceCreator>().InSingletonScope(); _kernel.Bind <ICodeVisualizer>().To <CodeVisualizer>().InSingletonScope(); _kernel.Bind <IMutantsCache>().To <MutantsCache>().InSingletonScope(); _kernel.Bind <NUnitTestsRunContext>().ToSelf().AndFromFactory(); _kernel.Bind <XUnitTestsRunContext>().ToSelf().AndFromFactory(); _kernel.Bind <OptionsModel>().ToConstant(options); _kernel.Bind <IMutationExecutor>().To <MutationExecutor>().InSingletonScope(); _kernel.Bind <TestingMutant>().ToSelf().AndFromFactory(); _kernel.Bind <TestLoader>().ToSelf().AndFromFactory(); _kernel.BindMock <IHostEnviromentConnection>(mock => { mock.Setup(_ => _.GetProjectAssemblyPaths()).Returns(paths); mock.Setup(_ => _.GetTempPath()).Returns(Path.GetTempPath()); }); _kernel.Get <ISettingsManager>()["NUnitConsoleDirPath"] = TestProjects.NUnitConsoleDirPath; _kernel.Get <ISettingsManager>()["XUnitConsoleDirPath"] = TestProjects.XUnitConsoleDirPath; _kernel.Bind <IWhiteSource>().ToConstant(new WhiteDummy(toMutate)); var testsClone = _kernel.Get <IProjectClonesManager>().CreateClone("Tests"); var testsTask = _kernel.Get <TestsLoader>().LoadTests(testsClone.Assemblies.AsStrings().ToList()); var strategy = new AllTestsSelectStrategy(testsTask); var choices = new MutationSessionChoices { Filter = method == null?MutationFilter.AllowAll() : new MutationFilter( new List <TypeIdentifier>(), method.InList()), SelectedOperators = operators, TestAssemblies = strategy.SelectTests(null).Result }; _kernel.Bind <MutationSessionChoices>().ToConstant(choices); var exec = _kernel.Get <MutationExecutor>(); var container = new MutantsContainer(exec, original); IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mutants = assemblies.Cast <CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>()) .OfType <Mutant>();//.Take(4); return(mutants); }
private ClassDecl convertToType(TypeDecl declaration) { ClassDeclBuilder result = new ClassDeclBuilder(); result.BaseClasses = new List <QualifiedName>(); if (declaration.BaseClassName.HasValue) { result.BaseClasses.Add(declaration.BaseClassName.Value.QualifiedName); } result.IsFinal = declaration.Type.IsFinal; result.IsInterface = declaration.Type.IsInterface; result.IsAbstract = declaration.Type.IsAbstract; result.QualifiedName = new QualifiedName(declaration.Name); foreach (var member in declaration.Members) { if (member is FieldDeclList) { foreach (FieldDecl field in (member as FieldDeclList).Fields) { Visibility visibility; if (member.Modifiers.HasFlag(PhpMemberAttributes.Private)) { visibility = Visibility.PRIVATE; } else if (member.Modifiers.HasFlag(PhpMemberAttributes.Protected)) { visibility = Visibility.PROTECTED; } else { visibility = Visibility.PUBLIC; } bool isStatic = member.Modifiers.HasFlag(PhpMemberAttributes.Static); //multiple declaration of fields if (result.Fields.ContainsKey(new FieldIdentifier(result.QualifiedName, field.Name))) { //dont need to set warning in simpleAnalysis // setWarning("Cannot redeclare field " + field.Name, member, AnalysisWarningCause.CLASS_MULTIPLE_FIELD_DECLARATION); } else { result.Fields.Add(new FieldIdentifier(result.QualifiedName, field.Name), new FieldInfo(field.Name, result.QualifiedName, "any", visibility, field.Initializer, isStatic)); } } } else if (member is ConstDeclList) { foreach (var constant in (member as ConstDeclList).Constants) { if (result.Constants.ContainsKey(new FieldIdentifier(result.QualifiedName, constant.Name))) { //dont need to set warning in simpleAnalysis // setWarning("Cannot redeclare constant " + constant.Name, member, AnalysisWarningCause.CLASS_MULTIPLE_CONST_DECLARATION); } else { //in php all object constatns are public Visibility visbility = Visibility.PUBLIC; result.Constants.Add(new FieldIdentifier(result.QualifiedName, constant.Name), new ConstantInfo(constant.Name, result.QualifiedName, visbility, constant.Initializer)); } } } else if (member is MethodDecl) { var methosIdentifier = new MethodIdentifier(result.QualifiedName, (member as MethodDecl).Name); if (!result.SourceCodeMethods.ContainsKey(methosIdentifier)) { result.SourceCodeMethods.Add(methosIdentifier, OutSet.CreateFunction(member as MethodDecl, Flow.CurrentScript)); } else { //dont need to set warning in simpleAnalysis // setWarning("Cannot redeclare constant " + (member as MethodDecl).Name, member, AnalysisWarningCause.CLASS_MULTIPLE_CONST_DECLARATION); } } else { //ignore traits are not supported by AST, only by parser } } // NativeTypeDecl result=new NativeTypeDecl(); return(result.Build()); }
public LimitedScopeStrategy(MethodIdentifier singleMethod) { _singleMethod = singleMethod; _matcher = new CciMethodMatcher(singleMethod); }
public MethodIdentifierAttribute(MethodIdentifier identifier) { this.argumentTypes = null; this.identifier = identifier; this.argumentTypes = new Type[0]; }
public MethodIdentifierAttribute(MethodIdentifier identifier, Type arg1, Type arg2, Type arg3, Type arg4) { this.argumentTypes = null; this.identifier = identifier; this.argumentTypes = new Type[] { arg1, arg2, arg3, arg4 }; }
public MethodIdentifierAttribute(MethodIdentifier identifier, Type arg1, Type arg2, Type arg3) : this(identifier, arg1, arg2, arg3, null) { this.identifier = identifier; this.argumentTypes = new Type[] { arg1, arg2, arg3 }; }
private IEnumerable<Mutant> SetupMutations(OriginalCodebase original, List<FilePathAbsolute> paths, List<string> toMutate, List<IMutationOperator> operators, MethodIdentifier method= null) { var options = new OptionsModel(); options.OtherParams = "--debugfiles true"; _kernel.Bind<IProjectClonesManager>().To<ProjectClonesManager>().InSingletonScope(); _kernel.Bind<ProjectFilesClone>().ToSelf().AndFromFactory(); _kernel.Bind<FilesManager>().ToSelf().InSingletonScope(); _kernel.Bind<TestServiceManager>().ToSelf().InSingletonScope(); _kernel.Bind<XUnitTestService>().ToSelf().InSingletonScope(); _kernel.Bind<XUnitResultsParser>().ToSelf().InSingletonScope(); _kernel.Bind<WhiteCache>().ToSelf().AndFromFactory(); _kernel.Bind<INUnitWrapper>().To<NUnitWrapper>().InSingletonScope(); _kernel.Bind<OriginalCodebase>().ToConstant(original); _kernel.Bind<ICodeDifferenceCreator>().To<CodeDifferenceCreator>().InSingletonScope(); _kernel.Bind<ICodeVisualizer>().To<CodeVisualizer>().InSingletonScope(); _kernel.Bind<IMutantsCache>().To<MutantsCache>().InSingletonScope(); _kernel.Bind<NUnitTestsRunContext>().ToSelf().AndFromFactory(); _kernel.Bind<XUnitTestsRunContext>().ToSelf().AndFromFactory(); _kernel.Bind<OptionsModel>().ToConstant(options); _kernel.Bind<IMutationExecutor>().To<MutationExecutor>().InSingletonScope(); _kernel.Bind<TestingMutant>().ToSelf().AndFromFactory(); _kernel.Bind<TestLoader>().ToSelf().AndFromFactory(); _kernel.BindMock<IHostEnviromentConnection>(mock => { mock.Setup(_ => _.GetProjectAssemblyPaths()).Returns(paths); mock.Setup(_ => _.GetTempPath()).Returns(Path.GetTempPath()); }); _kernel.Get<ISettingsManager>()["NUnitConsoleDirPath"] = TestProjects.NUnitConsoleDirPath; _kernel.Get<ISettingsManager>()["XUnitConsoleDirPath"] = TestProjects.XUnitConsoleDirPath; _kernel.Bind<IWhiteSource>().ToConstant(new WhiteDummy(toMutate)); var testsClone = _kernel.Get<IProjectClonesManager>().CreateClone("Tests"); var testsTask = _kernel.Get<TestsLoader>().LoadTests(testsClone.Assemblies.AsStrings().ToList()); var strategy = new AllTestsSelectStrategy(testsTask); var choices = new MutationSessionChoices { Filter = method == null ? MutationFilter.AllowAll() : new MutationFilter( new List<TypeIdentifier>(), method.InList()), SelectedOperators = operators, TestAssemblies = strategy.SelectTests(null).Result }; _kernel.Bind<MutationSessionChoices>().ToConstant(choices); var exec = _kernel.Get<MutationExecutor>(); var container = new MutantsContainer(exec, original); IList<AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mutants = assemblies.Cast<CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection<CheckedNode>()) .OfType<Mutant>();//.Take(4); return mutants; }
public CciMethodMatchingTests(string method) { _context = new MethodIdentifier(method); }
/// <summary> /// Models a called method. /// </summary> /// <param name="flow"></param> public void Analyze(FlowController flow) { if (NativeAnalyzerUtils.checkArgumentsCount(flow, Method)) { NativeAnalyzerUtils.checkArgumentTypes(flow, Method); } MethodIdentifier methodIdentifier = new MethodIdentifier(ObjectName, Method.Name.Name); var nativeClass = NativeObjectAnalyzer.GetInstance(flow.OutSet).GetClass(ObjectName); var fields = nativeClass.Fields; var functionResult = NativeAnalyzerUtils.ResolveReturnValue(Method.ReturnType, flow); var arguments = getArguments(flow); var thisVariable = flow.OutSet.GetVariable(new VariableIdentifier("this")); List <Value> inputValues = new List <Value>(); bool isStaticCall = false; if (thisVariable.ReadMemory(flow.OutSet.Snapshot).PossibleValues.Count() == 1 && thisVariable.ReadMemory(flow.OutSet.Snapshot).PossibleValues.First() is UndefinedValue) { isStaticCall = true; var fieldsEntries = new List <MemoryEntry>(); foreach (FieldInfo field in fields.Values) { var fieldEntry = thisVariable.ReadField(flow.OutSet.Snapshot, new VariableIdentifier(field.Name.Value)); fieldsEntries.Add(fieldEntry.ReadMemory(flow.OutSet.Snapshot)); inputValues.AddRange(fieldEntry.ReadMemory(flow.OutSet.Snapshot).PossibleValues); } fieldsEntries.AddRange(arguments); foreach (FieldInfo field in fields.Values) { var fieldEntry = thisVariable.ReadField(flow.OutSet.Snapshot, new VariableIdentifier(field.Name.Value)); MemoryEntry newfieldValues = NativeAnalyzerUtils.ResolveReturnValue(field.Type, flow); newfieldValues = new MemoryEntry(FlagsHandler.CopyFlags(inputValues, newfieldValues.PossibleValues)); HashSet <Value> newValues = new HashSet <Value>((fieldEntry.ReadMemory(flow.OutSet.Snapshot)).PossibleValues); foreach (var newValue in newfieldValues.PossibleValues) { newValues.Add(newValue); } thisVariable.ReadField(flow.OutSet.Snapshot, new VariableIdentifier(field.Name.Value)).WriteMemory(flow.OutSet.Snapshot, new MemoryEntry(newValues)); } } foreach (var argument in arguments) { inputValues.AddRange(argument.PossibleValues); } if (NativeObjectAnalyzer.ReportingFunctions.ContainsKey(methodIdentifier)) { foreach (var flag in NativeObjectAnalyzer.ReportingFunctions[methodIdentifier]) { if (FlagsHandler.IsDirty(inputValues, flag)) { AnalysisWarningHandler.SetWarning(flow.OutSet, new AnalysisSecurityWarning(NativeAnalyzerUtils.GetCallerScript(flow.OutSet), flow.CurrentPartial, flow.CurrentProgramPoint, flag, methodIdentifier.Name.ToString())); break; } } } if (isStaticCall == true) { thisVariable.WriteMemory(flow.OutSet.Snapshot, new MemoryEntry(FlagsHandler.CopyFlags(inputValues, thisVariable.ReadMemory(flow.OutSet.Snapshot).PossibleValues))); } functionResult = new MemoryEntry(FlagsHandler.CopyFlags(inputValues, functionResult.PossibleValues)); if (NativeObjectAnalyzer.CleaningFunctions.ContainsKey(methodIdentifier)) { foreach (var flag in NativeObjectAnalyzer.CleaningFunctions[methodIdentifier]) { functionResult = new MemoryEntry(FlagsHandler.Clean(functionResult.PossibleValues, flag)); } } flow.OutSet.GetLocalControlVariable(SnapshotBase.ReturnValue).WriteMemory(flow.OutSet.Snapshot, functionResult); var assigned_aliases = NativeAnalyzerUtils.ResolveAliasArguments(flow, inputValues, (new NativeFunction[1] { Method }).ToList()); }
/// <summary> /// Initializes a new instance of the <see cref="Method" /> class. /// </summary> /// <param name="identifier"> /// The identifier. /// </param> /// <param name="type"> /// The type. /// </param> public Method(MethodIdentifier identifier, DeclaredType type) : base(identifier) { Type = type; Returns = new Summary(); }
public async Task <MutationSessionChoices> Run(MethodIdentifier singleMethodToMutate = null, List <string> testAssemblies = null, bool auto = false) { _sessionCreationWindowShowTime = DateTime.Now; SessionCreator sessionCreator = _sessionCreatorFactory.Create(); Task <List <CciModuleSource> > assembliesTask = _sessionConfiguration.LoadAssemblies(); // Task<List<MethodIdentifier>> coveringTask = sessionCreator.FindCoveringTests(assembliesTask, matcher); Task <TestsRootNode> testsTask = _sessionConfiguration.LoadTests(); ITestsSelectStrategy testsSelector; bool constrainedMutation = false; ICodePartsMatcher matcher; if (singleMethodToMutate != null) { matcher = new CciMethodMatcher(singleMethodToMutate); testsSelector = new CoveringTestsSelectStrategy(assembliesTask, matcher, testsTask); constrainedMutation = true; } else { testsSelector = new AllTestsSelectStrategy(testsTask); matcher = new AllMatcher(); } _log.Info("Selecting tests in assemblies: " + testAssemblies.MakeString()); var testsSelecting = testsSelector.SelectTests(testAssemblies); var t1 = sessionCreator.GetOperators(); var t2 = sessionCreator.BuildAssemblyTree(assembliesTask, constrainedMutation, matcher); var t11 = t1.ContinueWith(task => { _viewModel.MutationsTree.MutationPackages = new ReadOnlyCollection <PackageNode>(task.Result.Packages); }, CancellationToken.None, TaskContinuationOptions.NotOnFaulted, _execute.GuiScheduler); var t22 = t2.ContinueWith(task => { if (_typesManager.IsAssemblyLoadError) { _svc.Logging.ShowWarning(UserMessages.WarningAssemblyNotLoaded()); } var assembliesToMutate = task.Result.Where(a => !testAssemblies.ToEmptyIfNull().Contains(a.AssemblyPath.Path)).ToList(); //assembliesToMutate = ClassCoverage.UnmarkNotCovered(assembliesToMutate,testAssemblies); _viewModel.TypesTreeMutate.Assemblies = new ReadOnlyCollection <AssemblyNode>(assembliesToMutate); _whiteSource = assembliesTask.Result; }, CancellationToken.None, TaskContinuationOptions.NotOnFaulted, _execute.GuiScheduler); var t33 = testsSelecting.ContinueWith(task => { _viewModel.TypesTreeToTest.TestAssemblies = new ReadOnlyCollection <TestNodeAssembly>(task.Result); if (_options.UseCodeCoverage) { ClassCoverage.UnmarkNotCovered(_viewModel.TypesTreeMutate.Assemblies, _viewModel.TypesTreeToTest.TestAssemblies); } }, CancellationToken.None, TaskContinuationOptions.NotOnFaulted, _execute.GuiScheduler); try { var mainTask = Task.WhenAll(t1, t2, testsSelecting, t11, t22, t33).ContinueWith(t => { if (t.Exception != null) { ShowError(t.Exception); _viewModel.Close(); tcs.TrySetCanceled(); } }, _execute.GuiScheduler); var wrappedTask = Task.WhenAll(tcs.Task, mainTask); if (_sessionConfiguration.AssemblyLoadProblem) { new TaskFactory(_dispatcher.GuiScheduler) .StartNew(() => _svc.Logging.ShowWarning(UserMessages.WarningAssemblyNotLoaded())); } return(await WaitForResult(auto, wrappedTask)); } catch (Exception e) { _log.Error(e); throw; } }
public CciMethodMatchingTests(string method) { _context = new MethodIdentifier(method); }
public MethodIdentifierAttribute(MethodIdentifier identifier, Type arg1, Type arg2, Type arg3) : this(identifier, arg1, arg2, arg3, null) { this.identifier = identifier; this.argumentTypes = new Type[] { arg1, arg2, arg3 }; }
public async Task<MutationResult> ExecuteMutation(Mutant mutant, CciModuleSource moduleSource) { var type = new TypeIdentifier((INamedTypeDefinition) mutant.MutationTarget.ProcessingContext.Type.Object); var method = new MethodIdentifier((IMethodDefinition) mutant.MutationTarget.ProcessingContext.Method.Object); var filter = new MutationFilter(type.InList(), method.InList()); _log.Debug("ExecuteMutation of: " + type+" - " +method ); IMutationOperator mutationOperator = mutant.MutationTarget.OperatorId == null ? new IdentityOperator() : _mutOperators.Single(m => mutant.MutationTarget.OperatorId == m.Info.Id); var cci = moduleSource; try { _log.Info("Execute mutation of " + mutant.MutationTarget + " contained in " + mutant.MutationTarget.MethodRaw + " modules. "); var mutatedModules = new List<IModuleInfo>(); var module = moduleSource.Modules.Single(); var visitorBack = new VisualCodeVisitorBack(mutant.MutationTarget.InList(), _sharedTargets.GetValues(mutationOperator, returnEmptySet: true), module.Module, mutationOperator.Info.Id); var traverser2 = new VisualCodeTraverser(_filter, visitorBack, moduleSource); traverser2.Traverse(module.Module); visitorBack.PostProcess(); var operatorCodeRewriter = mutationOperator.CreateRewriter(); var rewriter = new VisualCodeRewriter(cci.Host, visitorBack.TargetAstObjects, visitorBack.SharedAstObjects, _filter, operatorCodeRewriter, traverser2); operatorCodeRewriter.MutationTarget = new UserMutationTarget(mutant.MutationTarget.Variant.Signature, mutant.MutationTarget.Variant.AstObjects); operatorCodeRewriter.NameTable = cci.Host.NameTable; operatorCodeRewriter.Host = cci.Host; operatorCodeRewriter.Module = module.Module; operatorCodeRewriter.OperatorUtils = _operatorUtils; operatorCodeRewriter.Initialize(); var rewrittenModule = rewriter.Rewrite(module.Module); rewriter.CheckForUnfoundObjects(); mutant.MutationTarget.Variant.AstObjects = null; //TODO: avoiding leaking memory. refactor mutatedModules.Add(new ModuleInfo(rewrittenModule, "")); List<ICciModuleSource> cci1 = new List<ICciModuleSource>(); cci1.Add(cci); List<IMethodDefinition> methodMutated = new List<IMethodDefinition>(); methodMutated.Add(mutant.MutationTarget.MethodMutated); var result = new MutationResult(mutant, cci/*1*/, null, mutant.MutationTarget.MethodMutated); mutant.MutationTarget.MethodMutated = null; //TODO: avoiding leaking memory. refactor return result; } catch (Exception e) { throw new MutationException("CreateMutants failed on operator: {0}.".Formatted(mutationOperator.Info.Name), e); } }
protected bool Equals(MethodIdentifier other) { return string.Equals(_className, other._className) && string.Equals(_methodName, other._methodName); }