Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the correct Parsing #890

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions TestResultSummaryService/parsers/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,53 @@ class Parser {
const javaVersionRegex =
/=JAVA VERSION OUTPUT BEGIN=[\r\n]+([\s\S]*?)[\r\n]+.*=JAVA VERSION OUTPUT END=/;
const javaBuildDateRegex =
/\s([0-9]{4})-?(0[1-9]|1[012])-?(0[1-9]|[12][0-9]|3[01])/;
/(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])/; // Captures dates in the format YYYY-MM-DD
const sdkResourceRegex = /.*?SDK_RESOURCE\=(.*)[\r\n]+/;
let curRegexResult = null;
let javaVersion, jdkDate, sdkResource;

if ((curRegexResult = javaVersionRegex.exec(output)) !== null) {
javaVersion = removeTimestamp(curRegexResult[1]);
} else {
javaVersion = output; // Use the entire output if markers are missing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no javaVersionRegex match, we have no idea where the java -version is from and we should not handle the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case than should i use return null instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in this case, there is no java -version output.

}

curRegexResult = null;
if ((curRegexResult = sdkResourceRegex.exec(output)) != null) {
sdkResource = curRegexResult[1];
}
curRegexResult = null;
// parse jdk date from javaVersion

// parse jdk date from javaVersion or output
if ((curRegexResult = javaBuildDateRegex.exec(javaVersion)) !== null) {
jdkDate = curRegexResult[0];
} else if ((curRegexResult = javaBuildDateRegex.exec(output)) !== null) {
jdkDate = curRegexResult[0];
}

// Refine jdkDate extraction to match specific lines for HotSpot, OpenJ9, and Java 8 implementations
if (!jdkDate) {
// Try to extract date from specific lines for HotSpot
const hotspotBuildDateRegex =
/OpenJDK Runtime Environment [^ ]+ \([^)]+ (\d{4})(\d{2})(\d{2})/; // e.g., 20240626
const openj9BuildDateRegex =
/Eclipse OpenJ9 VM \([^)]+ (\d{4})(\d{2})(\d{2})/; // e.g., 20240627
const java8BuildDateRegex =
/OpenJDK Runtime Environment.*\(build [^\d]*(\d{4})(\d{2})(\d{2})/; // e.g., 1.8.0_412-b08

if ((curRegexResult = hotspotBuildDateRegex.exec(output)) !== null) {
jdkDate = `${curRegexResult[1]}-${curRegexResult[2]}-${curRegexResult[3]}`;
} else if ((curRegexResult = openj9BuildDateRegex.exec(output)) !== null) {
jdkDate = `${curRegexResult[1]}-${curRegexResult[2]}-${curRegexResult[3]}`;
} else if ((curRegexResult = java8BuildDateRegex.exec(output)) !== null) {
jdkDate = `${curRegexResult[1]}-${curRegexResult[2]}-${curRegexResult[3]}`;
}
}

return { javaVersion, jdkDate, sdkResource };
}

