-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from 0xPolygonHermez/feature/vcounters-2
Feature/vcounters 2
- Loading branch information
Showing
8 changed files
with
223 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ jobs: | |
run: | | ||
export NUM_CPUS=31 | ||
npm run test:start | ||
sh tools/checker.sh | ||
sh tools/parallel-testing/checker.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-disable no-use-before-define */ | ||
/* eslint-disable no-continue */ | ||
/* eslint-disable no-restricted-syntax */ | ||
const rom = require('../../build/rom.json'); | ||
const argv = require('yargs'); | ||
|
||
/** | ||
* This script checks if there are new registry operations in the rom build. It compares it with the rom input selected | ||
* The result is logged in the console. | ||
*/ | ||
async function main() { | ||
// load rom input | ||
let input = {}; | ||
|
||
if (argv._.length === 0) { | ||
console.log('You need to specify an input file'); | ||
process.exit(1); | ||
} else if (argv._.length === 1) { | ||
console.log('path input: ', argv._[0]); | ||
input = JSON.parse(await fs.promises.readFile(argv._[0], 'utf8')); | ||
} else { | ||
console.log('Only one input file at a time is permitted'); | ||
process.exit(1); | ||
} | ||
|
||
// Find free inputs at rom's build | ||
const regOpFound = getRegOpFromBuild(rom.program); | ||
const prevRegOpFound = getRegOpFromBuild(input.program); | ||
const diffFound = []; | ||
// Compare found registers with previous rom | ||
for (const op of regOpFound) { | ||
const found = prevRegOpFound.find((item) => item.key === op.key); | ||
if (!found) { | ||
diffFound.push(op); | ||
} | ||
} | ||
// Log warnings, f.e. a free input with more than one occurrence | ||
for (const op of diffFound) { | ||
console.log(`WARNING: Found new registry operation at ${op.fileName}:${op.line}->${op.lineStr}`); | ||
} | ||
console.log('FINISHED'); | ||
} | ||
|
||
function getRegOpFromBuild(build) { | ||
const regOpFound = []; | ||
// Check all steps | ||
for (const step of build) { | ||
let count = 0; | ||
// Get steps where we operate with registers | ||
for (const key of Object.keys(step)) { | ||
if (key === 'inA' || key === 'inB' || key === 'inC' || key === 'inD' || key === 'inE' || key === 'inF') { | ||
if (step.lineStr.includes('*')) { | ||
count += 1; | ||
} | ||
if (Object.keys(step).includes('CONST')) { | ||
count += 1; | ||
} | ||
count += 1; | ||
} | ||
} | ||
// Save steps with more than one register operation | ||
if (count > 1) { | ||
// Remove spaces from string | ||
step.key = `${step.lineStr.replace(/\s/g, '')}-${step.fileName}`; | ||
regOpFound.push(step); | ||
} | ||
} | ||
|
||
return regOpFound; | ||
} | ||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
tools/parallel-testing/parallel-tests-sample/sample.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* eslint-disable global-require */ | ||
/* eslint-disable import/no-dynamic-require */ | ||
/* eslint-disable no-use-before-define */ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
/* eslint-disable import/extensions */ | ||
/* eslint-disable import/no-unresolved */ | ||
const { expect } = require('chai'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const { newCommitPolsArray } = require('pilcom'); | ||
const smMain = require('@0xpolygonhermez/zkevm-proverjs/src/sm/sm_main/sm_main'); | ||
|
||
let rom = require('../../../build/rom.json'); | ||
|
||
let stepsN = 2 ** 23; | ||
let counters = false; | ||
|
||
const fileCachePil = path.join(__dirname, '../../../node_modules/@0xpolygonhermez/zkevm-proverjs/cache-main-pil.json'); | ||
|
||
const checkerDir = path.join(__dirname, 'checker.txt'); | ||
|
||
const inputPath = '%%INPUT_PATH%%'; | ||
const nameFile = path.basename(inputPath); | ||
const input = JSON.parse(fs.readFileSync(inputPath, 'utf8')); | ||
|
||
it(`${nameFile}`, async () => { | ||
if (fs.existsSync(checkerDir)) { | ||
process.exit(1); | ||
} | ||
const pil = JSON.parse(fs.readFileSync(fileCachePil)); | ||
const cmPols = newCommitPolsArray(pil); | ||
if (input.gasLimit) { | ||
rom = require(`../../../build/rom-${input.gasLimit}.test.json`); | ||
} | ||
if (input.stepsN) { | ||
stepsN = input.stepsN; | ||
counters = true; | ||
} | ||
await runTest(cmPols, stepsN); | ||
|
||
expect(true).to.be.equal(true); | ||
}); | ||
|
||
async function runTest(cmPols, steps) { | ||
try { | ||
const config = { | ||
debug: true, | ||
debugInfo: { | ||
inputName: path.basename(inputPath), | ||
}, | ||
stepsN: steps, | ||
counters, | ||
assertOutputs: true, | ||
}; | ||
|
||
const res = await smMain.execute(cmPols.Main, input, rom, config); | ||
compareCounters(input.virtualCounters, res.counters); | ||
} catch (err) { | ||
fs.writeFileSync(checkerDir, `Failed test ${inputPath} - ${err}}`); | ||
throw err; | ||
} | ||
} | ||
|
||
function compareCounters(virtualCounters, result) { | ||
const countersDiff = { | ||
steps: { | ||
virtual: virtualCounters.steps, | ||
real: Number(result.cntSteps), | ||
diff: getPercentageDiff(virtualCounters.steps, Number(result.cntSteps)), | ||
}, | ||
arith: { | ||
virtual: virtualCounters.arith, | ||
real: Number(result.cntArith), | ||
diff: getPercentageDiff(virtualCounters.arith, Number(result.cntArith)), | ||
}, | ||
binary: { | ||
virtual: virtualCounters.binary, | ||
real: Number(result.cntBinary), | ||
diff: getPercentageDiff(virtualCounters.binary, Number(result.cntBinary)), | ||
}, | ||
memAlign: { | ||
virtual: virtualCounters.memAlign, | ||
real: Number(result.cntMemAlign), | ||
diff: getPercentageDiff(virtualCounters.memAlign, Number(result.cntMemAlign)), | ||
}, | ||
keccaks: { | ||
virtual: virtualCounters.keccaks, | ||
real: Number(result.cntKeccakF), | ||
diff: getPercentageDiff(virtualCounters.keccaks, Number(result.cntKeccakF)), | ||
}, | ||
poseidon: { | ||
virtual: virtualCounters.poseidon, | ||
real: Number(result.cntPoseidonG), | ||
diff: getPercentageDiff(virtualCounters.poseidon, Number(result.cntPoseidonG)), | ||
}, | ||
padding: { | ||
virtual: virtualCounters.padding, | ||
real: Number(result.cntPaddingPG), | ||
diff: getPercentageDiff(virtualCounters.padding, Number(result.cntPaddingPG)), | ||
}, | ||
sha256: { | ||
virtual: virtualCounters.sha256, | ||
real: Number(result.cntSha256F), | ||
diff: getPercentageDiff(virtualCounters.sha256, Number(result.cntSha256F)), | ||
}, | ||
}; | ||
fs.appendFileSync(path.join(__dirname, '../countersDiffs.csv'), `${nameFile},${countersDiff.steps.virtual},${countersDiff.steps.real},${String(countersDiff.steps.diff).replace('.', ',')},${countersDiff.arith.virtual},${countersDiff.arith.real},${String(countersDiff.arith.diff).replace('.', ',')},${countersDiff.binary.virtual},${countersDiff.binary.real},${String(countersDiff.binary.diff).replace('.', ',')},${countersDiff.memAlign.virtual},${countersDiff.memAlign.real},${String(countersDiff.memAlign.diff).replace('.', ',')},${countersDiff.keccaks.virtual},${countersDiff.keccaks.real},${String(countersDiff.keccaks.diff).replace('.', ',')},${countersDiff.poseidon.virtual},${countersDiff.poseidon.real},${String(countersDiff.poseidon.diff).replace('.', ',')},${countersDiff.padding.virtual},${countersDiff.padding.real},${String(countersDiff.padding.diff).replace('.', ',')},${countersDiff.sha256.virtual},${countersDiff.sha256.real},${String(countersDiff.sha256.diff).replace('.', ',')}\n`); | ||
// Check percentages are greater than 0 | ||
Object.keys(countersDiff).forEach((key) => { | ||
if (Number(countersDiff[key].diff) < 0) { | ||
throw new Error(`Negative percentage diff: ${countersDiff[key].virtual}/${countersDiff[key].real}/${countersDiff[key].diff}% at ${key}}`); | ||
} | ||
}); | ||
} | ||
|
||
function getPercentageDiff(a, b) { | ||
if (a === 0) { | ||
// a and b are 0 | ||
if (b === 0) { | ||
return 0; | ||
} | ||
// a is 0 but b is not -> fail test | ||
|
||
return -100; | ||
} | ||
// a is not 0 but b is -> passed | ||
if (b === 0) { | ||
return 0; | ||
} | ||
|
||
return (((a - b) / b) * 100).toFixed(2); | ||
} |
This file was deleted.
Oops, something went wrong.