updated tests - references to actual COOJA code
This commit is contained in:
parent
9100b5710b
commit
95186aebcb
7 changed files with 452 additions and 394 deletions
|
@ -26,63 +26,138 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: Level4.java,v 1.1 2006/08/21 12:12:59 fros4943 Exp $
|
||||
* $Id: Level4.java,v 1.2 2007/09/10 14:07:12 fros4943 Exp $
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
|
||||
import se.sics.cooja.GUI;
|
||||
import se.sics.cooja.contikimote.ContikiMoteType;
|
||||
|
||||
public class Level4 {
|
||||
private final File externalToolsSettingsFile = new File("../exttools.cfg");
|
||||
|
||||
static {
|
||||
System.load(new File("level4.library").getAbsolutePath());
|
||||
}
|
||||
|
||||
final static private String bssSectionAddrRegExp =
|
||||
"^.bss[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$";
|
||||
final static private String bssSectionSizeRegExp =
|
||||
"^.bss[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$";
|
||||
final static private String dataSectionAddrRegExp =
|
||||
"^.data[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$";
|
||||
final static private String dataSectionSizeRegExp =
|
||||
"^.data[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$";
|
||||
final static private String varAddressRegExpPrefix =
|
||||
"^[ \t]*0x([0-9A-Fa-f]*)[ \t]*";
|
||||
final static private String varAddressRegExpSuffix =
|
||||
"[ \t]*$";
|
||||
final static private String varNameRegExp =
|
||||
"^[ \t]*(0x[0-9A-Fa-f]*)[ \t]*([^ ]*)[ \t]*$";
|
||||
final static private String varSizeRegExpPrefix =
|
||||
"^";
|
||||
final static private String varSizeRegExpSuffix =
|
||||
"[ \t]*(0x[0-9A-Fa-f]*)[ \t]*[^ ]*[ \t]*$";
|
||||
|
||||
private native void doCount();
|
||||
private native int getRefAddress();
|
||||
|
||||
public Level4() {
|
||||
File mapFile = new File("level4.map");
|
||||
// Configure logger
|
||||
DOMConfigurator.configure(GUI.class.getResource("/" + GUI.LOG_CONFIG_FILE));
|
||||
|
||||
// Check that map file exists
|
||||
if (!mapFile.exists()) {
|
||||
System.err.println("No map file could be loaded");
|
||||
// Load configuration
|
||||
System.out.println("Loading COOJA configuration");
|
||||
GUI.externalToolsUserSettingsFile = externalToolsSettingsFile;
|
||||
GUI.loadExternalToolsDefaultSettings();
|
||||
GUI.loadExternalToolsUserSettings();
|
||||
|
||||
// Should we parse addresses using map file or nm?
|
||||
boolean useNm = Boolean.parseBoolean(GUI.getExternalToolsSetting("PARSE_WITH_NM", "false"));
|
||||
|
||||
Properties addresses = new Properties();
|
||||
int relDataSectionAddr = -1;
|
||||
int dataSectionSize = -1;
|
||||
int relBssSectionAddr = -1;
|
||||
int bssSectionSize = -1;
|
||||
|
||||
if (useNm) {
|
||||
// Parse nm output
|
||||
System.out.println("Parsing using nm");
|
||||
|
||||
File libFile = new File("level4.library");
|
||||
if (!libFile.exists()) {
|
||||
System.err.println("Library file " + libFile.getAbsolutePath() + " could not be found!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Vector<String> nmData = ContikiMoteType.loadNmData(libFile);
|
||||
if (nmData == null) {
|
||||
System.err.println("No nm data could be loaded");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
boolean parseOK = ContikiMoteType.parseNmData(nmData, addresses);
|
||||
if (!parseOK) {
|
||||
System.err.println("Nm data parsing failed");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
relDataSectionAddr = ContikiMoteType.loadNmRelDataSectionAddr(nmData);
|
||||
dataSectionSize = ContikiMoteType.loadNmDataSectionSize(nmData);
|
||||
relBssSectionAddr = ContikiMoteType.loadNmRelBssSectionAddr(nmData);
|
||||
bssSectionSize = ContikiMoteType.loadNmBssSectionSize(nmData);
|
||||
} else {
|
||||
// Parse map file
|
||||
System.out.println("Parsing using map file");
|
||||
File mapFile = new File("level4.map");
|
||||
if (!mapFile.exists()) {
|
||||
System.err.println("No map file could be loaded");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Vector<String> mapData = ContikiMoteType.loadMapFile(mapFile);
|
||||
if (mapData == null) {
|
||||
System.err.println("No map data could be loaded");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
boolean parseOK = ContikiMoteType.parseMapFileData(mapData, addresses);
|
||||
if (!parseOK) {
|
||||
System.err.println("Map data parsing failed");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
relDataSectionAddr = ContikiMoteType.loadRelDataSectionAddr(mapData);
|
||||
dataSectionSize = ContikiMoteType.loadDataSectionSize(mapData);
|
||||
relBssSectionAddr = ContikiMoteType.loadRelBssSectionAddr(mapData);
|
||||
bssSectionSize = ContikiMoteType.loadBssSectionSize(mapData);
|
||||
}
|
||||
|
||||
String varName;
|
||||
varName = "initialized_counter";
|
||||
if (!addresses.containsKey(varName)) {
|
||||
System.err.println("Could not find address of: " + varName);
|
||||
System.exit(1);
|
||||
}
|
||||
varName = "uninitialized_counter";
|
||||
if (!addresses.containsKey(varName)) {
|
||||
System.err.println("Could not find address of: " + varName);
|
||||
System.exit(1);
|
||||
}
|
||||
varName = "ref_var";
|
||||
if (!addresses.containsKey(varName)) {
|
||||
System.err.println("Could not find address of: " + varName);
|
||||
System.exit(1);
|
||||
}
|
||||
if (relDataSectionAddr < 0) {
|
||||
System.err.println("Data segment address < 0: 0x" + Integer.toHexString(relDataSectionAddr));
|
||||
System.exit(1);
|
||||
}
|
||||
if (relBssSectionAddr < 0) {
|
||||
System.err.println("BSS segment address < 0: 0x" + Integer.toHexString(relBssSectionAddr));
|
||||
System.exit(1);
|
||||
}
|
||||
if (dataSectionSize <= 0) {
|
||||
System.err.println("Data segment size <= 0: 0x" + Integer.toHexString(dataSectionSize));
|
||||
System.exit(1);
|
||||
}
|
||||
if (bssSectionSize <= 0) {
|
||||
System.err.println("BSS segment size <= 0: 0x" + Integer.toHexString(bssSectionSize));
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Vector<String> mapContents = loadMapFile(mapFile);
|
||||
|
||||
int relDataSectionAddr = loadRelDataSectionAddr(mapContents);
|
||||
int dataSectionSize = (int) loadDataSectionSize(mapContents);
|
||||
int relBssSectionAddr = loadRelBssSectionAddr(mapContents);
|
||||
int bssSectionSize = (int) loadBssSectionSize(mapContents);
|
||||
|
||||
int referenceAddress = getRefAddress();
|
||||
System.err.println("Reference address: 0x" + Integer.toHexString(referenceAddress));
|
||||
|
||||
int offsetRelToAbs = referenceAddress - getRelVarAddr(mapContents, "ref_var");
|
||||
System.err.println("Offset relative-absolute: 0x" + Integer.toHexString(offsetRelToAbs));
|
||||
int absRefAddress = getRefAddress();
|
||||
System.out.println("Absolute reference address: 0x" + Integer.toHexString(absRefAddress));
|
||||
int relRefAddress = (Integer) addresses.get("ref_var");
|
||||
System.out.println("Relative reference address: 0x" + Integer.toHexString(relRefAddress));
|
||||
int offsetRelToAbs = absRefAddress - relRefAddress;
|
||||
System.out.println("Offset relative-absolute: 0x" + Integer.toHexString(offsetRelToAbs));
|
||||
|
||||
doCount();
|
||||
doCount();
|
||||
|
@ -93,82 +168,6 @@ public class Level4 {
|
|||
System.err.println("Level 4 OK!");
|
||||
}
|
||||
|
||||
private static int getRelVarAddr(Vector<String> mapContents, String varName) {
|
||||
String regExp = varAddressRegExpPrefix + varName + varAddressRegExpSuffix;
|
||||
String retString = getFirstMatchGroup(mapContents, regExp, 1);
|
||||
|
||||
if (retString != null)
|
||||
return Integer.parseInt(retString.trim(), 16);
|
||||
else return 0;
|
||||
}
|
||||
|
||||
private static Vector<String> loadMapFile(File mapFile) {
|
||||
Vector<String> mapContents = new Vector<String>();
|
||||
|
||||
try {
|
||||
BufferedReader in =
|
||||
new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(mapFile)));
|
||||
|
||||
while (in.ready())
|
||||
{
|
||||
mapContents.add(in.readLine());
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("File not found: " + e);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
System.err.println("IO error: " + e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return mapContents;
|
||||
}
|
||||
|
||||
private static int loadRelDataSectionAddr(Vector<String> mapFile) {
|
||||
String retString = getFirstMatchGroup(mapFile, dataSectionAddrRegExp, 1);
|
||||
|
||||
if (retString != null)
|
||||
return Integer.parseInt(retString.trim(), 16);
|
||||
else return 0;
|
||||
}
|
||||
|
||||
private static int loadDataSectionSize(Vector<String> mapFile) {
|
||||
String retString = getFirstMatchGroup(mapFile, dataSectionSizeRegExp, 1);
|
||||
|
||||
if (retString != null)
|
||||
return Integer.parseInt(retString.trim(), 16);
|
||||
else return 0;
|
||||
}
|
||||
|
||||
private static int loadRelBssSectionAddr(Vector<String> mapFile) {
|
||||
String retString = getFirstMatchGroup(mapFile, bssSectionAddrRegExp, 1);
|
||||
|
||||
if (retString != null)
|
||||
return Integer.parseInt(retString.trim(), 16);
|
||||
else return 0;
|
||||
}
|
||||
|
||||
private static int loadBssSectionSize(Vector<String> mapFile) {
|
||||
String retString = getFirstMatchGroup(mapFile, bssSectionSizeRegExp, 1);
|
||||
|
||||
if (retString != null)
|
||||
return Integer.parseInt(retString.trim(), 16);
|
||||
else return 0;
|
||||
}
|
||||
|
||||
private static String getFirstMatchGroup(Vector<String> lines, String regexp, int groupNr) {
|
||||
Pattern pattern = Pattern.compile(regexp);
|
||||
for (int i=0; i < lines.size(); i++) {
|
||||
Matcher matcher = pattern.matcher(lines.elementAt(i));
|
||||
if (matcher.find()) {
|
||||
return matcher.group(groupNr);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Level4();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue