Example #1
0
        public static Dictionary<TestCase.ExceptionDescription, Collection<FileInfo>> ClassifyTestsByMessage(Collection<FileInfo> tests)
        {
            Dictionary<TestCase.ExceptionDescription, Collection<FileInfo>> testsByMessage =
                new Dictionary<TestCase.ExceptionDescription, Collection<FileInfo>>();

            foreach (FileInfo t in tests)
            {
                TestCase tc;
                try
                {
                    tc = new TestCase(t);
                }
                catch (TestCase.TestCaseParseException e)
                {
                    Console.WriteLine("Problem parsing test {0}. (Ignoring test.)", t.FullName);
                    Console.WriteLine(Util.SummarizeException(e, ""));
                    continue;
                }

                Collection<FileInfo> l;

                if (!testsByMessage.ContainsKey(tc.exception))
                {
                    l = new Collection<FileInfo>();
                    testsByMessage[tc.exception] = l;
                }
                else
                {
                    l = testsByMessage[tc.exception];
                }

                l.Add(t);
            }
            return testsByMessage;
        }
Example #2
0
 private static bool Reproduce(FileInfo oneTest)
 {
     TestCase test = new TestCase(oneTest);
     TestCase.RunResults results = test.RunExternal();
     if (results.behaviorReproduced)
         return true;
     return false;
 }
Example #3
0
        public static int Minimize(FileInfo testPath)
        {
            TestCase testFile = new TestCase(testPath);

            testFile.WriteToFile(testPath + ".nonmin", false);

            int linesRemoved = 0;

            //            Console.WriteLine(testFile);

            for (int linePos = testFile.NumTestLines - 1; linePos >= 0; linePos--)
            {
                string oldLine = testFile.RemoveLine(linePos);

                if (!testFile.RunExternal().behaviorReproduced)
                {
                    testFile.AddLine(linePos, oldLine);
                }
                else
                {
                    linesRemoved++;
                }
            }

            testFile.WriteToFile(testPath, false);
            return linesRemoved;
        }
Example #4
0
        private static bool IsErrorRevealing(TestCase tc)
        {
            TestCase.ExceptionDescription d;

            d = TestCase.ExceptionDescription.GetDescription(typeof(System.AccessViolationException));
            if (d.Equals(tc.exception))
                return true;

            d = TestCase.ExceptionDescription.GetDescription(typeof(System.NullReferenceException));
            if (d.Equals(tc.exception))
                return true;

            d = TestCase.ExceptionDescription.GetDescription(typeof(System.NullReferenceException));
            if (d.Equals(tc.exception))
                return true;

            return false;
        }
Example #5
0
        public static Collection<FileInfo> Reduce(Collection<FileInfo> tests)
        {
            Dictionary<EquivClass, TestCase> representatives = new Dictionary<EquivClass, TestCase>();
            Dictionary<EquivClass, FileInfo> representativesFileInfos = new Dictionary<EquivClass, FileInfo>();


            foreach (FileInfo file in tests)
            {
                TestCase testCase;
                try
                {
                    testCase = new TestCase(file);
                }
                catch (Exception)
                {
                    // File does not contain a valid test case, or
                    // test case is malformed.
                    continue;
                }


                EquivClass partition = new EquivClass(testCase);
                // If there are no representatives for this partition,
                // use testCase as the representative.
                if (!representatives.ContainsKey(partition))
                {
                    representatives[partition] = testCase;
                    representativesFileInfos[partition] = file;
                }
                // if testCase is smaller than the current representative,
                // use testCase as the representative.
                // Delete the old representative.
                else if (testCase.NumTestLines < representatives[partition].NumTestLines)
                {
                    representativesFileInfos[partition].Delete();
                    representatives[partition] = testCase;
                    representativesFileInfos[partition] = file;
                }
                // Representative is redundant and larger than current representative.
                // Delete representative.
                else
                {
                    file.Delete();
                }
            }

            List<FileInfo> retval = new List<FileInfo>();
            retval.AddRange(representativesFileInfos.Values);
            return new Collection<FileInfo>(retval);
        }
Example #6
0
 public EquivClass(TestCase testCase)
 {
     if (testCase == null) throw new ArgumentNullException();
     this.representative = testCase;
 }
Example #7
0
        public static Collection<FileInfo> RemoveNonReproducibleErrors(Collection<FileInfo> partitionedTests)
        {
            Collection<FileInfo> reproducibleTests = new Collection<FileInfo>();
            foreach (FileInfo test in partitionedTests)
            {
                TestCase testCase = new TestCase(test);

                // Don't attempt to reproduce non-error-revealing tests (to save time).
                if (!IsErrorRevealing(testCase))
                {
                    reproducibleTests.Add(test);
                    continue;
                }

                TestCase.RunResults runResults = testCase.RunExternal();
                if (runResults.behaviorReproduced)
                    reproducibleTests.Add(test);
                else
                {
                    if (!runResults.compilationSuccessful)
                    {
                        //Console.WriteLine("@@@COMPILATIONFAILED:");
                        //foreach (CompilerError err in runResults.compilerErrors)
                        //    Console.WriteLine("@@@" + err);
                    }
                    test.Delete();
                }
            }
            return reproducibleTests;
        }
Example #8
0
        public static Collection<FileInfo> Reduce2(Collection<FileInfo> tests) 
        {
            Dictionary<EquivClass2, TestCase> representatives = new Dictionary<EquivClass2, TestCase>();
            Dictionary<EquivClass2, FileInfo> representativesFileInfos = new Dictionary<EquivClass2, FileInfo>();


            foreach (FileInfo file in tests)
            {
                TestCase testCase;
                try
                {
                    testCase = new TestCase(file);
                }
                catch (Exception)
                {
                    // File does not contain a valid test case, or
                    // test case is malformed.
                    continue;
                }


                EquivClass2 partition = new EquivClass2(testCase);
                // If there are no representatives for this partition,
                // use testCase as the representative.
                if (!representatives.ContainsKey(partition))
                {
                    representatives[partition] = testCase;
                    representativesFileInfos[partition] = file;
                }
                // if testCase is larger than the current representative (the current test sequence is a subset),
                // use testCase as the representative.
                // Delete the old representative.
                else if (testCase.NumTestLines > representatives[partition].NumTestLines)
                {
                    //representativesFileInfos[partition].Delete();
                    representativesFileInfos[partition].MoveTo(representativesFileInfos[partition].FullName + ".reduced");
                    representatives[partition] = testCase;
                    representativesFileInfos[partition] = file;
                }
                // sequence of testCase is a subset of the sequence of current representative.
                // Delete testCase.
                else
                {
                    //file.Delete();
                    file.MoveTo(file.FullName+".reduced");
                }
            }

            List<FileInfo> retval = new List<FileInfo>();
            retval.AddRange(representativesFileInfos.Values);
            return new Collection<FileInfo>(retval);
        }
Example #9
0
 public SequenceBasedEquivalenceClass(TestCase testCase)
 {
     representative = testCase ?? throw new ArgumentNullException();
 }