/* * Copyright 2009 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 Sequenic.T2ext.Analyzer; import java.util.*; import Sequenic.Graph.*; import Sequenic.T2ext.Instrumenter.Edge; import Sequenic.T2ext.Instrumenter.Node; import Sequenic.T2ext.Instrumenter.ObservedPath; public class CoverageResult { public LinkedList> directlyCoveredPaths = new LinkedList>() ; public LinkedList> detourlyCoveredPaths = new LinkedList>() ; public Map,Long> directlyClosestPaths = new HashMap,Long>() ; public Map,Long> detourlyClosestPaths = new HashMap,Long>() ; public void simplePrint(Map observedpaths){ assert observedpaths != null ; System.out.println("Directly covered paths:") ; for (LinkedList P : directlyCoveredPaths) { System.out.println(" " + PathUtil.pathSimpleShow(P)) ; } System.out.println("Detourly covered paths:") ; for (LinkedList P : detourlyCoveredPaths) { System.out.println(" " + PathUtil.pathSimpleShow(P)) ; } System.out.println("Closest directly covering paths:") ; for (Map.Entry,Long> entry : directlyClosestPaths.entrySet()) { LinkedList P = entry.getKey() ; if (directlyCoveredPaths.contains(P)) continue ; System.out.print(" " + PathUtil.pathSimpleShow(P)) ; System.out.print(" <=== ") ; ObservedPath O = observedpaths.get(entry.getValue()) ; assert O != null ; System.out.println(PathUtil.pathSimpleShow(O.getNodes())) ; /* System.out.println(">>> runid: " + directlyClosestPaths.get(P)) ; System.out.println(">>> path: " + O) ; System.out.println(">>> #observations: " + observedpaths.size()) ; Long rid_ = directlyClosestPaths.get(P) ; boolean found = false ; for (Long i : observedpaths.keySet()) if (i.equals(rid_)) { found = true ; break ; } assert found ; */ } System.out.println("Closest detourly covering paths:") ; for (Map.Entry,Long> entry : detourlyClosestPaths.entrySet()) { LinkedList P = entry.getKey() ; if (directlyCoveredPaths.contains(P) || detourlyCoveredPaths.contains(P)) continue ; System.out.print(" " + PathUtil.pathSimpleShow(P)) ; System.out.print(" <=== ") ; ObservedPath O = observedpaths.get(entry.getValue()) ; assert O != null ; System.out.println(PathUtil.pathSimpleShow(O.getNodes())) ; } } static public LinkedList convertToIntList(LinkedList NodeList){ LinkedList P = new LinkedList() ; for (Node N : NodeList) P.add(N.getId()) ; return P ; } /* static public String simplePrintPath(LinkedList path){ String r = "" ; for (Integer n : path) r = r + n + " --> " ; return r + "EXIT"; } */ /** * Return the set of all nodes passed by the given paths. */ static public List getPassedNodes(List> paths) { List result = new LinkedList() ; for (LinkedList path : paths) for (Node N : path) { if (! result.contains(N)) result.add(N) ; } return result ; } /** * Return the node-coverage induced by the given path coverage. * * @param targetpaths The set of target paths to cover; from this we * infer the set of nodes to cover. * * @param coveredpaths The set of covered paths. From this we infer * the set of covered nodes. * * @return the percentage of covered nodes vs the set of target nodes. */ static public float calcNodeCoverage( List> targetpaths, List> coveredpaths ) { int N = getPassedNodes(targetpaths).size() ; int C = getPassedNodes(coveredpaths).size() ; return T2TraceFileCoverageResult.calcPercentage(C,N) ; } /** * Return the set of branches passed by the given paths. * * @param setOfNodes the set of all nodes to consider; each node * carry its set of successors, thus its outgoing edges. PRE: * the set of nodes contains no duplicate nodes. */ static public List> getPassedBranches( List setOfNodes, List> paths ) { List> result = new LinkedList>() ; for (Node N : setOfNodes) { if (N.children.size() < 2) continue ; for (Vertex child : N.children) { Node O = (Node) child ; // Ok so (N,O) is an edge, now check if it occurs in // a target path: Edge edge = new Edge(N,O) ; if (occurInTargetPath(edge,paths)) result.add(edge) ; } } return result ; } static private boolean occurInTargetPath( Edge edge, List> paths ) { for (LinkedList path : paths) { int n = path.size() ; if (n<2) continue ; Iterator iter = path.iterator() ; Node N = null ; Node O = iter.next() ; int i = 1 ; while (i setOfNodes, List> targetpaths, List> coveredpaths ) { int N = getPassedBranches(setOfNodes,targetpaths).size() ; int C = getPassedBranches(setOfNodes,coveredpaths).size() ; return T2TraceFileCoverageResult.calcPercentage(C,N) ; } }