Skip to content

Commit

Permalink
Generate json test reports for mx native-unittest command
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigar-mx committed Nov 23, 2021
1 parent ac9240c commit 4609007
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
15 changes: 11 additions & 4 deletions substratevm/ci_includes/gate.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ gate-svm-js: {
]
}

svmUnittest : {
environment: {
"MX_TEST_RESULTS_PATTERN": "es-XXX.json",
"MX_TEST_RESULT_TAGS": "native-image"
}
}

builds += [
${labsjdk-ce-17} ${svm-common-linux-gate} ${gate-svm-js} ${svm-capabilities-base} {
name: "gate-svm-js"
Expand All @@ -25,7 +32,7 @@ builds += [
${labsjdk-ce-17} ${svm-common-darwin-gate} ${gate-svm-js} {
name: "gate-svm-darwin-js"
}
${labsjdk-ce-11} ${svm-common-linux-gate} ${linux-deploy} {
${labsjdk-ce-11} ${svm-common-linux-gate} ${linux-deploy} ${svmUnittest} {
name: "gate-svm-build-ce-11"
downloads: {
"MUSL_TOOLCHAIN": {
Expand All @@ -44,13 +51,13 @@ builds += [
${svm-cmd-gate} ["build,helloworld,test,nativeimagehelp,muslcbuild"]
]
}
${labsjdk-ce-11} ${svm-common-linux-gate} ${linux-deploy} {
${labsjdk-ce-11} ${svm-common-linux-gate} ${linux-deploy} ${svmUnittest} {
name: "gate-svm-modules-basic"
run: [
${svm-cmd-gate} ["build,hellomodule,test"]
]
}
${labsjdk-ce-17} ${svm-common-linux-gate} ${eclipse} ${jdt} ${linux-deploy} {
${labsjdk-ce-17} ${svm-common-linux-gate} ${eclipse} ${jdt} ${linux-deploy} ${svmUnittest} {
name: "gate-svm-style-fullbuild"
timelimit: "45:00"
environment : {
Expand All @@ -60,7 +67,7 @@ builds += [
${svm-cmd-gate} ["style,fullbuild,helloworld,test,svmjunit"]
]
}
${labsjdk-ce-17} ${svm-common-gate} ${svm-common-windows-jdk17} {
${labsjdk-ce-17} ${svm-common-gate} ${svm-common-windows-jdk17} ${svmUnittest} {
name: "gate-svm-windows-basics"
run: [
${svm-cmd-gate} ["build,helloworld,test,svmjunit"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import org.graalvm.compiler.options.Option;
import org.graalvm.nativeimage.ImageSingletons;
Expand Down Expand Up @@ -115,6 +118,38 @@ private String getMissingClasses() {
return null;
}

private static String formatJsonTestResultsPattern(JUnitSystem system, String testResultsPattern) {
if (!testResultsPattern.contains("XXX")) {
system.out().println("MX_TEST_RESULTS_PATTERN doesn't contain `XXX`. " +
"Results will probably be overwritten if used multiple times.");
return testResultsPattern;
}

String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
// Generate a random int of 8 digits
String randNum = "00000000" + Math.abs(new Random().nextInt());
randNum = randNum.substring(randNum.length() - 8);
String identifier = "unittest-" + timeStamp + "-" + randNum;

return testResultsPattern.replaceFirst("XXXX*", identifier);
}

/* Get current os name in a standarized form. */
private static String getOS() {
String os = System.getProperty("os.name").toLowerCase();

if (os.contains("windows")) {
return "windows";
}
if (os.contains("linux")) {
return "linux";
}
if (os.contains("mac") || os.contains("darwin")) {
return "darwin";
}
return os;
}

private void run(String[] args) {
JUnitSystem system = new RealSystem();
JUnitCore junitCore = new JUnitCore();
Expand All @@ -123,6 +158,21 @@ private void run(String[] args) {

MxJUnitConfig config = new MxJUnitConfig();

// Add flags for json test reports accordingly
String testResultsPattern = System.getenv("MX_TEST_RESULTS_PATTERN");
String jsonResultTags = System.getenv("MX_TEST_RESULT_TAGS");
if (testResultsPattern != null && !testResultsPattern.isEmpty()) {
config.jsonResults = formatJsonTestResultsPattern(system, testResultsPattern);
}
if (jsonResultTags != null && !jsonResultTags.isEmpty()) {
config.jsonResultTags = jsonResultTags;
}
config.jsonResultTags += "," + getOS();
config.jsonResultTags += "," + System.getProperty("os.arch");
if (!config.jsonResultTags.contains("native-image")) {
config.jsonResultTags += "," + "native-image";
}

int i = 0;
while (i < args.length) {
String arg = args[i++];
Expand Down

0 comments on commit 4609007

Please sign in to comment.