Exemple #1
0
        private void exportSuspiciousnessRanking()
        {
            string filenameTemplate = "cluster_";

            foreach (int key in suspiciousnessListForEveryCluster.Keys)
            {
                if (suspiciousnessListForEveryCluster[key].Count > 0)
                {
                    string      output  = "Rank" + separator + "Functionname" + separator + "Suspiciousness Value(" + faultLocalizationStrategy.ToString() + ")\n";
                    string      path    = parentPath + "\\" + filenameTemplate + key + ".csv";
                    List <Item> tmpList = suspiciousnessListForEveryCluster[key];

                    int    rank  = 1;
                    double value = tmpList.ElementAt(0).Suspiciousness;
                    foreach (Item item in tmpList)
                    {
                        if (Math.Abs(value - item.Suspiciousness) > 0.0000001)
                        {
                            rank++;
                        }
                        output += Convert.ToString(rank) + separator + item.ItemName + separator + item.Suspiciousness + "\n";
                        value   = item.Suspiciousness;
                    }



                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(path))
                    {
                        file.Write(output);
                    }

                    CommandLinePrinter.printToCommandLine(".");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Prints command line parameters on the console
        /// </summary>
        private static void printCommandLineParameters()
        {
            string output = "**********************************\n"
                            + "* Summary Commandline Parameters *\n"
                            + "**********************************\n";

            foreach (string key in commandLineArguments.Keys)
            {
                CommandLineArgument arg = commandLineArguments[key];
                output += arg.Key + " = " + arg.Value + "\n";
            }

            CommandLinePrinter.printToCommandLine(output);
        }
Exemple #3
0
        public void exportClusteringResults()
        {
            string toPrint = "\nExporting Clustering results\n";

            if (Do.Equals("cluster", StringComparison.OrdinalIgnoreCase))
            {
                CommandLinePrinter.printToCommandLine(toPrint);
            }

            exportClustering();
            //exportSuspiciousnessRanking();
            drawDendrogram();
            if (Do.Equals("cluster", StringComparison.OrdinalIgnoreCase))
            {
                CommandLinePrinter.printToCommandLine("\nFinished Exporting Clustering results\n");
            }
        }
Exemple #4
0
        public void linkage()
        {
            string output = "\nDoing Linkage\n";

            CommandLinePrinter.printToCommandLine(output);
            int     numFailedTest = failedTestcasesInHitSpectraMatrix.GetLength(0);
            MWArray tmpSolution;

            if (numFailedTest == 1)
            {
                tmpSolution = new MWNumericArray(failedTestcasesInHitSpectraMatrix);
            }
            else
            {
                tmpSolution = matlabClustering.matlabLinkage(new MWNumericArray(failedTestcasesInHitSpectraMatrix), new MWCharArray(linkage_method), new MWCharArray(linkage_metric));
            }
            binaryClusterTree = Tools.buildTwoDimensionalDoubleArrayFromMWArray(tmpSolution);

            output = "\nFinished Linkage\n";
            CommandLinePrinter.printToCommandLine(output);
        }
Exemple #5
0
        /// <summary>
        /// the main function.
        /// Aletheia starts here. It directs the program what to do based on command line input
        /// </summary>
        /// <param name="args">It is an array of argument</param>
        public static void Main(string[] args)
        {
            // Reading command line arguments
            CommandLineReader commandLineReader = new CommandLineReader(args);

            commandLineArguments = commandLineReader.CommandLineArguments;
            if (commandLineArguments.Count() == 0)
            {
                Console.WriteLine("No Recognized parameter\n\n use Spectralizer.exe do=getHelp for help\n");
                return;
            }


            printCommandLineParameters();


            //check which operation is seleced

            if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.OPERATION))
            {
                throw new Exception("Please select a operation: GenerateHitSpectra/Cluster/FaultLocalization!");
            }
            operation = commandLineArguments[PossibleCommandLineArguments.OPERATION].Value;
            // Check, which mode is selected
            //if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.MODE)) throw new Exception("Please select a operation mode!");
            //mode = commandLineArguments[PossibleCommandLineArguments.MODE].Value;

            string outputDirectory = "";

            //check debug value
            if (commandLineArguments.Keys.Contains(PossibleCommandLineArguments.DEBUG))
            {
                DEBUG = Convert.ToBoolean(commandLineArguments[PossibleCommandLineArguments.DEBUG].Value);
            }

            // Check, if output directory is available
            if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.OUTPUT_DIRECTORY))
            {
                outputDirectory = "C:\\HitSpectras";
            }
            else
            {
                outputDirectory = commandLineArguments[PossibleCommandLineArguments.OUTPUT_DIRECTORY].Value;
            }
            if ((workingDirectory = Program.createWorkingDirectory(outputDirectory)) == null)
            {
                return;
            }

            // Check if clustering should be done
            //if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.CLUSTERING)) return;
            //clustering = Convert.ToBoolean(commandLineArguments[PossibleCommandLineArguments.CLUSTERING].Value);

            if (operation.Equals("GenerateHitSpectra", StringComparison.OrdinalIgnoreCase))
            {
                if (!commandLineArguments.Keys.Contains(PossibleCommandLineArguments.GTEST_PATH))
                {
                    Console.WriteLine("Gtest path is mandatory for current settings.\n");
                    return;
                }
                HitSpectra.Spectralizer spectralizer = new HitSpectra.Spectralizer(commandLineArguments, workingDirectory);
                if (DEBUG)
                {
                    Console.WriteLine("Generation of Spectralizer object is complete\n");
                }
                spectralizer.executeTestSuite();
                if (DEBUG)
                {
                    Console.WriteLine("Execution of Test Suite is complete\n");
                }
                spectralizer.exportHitSpectraMatrices();
                if (DEBUG)
                {
                    Console.WriteLine("Exporting of HitSpectra matrix is complete\n");
                }

                FunctionHitSpectraMatrix = spectralizer.FunctionHitSpectraMatrix;
                CountingFunctionInvokationsHitSpectraMatrix    = spectralizer.CountingFunctionInvokationsHitSpectraMatrix;
                InvokedFunctionsHitSpectraMatrix               = spectralizer.InvokedFunctionsHitSpectraMatrix;
                InvokedFunctionsWithParametersHitSpectraMatrix = spectralizer.InvokedFunctionsWithParametersHitSpectraMatrix;
                LineCoverageHitSpectraMatrix = spectralizer.LineCoverageHitSpectraMatrix;
                Console.WriteLine("Spectra Matrix generated\n");
            }
            else if (operation.Equals("Cluster", StringComparison.OrdinalIgnoreCase))
            {
                string output = "\nClustering Given HitSpectraMatrix\n";
                if (operation.Equals("Cluster", StringComparison.OrdinalIgnoreCase))
                {
                    CommandLinePrinter.printToCommandLine(output);
                }
                else
                {
                    Console.WriteLine("\nCreating Fault Localization with given HitSpectra");
                }

                char   separator;
                string inputPath;

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.SEPARATOR))
                {
                    separator = ' ';
                }
                else
                {
                    separator = commandLineArguments[PossibleCommandLineArguments.SEPARATOR].Value.Trim()[0];
                }

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.INPUT_PATH))
                {
                    throw new Exception("No input path");
                }
                inputPath = commandLineArguments[PossibleCommandLineArguments.INPUT_PATH].Value;

                HitSpectraCsvSheetReader reader = new HitSpectraCsvSheetReader(inputPath, separator);
                reader.parseSheet();
                DataTable dataTable = reader.getDataTable();

                string pathAdditional = "Clustering";
                string path           = workingDirectory + "\\" + pathAdditional;

                doClustering(dataTable, path);
            }
            else if (operation.Equals("faultLocalization", StringComparison.OrdinalIgnoreCase))
            {
                string output = "\nRunning Fault Localization\n";

                CommandLinePrinter.printToCommandLine(output);
                char   separator;
                string inputPath;

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.SEPARATOR))
                {
                    separator = ' ';
                }
                else
                {
                    separator = commandLineArguments[PossibleCommandLineArguments.SEPARATOR].Value.Trim()[0];
                }

                if (!commandLineArguments.ContainsKey(PossibleCommandLineArguments.INPUT_PATH))
                {
                    throw new Exception("No input path");
                }
                inputPath = commandLineArguments[PossibleCommandLineArguments.INPUT_PATH].Value;

                HitSpectraCsvSheetReader reader = new HitSpectraCsvSheetReader(inputPath, separator);
                reader.parseSheet();
                DataTable dataTable = reader.getDataTable();

                string pathAdditional = "FaultLocalization";
                string path           = workingDirectory + "\\" + pathAdditional;
                if (commandLineArguments.ContainsKey(PossibleCommandLineArguments.FAULT_RANKING_METRIC))
                {
                    rankingMetric = commandLineArguments[PossibleCommandLineArguments.FAULT_RANKING_METRIC].Value;
                }
                EStrategy rankingStrategy = getFaultLocalizationStrategy(rankingMetric);
                Detective detective       = new Clustering.FaultLocalization.Detective(dataTable, rankingStrategy, commandLineArguments, path);
                detective.DetectFault();
                CommandLinePrinter.printToCommandLine("Fault Localization complete\n");
            }
            else if (operation.Equals("getHelp", StringComparison.OrdinalIgnoreCase))
            {
                String output = "These are accepted command parameters\nCommand should be given in key=value fashion\n\n";
                output += "do: specifies the operation to be performed\n\tPossible values={'GenerateHitSpectra', 'Cluster', 'FaultLocalization', 'GetHelp'}\n";
                output += "separator: specifies the separator character for csv file\nBy default white space is the separator\n";
                output += "output_directory: where the output will be generated, default output directory is C:\\HitSpectras\n";
                output += "project_path: it is a mandatory argument for HitSpectra Generation part, show the *.vcxproj file\n";

                output += "source_directory: show the directory where the source files are located\n";
                output += "degreeofparallelism: number of threads to run in parallel for HitSpectra generation, default value is 12\n";
                output += "gtest_path: mandatory argument for HitSpectra Generation, show the exe file of test project\n";
                output += "ranking_metric: ranking metric for fault localization, default is Jaccard";
                output += "clustering_method: default is maxclust\n";
                output += "linkage_method: default is average\n";
                output += "linkage_metric: default is euclidean\n";
                output += "similarity_threshold: default is 0.8\ncomparison_range: default is 0.1\n";
                output += "function_coverage: boolean argument, default is true\n";
                output += "invoked_function_coverage: boolean argument, default is true\n";
                output += "invoked_function_with_param_coverage: boolean argument, default is true\n";
                output += "counting_function_invokation_coverage: boolean argument, default is true\n";
                output += "line_coverage: boolean argument, default is true\n";
                CommandLinePrinter.printToCommandLine(output);
            }


            // Do the clustering
            //if (clustering)
            if (operation.Equals("clustering", StringComparison.OrdinalIgnoreCase))
            {
                string output = "\nClustering   HitSpectraMatrices\n";
                CommandLinePrinter.printToCommandLine(output);
                if (FunctionHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_FunctionHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(FunctionHitSpectraMatrix, path);
                }

                if (CountingFunctionInvokationsHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_CountingFunctionInvokationsHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(CountingFunctionInvokationsHitSpectraMatrix, path);
                }

                if (InvokedFunctionsHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_InvokedFunctionsHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(InvokedFunctionsHitSpectraMatrix, path);
                }

                if (InvokedFunctionsWithParametersHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_InvokedFunctionsWithParametersHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(InvokedFunctionsWithParametersHitSpectraMatrix, path);
                }

                if (LineCoverageHitSpectraMatrix != null)
                {
                    string pathAdditional = "Clustering_LineCoverageHitSpectra";
                    string path           = workingDirectory + "\\" + pathAdditional;

                    doClustering(LineCoverageHitSpectraMatrix, path);
                }
            }
        }
