Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…with cygwin).
  • Loading branch information
Xavier Raynaud committed Mar 9, 2011
1 parent 43f6c40 commit 33942c1
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void testGcovParsing(
File parserRefFile, File parserDumpFile)
throws Exception {
CovManager covManager = new CovManager(binaryFile.getAbsolutePath());
covManager.processCovFiles(covFilesPaths);
covManager.processCovFiles(covFilesPaths, null);
covManager.dumpProcessCovFilesResult(new PrintStream(parserDumpFile));
STJunitUtils.compareIgnoreEOL(parserDumpFile.getAbsolutePath(), parserRefFile.getAbsolutePath(), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void testView(
File refFile, File dumpFile) throws Exception {
Locale.setDefault( Locale.US );
CovManager cvrgeMnger = new CovManager(binaryFile.getAbsolutePath());
cvrgeMnger.processCovFiles(covFilesPaths);
cvrgeMnger.processCovFiles(covFilesPaths, null);
// generate model for view
cvrgeMnger.fillGcovView();
//load an Eclipse view
Expand Down
3 changes: 2 additions & 1 deletion gcov/org.eclipse.linuxtools.gcov/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jface.text,
org.eclipse.debug.ui,
org.eclipse.linuxtools.dataviewers.charts,
org.eclipse.linuxtools.dataviewers.annotatedsourceeditor
org.eclipse.linuxtools.dataviewers.annotatedsourceeditor,
org.eclipse.cdt.debug.core
Export-Package: org.eclipse.linuxtools.gcov.utils,
org.eclipse.linuxtools.gcov.view
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void open(IPath file) {
}
String binaryPath = d.getBinaryFile();
if (d.isCompleteCoverageResultWanted()) {
CovView.displayCovResults(binaryPath);
CovView.displayCovResults(binaryPath, gcda.getAbsolutePath());
} else {
CovView.displayCovDetailedResult(binaryPath, gcda.getAbsolutePath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -39,6 +40,10 @@
import org.eclipse.linuxtools.gcov.model.CovFolderTreeElement;
import org.eclipse.linuxtools.gcov.model.CovFunctionTreeElement;
import org.eclipse.linuxtools.gcov.model.CovRootTreeElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;


/**
Expand Down Expand Up @@ -71,20 +76,44 @@ public CovManager(String binaryPath) {
}



/**
* parse coverage files, execute resolve graph algorithm, process counts for functions,
* lines and folders.
* @param List of coverage files paths
* @throws CoreException, IOException, InterruptedException
*/

public void processCovFiles(List<String> covFilesPaths) throws CoreException, IOException, InterruptedException {
public void processCovFiles(List<String> covFilesPaths, String initialGcda) throws CoreException, IOException, InterruptedException {
GcdaRecordsParser daRcrd = null;
DataInput traceFile;

Map<File, File> sourcePath = new HashMap<File, File>();

if (initialGcda != null) {
File initialGcdaFile = new File(initialGcda).getAbsoluteFile();
for (String s : covFilesPaths) {
File gcda = new File(s).getAbsoluteFile();
if (gcda.getName().equals(initialGcdaFile.getName()) && !gcda.equals(initialGcdaFile)) {
if (!sourcePath.isEmpty()) {
// hum... another file has the same name...
// sorry, we have to clean sourcePath
sourcePath.clear();
break;
} else {
addSourceLookup(sourcePath, initialGcdaFile, gcda);
}
}
}
}



for (String gcdaPath: covFilesPaths) {
String gcnoPath = gcdaPath.replace(".gcda", ".gcno");
// parse GCNO file
traceFile = OpenTraceFileStream(gcnoPath);
traceFile = OpenTraceFileStream(gcnoPath, ".gcno", sourcePath);
if (traceFile == null) return;
GcnoRecordsParser noRcrd = new GcnoRecordsParser(sourceMap, allSrcs);
noRcrd.parseData(traceFile);

Expand All @@ -98,7 +127,8 @@ public void processCovFiles(List<String> covFilesPaths) throws CoreException, IO
((DataInputStream)traceFile).close();

// parse GCDA file
traceFile = OpenTraceFileStream(gcdaPath);
traceFile = OpenTraceFileStream(gcdaPath, ".gcda", sourcePath);
if (traceFile == null) return;
if (noRcrd.getFnctns().isEmpty()){
String message = gcnoPath + " doesn't contain any function:\n";
Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, message);
Expand Down Expand Up @@ -209,12 +239,49 @@ public void fillGcovView() {
}

// transform String path to stream
private DataInput OpenTraceFileStream(String filePath) throws FileNotFoundException{

FileInputStream fis = new FileInputStream(filePath);
InputStream inputStream = new BufferedInputStream(fis);

return new DataInputStream(inputStream);
private DataInput OpenTraceFileStream(String filePath, String extension, Map<File, File> sourcePath) throws FileNotFoundException{
File f = new File(filePath).getAbsoluteFile();
if (f.isFile() && f.canRead()) {
FileInputStream fis = new FileInputStream(f);
InputStream inputStream = new BufferedInputStream(fis);
return new DataInputStream(inputStream);
} else {
String postfix = "";
File dir = null;
do {
if ("".equals(postfix)) postfix = f.getName();
else postfix = f.getName() + File.separator + postfix;
f = f.getParentFile();
if (f != null) {
dir = sourcePath.get(f);
} else break;
} while (dir == null);

if (dir != null) {
f = new File(dir, postfix);
if (f.isFile() && f.canRead()) {
return OpenTraceFileStream(f.getAbsolutePath(), extension, sourcePath);
}
}


Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
FileDialog fg = new FileDialog(shell, SWT.OPEN);
fg.setFilterExtensions(new String[] {"*" + extension, "*.*", "*"});
fg.setFileName(f.getName());
String s = fg.open();
if (s == null) return null;
else {
f = new File(s).getAbsoluteFile();
addSourceLookup(sourcePath, f, new File(filePath).getAbsoluteFile());
if (f.isFile() && f.canRead()) {
FileInputStream fis = new FileInputStream(f);
InputStream inputStream = new BufferedInputStream(fis);
return new DataInputStream(inputStream);
}
}
}
return null;
}


Expand Down Expand Up @@ -331,6 +398,8 @@ private void populateGCDAFiles(InputStream s) throws IOException
}
IPath p = new Path(line);
String filename = p.toString();


if (!list.contains(filename)) list.add(filename);
}
}
Expand Down Expand Up @@ -363,4 +432,14 @@ public void dumpProcessCovFilesResult(PrintStream ps) throws FileNotFoundExcepti
public HashMap<String, SourceFile> getSourceMap() {
return sourceMap;
}


private void addSourceLookup(Map<File, File> map, File hostPath, File compilerPath) {
while (hostPath.getName().equals(compilerPath.getName())) {
hostPath = hostPath.getParentFile();
compilerPath = compilerPath.getParentFile();
}
map.put(compilerPath, hostPath);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static void displayCovDetailedResult(String binaryPath, String gcdaFile)
CovManager cvrgeMnger = new CovManager(binaryPath);
List<String> gcdaPaths = new LinkedList<String>();
gcdaPaths.add(gcdaFile);
cvrgeMnger.processCovFiles(gcdaPaths);
cvrgeMnger.processCovFiles(gcdaPaths, gcdaFile);
// generate model for view
cvrgeMnger.fillGcovView();

Expand Down Expand Up @@ -174,12 +174,12 @@ public void run() {
}
}

public static CovView displayCovResults(String binaryPath) {
public static CovView displayCovResults(String binaryPath, String gcda) {
try {
// parse and process coverage data
CovManager cvrgeMnger = new CovManager(binaryPath);
List<String> gcdaPaths = cvrgeMnger.getGCDALocations();
cvrgeMnger.processCovFiles(gcdaPaths);
cvrgeMnger.processCovFiles(gcdaPaths, gcda);
// generate model for view
cvrgeMnger.fillGcovView();
//load an Eclipse view
Expand Down

0 comments on commit 33942c1

Please sign in to comment.