Summary: - Better CLI arguments parsing - Builtin compression support for large source files Change-Id: Ia0bf37ae5405adb218a2da2c072a1f9cf0ee9f95 Reviewed-on: https://chromium-review.googlesource.com/c/external/github.com/WebKit/JetStream/+/7021129 Reviewed-by: Marja Hölttä <marja@chromium.org>
166 lines
6.4 KiB
JavaScript
166 lines
6.4 KiB
JavaScript
"use strict";
|
|
|
|
/*
|
|
* Copyright (C) 2025 Apple Inc. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
const defaultEmptyMap = Object.freeze({});
|
|
|
|
class Params {
|
|
// Enable a detailed developer menu to change the current Params.
|
|
developerMode = false;
|
|
startAutomatically = false;
|
|
report = false;
|
|
startDelay = undefined;
|
|
|
|
testList = [];
|
|
testIterationCount = undefined;
|
|
testWorstCaseCount = undefined;
|
|
prefetchResources = true;
|
|
|
|
// Display group details.
|
|
groupDetails = false
|
|
|
|
RAMification = false;
|
|
dumpJSONResults = false;
|
|
dumpTestList = false;
|
|
// Override iteration and worst-case counts per workload.
|
|
// Example:
|
|
// testIterationCountMap = { "acorn-wtb": 5 };
|
|
testIterationCountMap = defaultEmptyMap;
|
|
testWorstCaseCountMap = defaultEmptyMap;
|
|
|
|
customPreIterationCode = undefined;
|
|
customPostIterationCode = undefined;
|
|
|
|
constructor(sourceParams = undefined) {
|
|
if (sourceParams)
|
|
this._copyFromSearchParams(sourceParams);
|
|
if (!this.developerMode)
|
|
Object.freeze(this);
|
|
}
|
|
|
|
_copyFromSearchParams(sourceParams) {
|
|
this.startAutomatically = this._parseBooleanParam(sourceParams, "startAutomatically");
|
|
this.developerMode = this._parseBooleanParam(sourceParams, "developerMode");
|
|
this.report = this._parseBooleanParam(sourceParams, "report");
|
|
this.prefetchResources = this._parseBooleanParam(sourceParams, "prefetchResources");
|
|
this.RAMification = this._parseBooleanParam(sourceParams, "RAMification");
|
|
this.dumpJSONResults = this._parseBooleanParam(sourceParams, "dumpJSONResults");
|
|
this.groupDetails = this._parseBooleanParam(sourceParams, "groupDetails");
|
|
this.dumpTestList = this._parseBooleanParam(sourceParams, "dumpTestList");
|
|
|
|
this.customPreIterationCode = this._parseStringParam(sourceParams, "customPreIterationCode");
|
|
this.customPostIterationCode = this._parseStringParam(sourceParams, "customPostIterationCode");
|
|
|
|
this.startDelay = this._parseIntParam(sourceParams, "startDelay", 0);
|
|
if (this.report && !this.startDelay)
|
|
this.startDelay = 4000;
|
|
|
|
for (const paramKey of ["tag", "tags", "test", "tests"])
|
|
this.testList = this._parseTestListParam(sourceParams, paramKey);
|
|
|
|
this.testIterationCount = this._parseIntParam(sourceParams, "iterationCount", 1);
|
|
this.testWorstCaseCount = this._parseIntParam(sourceParams, "worstCaseCount", 1);
|
|
|
|
const unused = Array.from(sourceParams.keys());
|
|
if (unused.length > 0)
|
|
console.error("Got unused source params", unused);
|
|
}
|
|
|
|
_parseTestListParam(sourceParams, key) {
|
|
if (!sourceParams.has(key))
|
|
return this.testList;
|
|
let testList = [];
|
|
if (sourceParams?.getAll) {
|
|
testList = sourceParams?.getAll(key);
|
|
} else {
|
|
// fallback for cli sourceParams which is just a Map;
|
|
testList = sourceParams.get(key).split(",");
|
|
}
|
|
sourceParams.delete(key);
|
|
if (this.testList.length > 0 && testList.length > 0)
|
|
throw new Error(`Overriding previous testList='${this.testList.join()}' with ${key} url-parameter.`);
|
|
return testList;
|
|
}
|
|
|
|
_parseStringParam(sourceParams, paramKey) {
|
|
if (!sourceParams.has(paramKey))
|
|
return DefaultJetStreamParams[paramKey];
|
|
const value = sourceParams.get(paramKey);
|
|
sourceParams.delete(paramKey);
|
|
return value;
|
|
}
|
|
|
|
_parseBooleanParam(sourceParams, paramKey) {
|
|
if (!sourceParams.has(paramKey))
|
|
return DefaultJetStreamParams[paramKey];
|
|
const value = sourceParams.get(paramKey).toLowerCase();
|
|
sourceParams.delete(paramKey);
|
|
return !(value === "false" || value === "0");
|
|
}
|
|
|
|
_parseIntParam(sourceParams, paramKey, minValue) {
|
|
if (!sourceParams.has(paramKey))
|
|
return DefaultJetStreamParams[paramKey];
|
|
|
|
const parsedValue = this._parseInt(sourceParams.get(paramKey), paramKey);
|
|
if (parsedValue < minValue)
|
|
throw new Error(`Invalid ${paramKey} param: '${parsedValue}', value must be >= ${minValue}.`);
|
|
sourceParams.delete(paramKey);
|
|
return parsedValue;
|
|
}
|
|
|
|
_parseInt(value, errorMessage) {
|
|
const number = Number(value);
|
|
if (!Number.isInteger(number) && errorMessage)
|
|
throw new Error(`Invalid ${errorMessage} param: '${value}', expected int.`);
|
|
return parseInt(number);
|
|
}
|
|
|
|
get isDefault() {
|
|
return this === DefaultJetStreamParams;
|
|
}
|
|
|
|
get nonDefaultParams() {
|
|
const diff = Object.create(null);
|
|
for (const [key, value] of Object.entries(this)) {
|
|
if (value !== DefaultJetStreamParams[key]) {
|
|
diff[key] = value;
|
|
}
|
|
}
|
|
return diff;
|
|
}
|
|
}
|
|
|
|
const DefaultJetStreamParams = new Params();
|
|
let maybeCustomParams = DefaultJetStreamParams;
|
|
if (globalThis?.JetStreamParamsSource) {
|
|
try {
|
|
maybeCustomParams = new Params(globalThis?.JetStreamParamsSource);
|
|
} catch (e) {
|
|
console.error("Invalid Params", e, "\nUsing defaults as fallback:", maybeCustomParams);
|
|
}
|
|
}
|
|
const JetStreamParams = maybeCustomParams;
|