Exemple #6
0
        private void exportClustering()
        {
            string path   = parentPath + @"\clustering.csv";
            string output = "Testcase" + separator + "Cluster" + separator + "Link\n";
            int    i      = 1;

            foreach (int n in clusterClassification)
            {
                output += idListFailed[i] + separator + n + separator + "=HYPERLINK(\"" + @"ClusterHitSpectra\Cluster_" + n + "HitSpectra.csv\")\n";
                i++;

                CommandLinePrinter.printToCommandLine(".");
            }

            /*output += "\n\nCluster Centers\n\n";
             * int N = idClusterCenter.Count();
             * for (i = 0; i < N; i++)
             * {
             *  output += "Cluster ID: " + (i + 1) + "  Cluster Center: " + idClusterCenter[i] + "\n";
             * }
             * output += "\n\nkNN data for k="+K+"\n";
             */
            int len = kNNData.Count();

            for (i = 0; i < len; i++)
            {
                if (kNNData.ContainsKey(i))
                {
                    string[] str = kNNData[i];

                    if (str.Length >= K)
                    {
                        output += "For Cluster " + (i + 1) + " " + K + " representative test(s) is/are: \n\t";
                        for (int j = 0; j < K; j++)
                        {
                            if (j == K - 1)
                            {
                                output += (j + 1) + ") " + str[j] + "\n";
                            }
                            else
                            {
                                output += (j + 1) + ") " + str[j] + "\n\t";
                            }
                        }
                    }
                    else if (str.Length > 1)
                    {
                        output += "For Cluster " + (i + 1) + " Available " + (str.Length) + " representative test(s) is/are: \n\t";
                        for (int j = 0; j < str.Length; j++)
                        {
                            if (j == str.Length - 1)
                            {
                                output += (j + 1) + ") " + str[j] + "\n";
                            }
                            else
                            {
                                output += (j + 1) + ") " + str[j] + "\n\t";
                            }
                        }
                    }
                    else
                    {
                        output += "Cluster " + (i + 1) + " has only one Represenntative test\n\t1) " + str[0] + "\n";
                    }
                }
            }
            output += "\n";
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(path))
            {
                file.Write(output);
            }
        }
