use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.
the class BuildResultValidator method validate.
public void validate() throws Exception {
HashMap<String, HashMap<String, String>> expectedValues = expectedResults.getBuildResults().get(build.number);
HashMap<String, MemoryMapConfigMemoryItem> actualValues = getMemoryItems(build);
System.out.println("¤¤¤¤¤ VALIDATING BUILD " + build.number + " ¤¤¤¤¤");
// printExpected(expectedValues);
printActual(actualValues);
if (validateValues) {
for (Map.Entry<String, HashMap<String, String>> expectedSection : expectedValues.entrySet()) {
String expectedSectionName = expectedSection.getKey();
MemoryMapConfigMemoryItem actualSection = actualValues.get(expectedSectionName);
assertNotNull(String.format("Expected value for key '%s' not found in build result for build #%s: Possible values: %n%s%n======", expectedSectionName, build.number, actualValues), actualSection);
for (Map.Entry<String, String> x : expectedSection.getValue().entrySet()) {
String expectedField = x.getKey();
String expectedValue = x.getValue() == null || x.getValue().equals("N/A") ? "N/A" : new HexUtils.HexifiableString(x.getValue()).toFormattedHexString().rawString;
Object fieldValue = FieldUtils.readField(actualSection, expectedField, true);
String actualValue = fieldValue == null ? "N/A" : new HexUtils.HexifiableString(fieldValue.toString()).toFormattedHexString().rawString;
assertEquals(String.format("Expected %s, was %s for key '%s' for build #%s", expectedValue, actualValue, expectedSection, build.number), expectedValue, actualValue);
}
}
}
if (validateGraphs) {
// TODO: Implement me
}
}
use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.
the class TestUtils method getMemoryItems.
/**
* Returns a map of all the MemoryMapConfigMemoryItems with their name as
* key.
*
* TODO: there's probably a better way to deserialize all the items..
*
* @param build the build of which to get the MemoryMapConfigMemoryItems
* @return the MemoryMapConfigMemoryItems
* @throws Exception when items cannot be found
*/
private static HashMap<String, MemoryMapConfigMemoryItem> getMemoryItems(FreeStyleBuild build) throws Exception {
File buildFile = new File(build.getLogFile().getParent() + "/build.xml");
Document document = parseXml(buildFile);
HashMap<String, MemoryMapConfigMemoryItem> usageMap = new HashMap<>();
NodeList allNodes = document.getElementsByTagName("*");
for (int i = 0; i < allNodes.getLength(); i++) {
if (allNodes.item(i).getNodeName().equals("net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem")) {
String nodeRaw = getRawXml(allNodes.item(i));
MemoryMapConfigMemoryItem item = gsonXml.fromXml(nodeRaw, MemoryMapConfigMemoryItem.class);
usageMap.put(item.getName(), item);
}
}
return usageMap;
}
use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.
the class TestUtils method doBuildAssert.
/**
* Runs a build and asserts all the given usage values.
*
* @param project the project to build and test
* @param jenkins a JenkinsRule instance
* @param expectedValues map of the values you want to check. key = name,
* value = expected usage value
* @throws Exception when assert fails
*/
public static void doBuildAssert(FreeStyleProject project, JenkinsRule jenkins, Map<String, String> expectedValues) throws Exception {
FreeStyleBuild build = TestUtils.runNewBuild(project);
TestUtils.printBuildConsoleLog(build, jenkins);
jenkins.assertBuildStatus(Result.SUCCESS, build);
// Assert the values are correct
HashMap<String, MemoryMapConfigMemoryItem> usage = TestUtils.getMemoryItems(build);
for (String key : expectedValues.keySet()) {
assertTrue(String.format("Key '%s' not found.", key), usage.containsKey(key));
String expectedValue = new HexUtils.HexifiableString(expectedValues.get(key)).toFormattedHexString().rawString;
String actualValue = new HexUtils.HexifiableString(usage.get(key).getUsed()).toFormattedHexString().rawString;
assertEquals(String.format("Value for key '%s' did not match expectations.", key), expectedValue, actualValue);
}
}
use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.
the class GccMemoryMapParser method parseMapFile.
@Override
public MemoryMapConfigMemory parseMapFile(File f, MemoryMapConfigMemory configuration) throws IOException {
CharSequence sequence = createCharSequenceFromFile(f);
for (MemoryMapConfigMemoryItem item : configuration) {
Matcher m = getLinePatternForMapFile(item.getName()).matcher(sequence);
while (m.find()) {
item.setOrigin(m.group(3));
item.setUsed(m.group(5));
}
}
configuration = guessLengthOfSections(configuration);
return configuration;
}
Aggregations