public void Test1() { var assemblyFile = new TestAssemblyFile(); var assembly = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath); var dinnersController = assembly.MainModule.Types.Single(t => t.Name == "DinnersController"); var createMethod = dinnersController.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1); var instr = createMethod.Body.Instructions.Single(i => { if (i.OpCode == OpCodes.Call) { var method = ((MethodReference)i.Operand); if (method.DeclaringType.FullName == "System.Web.Mvc.Controller" && method.Name == "View") // && method.Parameters.Count == 0) { return(true); } } return(false); }); var mutator = new ReplaceViewWithRedirectToAction(); var mutationSessionChoices = new MutationSessionChoices { SelectedOperators = new[] { mutator }, Assemblies = new[] { assembly }, SelectedTypes = assembly.MainModule.Types }; MutantsContainer mutantsContainer = new MutantsContainer(); var executedOperator = mutantsContainer.GenerateMutantsForOperators(mutationSessionChoices).Single(); executedOperator.Mutants.Single(mut => { var assembly2 = mut.MutationResult.MutatedAssemblies.Single(); var dinnersController2 = assembly2.MainModule.Types.Single(t => t.Name == "DinnersController"); var createMethod2 = dinnersController2.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1); var instr3 = createMethod2.Body.Instructions.Where(i => { if (i.OpCode == OpCodes.Call) { var method = ((MethodReference)i.Operand); if (method.DeclaringType.FullName == "System.Web.Mvc.Controller" && method.Name == "RedirectToAction") // && method.Parameters.Count == 0) { return(true); } } return(false); }); return(instr3.Count() == (2)); }); }
public SessionController( IDispatcherExecute dispatcher, CommonServices svc, MutantDetailsController mutantDetailsController, IMutantsContainer mutantsContainer, ITestsContainer testsContainer, IFactory <ResultsSavingController> resultsSavingFactory, IFactory <TestingProcess> testingProcessFactory, IRootFactory <TestingMutant> testingMutantFactory, MutationSessionChoices choices, OptionsModel options) { _dispatcher = dispatcher; _svc = svc; _mutantDetailsController = mutantDetailsController; _mutantsContainer = mutantsContainer; _testsContainer = testsContainer; _resultsSavingFactory = resultsSavingFactory; _testingProcessFactory = testingProcessFactory; _testingMutantFactory = testingMutantFactory; _choices = choices; _sessionState = SessionState.NotStarted; _sessionEventsSubject = new Subject <SessionEventArgs>(); _subscriptions = new List <IDisposable>(); _options = options; }
public void Test0() { var cci = new CciModuleSource(TestProjects.DsaPath); var cci2 = new CciModuleSource(TestProjects.DsaPath); var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Deque") as NamedTypeDefinition; var method = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List <TypeIdentifier>(), new MethodIdentifier(method).InList()), SelectedOperators = new AOR_ArithmeticOperatorReplacement().InList <IMutationOperator>(), }; var exec = new MutationExecutor(null, choices, null); var container = new MutantsContainer(exec, new OriginalCodebase(cci.InList(), new List <string>()), new OptionsModel()); IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mut = assemblies.Cast <CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>()) .OfType <Mutant>().First(); var sourceMethod = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); MutationResult executeMutation = exec.ExecuteMutation(mut, cci2).Result; // var viss = new Viss(cci2.Host, sourceMethod); // IModule newMod = viss.Rewrite(executeMutation.MutatedModules.Modules.Single().Module); cci2.ReplaceWith(executeMutation.MutatedModules.Modules.Single().Module); MutationResult executeMutation2 = exec.ExecuteMutation(mut, cci2).Result; }
public SessionController( IDispatcherExecute dispatcher, CommonServices svc, MutantDetailsController mutantDetailsController, IMutantsContainer mutantsContainer, ITestsContainer testsContainer, IFactory<ResultsSavingController> resultsSavingFactory, IFactory<TestingProcess> testingProcessFactory, IRootFactory<TestingMutant> testingMutantFactory, MutationSessionChoices choices) { _dispatcher = dispatcher; _svc = svc; _mutantDetailsController = mutantDetailsController; _mutantsContainer = mutantsContainer; _testsContainer = testsContainer; _resultsSavingFactory = resultsSavingFactory; _testingProcessFactory = testingProcessFactory; _testingMutantFactory = testingMutantFactory; _choices = choices; _sessionState = SessionState.NotStarted; _sessionEventsSubject = new Subject<SessionEventArgs>(); _subscriptions = new List<IDisposable>(); }
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); }
public MutationExecutor( OptionsModel options, MutationSessionChoices choices, CommonServices svc ) { _svc = svc; _operatorUtils = new OperatorUtils(); _options = options; _filter = choices.Filter; _mutOperators = choices.SelectedOperators; _sharedTargets = new MultiDictionary<IMutationOperator, MutationTarget>(); }
public MutationExecutor( OptionsModel options, MutationSessionChoices choices, CommonServices svc ) { _svc = svc; _operatorUtils = new OperatorUtils(); _options = options; _filter = choices.Filter; _mutOperators = choices.SelectedOperators; _sharedTargets = new MultiDictionary <IMutationOperator, MutationTarget>(); }
public void IntegrationTestingMiscUtilLight() { var cci = new CciModuleSource(TestProjects.MiscUtil); 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())); 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(TestProjects.MiscUtil); var resu = muexe.ExecuteMutation(mutant, cciWhite).Result; string filePath = @"C:\PLIKI\VisualMutator\testprojects\MiscUtil-Integration-Tests\TestGround\MiscUtil.dll"; string filePathTests = @"C:\PLIKI\VisualMutator\testprojects\MiscUtil-Integration-Tests\TestGround\MiscUtil.UnitTests.dll"; 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); }
public TestingMutant( MutantMaterializer mutantMaterializer, OptionsModel options, MutationSessionChoices choices, NUnitXmlTestService testService, TestServiceManager testServiceManager, //-------- IObserver<SessionEventArgs> sessionEventsSubject, Mutant mutant) { _mutantMaterializer = mutantMaterializer; _options = options; _choices = choices; _sessionEventsSubject = sessionEventsSubject; _testServiceManager = testServiceManager; _mutant = mutant; }
public TestingMutant( MutantMaterializer mutantMaterializer, OptionsModel options, MutationSessionChoices choices, NUnitXmlTestService testService, TestServiceManager testServiceManager, //-------- IObserver <SessionEventArgs> sessionEventsSubject, Mutant mutant) { _mutantMaterializer = mutantMaterializer; _options = options; _choices = choices; _sessionEventsSubject = sessionEventsSubject; _testServiceManager = testServiceManager; _mutant = mutant; }
public MutantsCache( OptionsModel options, IWhiteSource whiteCache, MutationSessionChoices choices, IMutationExecutor mutationExecutor) { _options = options; _whiteCache = whiteCache; _choices = choices; _mutationExecutor = mutationExecutor; _disableCache = !_options.MutantsCacheEnabled; var config = new NameValueCollection { {"physicalMemoryLimitPercentage", "40"}, {"cacheMemoryLimitMegabytes", "256"} }; _cache = new MemoryCache("CustomCache", config); _map = new ConcurrentDictionary<string, ConcurrentBag<TaskCompletionSource<MutationResult>>>(); }
public MutantsCache( OptionsModel options, IWhiteSource whiteCache, MutationSessionChoices choices, IMutationExecutor mutationExecutor) { _options = options; _whiteCache = whiteCache; _choices = choices; _mutationExecutor = mutationExecutor; _disableCache = !_options.MutantsCacheEnabled; var config = new NameValueCollection { { "physicalMemoryLimitPercentage", "40" }, { "cacheMemoryLimitMegabytes", "256" } }; _cache = new MemoryCache("CustomCache", config); _map = new ConcurrentDictionary <string, ConcurrentBag <TaskCompletionSource <MutationResult> > >(); }
public void IntegrationTestMutation() { var cci = new CciModuleSource(TestProjects.MiscUtil); var original = new OriginalCodebase(cci.InList()); var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Adler32") as NamedTypeDefinition; var method = type.Methods.First(m => m.Name.Value == "ComputeChecksum"); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List <TypeIdentifier>(), new MethodIdentifier(method).InList()), SelectedOperators = new LOR_LogicalOperatorReplacement().InList <IMutationOperator>(), }; var exec = new MutationExecutor(new OptionsModel(), choices, null); var container = new MutantsContainer(exec, original, new OptionsModel()); IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mutants = assemblies.Cast <CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>()) .OfType <Mutant>(); var diff = new CodeDifferenceCreator(); var vis = new CodeVisualizer(original, diff); foreach (var mutant in mutants) { var copy = new CciModuleSource(TestProjects.MiscUtil); MutationResult result = exec.ExecuteMutation(mutant, copy).Result; CodeWithDifference differenceListing = vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result; differenceListing.LineChanges.Count.ShouldEqual(2); } }
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 void Test00() { const string code = @"using System; namespace Ns { public class Test { public int Method1(int a, int b) { return a + b; } } }"; var cci = new CciModuleSource(TestProjects.DsaPath); var cci2 = new CciModuleSource(TestProjects.DsaPath); var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Deque") as NamedTypeDefinition; var method = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); var cci3 = MutationTestsHelper.CreateModuleFromCode(code); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List <TypeIdentifier>(), new MethodIdentifier(method).InList()), //Filter = MutationFilter.AllowAll(), SelectedOperators = new AOR_ArithmeticOperatorReplacement().InList <IMutationOperator>(), }; // var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Test") as NamedTypeDefinition; // var method = type.Methods.Single(m => m.Name.Value == "Method1"); var exec = new MutationExecutor(null, choices, null); var container = new MutantsContainer(exec, new OriginalCodebase(cci.InList()), new OptionsModel()); IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mut = assemblies.Cast <CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>()) .OfType <Mutant>().ElementAt(4); MutationResult executeMutation = exec.ExecuteMutation(mut, cci2).Result; var c = new CodeDeepCopier(cci.Host); MethodDefinition methodDefinition = c.Copy(mut.MutationTarget.MethodRaw); var vis = new CodeVisualizer(null, null); var s = vis.Visualize(CodeLanguage.CSharp, cci2); var v = new MutantsCache.Viss(cci2.Host, methodDefinition); var modClean = v.Rewrite(cci2.Modules.Single().Module); cci2.ReplaceWith(modClean); var debug = new DebugOperatorCodeVisitor(); var debug2 = new DebugOperatorCodeVisitor(); new DebugCodeTraverser(debug).Traverse(cci.Modules.Single().Module); new DebugCodeTraverser(debug2).Traverse(cci2.Modules.Single().Module); File.WriteAllText(@"C:\PLIKI\tree1.txt", debug.ToString()); File.WriteAllText(@"C:\PLIKI\tree2.txt", debug2.ToString()); // Console.WriteLine(debug); // Console.WriteLine(debug2); // cci.ReplaceWith(executeMutation.MutatedModules.Modules.Single().Module); // var s2 = vis.Visualize(CodeLanguage.CSharp, cci2); // Console.WriteLine(s); // Console.WriteLine(s2); // var viss = new Viss(cci2.Host, sourceMethod); // IModule newMod = viss.Rewrite(executeMutation.MutatedModules.Modules.Single().Module); // cci2.ReplaceWith(executeMutation.MutatedModules.Modules.Single().Module); // MutationResult executeMutation2 = exec.ExecuteMutation(mut, cci2).Result; }
public void trace(string file) { var cci = new CciModuleSource(file); // ModuleInfo mod = (ModuleInfo) cci.Modules.Single(); // var copied = cci.CreateCopier().Copy(cci.Modules.Single().Module); // var copied2 = cci.CreateCopier().Copy(cci.Modules.Single().Module); var copied3 = cci.CreateCopier().Copy(cci.Modules.Single().Module); var white = cci.CloneWith(copied3); var type = white.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Deque") as NamedTypeDefinition; var method = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List <TypeIdentifier>(), new MethodIdentifier(method).InList()), SelectedOperators = new AOR_ArithmeticOperatorReplacement().InList <IMutationOperator>(), }; var exec = new MutationExecutor(null, choices, null); var container = new MutantsContainer(exec, new OriginalCodebase(cci.InList(), new List <string>()), new OptionsModel()); IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mutants = assemblies.Cast <CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>()) .OfType <Mutant>().ToList(); string name = Path.GetFileNameWithoutExtension(file); var debug = new DebugOperatorCodeVisitor(); new DebugCodeTraverser(debug).Traverse(copied3);//.Modules.Single().Module); File.WriteAllText(@"C:\PLIKI\VisualMutator\trace\" + name + "1.txt", debug.ToString(), Encoding.ASCII); var cci2 = new CciModuleSource(file); // ModuleInfo mod = (ModuleInfo) cci.Modules.Single(); var copied21 = cci2.CreateCopier().Copy(cci2.Modules.Single().Module); var copied22 = cci2.CreateCopier().Copy(cci2.Modules.Single().Module); var debug1 = new DebugOperatorCodeVisitor(); var debug2 = new DebugOperatorCodeVisitor(); new DebugCodeTraverser(debug1).Traverse(copied21); new DebugCodeTraverser(debug2).Traverse(copied22); File.WriteAllText(@"C:\PLIKI\VisualMutator\trace\tree1" + ".txt", debug1.ToString(), Encoding.ASCII); File.WriteAllText(@"C:\PLIKI\VisualMutator\trace\tree2" + ".txt", debug2.ToString(), Encoding.ASCII); // // foreach (var mutant in mutants) // { // var copied23 = cci2.CreateCopier().Copy(cci.Modules.Single().Module); // var mutCci = cci2.CloneWith(copied23); // // // debug2.ToString().ShouldEqual(debug.ToString()); // // // // MutationResult executeMutation = exec.ExecuteMutation(mutant, mutCci).Result; // // } // var copier2 = new CodeDeepCopier(new DefaultWindowsRuntimeHost()); // var copied2 = copier2.Copy(cci.Modules.Single().Module); // // var a1 = new Assembly(); // var copier3 = new CodeDeepCopier(new PeReader.DefaultHost(), a1); // var copied3 = copier3.Copy(cci.Modules.Single().Module); // // var a2 = new Assembly(); // var copier4 = new CodeDeepCopier(new PeReader.DefaultHost(), a2); // var copied4 = copier4.Copy(cci.Modules.Single().Module); //var copier5 = new CodeDeepCopier(cci.Host); //var copied5 = copier5.Copy(cci.Modules.Single().Module); // var copied1 = cci.Copy(); // var copied2 = cci.Copy(); // var copied3 = cci.Copy(); // var copied4 = cci.Copy(); }
public void Test00() { const string code = @"using System; namespace Ns { public class Test { public int Method1(int a, int b) { return a + b; } } }"; var cci = new CciModuleSource(TestProjects.DsaPath); var cci2 = new CciModuleSource(TestProjects.DsaPath); var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Deque") as NamedTypeDefinition; var method = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); var cci3 = MutationTestsHelper.CreateModuleFromCode(code); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List<TypeIdentifier>(), new MethodIdentifier(method).InList()), //Filter = MutationFilter.AllowAll(), SelectedOperators = new AOR_ArithmeticOperatorReplacement().InList<IMutationOperator>(), }; // var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Test") as NamedTypeDefinition; // var method = type.Methods.Single(m => m.Name.Value == "Method1"); var exec = new MutationExecutor(null, choices, null); var container = new MutantsContainer(exec, new OriginalCodebase(cci.InList(), new List<string>())); IList<AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mut = assemblies.Cast<CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection<CheckedNode>()) .OfType<Mutant>().ElementAt(4); MutationResult executeMutation = exec.ExecuteMutation(mut, cci2).Result; var c = new CodeDeepCopier(cci.Host); MethodDefinition methodDefinition = c.Copy(mut.MutationTarget.MethodRaw); var vis = new CodeVisualizer(null, null); var s = vis.Visualize(CodeLanguage.CSharp, cci2); var v = new MutantsCache.Viss(cci2.Host, methodDefinition); var modClean = v.Rewrite(cci2.Modules.Single().Module); cci2.ReplaceWith(modClean); var debug = new DebugOperatorCodeVisitor(); var debug2 = new DebugOperatorCodeVisitor(); new DebugCodeTraverser(debug).Traverse(cci.Modules.Single().Module); new DebugCodeTraverser(debug2).Traverse(cci2.Modules.Single().Module); File.WriteAllText(@"C:\PLIKI\tree1.txt", debug.ToString()); File.WriteAllText(@"C:\PLIKI\tree2.txt", debug2.ToString()); // Console.WriteLine(debug); // Console.WriteLine(debug2); // cci.ReplaceWith(executeMutation.MutatedModules.Modules.Single().Module); // var s2 = vis.Visualize(CodeLanguage.CSharp, cci2); // Console.WriteLine(s); // Console.WriteLine(s2); // var viss = new Viss(cci2.Host, sourceMethod); // IModule newMod = viss.Rewrite(executeMutation.MutatedModules.Modules.Single().Module); // cci2.ReplaceWith(executeMutation.MutatedModules.Modules.Single().Module); // MutationResult executeMutation2 = exec.ExecuteMutation(mut, cci2).Result; }
public void trace(string file) { var cci = new CciModuleSource(file); // ModuleInfo mod = (ModuleInfo) cci.Modules.Single(); // var copied = cci.CreateCopier().Copy(cci.Modules.Single().Module); // var copied2 = cci.CreateCopier().Copy(cci.Modules.Single().Module); var copied3 = cci.CreateCopier().Copy(cci.Modules.Single().Module); var white = cci.CloneWith(copied3); var type = white.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Deque") as NamedTypeDefinition; var method = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List<TypeIdentifier>(), new MethodIdentifier(method).InList()), SelectedOperators = new AOR_ArithmeticOperatorReplacement().InList<IMutationOperator>(), }; var exec = new MutationExecutor(null, choices, null); var container = new MutantsContainer(exec, new OriginalCodebase(cci.InList(), new List<string>())); IList<AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mutants = assemblies.Cast<CheckedNode>() .SelectManyRecursive(n => n.Children ?? new NotifyingCollection<CheckedNode>()) .OfType<Mutant>().ToList(); string name = Path.GetFileNameWithoutExtension(file); var debug = new DebugOperatorCodeVisitor(); new DebugCodeTraverser(debug).Traverse(copied3);//.Modules.Single().Module); File.WriteAllText(@"C:\PLIKI\VisualMutator\trace\" + name + "1.txt", debug.ToString(), Encoding.ASCII); var cci2 = new CciModuleSource(file); // ModuleInfo mod = (ModuleInfo) cci.Modules.Single(); var copied21 = cci2.CreateCopier().Copy(cci2.Modules.Single().Module); var copied22 = cci2.CreateCopier().Copy(cci2.Modules.Single().Module); var debug1 = new DebugOperatorCodeVisitor(); var debug2 = new DebugOperatorCodeVisitor(); new DebugCodeTraverser(debug1).Traverse(copied21); new DebugCodeTraverser(debug2).Traverse(copied22); File.WriteAllText(@"C:\PLIKI\VisualMutator\trace\tree1" + ".txt", debug1.ToString(), Encoding.ASCII); File.WriteAllText(@"C:\PLIKI\VisualMutator\trace\tree2" + ".txt", debug2.ToString(), Encoding.ASCII); // // foreach (var mutant in mutants) // { // var copied23 = cci2.CreateCopier().Copy(cci.Modules.Single().Module); // var mutCci = cci2.CloneWith(copied23); // // // debug2.ToString().ShouldEqual(debug.ToString()); // // // // MutationResult executeMutation = exec.ExecuteMutation(mutant, mutCci).Result; // // } // var copier2 = new CodeDeepCopier(new DefaultWindowsRuntimeHost()); // var copied2 = copier2.Copy(cci.Modules.Single().Module); // // var a1 = new Assembly(); // var copier3 = new CodeDeepCopier(new PeReader.DefaultHost(), a1); // var copied3 = copier3.Copy(cci.Modules.Single().Module); // // var a2 = new Assembly(); // var copier4 = new CodeDeepCopier(new PeReader.DefaultHost(), a2); // var copied4 = copier4.Copy(cci.Modules.Single().Module); //var copier5 = new CodeDeepCopier(cci.Host); //var copied5 = copier5.Copy(cci.Modules.Single().Module); // var copied1 = cci.Copy(); // var copied2 = cci.Copy(); // var copied3 = cci.Copy(); // var copied4 = cci.Copy(); }
public void Test1() { var assemblyFile = new TestAssemblyFile(); var assembly = AssemblyDefinition.ReadAssembly(assemblyFile.FilePath); var dinnersController = assembly.MainModule.Types.Single(t => t.Name == "DinnersController"); var createMethod = dinnersController.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1); var instr = createMethod.Body.Instructions.Single(i => { if (i.OpCode == OpCodes.Call) { var method = ((MethodReference)i.Operand); if (method.DeclaringType.FullName == "System.Web.Mvc.Controller" && method.Name == "View") // && method.Parameters.Count == 0) { return true; } } return false; }); var mutator = new ReplaceViewWithRedirectToAction(); var mutationSessionChoices = new MutationSessionChoices { SelectedOperators = new[] { mutator }, Assemblies = new[] { assembly }, SelectedTypes = assembly.MainModule.Types }; MutantsContainer mutantsContainer = new MutantsContainer(); var executedOperator = mutantsContainer.GenerateMutantsForOperators(mutationSessionChoices).Single(); executedOperator.Mutants.Single(mut => { var assembly2 = mut.MutationResult.MutatedAssemblies.Single(); var dinnersController2 = assembly2.MainModule.Types.Single(t => t.Name == "DinnersController"); var createMethod2 = dinnersController2.Methods.Single(m => m.Name == "Create" && m.Parameters.Count == 1); var instr3 = createMethod2.Body.Instructions.Where(i => { if (i.OpCode == OpCodes.Call) { var method = ((MethodReference)i.Operand); if (method.DeclaringType.FullName == "System.Web.Mvc.Controller" && method.Name == "RedirectToAction") // && method.Parameters.Count == 0) { return true; } } return false; }); return instr3.Count()==(2); }); }
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 void Test0() { var cci = new CciModuleSource(TestProjects.DsaPath); var cci2 = new CciModuleSource(TestProjects.DsaPath); var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Deque") as NamedTypeDefinition; var method = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List<TypeIdentifier>(), new MethodIdentifier(method).InList()), SelectedOperators = new AOR_ArithmeticOperatorReplacement().InList<IMutationOperator>(), }; var exec = new MutationExecutor(null, choices, null); var container = new MutantsContainer(exec, new OriginalCodebase(cci.InList(), new List<string>())); IList<AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive()); var mut = assemblies.Cast<CheckedNode>() .SelectManyRecursive(n => n.Children?? new NotifyingCollection<CheckedNode>()) .OfType<Mutant>().First(); var sourceMethod = type.Methods.Single(m => m.Name.Value == "EnqueueFront"); MutationResult executeMutation = exec.ExecuteMutation(mut, cci2).Result; // var viss = new Viss(cci2.Host, sourceMethod); // IModule newMod = viss.Rewrite(executeMutation.MutatedModules.Modules.Single().Module); cci2.ReplaceWith(executeMutation.MutatedModules.Modules.Single().Module); MutationResult executeMutation2 = exec.ExecuteMutation(mut, cci2).Result; }
public void IntegrationTestMutation() { var cci = new CciModuleSource(TestProjects.MiscUtil); var original = new OriginalCodebase(cci.InList()); var type = cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Adler32") as NamedTypeDefinition; var method = type.Methods.First(m => m.Name.Value == "ComputeChecksum"); var choices = new MutationSessionChoices { Filter = new MutationFilter( new List<TypeIdentifier>(), new MethodIdentifier(method).InList()), SelectedOperators = new LOR_LogicalOperatorReplacement().InList<IMutationOperator>(), }; var exec = new MutationExecutor(new OptionsModel(), choices, null); 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>(); var diff = new CodeDifferenceCreator(); var vis = new CodeVisualizer(original, diff); foreach (var mutant in mutants) { var copy = new CciModuleSource(TestProjects.MiscUtil); MutationResult result = exec.ExecuteMutation(mutant, copy).Result; CodeWithDifference differenceListing = vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result; differenceListing.LineChanges.Count.ShouldEqual(2); } }