Example #1
0
        public async Task <MutantResultState> RunAsync()
        {
            var sw = new Stopwatch();

            sw.Start();
            _storedMutantInfo = await _mutantMaterializer.StoreMutant(_mutant);

            _sessionEventsSubject.OnNext(new MutantStoredEventArgs(_storedMutantInfo));

            sw.Stop();
            _mutant.CreationTimeMilis = sw.ElapsedMilliseconds;
            //                    CodeWithDifference diff = _codeDifferenceCreator.CreateDifferenceListing(
            //                        CodeLanguage.IL, mutant);
            //
            //                    if (diff.LineChanges.Count == 0)
            //                    {
            //                        mutant.IsEquivalent = true;
            //                    }
            if (!_mutant.IsEquivalent) //todo: somewhat non-threadsafe, but valid
            {
                await RunTestsForMutant(_choices.MutantsTestingOptions, _storedMutantInfo);

                if (!_options.ParsedParams.DebugFiles)
                {
                    _storedMutantInfo.Dispose();
                }

                return(_mutant.State);
            }
            //_sessionEventsSubject.OnNext(new MutantTestedEvent(mutant.State));
            else
            {
                return(MutantResultState.Untested);
            }
        }
Example #2
0
        public async Task<MutantResultState> RunAsync()
        {
            
            var sw = new Stopwatch();
            sw.Start();
            _storedMutantInfo = await _mutantMaterializer.StoreMutant(_mutant);
            _sessionEventsSubject.OnNext(new MutantStoredEventArgs(_storedMutantInfo));
       
            sw.Stop();
            _mutant.CreationTimeMilis = sw.ElapsedMilliseconds;
            //                    CodeWithDifference diff = _codeDifferenceCreator.CreateDifferenceListing(
            //                        CodeLanguage.IL, mutant);
            //
            //                    if (diff.LineChanges.Count == 0)
            //                    {
            //                        mutant.IsEquivalent = true;
            //                    }
            if (!_mutant.IsEquivalent) //todo: somewhat non-threadsafe, but valid
            {
                await RunTestsForMutant(_choices.MutantsTestingOptions, _storedMutantInfo);
                if (!_options.ParsedParams.DebugFiles)
                {
                    _storedMutantInfo.Dispose();
                }

                return _mutant.State;
            }
                //_sessionEventsSubject.OnNext(new MutantTestedEvent(mutant.State));
            else
            {
                return (MutantResultState.Untested);
            }
        }
Example #3
0
        public async Task RunTestsForMutant(MutantsTestingOptions options, StoredMutantInfo storedMutantInfo)
        {
            _mutant.State = MutantResultState.Tested;

            var sw = new Stopwatch();

            sw.Start();

            _log.Info("Loading tests for mutant " + _mutant.Id);

            if (_choices.TestAssemblies.Count == 0)
            {
                throw new InvalidOperationException("_choices.TestAssemblies.Count == 0");
            }

            _contexts = CreateTestContexts(storedMutantInfo.AssembliesPaths,
                                           _choices.TestAssemblies).ToList();


            _log.Info("Running tests for mutant " + _mutant.Id);


            //     _nUnitTesters = contexts.Select(_nunitService.SpawnTester).ToList();
            //   _nUnitTesterFactory.CreateWithParams(_nunitConsolePath, arg);

            IDisposable timoutDisposable =
                Observable.Timer(TimeSpan.FromMilliseconds(options.TestingTimeoutSeconds))
                .Subscribe(e => CancelTestRun());

            try
            {
                var results = await Task.WhenAll(_contexts.Select(t => t.RunTests()));

                _log.Debug("Finished waiting for tests. ");
                _mutant.TestRunContexts = _contexts;

                ResolveMutantState(results);

                _mutant.MutantTestSession.IsComplete = true;
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
                SetError(e);
            }
            finally
            {
                timoutDisposable.Dispose();
                sw.Stop();
                _mutant.MutantTestSession.TestingTimeMiliseconds = sw.ElapsedMilliseconds;
                _mutant.MutantTestSession.TestingEnd             = DateTime.Now;
            }
        }
 public MutantStoredEventArgs(StoredMutantInfo storedMutantInfo)
     : base(OperationsState.None)
 {
     _storedMutantInfo = storedMutantInfo;
 }
        public async Task<StoredMutantInfo> StoreMutant(Mutant mutant)
        {
            mutant.State = MutantResultState.Creating;

            var mutationResult = await _mutantsCache.GetMutatedModulesAsync(mutant);

            mutant.State = MutantResultState.Writing;

            var clone = await _clonesManager.CreateCloneAsync("InitTestEnvironment");
            var info = new StoredMutantInfo(clone);


            if(mutationResult.MutatedModules != null)
            {
                var singleMutated = mutationResult.MutatedModules.Modules.SingleOrDefault();
                if (singleMutated != null)
                {
                    //TODO: remove: assemblyDefinition.Name.Name + ".dll", use factual original file name
                    string file = Path.Combine(info.Directory, singleMutated.Name + ".dll");
//
//                    var memory = mutationResult.MutatedModules.WriteToStream(singleMutated);
//                    // _mutantsCache.Release(mutationResult);
//
//                    using (FileStream peStream = File.Create(file))
//                    {
//                        await memory.CopyToAsync(peStream);
//                    }
                    using (FileStream peStream = File.Create(file))
                    {
                        mutationResult.MutatedModules.WriteToStream(singleMutated, peStream, file);
                        //  await memory.CopyToAsync(peStream);
                    }

                    info.AssembliesPaths.Add(file);
                }

                var otherModules = _originalCodebase.Modules
                    .Where(_ => singleMutated == null || _.Module.Name != singleMutated.Name);

                foreach (var otherModule in otherModules)
                {
                    string file = Path.Combine(info.Directory, otherModule.Module.Name + ".dll");
                    info.AssembliesPaths.Add(file);
                }
            }
            else
            {
                foreach (var cciModuleSource in mutationResult.Old)
                {
                    var module = cciModuleSource.Modules.Single();
                    //TODO: remove: assemblyDefinition.Name.Name + ".dll", use factual original file name
                    string file = Path.Combine(info.Directory, module.Name + ".dll");

                    
                    // _mutantsCache.Release(mutationResult);

                    using (FileStream peStream = File.Create(file))
                    {
                         cciModuleSource.WriteToStream(module, peStream, file);
                      //  await memory.CopyToAsync(peStream);
                    }

                    info.AssembliesPaths.Add(file);
                }
            }
            

            return info;
        }