Exemple #7
0
        public void doClustering()
        {
            string output = "\nStarting Clustering\n";

            if (Do.Equals("cluster", StringComparison.OrdinalIgnoreCase))
            {
                CommandLinePrinter.printToCommandLine(output);
            }

            int numberOfNodes     = 2;
            int prevNumberOfNodes = 1;
            int maxNumberOfNodes  = failedTestcasesInHitSpectraMatrix.GetLength(0);

            int[] tmpClusterClassification;
            int[] prevClusterClassification =
                Tools.buildOneDimensionalIntArray(matlabClustering.buildNCluster(new MWNumericArray(binaryClusterTree), new MWNumericArray(1), new MWCharArray(clustering_method)));
            Dictionary <int, List <int[]> > prevListOfClusters = Tools.allocateTestcasesIntoClusters(Tools.buildOneDimensionalIntArray(matlabClustering.buildNCluster(new MWNumericArray(binaryClusterTree), new MWNumericArray(1), new MWCharArray(clustering_method))), failedTestcasesInHitSpectraMatrix);

            while (numberOfNodes < maxNumberOfNodes)
            {
                MWArray tmpSolution = matlabClustering.buildNCluster(new MWNumericArray(binaryClusterTree), new MWNumericArray(numberOfNodes), new MWCharArray(clustering_method));
                tmpClusterClassification = Tools.buildOneDimensionalIntArray(tmpSolution);
                //MWArray tmpCenter = matlabClustering.findClusterCenter(new MWNumericArray(binaryClusterTree), 0.6);
                Dictionary <int, List <int[]> > tmpListOfClusters = Tools.allocateTestcasesIntoClusters(tmpClusterClassification, failedTestcasesInHitSpectraMatrix);

                int[,] firstCluster  = Tools.transformJaggedArrayToTwoDimensionalArray(tmpListOfClusters[1].ToArray());
                firstCluster         = Tools.mergeTwoTwoDimensionalIntArrays(firstCluster, passedTestcasesInHitSpectraMatrix);
                int[,] secondCluster = Tools.transformJaggedArrayToTwoDimensionalArray(tmpListOfClusters[2].ToArray());
                secondCluster        = Tools.mergeTwoTwoDimensionalIntArrays(secondCluster, passedTestcasesInHitSpectraMatrix);

                List <Item> suspiciousnessList1 = new FaultLocalizer(firstCluster, Tools.generateFunctionNamesArray(hitSpectraMatrix), faultLocalizationStrategy).calculateSuspiciousnessRanking();
                List <Item> suspiciousnessList2 = new FaultLocalizer(secondCluster, Tools.generateFunctionNamesArray(hitSpectraMatrix), faultLocalizationStrategy).calculateSuspiciousnessRanking();

                Comparator comparator = new Comparator(ComparingStrategy.JaccardTwoSets, comparisonRange);
                double     similarity = comparator.compare(suspiciousnessList1, suspiciousnessList2);

                if (similarity > similarityThreshold)
                {
                    break;
                }

                prevNumberOfNodes = numberOfNodes;
                numberOfNodes++;
                prevClusterClassification = tmpClusterClassification;
                prevListOfClusters        = tmpListOfClusters;
            }

            numberOfClusters      = prevNumberOfNodes;
            clusterClassification = prevClusterClassification;
            listOfClusters        = prevListOfClusters;

            buildSuspiciousnessRankingForCluster();


            if (Do.Equals("cluster", StringComparison.OrdinalIgnoreCase))
            {
                output = "\nFinished Clustering\n";
                //distance = D.getDistance(new MWNumericArray(failedTestcasesInHitSpectraMatrix), new MWCharArray(linkage_metric));
                CommandLinePrinter.printToCommandLine(output);
            }
        }
