Skip to content

Commit

Permalink
Merge branch 'JENKINS-31021' into useCaseTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Lacour committed Oct 21, 2015
2 parents ac1e92f + f761bad commit 32fa80f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
22 changes: 11 additions & 11 deletions pom.xml
Expand Up @@ -229,7 +229,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
<!--
<!--
Generate coverate reports based on instrumented tests.
It does not get automatically executed, but invokes the execution of the
lifecycle phase test prior to executing itself.
Expand All @@ -249,7 +249,7 @@
</formats>
</configuration>
</plugin>
<!--
<!--
Enables the site phase and site goal 'mvn site' to generate nice
project site documentation, including project summary and all reports from other
plugins that creates interesting reports (PMD, Findbugs, Checkstyle, test and coverage
Expand All @@ -273,7 +273,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<!--
<!--
Run pmd:pmd and pmd:cpd goals directly without being part of 'mvn site' lifecycle
PMD and CPD scans java code for possible problems and copy-pasted code
The two goals create output for the Jenkins build pipeline jobs
Expand All @@ -284,7 +284,7 @@
<artifactId>maven-pmd-plugin</artifactId>
<version>3.2</version>
</plugin>
<!--
<!--
Use findbugs:findbugs goal to produce xml report for Jenkins
build pipeline setup.
Requires compile goal in default phase to be executed prior to findbugs
Expand All @@ -301,7 +301,7 @@
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
<!--
<!--
Enables checkstyle:checkstyle goal to be used manually
but does not hook checkstyle up on any phases in the default
lifecycle. We want to run it manually in specific part of the
Expand Down Expand Up @@ -332,7 +332,7 @@
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
<!--
<!--
Another Java code metric reporting tool. Included in the site report
as a plugin under reporting.
use 'mvn jdepend:generate' to generate jdepende report in xml (and html) reports
Expand All @@ -347,7 +347,7 @@
</build>
<reporting>
<plugins>
<!--
<!--
Converts maven-surefire-plugin test reports to html reports, for the site report from 'mvn site'
lifecycle. The maven-surefire-plugin creates output for the Jenkins build pipeline
and don't need this reporting conversion.
Expand All @@ -369,7 +369,7 @@
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
<!--
<!--
To generate the FindBugs xdoc report as part of the Project Reports
and will be the format used by Jenkins.
Can't use version 3.x as it requires Java runtime 1.7 - we are using
Expand All @@ -381,7 +381,7 @@
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.5</version>
</plugin>
<!--
<!--
Also adding javadoc plugin to reporting section so it automatically runs a part of
'mvn site' lifecycle.
javadoc plugin is also added in build/plugins-section to enable 'mvn javadoc:javadoc' as
Expand All @@ -392,7 +392,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<!--
<!--
Includes the PMD/CPD reports in the mvn site reports
Plugin is also mentioned in build/plugin-section to enable to use the
individual goals for the build pipeline reporting, without running
Expand All @@ -419,7 +419,7 @@
</reportSet>
</reportSets>
</plugin>
<!--
<!--
Include java complexity metrics in the site report.
Also used in build/plugin as a goal to manually use for developers
or in the build pipeline.
Expand Down
Expand Up @@ -475,8 +475,6 @@ public double buildDataSet(List<String> graphData, String dataset, DataSetBuilde
logger.log(Level.FINEST, "found {0}", key);
}
}


ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel((Run<?,?>)membuild.build);
if (result != null) {
//Do something we have a result
Expand Down Expand Up @@ -513,7 +511,7 @@ public double buildDataSet(List<String> graphData, String dataset, DataSetBuilde
public Object readResolve() {
if (getMemoryMapConfig() != null) {
logger.log(Level.FINE, "Entering 1.x compatibility block, assigning memory map to Default parser");
HashMap<String, MemoryMapConfigMemory> configs = new HashMap<String, MemoryMapConfigMemory>();
HashMap<String, MemoryMapConfigMemory> configs = new HashMap<>();
configs.put("Default", getMemoryMapConfig());
setMemoryMapConfigs(configs);
}
Expand Down
Expand Up @@ -60,6 +60,7 @@
@JsonSubTypes({
@Type(value = TexasInstrumentsMemoryMapParser.class, name = "TexasInstrumentsMemoryMapParser"),
@Type(value = GccMemoryMapParser.class, name = "GccMemoryMapParser") })

public abstract class AbstractMemoryMapParser implements Describable<AbstractMemoryMapParser>, ExtensionPoint, Serializable {

private static final String UTF_8_CHARSET = "UTF8";
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/net/praqma/jenkins/memorymap/util/HexUtils.java
Expand Up @@ -26,6 +26,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;

/**
* @author Praqma
Expand All @@ -40,7 +41,7 @@ public class HexUtils {
private static final double MEGA = KILO*1024;
private static final double GIGA = MEGA*1024;

private static final Map<String, Double> scale = new HashMap<String, Double>();
private static final Map<String, Double> scale = new HashMap<>();
private static final Pattern VALID_HEX = Pattern.compile("^[0xX]*[0-9a-fA-F]+$");
private static final Pattern VALID_NUMERICAL = Pattern.compile("^\\d+[mMgGkK]+$");

Expand Down Expand Up @@ -137,5 +138,20 @@ public int compareTo(HexifiableString t) {
return 0;
}
}

/**
* Returns a new HexifiableString with a formatted rawString.
* Format: 0x\d{8}
* @return A HexifiableString with a formatted rawString.
*/
public HexifiableString toFormattedHexString() {
HexifiableString hexString = toValidHexString();
String baseString = hexString.rawString.replace("0x", "");

int targetLength = ((baseString.length() - 1) | 7) + 1; // Next multiple of 8.
String formattedRawString = "0x" + StringUtils.leftPad(baseString, targetLength, "0");

return new HexifiableString(formattedRawString);
}
}
}
10 changes: 5 additions & 5 deletions src/test/java/net/praqma/jenkins/integration/TestUtils.java
Expand Up @@ -35,16 +35,16 @@
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.SubmoduleConfig;
import hudson.plugins.git.UserRemoteConfig;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import net.praqma.jenkins.memorymap.MemoryMapRecorder;
Expand Down
28 changes: 27 additions & 1 deletion src/test/java/net/praqma/jenkins/unit/HexUtilsTest.java
Expand Up @@ -23,6 +23,8 @@
*/
package net.praqma.jenkins.unit;

import java.util.HashMap;
import java.util.Map;
import net.praqma.jenkins.memorymap.util.HexUtils;
import org.junit.After;
import org.junit.AfterClass;
Expand Down Expand Up @@ -148,5 +150,29 @@ public void testValidHexStrings() {
HexUtils.HexifiableString metricToHex = new HexUtils.HexifiableString("2m");
HexUtils.HexifiableString hexified = metricToHex.toValidHexString();
}


@Test
public void testFormatting() {
Map<String, String> stringTests = new HashMap<String,String>(){{
put("0x00123456", "0x00123456");
put("7fc3", "0x00007fc3");
put("64M", "0x04000000");
}};
for (Map.Entry<String, String> test : stringTests.entrySet()) {
HexUtils.HexifiableString hexString = new HexUtils.HexifiableString(test.getKey()).toValidHexString();
assertTrue("Failure for test '" + test.getKey() + "': Not a valid hex string.", hexString.isValidHexString());
assertEquals("Failure for test '" + test.getKey() + "': Expected formatted hex string.", test.getValue(), hexString.toFormattedHexString().rawString);
}

Map<Integer, String> intTests = new HashMap<Integer,String>(){{
put(1,"0x00000001");
put(316, "0x0000013c");
put(2000000000, "0x77359400");
}};
for (Map.Entry<Integer, String> test : intTests.entrySet()) {
HexUtils.HexifiableString hexString = new HexUtils.HexifiableString(test.getKey()).toValidHexString();
assertTrue("Failure for test '" + test.getKey() + "': Not a valid hex string.", hexString.isValidHexString());
assertEquals("Failure for test '" + test.getKey() + "': Expected formatted hex string.", test.getValue(), hexString.toFormattedHexString().rawString);
}
}
}
Expand Up @@ -51,10 +51,10 @@ public void testParsingOfMemorySegmentInLinkerCommandFile() throws IOException {

String fileNameLinker = MemoryMapGccParserTest.class.getResource("prom.ld").getFile();
String fileNameMap = MemoryMapGccParserTest.class.getResource("prom.map").getFile();

assertNotNull(fileNameLinker);
assertNotNull(fileNameMap);

File f = new File(fileNameLinker);
MemoryMapConfigMemory mem = parser.parseConfigFile(f);

Expand Down

0 comments on commit 32fa80f

Please sign in to comment.