Search in sources :

Example 11 with MemoryMapConfigMemoryItem

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
    }
}
Also used : MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) HashMap(java.util.HashMap) HexUtils(net.praqma.jenkins.memorymap.util.HexUtils) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with MemoryMapConfigMemoryItem

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;
}
Also used : MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) File(java.io.File)

Example 13 with MemoryMapConfigMemoryItem

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);
    }
}
Also used : MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) FreeStyleBuild(hudson.model.FreeStyleBuild)

Example 14 with MemoryMapConfigMemoryItem

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;
}
Also used : MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) Matcher(java.util.regex.Matcher)

Aggregations

MemoryMapConfigMemoryItem (net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem)14 Matcher (java.util.regex.Matcher)5 MemoryMapConfigMemory (net.praqma.jenkins.memorymap.result.MemoryMapConfigMemory)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Pattern (java.util.regex.Pattern)2 AbstractMemoryMapParser (net.praqma.jenkins.memorymap.parser.AbstractMemoryMapParser)2 HexifiableString (net.praqma.jenkins.memorymap.util.HexUtils.HexifiableString)2 MemoryMapMemorySelectionError (net.praqma.jenkins.memorymap.util.MemoryMapMemorySelectionError)2 Document (org.w3c.dom.Document)2 NodeList (org.w3c.dom.NodeList)2 AbortException (hudson.AbortException)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 ChartUtil (hudson.util.ChartUtil)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 MemoryMapGraphConfiguration (net.praqma.jenkins.memorymap.graph.MemoryMapGraphConfiguration)1 TexasInstrumentsMemoryMapParser (net.praqma.jenkins.memorymap.parser.ti.TexasInstrumentsMemoryMapParser)1 HexUtils (net.praqma.jenkins.memorymap.util.HexUtils)1