/* * Copyright 2008 Wishnu Prasetya. * * This file is part of T2. * T2 is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License (GPL) as published by the * Free Software Foundation; either version 3 of the License, or any * later version. * * T2 is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * A copy of the GNU General Public License can be found in T2 distribution. * If it is missing, see http://www.gnu.org/licenses. */ package t2ext; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import t2ext.trace.PathFinder; import t2ext.util.InfoFile; import t2ext.xml.XMLBuilder; import Sequenic.T2.Main; /** * @author Maaike Gerritsen */ public class ExecuteRndEngine { /** * @param args */ public static void main(String[] args) { String className = args[0]; InfoFile infoFile = InfoFile.load(); String totalArgument = getTotalArgument(args, infoFile); Main.main(totalArgument); long percentage = countRatio(false); long oldPercentage = percentage; System.out.println("ALLOW SIDETRIPS"); long percentageN = countRatio(true); long oldPercentageS = percentageN; if (percentage < 100) { // start to improve branch coverage PathFinder fPaths = new PathFinder(className, infoFile); fPaths.updateFoundPaths(); percentage = countRatio(false); System.out.println("T2 percentage: " + oldPercentage + "%"); if (percentage < 100) { // if we still haven't reached 100%, try // paths with sidetrips System.out.println("ALLOW SIDETRIPS"); countRatio(true); System.out.println("T2 percentage: " + oldPercentageS + "%"); } } } private static String getTotalArgument(String[] args, InfoFile infoFile) { String className = args[0]; String saveTraces = " --savegoodtr=" + infoFile.saveGoodTraces; String total = className + " --ownclassonly"; for (int i = 1; i < args.length; i++) { String arg = args[i]; if (!arg.contains("maxattempts") && !arg.contains("pathoptm")) total += " " + arg; } if (!total.contains("savegoodtr")) total += saveTraces; return total; } @SuppressWarnings("unchecked") private static long countRatio(boolean countSideTrips) { int countFalse = 0; int countTrue = 0; XMLBuilder builder = new XMLBuilder(); Document paths = builder.readXMLFile("paths.xml"); NodeList foundPaths = builder.getNodesFromXML(paths, "//path[@found='true']"); countTrue = foundPaths.getLength(); foundPaths = builder.getNodesFromXML(paths, "//path[@found='false']"); countFalse = foundPaths.getLength(); foundPaths = builder.getNodesFromXML(paths, "//method[contains(@official,'_spec')]"); if (countFalse >= foundPaths.getLength()) countFalse -= foundPaths.getLength(); if (countSideTrips) { foundPaths = builder.getNodesFromXML(paths, "//path[@found='false' and @foundws='true']"); int sideTrips = foundPaths.getLength(); System.out.println("sidetrips: " + sideTrips); countFalse -= sideTrips; countTrue += sideTrips; } System.out.println("amount of paths found: " + countTrue); System.out.println("amount of paths not found: " + countFalse); double perc = ((countTrue * 1.0) / ((countTrue + countFalse) * 1.0)) * 100.0; System.out.println("foundPercentage: " + Math.round(perc) + "%"); return Math.round(perc); } }