|
| 1 | +// The script generates a random subset of valid jdk, os, timezone, and other axes. |
| 2 | +// You can preview the results by running "node matrix.js" |
| 3 | +// See https://github.com/vlsi/github-actions-random-matrix |
| 4 | +let fs = require('fs'); |
| 5 | +let os = require('os'); |
| 6 | +let {MatrixBuilder} = require('./matrix_builder'); |
| 7 | +const matrix = new MatrixBuilder(); |
| 8 | +matrix.addAxis({ |
| 9 | + name: 'java_distribution', |
| 10 | + values: [ |
| 11 | + {value: 'corretto', weight: 1}, |
| 12 | + {value: 'liberica', weight: 1}, |
| 13 | + {value: 'microsoft', weight: 1}, |
| 14 | + {value: 'oracle', weight: 1}, |
| 15 | + {value: 'semeru', weight: 4}, |
| 16 | + {value: 'temurin', weight: 1}, |
| 17 | + {value: 'zulu', weight: 1}, |
| 18 | + ] |
| 19 | +}); |
| 20 | + |
| 21 | +matrix.addAxis({ |
| 22 | + name: 'java_version', |
| 23 | + // Strings allow versions like 18-ea |
| 24 | + values: [ |
| 25 | + '8', |
| 26 | + '11', |
| 27 | + '17', |
| 28 | + ] |
| 29 | +}); |
| 30 | + |
| 31 | +matrix.addAxis({ |
| 32 | + name: 'tz', |
| 33 | + values: [ |
| 34 | + 'America/New_York', |
| 35 | + 'Pacific/Chatham', |
| 36 | + 'UTC' |
| 37 | + ] |
| 38 | +}); |
| 39 | + |
| 40 | +matrix.addAxis({ |
| 41 | + name: 'os', |
| 42 | + title: x => x.replace('-latest', ''), |
| 43 | + values: [ |
| 44 | + // TODO: X11 is not available. Un-comment when https://github.com/burrunan/gradle-cache-action/issues/48 is resolved |
| 45 | + // 'ubuntu-latest', |
| 46 | + 'windows-latest', |
| 47 | + 'macos-latest' |
| 48 | + ] |
| 49 | +}); |
| 50 | + |
| 51 | +// Test cases when Object#hashCode produces the same results |
| 52 | +// It allows capturing cases when the code uses hashCode as a unique identifier |
| 53 | +matrix.addAxis({ |
| 54 | + name: 'hash', |
| 55 | + values: [ |
| 56 | + {value: 'regular', title: '', weight: 42}, |
| 57 | + {value: 'same', title: 'same hashcode', weight: 1} |
| 58 | + ] |
| 59 | +}); |
| 60 | +matrix.addAxis({ |
| 61 | + name: 'locale', |
| 62 | + title: x => x.language + '_' + x.country, |
| 63 | + values: [ |
| 64 | + {language: 'de', country: 'DE'}, |
| 65 | + {language: 'fr', country: 'FR'}, |
| 66 | + // TODO: fix :src:dist-check:batchBUG_62847 |
| 67 | + // Fails with "ERROR o.a.j.u.JMeterUtils: Could not find resources for 'ru_EN'" |
| 68 | + // {language: 'ru', country: 'RU'}, |
| 69 | + {language: 'tr', country: 'TR'}, |
| 70 | + ] |
| 71 | +}); |
| 72 | + |
| 73 | +matrix.setNamePattern(['java_version', 'java_distribution', 'hash', 'os', 'tz', 'locale']); |
| 74 | + |
| 75 | +// Semeru uses OpenJ9 jit which has no option for making hash codes the same |
| 76 | +matrix.exclude({java_distribution: {value: 'semeru'}, hash: {value: 'same'}}); |
| 77 | +// Microsoft Java has no distribution for 8 |
| 78 | +matrix.exclude({java_distribution: {value: 'microsoft'}, java_version: '8'}); |
| 79 | +// Oracle JDK is only supported for JDK 17 and later |
| 80 | +matrix.exclude({java_distribution: {value: 'oracle'}, java_version: ['8', '11']}); |
| 81 | +// Ensure at least one job with "same" hashcode exists |
| 82 | +matrix.generateRow({hash: {value: 'same'}}); |
| 83 | +// Ensure at least one Windows and at least one Linux job is present (macOS is almost the same as Linux) |
| 84 | +matrix.generateRow({os: 'windows-latest'}); |
| 85 | +// TODO: un-comment when xvfb will be possible |
| 86 | +// matrix.generateRow({os: 'ubuntu-latest'}); |
| 87 | +// Ensure there will be at least one job with Java 8 |
| 88 | +matrix.generateRow({java_version: "8"}); |
| 89 | +// Ensure there will be at least one job with Java 11 |
| 90 | +matrix.generateRow({java_version: "11"}); |
| 91 | +// Ensure there will be at least one job with Java 17 |
| 92 | +matrix.generateRow({java_version: "17"}); |
| 93 | +const include = matrix.generateRows(process.env.MATRIX_JOBS || 5); |
| 94 | +if (include.length === 0) { |
| 95 | + throw new Error('Matrix list is empty'); |
| 96 | +} |
| 97 | +include.sort((a, b) => a.name.localeCompare(b.name, undefined, {numeric: true})); |
| 98 | +include.forEach(v => { |
| 99 | + // Pass locale via Gradle arguments in case it won't be inherited from _JAVA_OPTIONS |
| 100 | + // In fact, _JAVA_OPTIONS is non-standard and might be ignored by some JVMs |
| 101 | + let gradleArgs = [ |
| 102 | + `-Duser.country=${v.locale.country}`, |
| 103 | + `-Duser.language=${v.locale.language}`, |
| 104 | + ]; |
| 105 | + if (v.hash.value === 'same' && v.java_version <= 8) { |
| 106 | + // processSiteXslt fails with VerifyError when running with Java 8 and the same hashcode |
| 107 | + // Skip the task in that case |
| 108 | + //java.lang.VerifyError: (class: website_style, method: issue_separator signature: (Lcom/sun/org/apache/xala...) |
| 109 | + // Illegal target of jump or branch |
| 110 | + gradleArgs.push('-x :src:dist:processSiteXslt'); |
| 111 | + // javadoc tool seems take too much CPU when there are many hash collisions |
| 112 | + gradleArgs.push('-x :src:dist:javadocAggregate'); |
| 113 | + } |
| 114 | + v.extraGradleArgs = gradleArgs.join(' '); |
| 115 | +}); |
| 116 | +include.forEach(v => { |
| 117 | + let jvmArgs = []; |
| 118 | + // Extra JVM arguments passed to test execution |
| 119 | + let testJvmArgs = []; |
| 120 | + if (v.hash.value === 'same') { |
| 121 | + testJvmArgs.push('-XX:+UnlockExperimentalVMOptions', '-XX:hashCode=2'); |
| 122 | + } |
| 123 | + // Gradle does not work in tr_TR locale, so pass locale to test only: https://github.com/gradle/gradle/issues/17361 |
| 124 | + jvmArgs.push(`-Duser.country=${v.locale.country}`); |
| 125 | + jvmArgs.push(`-Duser.language=${v.locale.language}`); |
| 126 | + v.java_distribution = v.java_distribution.value; |
| 127 | + if (v.java_distribution !== 'semeru' && Math.random() > 0.5) { |
| 128 | + // The following options randomize instruction selection in JIT compiler |
| 129 | + // so it might reveal missing synchronization in TestNG code |
| 130 | + v.name += ', stress JIT'; |
| 131 | + v.testDisableCaching = 'JIT randomization should not be cached'; |
| 132 | + jvmArgs.push('-XX:+UnlockDiagnosticVMOptions'); |
| 133 | + if (v.java_version >= 8) { |
| 134 | + // Randomize instruction scheduling in GCM |
| 135 | + // share/opto/c2_globals.hpp |
| 136 | + jvmArgs.push('-XX:+StressGCM'); |
| 137 | + // Randomize instruction scheduling in LCM |
| 138 | + // share/opto/c2_globals.hpp |
| 139 | + jvmArgs.push('-XX:+StressLCM'); |
| 140 | + } |
| 141 | + if (v.java_version >= 16) { |
| 142 | + // Randomize worklist traversal in IGVN |
| 143 | + // share/opto/c2_globals.hpp |
| 144 | + jvmArgs.push('-XX:+StressIGVN'); |
| 145 | + } |
| 146 | + if (v.java_version >= 17) { |
| 147 | + // Randomize worklist traversal in CCP |
| 148 | + // share/opto/c2_globals.hpp |
| 149 | + jvmArgs.push('-XX:+StressCCP'); |
| 150 | + } |
| 151 | + } |
| 152 | + v.extraJvmArgs = jvmArgs.join(' '); |
| 153 | + v.testExtraJvmArgs = testJvmArgs.join(' ::: '); |
| 154 | + delete v.hash; |
| 155 | +}); |
| 156 | + |
| 157 | +console.log(include); |
| 158 | + |
| 159 | +let filePath = process.env['GITHUB_OUTPUT'] || ''; |
| 160 | +if (filePath) { |
| 161 | + fs.appendFileSync(filePath, `matrix<<MATRIX_BODY${os.EOL}${JSON.stringify({include})}${os.EOL}MATRIX_BODY${os.EOL}`, { |
| 162 | + encoding: 'utf8' |
| 163 | + }); |
| 164 | +} |
0 commit comments