testOutput.addMessage("### Creating data and BSS memory sections");
byte[] initialDataSection = new byte[dataSectionSize];
byte[] initialBssSection = new byte[bssSectionSize];
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, initialDataSection);
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
SectionMoteMemory memory = new SectionMoteMemory(addresses);
VarMemory varMem = new VarMemory(memory);
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
int contikiDataCounter, contikiBSSCounter;
testOutput.addMessage("### Checking initial variable values: 1,0");
contikiDataCounter = varMem.getIntValueOf("var1");
contikiBSSCounter = varMem.getIntValueOf("uvar1");
int javaDataCounter = 1;
int javaBSSCounter = 0;
if (contikiDataCounter != javaDataCounter) {
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
return false;
}
if (contikiBSSCounter != javaBSSCounter) {
testOutput.addMessage("### BSS section mismatch (" + contikiBSSCounter + " != " + javaBSSCounter + ")", MessageList.ERROR);
return false;
}
testOutput.addMessage("### Increasing data and BSS counters 5 times: 6,5");
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
testOutput.addMessage("### Fetching memory, comparing counters");
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, initialDataSection);
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
contikiDataCounter = varMem.getIntValueOf("var1");
contikiBSSCounter = varMem.getIntValueOf("uvar1");
if (contikiDataCounter != javaDataCounter) {
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
return false;
}
if (contikiBSSCounter != javaBSSCounter) {
testOutput.addMessage("### BSS section mismatch (" + contikiBSSCounter + " != " + javaBSSCounter + ")", MessageList.ERROR);
return false;
}
testOutput.addMessage("### Backup memory sections: 6,5");
byte[] savedDataSection = new byte[dataSectionSize];
byte[] savedBssSection = new byte[bssSectionSize];
int backupDataCounter = contikiDataCounter;
int backupBssCounter = contikiBSSCounter;
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, savedDataSection);
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, savedBssSection);
testOutput.addMessage("### Increasing data and BSS counters 3 times: 9,8");
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
testOutput.addMessage("### Fetching memory, comparing counters");
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, initialDataSection);
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
contikiDataCounter = varMem.getIntValueOf("var1");
contikiBSSCounter = varMem.getIntValueOf("uvar1");
if (contikiDataCounter != javaDataCounter) {
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
return false;
}
if (contikiBSSCounter != javaBSSCounter) {
testOutput.addMessage("### BSS section mismatch (" + contikiBSSCounter + " != " + javaBSSCounter + ")", MessageList.ERROR);
return false;
}
testOutput.addMessage("### Restoring backup data section: 6,8");
javaLibrary.setMemory(relDataSectionAddr, dataSectionSize, savedDataSection);
javaDataCounter = backupDataCounter;
testOutput.addMessage("### Increasing data and BSS counters 3 times: 9,11");
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
javaLibrary.tick(); javaDataCounter++; javaBSSCounter++;
testOutput.addMessage("### Fetching memory, comparing counters");
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, initialDataSection);
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
contikiDataCounter = varMem.getIntValueOf("var1");
contikiBSSCounter = varMem.getIntValueOf("uvar1");
if (contikiDataCounter != javaDataCounter) {
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
return false;
}
if (contikiBSSCounter != javaBSSCounter) {
testOutput.addMessage("### BSS section mismatch (" + contikiBSSCounter + " != " + javaBSSCounter + ")", MessageList.ERROR);
return false;
}
testOutput.addMessage("### Restoring backup BSS section: 9,5");
javaLibrary.setMemory(relBssSectionAddr, bssSectionSize, savedBssSection);
javaBSSCounter = backupBssCounter;
testOutput.addMessage("### Fetching memory, comparing counters");
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, initialDataSection);
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
contikiDataCounter = varMem.getIntValueOf("var1");
contikiBSSCounter = varMem.getIntValueOf("uvar1");
if (contikiDataCounter != javaDataCounter) {
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
return false;