exactNodeVersion(output) {
// Example: "Node Version v13.3.1-nightly20191214b3ae532392\nRundate -20191216"
Sangyoon21 marked this conversation as resolved.
Show resolved Hide resolved
const nodejsVersionRegex = /(Node Version[\s\S]*Rundate.*)/;
const nodeRunDateRegex = /-(20[0-9][0-9][0-9][0-9][0-9][0-9])/;
let curRegexResult = null;
Expand All @@ -43,7 +69,6 @@ class Parser {
nodeVersion = curRegexResult[1];
}
curRegexResult = null;
// parse build run date from nodeVersion
if ((curRegexResult = nodeRunDateRegex.exec(nodeVersion)) !== null) {
nodeRunDate = curRegexResult[1];
}
Expand Down Expand Up @@ -102,7 +127,7 @@ class Parser {
let versions = {};

const releaseInfoRegex =
/=RELEASE INFO BEGIN=\n[\s\S]*?SOURCE="(.*)"[\s\S]*?=RELEASE INFO END=/;
/=RELEASE INFO BEGIN=\n[\s\S]*?SOURCE="(.*)"\n[\s\S]*?=RELEASE INFO END=/;
const generalOpenjdkShaRegex = /git:(.*)/;
const openjdkShaRegex = /OpenJDK:\s?([^\s\:]*)/;
const j9AndOmrShaRegex = /OpenJ9:\s?([^\s\:]*).*OMR:\s?([^\s\:]*)/;
Expand Down Expand Up @@ -140,7 +165,6 @@ class Parser {
let failed = 0;
let skipped = 0;
let disabled = 0;
// An example of test result summary: "TOTAL: 69 EXECUTED: 64 PASSED: 64 FAILED: 0 DISABLED: 0 SKIPPED: 5\n"
const summaryRegex =
/\S*\s*?TOTAL:\s*([0-9]*)\s*EXECUTED:\s*([0-9]*)\s*PASSED:\s*([0-9]*)\s*FAILED:\s*([0-9]*)\s*DISABLED:\s*([0-9]*)\s*SKIPPED:\s*([0-9]*)\s*(\r\n|\r|\n)/;
if ((m = summaryRegex.exec(output)) !== null) {
Expand Down
116 changes: 116 additions & 0 deletions TestResultSummaryService/parsers/Parser.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const Parser = require('./Parser'); // Adjust the path if necessary

describe('Parser', () => {
let parser;

beforeEach(() => {
parser = new Parser('TestBuild');
});

test('should extract Java version and build date for HotSpot implementation', () => {
const hotspotOutput = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "21.0.4-beta" 2024-07-16
16:38:54 OpenJDK Runtime Environment Temurin-21.0.4+6-202406261902 (build 21.0.4-beta+6-ea)
16:38:54 OpenJDK 64-Bit Server VM Temurin-21.0.4+6-202406261902 (build 21.0.4-beta+6-ea, mixed mode, sharing)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(hotspotOutput);
expect(result.jdkDate).toBe('2024-06-26');
});

test('should extract Java version and build date for OpenJ9 implementation', () => {
const openj9Output = `
11:53:15 =JAVA VERSION OUTPUT BEGIN=
11:53:19 openjdk version "11.0.24-internal" 2024-07-16
11:53:19 OpenJDK Runtime Environment (build 11.0.24-internal+0-adhoc.jenkins.BuildJDK11aarch64macPersonal)
11:53:19 Eclipse OpenJ9 VM (build master-2a2df9f1117, JRE 11 Mac OS X aarch64-64-Bit 20240627_514 (JIT enabled, AOT enabled)
11:53:19 OpenJ9 - 2a2df9f1117
11:53:19 OMR - 47a9d248db0
11:53:19 JCL - c535515f053 based on jdk-11.0.24+6)
11:53:19 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(openj9Output);
expect(result.jdkDate).toBe('2024-06-27');
});

test('should extract Java version and build date for Java 8 implementation', () => {
const java8Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "1.8.0_412"
16:38:54 OpenJDK Runtime Environment (Temurin)(build 1.8.0_412-b08)
16:38:54 OpenJDK 64-Bit Server VM (Temurin)(build 25.412-b08, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java8Output);
expect(result.jdkDate).toBe('2024-06-27'); // Adjust the expected date based on your requirements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we get 2024-06-27?

Copy link
Contributor Author

@Sangyoon21 Sangyoon21 Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i am not sure what should be the date for those different version. Could you clarify it please?

This was the part where i was not sure and had asked in the previous comment, so i had just added an random date.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, there is no jdk build date in java -version output.

});

test('should extract Java version and build date for Java 8u152-b01 implementation', () => {
const java8u152Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "1.8.0_152"
16:38:54 OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_152-b01)
16:38:54 OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.152-b01, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java8u152Output);
expect(result.jdkDate).toBe('2024-06-27'); // Adjust the expected date based on your requirements
});

test('should extract Java version and build date for Java 9.0.4+11 implementation', () => {
const java904Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "9.0.4"
16:38:54 OpenJDK Runtime Environment (build 9.0.4+11)
16:38:54 OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java904Output);
expect(result.jdkDate).toBe('2024-06-27'); // Adjust the expected date based on your requirements
});

test('should extract Java version and build date for Java 10.0.2+13.1 implementation', () => {
const java1002Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "10.0.2"
16:38:54 OpenJDK Runtime Environment (build 10.0.2+13.1)
16:38:54 OpenJDK 64-Bit Server VM (build 10.0.2+13.1, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java1002Output);
expect(result.jdkDate).toBe('2024-06-27'); // Adjust the expected date based on your requirements
});

test('should extract Java version and build date for Java 11.0.4+11.4 implementation', () => {
const java1104Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "11.0.4"
16:38:54 OpenJDK Runtime Environment (build 11.0.4+11.4)
16:38:54 OpenJDK 64-Bit Server VM (build 11.0.4+11.4, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java1104Output);
expect(result.jdkDate).toBe('2024-06-27'); // Adjust the expected date based on your requirements
});

test('should extract Java version and build date for Java 13+33_openj9-0.16.0 implementation', () => {
const java1333Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "13"
16:38:54 OpenJDK Runtime Environment (build 13+33)
16:38:54 Eclipse OpenJ9 VM (build 13+33_openj9-0.16.0, JRE 13 Mac OS X aarch64-64-Bit)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java1333Output);
expect(result.jdkDate).toBe('2024-06-27'); // Adjust the expected date based on your requirements
});
});
Loading