Example #6
0
        public async Task <StoredMutantInfo> StoreMutant(Mutant mutant)
        {
            mutant.State = MutantResultState.Creating;

            var mutationResult = await _mutantsCache.GetMutatedModulesAsync(mutant);

            mutant.State = MutantResultState.Writing;

            var clone = await _clonesManager.CreateCloneAsync("InitTestEnvironment");

            var info = new StoredMutantInfo(clone);


            if (mutationResult.MutatedModules != null)
            {
                //AKB

                /*foreach (ICciModuleSource mutatedModule in mutationResult.MutatedModules)
                 * {*/
                var singleMutated = mutationResult.MutatedModules.Modules.SingleOrDefault();
                if (singleMutated != null)
                {
                    //TODO: remove: assemblyDefinition.Name.Name + ".dll", use factual original file name
                    string file = Path.Combine(info.Directory, singleMutated.Name + ".dll");
                    //
                    //                    var memory = mutationResult.MutatedModules.WriteToStream(singleMutated);
                    //                    // _mutantsCache.Release(mutationResult);
                    //
                    //                    using (FileStream peStream = File.Create(file))
                    //                    {
                    //                        await memory.CopyToAsync(peStream);
                    //                    }
                    using (FileStream peStream = File.Create(file))
                    {
                        mutationResult.MutatedModules.WriteToStream(singleMutated, peStream, file);

                        //  await memory.CopyToAsync(peStream);
                    }

                    info.AssembliesPaths.Add(file);
                }

                var otherModules = _originalCodebase.Modules
                                   .Where(_ => singleMutated == null || _.Module.Name != singleMutated.Name);

                foreach (var otherModule in otherModules)
                {
                    string file = Path.Combine(info.Directory, otherModule.Module.Name + ".dll");
                    info.AssembliesPaths.Add(file);
                }
                //}
            }
            else
            {
                foreach (var cciModuleSource in mutationResult.Old)
                {
                    var module = cciModuleSource.Modules.Single();
                    //TODO: remove: assemblyDefinition.Name.Name + ".dll", use factual original file name
                    string file = Path.Combine(info.Directory, module.Name + ".dll");


                    // _mutantsCache.Release(mutationResult);

                    using (FileStream peStream = File.Create(file))
                    {
                        cciModuleSource.WriteToStream(module, peStream, file);
                        //  await memory.CopyToAsync(peStream);
                    }

                    info.AssembliesPaths.Add(file);
                }
            }


            return(info);
        }
Example #7
0
 public MutantStoredEventArgs(StoredMutantInfo storedMutantInfo)
     : base(OperationsState.None)
 {
     _storedMutantInfo = storedMutantInfo;
 }
Example #8
0
        public async Task RunTestsForMutant(MutantsTestingOptions options, StoredMutantInfo storedMutantInfo)
        {
            _mutant.State = MutantResultState.Tested;

            var sw = new Stopwatch();
            sw.Start();

            _log.Info("Loading tests for mutant " + _mutant.Id);

            if (_choices.TestAssemblies.Count == 0)
            {
                throw new InvalidOperationException("_choices.TestAssemblies.Count == 0");
            }

            _contexts = CreateTestContexts(storedMutantInfo.AssembliesPaths,
                _choices.TestAssemblies).ToList();
           

            _log.Info("Running tests for mutant " + _mutant.Id);

           
       //     _nUnitTesters = contexts.Select(_nunitService.SpawnTester).ToList();
         //   _nUnitTesterFactory.CreateWithParams(_nunitConsolePath, arg);

            IDisposable timoutDisposable =
              Observable.Timer(TimeSpan.FromMilliseconds(options.TestingTimeoutSeconds))
              .Subscribe(e => CancelTestRun());

            try
            {
                var results = await Task.WhenAll(_contexts.Select(t => t.RunTests()));
                
                _log.Debug("Finished waiting for tests. ");
                _mutant.TestRunContexts = _contexts;

                ResolveMutantState(results);

                _mutant.MutantTestSession.IsComplete = true;
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
                SetError(e);
            }
            finally
            {
                timoutDisposable.Dispose();
                sw.Stop();
                _mutant.MutantTestSession.TestingTimeMiliseconds = sw.ElapsedMilliseconds;
                _mutant.MutantTestSession.TestingEnd = DateTime.Now;
            }
        }