9
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
2
|
17 |
package com.nokia.cdt.debug.cw.symbian.tests;
|
|
18 |
|
|
19 |
import java.io.File;
|
|
20 |
import java.io.FileOutputStream;
|
|
21 |
import java.io.IOException;
|
|
22 |
import java.io.PrintStream;
|
|
23 |
import java.util.ArrayList;
|
|
24 |
import java.util.Arrays;
|
|
25 |
|
|
26 |
import junit.framework.TestCase;
|
|
27 |
|
|
28 |
import org.eclipse.cdt.utils.debug.dwarf.DwarfReader;
|
|
29 |
|
|
30 |
public class DwarfReaderTest extends TestCase {
|
|
31 |
|
|
32 |
private String m_outputFileName = "c:\\temp\\DwarfReaderOutput.txt";
|
|
33 |
|
|
34 |
// The Elf file to parse.
|
|
35 |
//
|
|
36 |
private String[] m_dataFileNames;
|
|
37 |
|
|
38 |
private PrintStream m_outputFileStream = null;
|
|
39 |
|
|
40 |
protected void setUp() throws Exception {
|
|
41 |
super.setUp();
|
|
42 |
|
|
43 |
m_dataFileNames = getDataFileNames();
|
|
44 |
|
|
45 |
if (m_outputFileStream == null) {
|
|
46 |
File outputFile = new File(m_outputFileName);
|
|
47 |
if (!outputFile.exists())
|
|
48 |
outputFile.createNewFile();
|
|
49 |
|
|
50 |
m_outputFileStream = new PrintStream(new FileOutputStream(
|
|
51 |
outputFile, false /* append? */));
|
|
52 |
|
|
53 |
m_outputFileStream.println("Output of test on CDT DwarfReader");
|
|
54 |
m_outputFileStream.println("==========================================");
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
protected void tearDown() throws Exception {
|
|
59 |
super.tearDown();
|
|
60 |
|
|
61 |
m_outputFileStream.close();
|
|
62 |
}
|
|
63 |
|
|
64 |
public final void testGetSourceFiles() {
|
|
65 |
for (String fname: m_dataFileNames) {
|
|
66 |
File f = new File(fname);
|
|
67 |
if (f == null || !f.exists())
|
|
68 |
fail("Data file not found: " + f.getAbsolutePath());
|
|
69 |
|
|
70 |
// Currently this just check if the parsing process succeeds,
|
|
71 |
// not check if the output is correct.
|
|
72 |
// Look at the output file designated by "m_outputFileName"
|
|
73 |
// and see if it's correct.
|
|
74 |
getSourceFilesForBinary(fname);
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
// Get data files to test
|
|
79 |
//
|
|
80 |
private String[] getDataFileNames() throws Exception {
|
|
81 |
String[] fnames = null;
|
|
82 |
|
|
83 |
ArrayList<String> list = new ArrayList<String>(10);
|
|
84 |
|
|
85 |
// To add individual data files...
|
|
86 |
//
|
|
87 |
/*
|
|
88 |
list.add("M:\\epoc32\\RELEASE\\armv5\\udeb\\agenda.sym");
|
|
89 |
list.add(TestsPlugin.getPluginPath()+"\\data\\one2.sym");
|
|
90 |
list.add(TestsPlugin.getPluginPath()+"\\data\\_h2_dma.sym");
|
|
91 |
*/
|
|
92 |
|
|
93 |
// To add files under one folder...
|
|
94 |
//
|
|
95 |
// All all .sym files under data folder in the project.
|
|
96 |
list.addAll(Arrays.asList(TestsPlugin.getFileFullNamesInFolder(
|
|
97 |
TestsPlugin.getPluginPath()+"\\data\\", ".sym")));
|
|
98 |
/*
|
|
99 |
list.addAll(Arrays.asList(TestsPlugin.getFileFullNamesInFolder(
|
|
100 |
"M:\\epoc32\\RELEASE\\armv5\\udeb\\", ".sym")));
|
|
101 |
list.addAll(Arrays.asList(TestsPlugin.getFileFullNamesInFolder(
|
|
102 |
"M:\\epoc32\\RELEASE\\gcce\\udeb\\", ".sym")));
|
|
103 |
*/
|
|
104 |
|
|
105 |
fnames = new String[list.size()];
|
|
106 |
list.toArray(fnames);
|
|
107 |
|
|
108 |
return fnames;
|
|
109 |
}
|
|
110 |
|
|
111 |
private void getSourceFilesForBinary(String binaryFileName) {
|
|
112 |
DwarfReader reader = null;
|
|
113 |
|
|
114 |
try {
|
|
115 |
reader = new DwarfReader(binaryFileName);
|
|
116 |
} catch (IOException e) {
|
|
117 |
e.printStackTrace();
|
|
118 |
fail("File \"" + binaryFileName + "\" is not valid Elf file.");
|
|
119 |
return;
|
|
120 |
}
|
|
121 |
|
|
122 |
m_outputFileStream.println("\n----------------------------------------------------");
|
|
123 |
m_outputFileStream.println("Data file to check: ");
|
|
124 |
m_outputFileStream.println("\t" + binaryFileName);
|
|
125 |
m_outputFileStream.println("----------------------------------------------------");
|
|
126 |
|
|
127 |
String[] files = reader.getSourceFiles();
|
|
128 |
|
|
129 |
m_outputFileStream.print("Number of source files: ");
|
|
130 |
m_outputFileStream.println(files.length);
|
|
131 |
m_outputFileStream.println();
|
|
132 |
|
|
133 |
// Sort the file lists.
|
|
134 |
Arrays.sort(files);
|
|
135 |
|
|
136 |
for (String f : files) {
|
|
137 |
m_outputFileStream.println(f);
|
|
138 |
}
|
|
139 |
}
|
|
140 |
|
|
141 |
// --- NOTE ------
|
|
142 |
// This is for my own manual junit test only, not for public
|
|
143 |
// auto-test.
|
|
144 |
public void my_testLineInfoContainsMoreSourceFiles() {
|
|
145 |
|
|
146 |
// Iterate through those files and check...
|
|
147 |
for (String f : m_dataFileNames) {
|
|
148 |
m_outputFileStream.format("Check [%s] :\n", f);
|
|
149 |
|
|
150 |
if (lineInfoContainsMoreSourceFiles(f))
|
|
151 |
m_outputFileStream.println("yes !");
|
|
152 |
else
|
|
153 |
m_outputFileStream.println("No.");
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
/*
|
|
158 |
* This function checks if .debug_line section contains
|
|
159 |
* source files that are not referenced by any TAG_compile_units.
|
|
160 |
*
|
|
161 |
* @param dataFileName
|
|
162 |
*/
|
|
163 |
private boolean lineInfoContainsMoreSourceFiles(String dataFileName) {
|
|
164 |
DwarfReader reader = null;
|
|
165 |
|
|
166 |
try {
|
|
167 |
reader = new DwarfReader(dataFileName);
|
|
168 |
} catch (IOException e) {
|
|
169 |
e.printStackTrace();
|
|
170 |
fail("File \"" + dataFileName + "\" is not valid Elf file.");
|
|
171 |
return false;
|
|
172 |
}
|
|
173 |
|
|
174 |
// Hold on !
|
|
175 |
// Look at code of getSourceFiles() and add two public
|
|
176 |
// APIs like
|
|
177 |
// "getSourcesFromCompileUnit()" and
|
|
178 |
// "getSourcesFromDebugLine()"
|
|
179 |
// and then test here.
|
|
180 |
String[] filesFromCU = reader.getSourceFiles(); // change to getFromCompileUnit()
|
|
181 |
String[] filesFromLineInfo = reader.getSourceFiles(); // change to getFromDebugLine()
|
|
182 |
|
|
183 |
/*
|
|
184 |
// Sort the file lists and compare the list if needed.
|
|
185 |
//
|
|
186 |
Arrays.sort(filesFromCU);
|
|
187 |
Arrays.sort(filesFromLineInfo);
|
|
188 |
|
|
189 |
assertEquals(filesFromCU.length, filesFromLineInfo.length);
|
|
190 |
for (int i = 0; i < filesFromCU.length; i++) {
|
|
191 |
assertEquals(filesFromCU[i], filesFromLineInfo[i]);
|
|
192 |
}
|
|
193 |
*/
|
|
194 |
return (filesFromCU.length > filesFromLineInfo.length);
|
|
195 |
}
|
|
196 |
|
|
197 |
}
|