Exemple #8
0
        public void findClusterCenter()
        {
            string output = "\nFinding Cluster Center\n";

            if (Do.Equals("cluster", StringComparison.OrdinalIgnoreCase))
            {
                CommandLinePrinter.printToCommandLine(output);
            }
            int i = 0, j = 0, counter = 0;

            int[][] failedHitSpectra = Tools.transformTwoDimensionalArrayToJaggedArray(failedTestcasesInHitSpectraMatrix);
            //step 1. separate the test cases from listOfCluster per cluster
            //idListFailed contains the name of failed test cases
            //clusterClassification holds the cluster number for each test case
            //listOfClusters holds the cluster list
            int n = listOfClusters.Count();// number of clusters
            int F = idListFailed.Count();

            idClusterDistance = new Dictionary <int, double[]>();
            clusters          = new List <int> [n];

            for (i = 0; i < F; i++)
            {
                if (clusters[clusterClassification[i] - 1] == null)
                {
                    clusters[clusterClassification[i] - 1] = new List <int>();
                }
                clusters[clusterClassification[i] - 1].Add(i);
            }



            //step 2. for each cluster separate the hitSpectra from failedTestCaseInHitSpectra matrix
            idClusterCenter = new Dictionary <int, string>();
            int L = failedTestcasesInHitSpectraMatrix.GetLength(1);

            //dumpArray(failedTestcasesInHitSpectraMatrix);
            for (i = 0; i < n; i++) //for each cluster
            {
                double[][] failedCluster = new double[clusters[i].Count()][];
                counter = 0;
                //double D = euclideanDistance(getRow(0, failedTestcasesInHitSpectraMatrix, L), getRow(6, failedTestcasesInHitSpectraMatrix, L), L);
                foreach (int a in clusters[i])
                {
                    //failedCluster[counter] = new double[L];
                    failedCluster[counter] = getRow(a, failedTestcasesInHitSpectraMatrix, L);
                    counter++;
                }
                //step 3. for each set of hitSpectra run find cluster center
                string centerName = "";
                if (counter > 2)
                {
                    centerName = ClusterCenter(failedCluster, clusters[i], i);
                }
                else if (counter == 2)
                {
                    centerName = idListFailed[clusters[i][0] + 1];
                    double[] dist2 = new double[2];
                    dist2[0] = 0.0;
                    dist2[1] = euclideanDistance(failedCluster[0], failedCluster[1], failedCluster[0].Length);
                    idClusterDistance.Add(i, dist2);
                }
                else
                {
                    centerName = idListFailed[clusters[i][0] + 1];
                    double[] dist2 = new double[1];
                    dist2[0] = 0.0;
                    idClusterDistance.Add(i, dist2);
                }

                //if(Do.Equals("cluster", StringComparison.OrdinalIgnoreCase))
                //  Console.WriteLine("Cluster id: "+ (i+1)+" Cluster Center: "+centerName);
                idClusterCenter.Add(i, centerName);
            }
            KNNData();
            exportClusterHitSpectra();
        }