@ohos-perf/core 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +246 -2
- package/dist/index.js +764 -79
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
2
|
var OhosPerfError = class extends Error {
|
|
3
3
|
code;
|
|
4
|
-
constructor(
|
|
5
|
-
super(
|
|
4
|
+
constructor(message3, opts = {}) {
|
|
5
|
+
super(message3, { cause: opts.cause });
|
|
6
6
|
this.name = new.target.name;
|
|
7
7
|
this.code = opts.code;
|
|
8
8
|
}
|
|
@@ -39,15 +39,15 @@ var StreamerNotFoundError = class extends OhosPerfError {
|
|
|
39
39
|
};
|
|
40
40
|
var EmulatorCommandError = class extends OhosPerfError {
|
|
41
41
|
output;
|
|
42
|
-
constructor(
|
|
43
|
-
super(
|
|
42
|
+
constructor(message3, output, opts = {}) {
|
|
43
|
+
super(message3, opts);
|
|
44
44
|
this.output = output;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
var EmulatorImageMissingError = class extends OhosPerfError {
|
|
48
48
|
installCommand;
|
|
49
|
-
constructor(
|
|
50
|
-
super(
|
|
49
|
+
constructor(message3, installCommand, opts = {}) {
|
|
50
|
+
super(message3, opts);
|
|
51
51
|
this.installCommand = installCommand;
|
|
52
52
|
}
|
|
53
53
|
};
|
|
@@ -63,8 +63,8 @@ var EmulatorNotFoundError = class extends OhosPerfError {
|
|
|
63
63
|
};
|
|
64
64
|
var IngestError = class extends OhosPerfError {
|
|
65
65
|
stderr;
|
|
66
|
-
constructor(
|
|
67
|
-
super(
|
|
66
|
+
constructor(message3, stderr, code, opts = {}) {
|
|
67
|
+
super(message3, { cause: opts.cause, code });
|
|
68
68
|
this.stderr = stderr;
|
|
69
69
|
}
|
|
70
70
|
};
|
|
@@ -472,6 +472,7 @@ function firstLine(result) {
|
|
|
472
472
|
import {
|
|
473
473
|
existsSync as existsSync10,
|
|
474
474
|
mkdirSync as mkdirSync7,
|
|
475
|
+
mkdtempSync,
|
|
475
476
|
readFileSync as readFileSync7,
|
|
476
477
|
renameSync as renameSync3,
|
|
477
478
|
rmSync as rmSync3,
|
|
@@ -479,6 +480,8 @@ import {
|
|
|
479
480
|
unlinkSync as unlinkSync6,
|
|
480
481
|
writeFileSync as writeFileSync6
|
|
481
482
|
} from "node:fs";
|
|
483
|
+
import { tmpdir } from "node:os";
|
|
484
|
+
import { join as join5 } from "node:path";
|
|
482
485
|
|
|
483
486
|
// src/collectors/hitrace.ts
|
|
484
487
|
var HITRACE_DEFAULT_CATEGORIES = Object.freeze([
|
|
@@ -538,10 +541,10 @@ function assertCategories(categories) {
|
|
|
538
541
|
{ code: "HITRACE_BAD_CATEGORIES" }
|
|
539
542
|
);
|
|
540
543
|
}
|
|
541
|
-
const
|
|
542
|
-
if (
|
|
544
|
+
const bad5 = categories.find((c) => !CATEGORY_PATTERN.test(c));
|
|
545
|
+
if (bad5 !== void 0) {
|
|
543
546
|
throw new OhosPerfError(
|
|
544
|
-
`category ${JSON.stringify(
|
|
547
|
+
`category ${JSON.stringify(bad5)} is not a bare trace category name; allowed pattern: ${String(CATEGORY_PATTERN)}`,
|
|
545
548
|
{ code: "HITRACE_BAD_CATEGORIES" }
|
|
546
549
|
);
|
|
547
550
|
}
|
|
@@ -1163,7 +1166,7 @@ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as rea
|
|
|
1163
1166
|
var LINE_PATTERN = /^(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})\.(\d{3})\s+(\d+)\s+(\d+)\s+(\S)\s+([^/\s]+)\/(\S+?):\s?(.*)$/;
|
|
1164
1167
|
var MS_PER_YEAR = 365.25 * 24 * 60 * 60 * 1e3;
|
|
1165
1168
|
var NS_PER_MS = 1e6;
|
|
1166
|
-
function rawLine(index,
|
|
1169
|
+
function rawLine(index, message3) {
|
|
1167
1170
|
return {
|
|
1168
1171
|
index,
|
|
1169
1172
|
ts: 0,
|
|
@@ -1172,14 +1175,14 @@ function rawLine(index, message2) {
|
|
|
1172
1175
|
tid: 0,
|
|
1173
1176
|
domain: "",
|
|
1174
1177
|
tag: "",
|
|
1175
|
-
message:
|
|
1178
|
+
message: message3,
|
|
1176
1179
|
parsed: false
|
|
1177
1180
|
};
|
|
1178
1181
|
}
|
|
1179
1182
|
function parseHilogLine(line, year, captureNs) {
|
|
1180
1183
|
const match = LINE_PATTERN.exec(line);
|
|
1181
1184
|
if (match === null) return rawLine(0, line);
|
|
1182
|
-
const [, month, day, hour, minute, second, milli, pid, tid, level, domain, tag,
|
|
1185
|
+
const [, month, day, hour, minute, second, milli, pid, tid, level, domain, tag, message3] = match;
|
|
1183
1186
|
const monthIndex = Number(month) - 1;
|
|
1184
1187
|
const dayOfMonth = Number(day);
|
|
1185
1188
|
const h = Number(hour);
|
|
@@ -1201,7 +1204,7 @@ function parseHilogLine(line, year, captureNs) {
|
|
|
1201
1204
|
tid: Number(tid),
|
|
1202
1205
|
domain,
|
|
1203
1206
|
tag,
|
|
1204
|
-
message:
|
|
1207
|
+
message: message3,
|
|
1205
1208
|
parsed: true
|
|
1206
1209
|
};
|
|
1207
1210
|
}
|
|
@@ -1343,10 +1346,10 @@ function assertEvents(events) {
|
|
|
1343
1346
|
{ code: "HIPERF_BAD_EVENT" }
|
|
1344
1347
|
);
|
|
1345
1348
|
}
|
|
1346
|
-
const
|
|
1347
|
-
if (
|
|
1349
|
+
const bad5 = events.find((event) => !EVENT_PATTERN.test(event));
|
|
1350
|
+
if (bad5 !== void 0) {
|
|
1348
1351
|
throw new OhosPerfError(
|
|
1349
|
-
`event ${JSON.stringify(
|
|
1352
|
+
`event ${JSON.stringify(bad5)} is not a bare event name; allowed pattern: ${String(EVENT_PATTERN)}`,
|
|
1350
1353
|
{ code: "HIPERF_BAD_EVENT" }
|
|
1351
1354
|
);
|
|
1352
1355
|
}
|
|
@@ -1400,15 +1403,15 @@ var HiperfCollector = class {
|
|
|
1400
1403
|
try {
|
|
1401
1404
|
record = await hdc.shell(target, hiperfRecordCommand(opts, devicePath));
|
|
1402
1405
|
} catch (err) {
|
|
1403
|
-
const
|
|
1404
|
-
if (NOT_DEBUGGABLE.test(
|
|
1406
|
+
const message3 = err instanceof Error ? err.message : String(err);
|
|
1407
|
+
if (NOT_DEBUGGABLE.test(message3)) {
|
|
1405
1408
|
throw new OhosPerfError(
|
|
1406
|
-
`hiperf cannot profile ${opts.app}: the app is not debuggable (device said: ${detail4(
|
|
1409
|
+
`hiperf cannot profile ${opts.app}: the app is not debuggable (device said: ${detail4(message3)}); install a debug build to sample it`,
|
|
1407
1410
|
{ code: "HIPERF_NOT_DEBUGGABLE", cause: err }
|
|
1408
1411
|
);
|
|
1409
1412
|
}
|
|
1410
1413
|
throw new OhosPerfError(
|
|
1411
|
-
`hiperf record failed for ${opts.app}: ${
|
|
1414
|
+
`hiperf record failed for ${opts.app}: ${message3}`,
|
|
1412
1415
|
{ code: "HIPERF_RECORD_FAILED", cause: err }
|
|
1413
1416
|
);
|
|
1414
1417
|
}
|
|
@@ -1798,7 +1801,7 @@ ${dump.stderr}`;
|
|
|
1798
1801
|
);
|
|
1799
1802
|
}
|
|
1800
1803
|
await hdc.recv(target, DEVICE_UI_PATH, layout.uiFile);
|
|
1801
|
-
const nodes = readUiTree(layout.uiFile);
|
|
1804
|
+
const nodes = readUiTree(layout.uiFile, opts.full === true ? { full: true } : {});
|
|
1802
1805
|
if (nodes === void 0) {
|
|
1803
1806
|
removeFile(layout.uiFile);
|
|
1804
1807
|
throw new OhosPerfError(
|
|
@@ -1826,8 +1829,8 @@ var CHANNELS = {
|
|
|
1826
1829
|
6: 4
|
|
1827
1830
|
// RGBA
|
|
1828
1831
|
};
|
|
1829
|
-
function bad(code,
|
|
1830
|
-
return new OhosPerfError(
|
|
1832
|
+
function bad(code, message3) {
|
|
1833
|
+
return new OhosPerfError(message3, { code });
|
|
1831
1834
|
}
|
|
1832
1835
|
function readChunk(bytes, offset) {
|
|
1833
1836
|
if (offset + 8 > bytes.length) {
|
|
@@ -2466,8 +2469,8 @@ var VELOCITY_MIN = 200;
|
|
|
2466
2469
|
var VELOCITY_MAX = 4e4;
|
|
2467
2470
|
var KEY_NAMES = /^(?:Back|Home|Power)$/;
|
|
2468
2471
|
var CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
2469
|
-
function badGesture(
|
|
2470
|
-
return new OhosPerfError(
|
|
2472
|
+
function badGesture(message3) {
|
|
2473
|
+
return new OhosPerfError(message3, { code: "UITEST_BAD_GESTURE" });
|
|
2471
2474
|
}
|
|
2472
2475
|
function assertPosition(field, value) {
|
|
2473
2476
|
if (!Number.isSafeInteger(value) || value < 0) {
|
|
@@ -3168,6 +3171,38 @@ var Device = class {
|
|
|
3168
3171
|
const hdc = this.requireHdc();
|
|
3169
3172
|
return (this.deps.gesture ?? new GestureDriver()).perform(hdc, this.id, request);
|
|
3170
3173
|
}
|
|
3174
|
+
/**
|
|
3175
|
+
* Flattened on-screen UI tree, for selector actions and step assertions.
|
|
3176
|
+
*
|
|
3177
|
+
* A fresh `uitest dumpLayout` each call, written into a temporary directory
|
|
3178
|
+
* that is removed afterwards: a step may dump several times (once per
|
|
3179
|
+
* scroll, once per assertion), and none of those are scene artifacts — the
|
|
3180
|
+
* capture's own `ui.json` is written by the collector inside its window.
|
|
3181
|
+
* Requires the `ui.tree` capability, like every other screen read.
|
|
3182
|
+
*/
|
|
3183
|
+
async uiTree() {
|
|
3184
|
+
const caps = await this.capabilities();
|
|
3185
|
+
if (!caps.has("ui.tree")) {
|
|
3186
|
+
const reason = caps.get("ui.tree")?.reason;
|
|
3187
|
+
throw new OhosPerfError(
|
|
3188
|
+
"reading the UI tree requires ui.tree capability" + (reason ? ` (${reason})` : ""),
|
|
3189
|
+
{ code: "MISSING_CAPABILITY" }
|
|
3190
|
+
);
|
|
3191
|
+
}
|
|
3192
|
+
const hdc = this.requireHdc();
|
|
3193
|
+
const root = mkdtempSync(join5(tmpdir(), "ohosperf-ui-"));
|
|
3194
|
+
try {
|
|
3195
|
+
const layout = createSceneLayout(root);
|
|
3196
|
+
return await (this.deps.uitest ?? new UitestCollector()).collect(
|
|
3197
|
+
hdc,
|
|
3198
|
+
this.id,
|
|
3199
|
+
{ full: true },
|
|
3200
|
+
layout
|
|
3201
|
+
);
|
|
3202
|
+
} finally {
|
|
3203
|
+
rmSync3(root, { recursive: true, force: true });
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3171
3206
|
/**
|
|
3172
3207
|
* Prepare a capture session. The capability gate runs here so a device that
|
|
3173
3208
|
* cannot produce frames fails before any device state is touched.
|
|
@@ -3617,7 +3652,7 @@ async function connect(opts = {}) {
|
|
|
3617
3652
|
// src/device/emulator.ts
|
|
3618
3653
|
import { spawn as spawn3 } from "node:child_process";
|
|
3619
3654
|
import { existsSync as existsSync11, readdirSync as readdirSync2, readFileSync as readFileSync8 } from "node:fs";
|
|
3620
|
-
import { delimiter as delimiter3, join as
|
|
3655
|
+
import { delimiter as delimiter3, join as join6 } from "node:path";
|
|
3621
3656
|
var FAILURE_LINE = /^(?:Emulator: |Unable to )/;
|
|
3622
3657
|
var START_SETTLE_MS = 3e3;
|
|
3623
3658
|
function emulatorBinName(platform) {
|
|
@@ -3627,9 +3662,9 @@ function defaultCommonPaths3(env, platform) {
|
|
|
3627
3662
|
if (platform !== "win32") return [];
|
|
3628
3663
|
const tail = ["tools", "emulator", "Emulator.exe"];
|
|
3629
3664
|
const paths = [];
|
|
3630
|
-
if (env.DEVECO_SDK_HOME) paths.push(
|
|
3631
|
-
paths.push(
|
|
3632
|
-
paths.push(
|
|
3665
|
+
if (env.DEVECO_SDK_HOME) paths.push(join6(env.DEVECO_SDK_HOME, ...tail));
|
|
3666
|
+
paths.push(join6("D:", "Application", "DevEco Studio", ...tail));
|
|
3667
|
+
paths.push(join6("C:", "Program Files", "Huawei", "DevEco Studio", ...tail));
|
|
3633
3668
|
return paths;
|
|
3634
3669
|
}
|
|
3635
3670
|
function parseEmuConfig(text) {
|
|
@@ -3647,7 +3682,7 @@ function readEmuConfigRoots(env, platform) {
|
|
|
3647
3682
|
if (platform !== "win32") return {};
|
|
3648
3683
|
const base = env.LOCALAPPDATA;
|
|
3649
3684
|
if (!base) return {};
|
|
3650
|
-
const huawei =
|
|
3685
|
+
const huawei = join6(base, "Huawei");
|
|
3651
3686
|
let dirs;
|
|
3652
3687
|
try {
|
|
3653
3688
|
dirs = readdirSync2(huawei, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.startsWith("Emulator")).map((entry) => entry.name).sort((a, b) => a < b ? 1 : a > b ? -1 : 0);
|
|
@@ -3658,7 +3693,7 @@ function readEmuConfigRoots(env, platform) {
|
|
|
3658
3693
|
for (const dir of dirs) {
|
|
3659
3694
|
let text;
|
|
3660
3695
|
try {
|
|
3661
|
-
text = readFileSync8(
|
|
3696
|
+
text = readFileSync8(join6(huawei, dir, ".emu_config"), "utf8");
|
|
3662
3697
|
} catch {
|
|
3663
3698
|
continue;
|
|
3664
3699
|
}
|
|
@@ -3698,7 +3733,7 @@ var EmulatorClient = class {
|
|
|
3698
3733
|
const fromConfig = this.emuConfig().instancePath;
|
|
3699
3734
|
if (fromConfig !== void 0) return fromConfig;
|
|
3700
3735
|
if (this.platform === "win32" && this.env.LOCALAPPDATA) {
|
|
3701
|
-
return
|
|
3736
|
+
return join6(this.env.LOCALAPPDATA, "Huawei", "Emulator", "deployed");
|
|
3702
3737
|
}
|
|
3703
3738
|
return void 0;
|
|
3704
3739
|
}
|
|
@@ -3709,7 +3744,7 @@ var EmulatorClient = class {
|
|
|
3709
3744
|
const fromConfig = this.emuConfig().imageRoot;
|
|
3710
3745
|
if (fromConfig !== void 0) return fromConfig;
|
|
3711
3746
|
if (this.platform === "win32" && this.env.LOCALAPPDATA) {
|
|
3712
|
-
return
|
|
3747
|
+
return join6(this.env.LOCALAPPDATA, "Huawei", "Sdk");
|
|
3713
3748
|
}
|
|
3714
3749
|
return void 0;
|
|
3715
3750
|
}
|
|
@@ -3734,7 +3769,7 @@ var EmulatorClient = class {
|
|
|
3734
3769
|
for (const p of this.opts.commonPaths ?? defaultCommonPaths3(this.env, this.platform)) push(p);
|
|
3735
3770
|
const bin = emulatorBinName(this.platform);
|
|
3736
3771
|
for (const dir of (this.env.PATH ?? "").split(delimiter3)) {
|
|
3737
|
-
if (dir) push(
|
|
3772
|
+
if (dir) push(join6(dir, bin));
|
|
3738
3773
|
}
|
|
3739
3774
|
for (const candidate of candidates) {
|
|
3740
3775
|
if (existsSync11(candidate)) {
|
|
@@ -4864,7 +4899,7 @@ function diffTrees(before, after) {
|
|
|
4864
4899
|
|
|
4865
4900
|
// src/ui/compare.ts
|
|
4866
4901
|
import { existsSync as existsSync12, mkdirSync as mkdirSync8, readFileSync as readFileSync9, writeFileSync as writeFileSync7 } from "node:fs";
|
|
4867
|
-
import { join as
|
|
4902
|
+
import { join as join7, resolve } from "node:path";
|
|
4868
4903
|
|
|
4869
4904
|
// src/report/escape.ts
|
|
4870
4905
|
function escapeHtml(value) {
|
|
@@ -5100,18 +5135,18 @@ async function compareSceneDirs(a, b, opts) {
|
|
|
5100
5135
|
};
|
|
5101
5136
|
const outDir = resolve(opts.outDir);
|
|
5102
5137
|
mkdirSync8(outDir, { recursive: true });
|
|
5103
|
-
writeFileSync7(
|
|
5138
|
+
writeFileSync7(join7(outDir, FILES.json), `${JSON.stringify(diff, null, 2)}
|
|
5104
5139
|
`);
|
|
5105
|
-
writeFileSync7(
|
|
5140
|
+
writeFileSync7(join7(outDir, FILES.html), renderUiDiffHtml(diff));
|
|
5106
5141
|
if (left.image !== void 0) {
|
|
5107
5142
|
writeFileSync7(
|
|
5108
|
-
|
|
5143
|
+
join7(outDir, FILES.markedA),
|
|
5109
5144
|
encodePng(markRegions(left.image, regions))
|
|
5110
5145
|
);
|
|
5111
5146
|
}
|
|
5112
5147
|
if (right.image !== void 0) {
|
|
5113
5148
|
writeFileSync7(
|
|
5114
|
-
|
|
5149
|
+
join7(outDir, FILES.markedB),
|
|
5115
5150
|
encodePng(markRegions(right.image, regions))
|
|
5116
5151
|
);
|
|
5117
5152
|
}
|
|
@@ -5124,6 +5159,256 @@ var UI_DIFF_FILES = [
|
|
|
5124
5159
|
FILES.markedB
|
|
5125
5160
|
];
|
|
5126
5161
|
|
|
5162
|
+
// src/scenario/selector.ts
|
|
5163
|
+
var RELATIONS = ["above", "below", "leftOf", "rightOf"];
|
|
5164
|
+
function isRecord5(value) {
|
|
5165
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5166
|
+
}
|
|
5167
|
+
function bad3(path, message3) {
|
|
5168
|
+
throw new OhosPerfError(`${path}: ${message3}`, { code: "SCENARIO_BAD_SELECTOR" });
|
|
5169
|
+
}
|
|
5170
|
+
function requiredText(value, path) {
|
|
5171
|
+
if (typeof value !== "string" || value === "") {
|
|
5172
|
+
bad3(path, "expected a non-empty string");
|
|
5173
|
+
}
|
|
5174
|
+
return value;
|
|
5175
|
+
}
|
|
5176
|
+
function requiredNumber(value, path) {
|
|
5177
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
5178
|
+
bad3(path, "expected a number");
|
|
5179
|
+
}
|
|
5180
|
+
return value;
|
|
5181
|
+
}
|
|
5182
|
+
function requiredRect(value, path) {
|
|
5183
|
+
if (!isRecord5(value)) bad3(path, "expected an object with left, top, right, bottom");
|
|
5184
|
+
const rect = {
|
|
5185
|
+
left: requiredNumber(value.left, `${path}.left`),
|
|
5186
|
+
top: requiredNumber(value.top, `${path}.top`),
|
|
5187
|
+
right: requiredNumber(value.right, `${path}.right`),
|
|
5188
|
+
bottom: requiredNumber(value.bottom, `${path}.bottom`)
|
|
5189
|
+
};
|
|
5190
|
+
if (rect.right < rect.left || rect.bottom < rect.top) {
|
|
5191
|
+
bad3(path, "right must not be left of left, and bottom must not be above top");
|
|
5192
|
+
}
|
|
5193
|
+
return rect;
|
|
5194
|
+
}
|
|
5195
|
+
var KEYS = {
|
|
5196
|
+
text: ["kind", "text", "exact"],
|
|
5197
|
+
id: ["kind", "id"],
|
|
5198
|
+
type: ["kind", "type"],
|
|
5199
|
+
clickable: ["kind"],
|
|
5200
|
+
all: ["kind", "of"],
|
|
5201
|
+
any: ["kind", "of"],
|
|
5202
|
+
not: ["kind", "of"],
|
|
5203
|
+
index: ["kind", "of", "index"],
|
|
5204
|
+
bounds: ["kind", "of", "within"],
|
|
5205
|
+
relative: ["kind", "of", "relation", "to"]
|
|
5206
|
+
};
|
|
5207
|
+
function checkKeys(value, kind, path) {
|
|
5208
|
+
for (const key of Object.keys(value)) {
|
|
5209
|
+
if (!KEYS[kind].includes(key)) {
|
|
5210
|
+
bad3(path, `unknown key ${JSON.stringify(key)} for a ${kind} selector`);
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
function parseSelector(value, path) {
|
|
5215
|
+
if (!isRecord5(value)) bad3(path, "expected a selector object");
|
|
5216
|
+
const kind = value.kind;
|
|
5217
|
+
if (typeof kind !== "string" || !Object.hasOwn(KEYS, kind)) {
|
|
5218
|
+
bad3(path, `unknown selector kind ${JSON.stringify(kind)}`);
|
|
5219
|
+
}
|
|
5220
|
+
const selectorKind = kind;
|
|
5221
|
+
checkKeys(value, selectorKind, path);
|
|
5222
|
+
switch (selectorKind) {
|
|
5223
|
+
case "text": {
|
|
5224
|
+
const text = requiredText(value.text, `${path}.text`);
|
|
5225
|
+
const exact = value.exact;
|
|
5226
|
+
if (exact !== void 0 && typeof exact !== "boolean") {
|
|
5227
|
+
bad3(`${path}.exact`, "expected true or false");
|
|
5228
|
+
}
|
|
5229
|
+
return exact === void 0 ? { kind: "text", text } : { kind: "text", text, exact };
|
|
5230
|
+
}
|
|
5231
|
+
case "id":
|
|
5232
|
+
return { kind: "id", id: requiredText(value.id, `${path}.id`) };
|
|
5233
|
+
case "type":
|
|
5234
|
+
return { kind: "type", type: requiredText(value.type, `${path}.type`) };
|
|
5235
|
+
case "clickable":
|
|
5236
|
+
return { kind: "clickable" };
|
|
5237
|
+
case "all":
|
|
5238
|
+
case "any": {
|
|
5239
|
+
if (!Array.isArray(value.of) || value.of.length === 0) {
|
|
5240
|
+
bad3(`${path}.of`, "expected a non-empty array of selectors");
|
|
5241
|
+
}
|
|
5242
|
+
return {
|
|
5243
|
+
kind: selectorKind,
|
|
5244
|
+
of: value.of.map(
|
|
5245
|
+
(child, index) => parseSelector(child, `${path}.of[${index}]`)
|
|
5246
|
+
)
|
|
5247
|
+
};
|
|
5248
|
+
}
|
|
5249
|
+
case "not":
|
|
5250
|
+
return { kind: "not", of: parseSelector(value.of, `${path}.of`) };
|
|
5251
|
+
case "index": {
|
|
5252
|
+
const index = requiredNumber(value.index, `${path}.index`);
|
|
5253
|
+
if (!Number.isSafeInteger(index) || index < 0) {
|
|
5254
|
+
bad3(`${path}.index`, "expected a non-negative whole number");
|
|
5255
|
+
}
|
|
5256
|
+
return { kind: "index", of: parseSelector(value.of, `${path}.of`), index };
|
|
5257
|
+
}
|
|
5258
|
+
case "bounds":
|
|
5259
|
+
return {
|
|
5260
|
+
kind: "bounds",
|
|
5261
|
+
of: parseSelector(value.of, `${path}.of`),
|
|
5262
|
+
within: requiredRect(value.within, `${path}.within`)
|
|
5263
|
+
};
|
|
5264
|
+
case "relative": {
|
|
5265
|
+
const relation = value.relation;
|
|
5266
|
+
if (typeof relation !== "string" || !RELATIONS.includes(relation)) {
|
|
5267
|
+
bad3(`${path}.relation`, `expected one of ${RELATIONS.join(", ")}`);
|
|
5268
|
+
}
|
|
5269
|
+
return {
|
|
5270
|
+
kind: "relative",
|
|
5271
|
+
of: parseSelector(value.of, `${path}.of`),
|
|
5272
|
+
relation,
|
|
5273
|
+
to: parseSelector(value.to, `${path}.to`)
|
|
5274
|
+
};
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
}
|
|
5278
|
+
function centre(node) {
|
|
5279
|
+
const rect = node.boundsRect;
|
|
5280
|
+
if (rect === void 0) return void 0;
|
|
5281
|
+
return {
|
|
5282
|
+
x: (rect.left + rect.right) / 2,
|
|
5283
|
+
y: (rect.top + rect.bottom) / 2
|
|
5284
|
+
};
|
|
5285
|
+
}
|
|
5286
|
+
function comparePosition(a, b) {
|
|
5287
|
+
const ra = a.boundsRect;
|
|
5288
|
+
const rb = b.boundsRect;
|
|
5289
|
+
if (ra === void 0 && rb !== void 0) return 1;
|
|
5290
|
+
if (ra !== void 0 && rb === void 0) return -1;
|
|
5291
|
+
if (ra !== void 0 && rb !== void 0) {
|
|
5292
|
+
if (ra.top !== rb.top) return ra.top - rb.top;
|
|
5293
|
+
if (ra.left !== rb.left) return ra.left - rb.left;
|
|
5294
|
+
if (ra.right !== rb.right) return ra.right - rb.right;
|
|
5295
|
+
if (ra.bottom !== rb.bottom) return ra.bottom - rb.bottom;
|
|
5296
|
+
}
|
|
5297
|
+
const ia = `${a.bundleName}|${a.type}|${a.id}|${a.text}`;
|
|
5298
|
+
const ib = `${b.bundleName}|${b.type}|${b.id}|${b.text}`;
|
|
5299
|
+
return ia < ib ? -1 : ia > ib ? 1 : 0;
|
|
5300
|
+
}
|
|
5301
|
+
function inside(node, rect) {
|
|
5302
|
+
const point = centre(node);
|
|
5303
|
+
if (point === void 0) return false;
|
|
5304
|
+
return point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom;
|
|
5305
|
+
}
|
|
5306
|
+
function relates(node, anchor, relation) {
|
|
5307
|
+
const a = centre(node);
|
|
5308
|
+
const b = centre(anchor);
|
|
5309
|
+
if (a === void 0 || b === void 0) return false;
|
|
5310
|
+
switch (relation) {
|
|
5311
|
+
case "above":
|
|
5312
|
+
return a.y < b.y;
|
|
5313
|
+
case "below":
|
|
5314
|
+
return a.y > b.y;
|
|
5315
|
+
case "leftOf":
|
|
5316
|
+
return a.x < b.x;
|
|
5317
|
+
case "rightOf":
|
|
5318
|
+
return a.x > b.x;
|
|
5319
|
+
}
|
|
5320
|
+
}
|
|
5321
|
+
function matchSelector(nodes, selector) {
|
|
5322
|
+
switch (selector.kind) {
|
|
5323
|
+
case "text": {
|
|
5324
|
+
const needle = selector.text.toLowerCase();
|
|
5325
|
+
return nodes.filter((node) => {
|
|
5326
|
+
const haystack = node.text.toLowerCase();
|
|
5327
|
+
return selector.exact === true ? haystack === needle : haystack.includes(needle);
|
|
5328
|
+
});
|
|
5329
|
+
}
|
|
5330
|
+
case "id":
|
|
5331
|
+
return nodes.filter((node) => node.id === selector.id);
|
|
5332
|
+
case "type":
|
|
5333
|
+
return nodes.filter((node) => node.type === selector.type);
|
|
5334
|
+
case "clickable":
|
|
5335
|
+
return nodes.filter((node) => node.clickable && node.enabled);
|
|
5336
|
+
case "all": {
|
|
5337
|
+
let candidates = [...nodes];
|
|
5338
|
+
for (const child of selector.of) candidates = matchSelector(candidates, child);
|
|
5339
|
+
return candidates;
|
|
5340
|
+
}
|
|
5341
|
+
case "any": {
|
|
5342
|
+
const matched = /* @__PURE__ */ new Set();
|
|
5343
|
+
for (const child of selector.of) {
|
|
5344
|
+
for (const node of matchSelector(nodes, child)) matched.add(node);
|
|
5345
|
+
}
|
|
5346
|
+
return nodes.filter((node) => matched.has(node));
|
|
5347
|
+
}
|
|
5348
|
+
case "not": {
|
|
5349
|
+
const excluded = new Set(matchSelector(nodes, selector.of));
|
|
5350
|
+
return nodes.filter((node) => !excluded.has(node));
|
|
5351
|
+
}
|
|
5352
|
+
case "index": {
|
|
5353
|
+
const matched = [...matchSelector(nodes, selector.of)].sort(comparePosition);
|
|
5354
|
+
const chosen = matched[selector.index];
|
|
5355
|
+
return chosen === void 0 ? [] : [chosen];
|
|
5356
|
+
}
|
|
5357
|
+
case "bounds":
|
|
5358
|
+
return matchSelector(nodes, selector.of).filter(
|
|
5359
|
+
(node) => inside(node, selector.within)
|
|
5360
|
+
);
|
|
5361
|
+
case "relative": {
|
|
5362
|
+
const anchors = [...matchSelector(nodes, selector.to)].sort(comparePosition);
|
|
5363
|
+
const anchor = anchors[0];
|
|
5364
|
+
if (anchor === void 0) return [];
|
|
5365
|
+
return matchSelector(nodes, selector.of).filter(
|
|
5366
|
+
(node) => relates(node, anchor, selector.relation)
|
|
5367
|
+
);
|
|
5368
|
+
}
|
|
5369
|
+
}
|
|
5370
|
+
}
|
|
5371
|
+
function resolveSelector(nodes, selector, label2) {
|
|
5372
|
+
const matched = matchSelector(nodes, selector);
|
|
5373
|
+
if (matched.length === 0) {
|
|
5374
|
+
throw new OhosPerfError(
|
|
5375
|
+
`${label2}: no node matched ${describe(selector)} (${nodes.length} nodes on screen)`,
|
|
5376
|
+
{ code: "SCENARIO_SELECTOR_NO_MATCH" }
|
|
5377
|
+
);
|
|
5378
|
+
}
|
|
5379
|
+
if (matched.length > 1) {
|
|
5380
|
+
throw new OhosPerfError(
|
|
5381
|
+
`${label2}: ${matched.length} nodes matched ${describe(selector)}; narrow it with index, bounds or a more specific selector`,
|
|
5382
|
+
{ code: "SCENARIO_SELECTOR_AMBIGUOUS" }
|
|
5383
|
+
);
|
|
5384
|
+
}
|
|
5385
|
+
return matched[0];
|
|
5386
|
+
}
|
|
5387
|
+
function describe(selector) {
|
|
5388
|
+
switch (selector.kind) {
|
|
5389
|
+
case "text":
|
|
5390
|
+
return selector.exact === true ? `text exactly ${JSON.stringify(selector.text)}` : `text containing ${JSON.stringify(selector.text)}`;
|
|
5391
|
+
case "id":
|
|
5392
|
+
return `id ${JSON.stringify(selector.id)}`;
|
|
5393
|
+
case "type":
|
|
5394
|
+
return `type ${JSON.stringify(selector.type)}`;
|
|
5395
|
+
case "clickable":
|
|
5396
|
+
return "a clickable node";
|
|
5397
|
+
case "all":
|
|
5398
|
+
return `all of [${selector.of.map(describe).join(" and ")}]`;
|
|
5399
|
+
case "any":
|
|
5400
|
+
return `any of [${selector.of.map(describe).join(" or ")}]`;
|
|
5401
|
+
case "not":
|
|
5402
|
+
return `not ${describe(selector.of)}`;
|
|
5403
|
+
case "index":
|
|
5404
|
+
return `#${selector.index} of [${describe(selector.of)}]`;
|
|
5405
|
+
case "bounds":
|
|
5406
|
+
return `[${describe(selector.of)}] within (${selector.within.left},${selector.within.top})-(${selector.within.right},${selector.within.bottom})`;
|
|
5407
|
+
case "relative":
|
|
5408
|
+
return `[${describe(selector.of)}] ${selector.relation} [${describe(selector.to)}]`;
|
|
5409
|
+
}
|
|
5410
|
+
}
|
|
5411
|
+
|
|
5127
5412
|
// src/scenario/schema.ts
|
|
5128
5413
|
var COLLECTOR_NAMES = [
|
|
5129
5414
|
"hitrace",
|
|
@@ -5141,20 +5426,20 @@ var CONTROL_CHARS2 = /[\u0000-\u001f\u007f]/;
|
|
|
5141
5426
|
var MAX_TIMEOUT_MS5 = 2147483647;
|
|
5142
5427
|
var VELOCITY_MIN2 = 200;
|
|
5143
5428
|
var VELOCITY_MAX2 = 4e4;
|
|
5144
|
-
function
|
|
5145
|
-
return new OhosPerfError(`invalid scenario: ${
|
|
5429
|
+
function bad4(message3, code) {
|
|
5430
|
+
return new OhosPerfError(`invalid scenario: ${message3}`, { code });
|
|
5146
5431
|
}
|
|
5147
|
-
function inputError(
|
|
5148
|
-
return
|
|
5432
|
+
function inputError(message3) {
|
|
5433
|
+
return bad4(message3, "SCENARIO_BAD_INPUT");
|
|
5149
5434
|
}
|
|
5150
|
-
function stepError(path,
|
|
5151
|
-
return
|
|
5435
|
+
function stepError(path, message3) {
|
|
5436
|
+
return bad4(`${path}: ${message3}`, "SCENARIO_BAD_STEP");
|
|
5152
5437
|
}
|
|
5153
|
-
function
|
|
5438
|
+
function isRecord6(value) {
|
|
5154
5439
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5155
5440
|
}
|
|
5156
5441
|
function fields(value, path, allowed, error) {
|
|
5157
|
-
if (!
|
|
5442
|
+
if (!isRecord6(value)) throw error(path, "expected an object");
|
|
5158
5443
|
for (const key of Object.keys(value)) {
|
|
5159
5444
|
if (!allowed.includes(key)) {
|
|
5160
5445
|
throw error(`${path}.${key}`, `unknown key ${JSON.stringify(key)}; expected one of ${allowed.join(", ")}`);
|
|
@@ -5203,10 +5488,15 @@ var ACTION_KEYS = {
|
|
|
5203
5488
|
text: ["kind", "text"],
|
|
5204
5489
|
inputText: ["kind", "x", "y", "text"],
|
|
5205
5490
|
wait: ["kind", "ms"],
|
|
5206
|
-
marker: ["kind", "name"]
|
|
5491
|
+
marker: ["kind", "name"],
|
|
5492
|
+
tap: ["kind", "target", "scrollTo", "timeoutMs"],
|
|
5493
|
+
tapText: ["kind", "text", "scrollTo"],
|
|
5494
|
+
swipeArea: ["kind", "area", "direction", "distance"],
|
|
5495
|
+
inputInto: ["kind", "target", "text"]
|
|
5207
5496
|
};
|
|
5497
|
+
var SWIPE_DIRECTIONS = ["up", "down", "left", "right"];
|
|
5208
5498
|
function parseAction(value, path, error) {
|
|
5209
|
-
if (!
|
|
5499
|
+
if (!isRecord6(value)) throw error(path, "expected an object");
|
|
5210
5500
|
const kind = value.kind;
|
|
5211
5501
|
if (typeof kind !== "string" || !Object.hasOwn(ACTION_KEYS, kind)) {
|
|
5212
5502
|
throw error(`${path}.kind`, `expected one of ${Object.keys(ACTION_KEYS).join(", ")}, got ${JSON.stringify(kind)}`);
|
|
@@ -5269,6 +5559,55 @@ function parseAction(value, path, error) {
|
|
|
5269
5559
|
}
|
|
5270
5560
|
return { kind: "marker", name };
|
|
5271
5561
|
}
|
|
5562
|
+
case "tap": {
|
|
5563
|
+
const target = parseSelector(action.target, at("target"));
|
|
5564
|
+
const scrollTo = action.scrollTo === void 0 ? void 0 : parseSelector(action.scrollTo, at("scrollTo"));
|
|
5565
|
+
const timeoutMs = action.timeoutMs === void 0 ? void 0 : nonNegativeInt(action.timeoutMs, at("timeoutMs"), error);
|
|
5566
|
+
return {
|
|
5567
|
+
kind: "tap",
|
|
5568
|
+
target,
|
|
5569
|
+
...scrollTo === void 0 ? {} : { scrollTo },
|
|
5570
|
+
...timeoutMs === void 0 ? {} : { timeoutMs }
|
|
5571
|
+
};
|
|
5572
|
+
}
|
|
5573
|
+
case "tapText": {
|
|
5574
|
+
const text = requiredString(action.text, at("text"), error);
|
|
5575
|
+
if (text === "") {
|
|
5576
|
+
throw error(at("text"), "expected a non-empty label; an empty one matches every node");
|
|
5577
|
+
}
|
|
5578
|
+
const scrollTo = action.scrollTo === void 0 ? void 0 : parseSelector(action.scrollTo, at("scrollTo"));
|
|
5579
|
+
return {
|
|
5580
|
+
kind: "tapText",
|
|
5581
|
+
text,
|
|
5582
|
+
...scrollTo === void 0 ? {} : { scrollTo }
|
|
5583
|
+
};
|
|
5584
|
+
}
|
|
5585
|
+
case "swipeArea": {
|
|
5586
|
+
const direction = action.direction;
|
|
5587
|
+
if (typeof direction !== "string" || !SWIPE_DIRECTIONS.includes(direction)) {
|
|
5588
|
+
throw error(at("direction"), `expected one of ${SWIPE_DIRECTIONS.join(", ")}, got ${JSON.stringify(direction)}`);
|
|
5589
|
+
}
|
|
5590
|
+
let distance;
|
|
5591
|
+
if (action.distance !== void 0) {
|
|
5592
|
+
const value2 = action.distance;
|
|
5593
|
+
if (typeof value2 !== "number" || !Number.isSafeInteger(value2) || value2 < 1 || value2 > 100) {
|
|
5594
|
+
throw error(at("distance"), `expected a whole number from 1 to 100, got ${JSON.stringify(value2)}`);
|
|
5595
|
+
}
|
|
5596
|
+
distance = value2;
|
|
5597
|
+
}
|
|
5598
|
+
return {
|
|
5599
|
+
kind: "swipeArea",
|
|
5600
|
+
area: parseSelector(action.area, at("area")),
|
|
5601
|
+
direction,
|
|
5602
|
+
...distance === void 0 ? {} : { distance }
|
|
5603
|
+
};
|
|
5604
|
+
}
|
|
5605
|
+
case "inputInto":
|
|
5606
|
+
return {
|
|
5607
|
+
kind: "inputInto",
|
|
5608
|
+
target: parseSelector(action.target, at("target")),
|
|
5609
|
+
text: gestureText(action.text, at("text"), error)
|
|
5610
|
+
};
|
|
5272
5611
|
}
|
|
5273
5612
|
}
|
|
5274
5613
|
function parseActions(value, path, error) {
|
|
@@ -5363,7 +5702,7 @@ function parseStep(value, path, seen) {
|
|
|
5363
5702
|
const step = fields(
|
|
5364
5703
|
value,
|
|
5365
5704
|
path,
|
|
5366
|
-
["id", "name", "setup", "actions", "cleanup", "capture"],
|
|
5705
|
+
["id", "name", "setup", "actions", "cleanup", "capture", "expect"],
|
|
5367
5706
|
stepError
|
|
5368
5707
|
);
|
|
5369
5708
|
const idPath = `${path}.id`;
|
|
@@ -5374,13 +5713,60 @@ function parseStep(value, path, seen) {
|
|
|
5374
5713
|
if (seen.has(id)) throw stepError(idPath, `duplicate step id ${JSON.stringify(id)}`);
|
|
5375
5714
|
seen.add(id);
|
|
5376
5715
|
const name = step.name === void 0 ? id : requiredString(step.name, `${path}.name`, stepError);
|
|
5716
|
+
const expect = step.expect === void 0 ? void 0 : parseExpect(step.expect, `${path}.expect`);
|
|
5377
5717
|
return {
|
|
5378
5718
|
id,
|
|
5379
5719
|
name,
|
|
5380
5720
|
setup: parseActions(step.setup, `${path}.setup`, stepError),
|
|
5381
5721
|
actions: parseActions(step.actions, `${path}.actions`, stepError),
|
|
5382
5722
|
cleanup: parseActions(step.cleanup, `${path}.cleanup`, stepError),
|
|
5383
|
-
capture: parseCapture(step.capture, `${path}.capture`, stepError)
|
|
5723
|
+
capture: parseCapture(step.capture, `${path}.capture`, stepError),
|
|
5724
|
+
...expect === void 0 ? {} : { expect }
|
|
5725
|
+
};
|
|
5726
|
+
}
|
|
5727
|
+
function parseExpect(value, path) {
|
|
5728
|
+
const block = fields(value, path, ["present", "absent", "foreground"], stepError);
|
|
5729
|
+
let present;
|
|
5730
|
+
if (block.present !== void 0) {
|
|
5731
|
+
if (!Array.isArray(block.present)) {
|
|
5732
|
+
throw stepError(`${path}.present`, "expected an array of { selector, min?, max? }");
|
|
5733
|
+
}
|
|
5734
|
+
present = block.present.map((entry, index) => {
|
|
5735
|
+
const at = `${path}.present[${index}]`;
|
|
5736
|
+
const clause = fields(entry, at, ["selector", "min", "max"], stepError);
|
|
5737
|
+
const selector = parseSelector(clause.selector, `${at}.selector`);
|
|
5738
|
+
const min = clause.min === void 0 ? void 0 : nonNegativeInt(clause.min, `${at}.min`, stepError);
|
|
5739
|
+
const max = clause.max === void 0 ? void 0 : nonNegativeInt(clause.max, `${at}.max`, stepError);
|
|
5740
|
+
if (min !== void 0 && max !== void 0 && min > max) {
|
|
5741
|
+
throw stepError(`${at}.max`, `expected max >= min (min is ${min}, max is ${max})`);
|
|
5742
|
+
}
|
|
5743
|
+
return {
|
|
5744
|
+
selector,
|
|
5745
|
+
...min === void 0 ? {} : { min },
|
|
5746
|
+
...max === void 0 ? {} : { max }
|
|
5747
|
+
};
|
|
5748
|
+
});
|
|
5749
|
+
}
|
|
5750
|
+
let absent;
|
|
5751
|
+
if (block.absent !== void 0) {
|
|
5752
|
+
if (!Array.isArray(block.absent)) {
|
|
5753
|
+
throw stepError(`${path}.absent`, "expected an array of selectors");
|
|
5754
|
+
}
|
|
5755
|
+
absent = block.absent.map(
|
|
5756
|
+
(entry, index) => parseSelector(entry, `${path}.absent[${index}]`)
|
|
5757
|
+
);
|
|
5758
|
+
}
|
|
5759
|
+
let foreground;
|
|
5760
|
+
if (block.foreground !== void 0) {
|
|
5761
|
+
if (typeof block.foreground !== "boolean") {
|
|
5762
|
+
throw stepError(`${path}.foreground`, "expected true or false");
|
|
5763
|
+
}
|
|
5764
|
+
foreground = block.foreground;
|
|
5765
|
+
}
|
|
5766
|
+
return {
|
|
5767
|
+
...present === void 0 ? {} : { present },
|
|
5768
|
+
...absent === void 0 ? {} : { absent },
|
|
5769
|
+
...foreground === void 0 ? {} : { foreground }
|
|
5384
5770
|
};
|
|
5385
5771
|
}
|
|
5386
5772
|
function parseScenario(text) {
|
|
@@ -5393,14 +5779,14 @@ function parseScenario(text) {
|
|
|
5393
5779
|
{ code: "SCENARIO_BAD_INPUT", cause: err }
|
|
5394
5780
|
);
|
|
5395
5781
|
}
|
|
5396
|
-
if (!
|
|
5782
|
+
if (!isRecord6(parsed)) {
|
|
5397
5783
|
throw inputError("expected a JSON object at the document root");
|
|
5398
5784
|
}
|
|
5399
5785
|
const doc = fields(
|
|
5400
5786
|
parsed,
|
|
5401
5787
|
"",
|
|
5402
5788
|
["version", "name", "description", "app", "rounds", "steps"],
|
|
5403
|
-
(path,
|
|
5789
|
+
(path, message3) => inputError(path === "" ? message3 : `${path.slice(1)}: ${message3}`)
|
|
5404
5790
|
);
|
|
5405
5791
|
if (doc.version !== 1) {
|
|
5406
5792
|
throw inputError(`version: expected 1, got ${JSON.stringify(doc.version)}`);
|
|
@@ -5429,7 +5815,84 @@ function parseScenario(text) {
|
|
|
5429
5815
|
};
|
|
5430
5816
|
}
|
|
5431
5817
|
|
|
5818
|
+
// src/scenario/cases.ts
|
|
5819
|
+
import { readFileSync as readFileSync10, readdirSync as readdirSync3, statSync as statSync3 } from "node:fs";
|
|
5820
|
+
import { basename, join as join8 } from "node:path";
|
|
5821
|
+
var CASE_SUFFIX = ".scenario.json";
|
|
5822
|
+
function discoverCases(dir, filter) {
|
|
5823
|
+
let entries;
|
|
5824
|
+
try {
|
|
5825
|
+
if (!statSync3(dir).isDirectory()) {
|
|
5826
|
+
throw new Error("not a directory");
|
|
5827
|
+
}
|
|
5828
|
+
entries = readdirSync3(dir);
|
|
5829
|
+
} catch (err) {
|
|
5830
|
+
throw new OhosPerfError(
|
|
5831
|
+
`cannot read the cases directory ${dir}: ${message(err)}`,
|
|
5832
|
+
{ code: "SCENARIO_CASES_EMPTY", cause: err }
|
|
5833
|
+
);
|
|
5834
|
+
}
|
|
5835
|
+
const found = entries.filter((name) => name.endsWith(CASE_SUFFIX)).map((name) => ({
|
|
5836
|
+
id: basename(name, CASE_SUFFIX),
|
|
5837
|
+
path: join8(dir, name)
|
|
5838
|
+
})).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
5839
|
+
if (found.length === 0) {
|
|
5840
|
+
throw new OhosPerfError(
|
|
5841
|
+
`no *${CASE_SUFFIX} file in ${dir}; a cases directory holds one scenario per file`,
|
|
5842
|
+
{ code: "SCENARIO_CASES_EMPTY" }
|
|
5843
|
+
);
|
|
5844
|
+
}
|
|
5845
|
+
if (filter === void 0) return found;
|
|
5846
|
+
let pattern;
|
|
5847
|
+
try {
|
|
5848
|
+
pattern = new RegExp(`^(?:${filter})$`);
|
|
5849
|
+
} catch (err) {
|
|
5850
|
+
throw new OhosPerfError(
|
|
5851
|
+
`invalid --filter ${JSON.stringify(filter)}: ${message(err)}`,
|
|
5852
|
+
{ code: "SCENARIO_BAD_INPUT", cause: err }
|
|
5853
|
+
);
|
|
5854
|
+
}
|
|
5855
|
+
const matched = found.filter((entry) => pattern.test(entry.id));
|
|
5856
|
+
if (matched.length === 0) {
|
|
5857
|
+
throw new OhosPerfError(
|
|
5858
|
+
`--filter ${JSON.stringify(filter)} matched no case; the directory has ${found.map((entry) => entry.id).join(", ")}`,
|
|
5859
|
+
{ code: "SCENARIO_CASES_EMPTY" }
|
|
5860
|
+
);
|
|
5861
|
+
}
|
|
5862
|
+
return matched;
|
|
5863
|
+
}
|
|
5864
|
+
function loadCases(cases) {
|
|
5865
|
+
return cases.map((entry) => {
|
|
5866
|
+
let text;
|
|
5867
|
+
try {
|
|
5868
|
+
text = readFileSync10(entry.path, "utf8");
|
|
5869
|
+
} catch (err) {
|
|
5870
|
+
return {
|
|
5871
|
+
id: entry.id,
|
|
5872
|
+
path: entry.path,
|
|
5873
|
+
error: `${basename(entry.path)}: cannot be read (${errorCode(err)})`
|
|
5874
|
+
};
|
|
5875
|
+
}
|
|
5876
|
+
try {
|
|
5877
|
+
return { id: entry.id, path: entry.path, scenario: parseScenario(text) };
|
|
5878
|
+
} catch (err) {
|
|
5879
|
+
return { id: entry.id, path: entry.path, error: `${basename(entry.path)}: ${message(err)}` };
|
|
5880
|
+
}
|
|
5881
|
+
});
|
|
5882
|
+
}
|
|
5883
|
+
function message(err) {
|
|
5884
|
+
return err instanceof Error ? err.message : String(err);
|
|
5885
|
+
}
|
|
5886
|
+
function errorCode(err) {
|
|
5887
|
+
const code = err?.code;
|
|
5888
|
+
return typeof code === "string" ? code : "unreadable";
|
|
5889
|
+
}
|
|
5890
|
+
|
|
5432
5891
|
// src/scenario/actions.ts
|
|
5892
|
+
var MAX_SCROLLS = 5;
|
|
5893
|
+
var DEFAULT_DISTANCE = 40;
|
|
5894
|
+
var POLL_MS = 250;
|
|
5895
|
+
var ACCEPTED_MARKER2 = "No Error";
|
|
5433
5896
|
function detail9(result) {
|
|
5434
5897
|
const lines = `${result.stdout}
|
|
5435
5898
|
${result.stderr}`.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
@@ -5468,7 +5931,105 @@ function toGesture(action) {
|
|
|
5468
5931
|
return void 0;
|
|
5469
5932
|
}
|
|
5470
5933
|
}
|
|
5471
|
-
|
|
5934
|
+
function requireDump(context) {
|
|
5935
|
+
if (context === void 0) {
|
|
5936
|
+
throw new OhosPerfError(
|
|
5937
|
+
"a selector action needs a UI dump; pass the action context (this action was executed without one)",
|
|
5938
|
+
{ code: "SCENARIO_SELECTOR_NO_TREE" }
|
|
5939
|
+
);
|
|
5940
|
+
}
|
|
5941
|
+
return context.dump;
|
|
5942
|
+
}
|
|
5943
|
+
function centreOf(node, label2) {
|
|
5944
|
+
const rect = node.boundsRect;
|
|
5945
|
+
if (rect === void 0) {
|
|
5946
|
+
throw new OhosPerfError(
|
|
5947
|
+
`${label2}: the selected ${JSON.stringify(node.type)} node has no parseable bounds (got ${JSON.stringify(node.bounds)}); it cannot be tapped`,
|
|
5948
|
+
{ code: "SCENARIO_SELECTOR_NO_MATCH" }
|
|
5949
|
+
);
|
|
5950
|
+
}
|
|
5951
|
+
return {
|
|
5952
|
+
x: Math.round((rect.left + rect.right) / 2),
|
|
5953
|
+
y: Math.round((rect.top + rect.bottom) / 2)
|
|
5954
|
+
};
|
|
5955
|
+
}
|
|
5956
|
+
function treeSignature(nodes) {
|
|
5957
|
+
return nodes.map((node) => `${node.id}|${node.text}|${node.bounds}`).join("\n");
|
|
5958
|
+
}
|
|
5959
|
+
function safeResolve(nodes, selector) {
|
|
5960
|
+
try {
|
|
5961
|
+
return resolveSelector(nodes, selector, "target");
|
|
5962
|
+
} catch {
|
|
5963
|
+
return void 0;
|
|
5964
|
+
}
|
|
5965
|
+
}
|
|
5966
|
+
async function gestureOrThrow(device, gesture) {
|
|
5967
|
+
const result = await device.gesture(gesture);
|
|
5968
|
+
if (!result.output.includes(ACCEPTED_MARKER2)) {
|
|
5969
|
+
throw new OhosPerfError(
|
|
5970
|
+
`uitest uiInput ${gesture.action} did not report "${ACCEPTED_MARKER2}": ${result.output === "" ? "(no output)" : result.output}`,
|
|
5971
|
+
{ code: "SCENARIO_ACTION_FAILED" }
|
|
5972
|
+
);
|
|
5973
|
+
}
|
|
5974
|
+
}
|
|
5975
|
+
async function findWithScroll(device, dump, target, scrollTo, label2) {
|
|
5976
|
+
const first = await dump();
|
|
5977
|
+
const direct = safeResolve(first, target);
|
|
5978
|
+
if (direct !== void 0) return direct;
|
|
5979
|
+
const container = resolveSelector(first, scrollTo, "scrollTo");
|
|
5980
|
+
if (!container.scrollable) {
|
|
5981
|
+
throw new OhosPerfError(
|
|
5982
|
+
`scrollTo: the selected ${JSON.stringify(container.type)} node is not scrollable; name the list, not its container`,
|
|
5983
|
+
{ code: "SCENARIO_SELECTOR_NO_MATCH" }
|
|
5984
|
+
);
|
|
5985
|
+
}
|
|
5986
|
+
const rect = container.boundsRect;
|
|
5987
|
+
if (rect === void 0) {
|
|
5988
|
+
throw new OhosPerfError(
|
|
5989
|
+
`scrollTo: the selected node has no parseable bounds (got ${JSON.stringify(container.bounds)})`,
|
|
5990
|
+
{ code: "SCENARIO_SELECTOR_NO_MATCH" }
|
|
5991
|
+
);
|
|
5992
|
+
}
|
|
5993
|
+
const middleX = Math.round((rect.left + rect.right) / 2);
|
|
5994
|
+
const fromY = Math.round(rect.top + (rect.bottom - rect.top) * 0.7);
|
|
5995
|
+
const toY = Math.round(rect.top + (rect.bottom - rect.top) * 0.3);
|
|
5996
|
+
const swipe = { action: "swipe", fromX: middleX, fromY, toX: middleX, toY };
|
|
5997
|
+
let previous = treeSignature(first);
|
|
5998
|
+
for (let attempt = 1; attempt <= MAX_SCROLLS; attempt += 1) {
|
|
5999
|
+
await gestureOrThrow(device, swipe);
|
|
6000
|
+
const next = await dump();
|
|
6001
|
+
const found = safeResolve(next, target);
|
|
6002
|
+
if (found !== void 0) return found;
|
|
6003
|
+
const signature = treeSignature(next);
|
|
6004
|
+
if (signature === previous) {
|
|
6005
|
+
throw new OhosPerfError(
|
|
6006
|
+
`${label2}: no node matched the selector after ${attempt} swipe${attempt === 1 ? "" : "s"} of the scrollTo container; it stopped changing, so it is at its edge and the target is not in it`,
|
|
6007
|
+
{ code: "SCENARIO_SELECTOR_NO_MATCH" }
|
|
6008
|
+
);
|
|
6009
|
+
}
|
|
6010
|
+
previous = signature;
|
|
6011
|
+
}
|
|
6012
|
+
throw new OhosPerfError(
|
|
6013
|
+
`${label2}: no node matched the selector after ${MAX_SCROLLS} swipes of the scrollTo container; the target may be past its end or on another screen`,
|
|
6014
|
+
{ code: "SCENARIO_SELECTOR_NO_MATCH" }
|
|
6015
|
+
);
|
|
6016
|
+
}
|
|
6017
|
+
async function resolveWithWait(dump, target, label2, timeoutMs) {
|
|
6018
|
+
const deadline = timeoutMs === void 0 ? 0 : Date.now() + timeoutMs;
|
|
6019
|
+
for (; ; ) {
|
|
6020
|
+
const nodes = await dump();
|
|
6021
|
+
const node = safeResolve(nodes, target);
|
|
6022
|
+
if (node !== void 0) return node;
|
|
6023
|
+
const remaining = deadline - Date.now();
|
|
6024
|
+
if (timeoutMs === void 0 || remaining <= 0) {
|
|
6025
|
+
return resolveSelector(nodes, target, label2);
|
|
6026
|
+
}
|
|
6027
|
+
await new Promise(
|
|
6028
|
+
(resolve2) => setTimeout(resolve2, Math.min(POLL_MS, remaining))
|
|
6029
|
+
);
|
|
6030
|
+
}
|
|
6031
|
+
}
|
|
6032
|
+
async function executeAction(device, app, action, context) {
|
|
5472
6033
|
switch (action.kind) {
|
|
5473
6034
|
case "launch":
|
|
5474
6035
|
return runAa(device, `aa start -a ${action.ability} -b ${app}`);
|
|
@@ -5482,6 +6043,48 @@ async function executeAction(device, app, action) {
|
|
|
5482
6043
|
`marker ${JSON.stringify(action.name)} is recorded by the scenario runner, not executed as an action`,
|
|
5483
6044
|
{ code: "SCENARIO_BAD_ACTION" }
|
|
5484
6045
|
);
|
|
6046
|
+
case "tap": {
|
|
6047
|
+
const dump = requireDump(context);
|
|
6048
|
+
const node = action.scrollTo === void 0 ? await resolveWithWait(dump, action.target, "target", action.timeoutMs) : await findWithScroll(device, dump, action.target, action.scrollTo, "target");
|
|
6049
|
+
const point = centreOf(node, "target");
|
|
6050
|
+
const result = await device.gesture({ action: "click", x: point.x, y: point.y });
|
|
6051
|
+
return { output: result.output };
|
|
6052
|
+
}
|
|
6053
|
+
case "tapText": {
|
|
6054
|
+
const dump = requireDump(context);
|
|
6055
|
+
const selector = { kind: "text", text: action.text };
|
|
6056
|
+
const node = action.scrollTo === void 0 ? resolveSelector(await dump(), selector, "text") : await findWithScroll(device, dump, selector, action.scrollTo, "text");
|
|
6057
|
+
const point = centreOf(node, "text");
|
|
6058
|
+
const result = await device.gesture({ action: "click", x: point.x, y: point.y });
|
|
6059
|
+
return { output: result.output };
|
|
6060
|
+
}
|
|
6061
|
+
case "swipeArea": {
|
|
6062
|
+
const dump = requireDump(context);
|
|
6063
|
+
const node = resolveSelector(await dump(), action.area, "area");
|
|
6064
|
+
const rect = node.boundsRect;
|
|
6065
|
+
if (rect === void 0) {
|
|
6066
|
+
throw new OhosPerfError(
|
|
6067
|
+
`area: the selected node has no parseable bounds (got ${JSON.stringify(node.bounds)}); it cannot be swiped`,
|
|
6068
|
+
{ code: "SCENARIO_SELECTOR_NO_MATCH" }
|
|
6069
|
+
);
|
|
6070
|
+
}
|
|
6071
|
+
const travel = (action.distance ?? DEFAULT_DISTANCE) / 100;
|
|
6072
|
+
const result = await device.gesture(swipeInside(rect, action.direction, travel));
|
|
6073
|
+
return { output: result.output };
|
|
6074
|
+
}
|
|
6075
|
+
case "inputInto": {
|
|
6076
|
+
const dump = requireDump(context);
|
|
6077
|
+
const node = resolveSelector(await dump(), action.target, "target");
|
|
6078
|
+
const point = centreOf(node, "target");
|
|
6079
|
+
await device.gesture({ action: "click", x: point.x, y: point.y });
|
|
6080
|
+
const result = await device.gesture({
|
|
6081
|
+
action: "inputText",
|
|
6082
|
+
x: point.x,
|
|
6083
|
+
y: point.y,
|
|
6084
|
+
text: action.text
|
|
6085
|
+
});
|
|
6086
|
+
return { output: result.output };
|
|
6087
|
+
}
|
|
5485
6088
|
default: {
|
|
5486
6089
|
const gesture = toGesture(action);
|
|
5487
6090
|
if (gesture === void 0) {
|
|
@@ -5495,10 +6098,26 @@ async function executeAction(device, app, action) {
|
|
|
5495
6098
|
}
|
|
5496
6099
|
}
|
|
5497
6100
|
}
|
|
6101
|
+
function swipeInside(rect, direction, travel) {
|
|
6102
|
+
const midX = Math.round((rect.left + rect.right) / 2);
|
|
6103
|
+
const midY = Math.round((rect.top + rect.bottom) / 2);
|
|
6104
|
+
const halfX = Math.round((rect.right - rect.left) * travel / 2);
|
|
6105
|
+
const halfY = Math.round((rect.bottom - rect.top) * travel / 2);
|
|
6106
|
+
switch (direction) {
|
|
6107
|
+
case "up":
|
|
6108
|
+
return { action: "swipe", fromX: midX, fromY: midY + halfY, toX: midX, toY: midY - halfY };
|
|
6109
|
+
case "down":
|
|
6110
|
+
return { action: "swipe", fromX: midX, fromY: midY - halfY, toX: midX, toY: midY + halfY };
|
|
6111
|
+
case "left":
|
|
6112
|
+
return { action: "swipe", fromX: midX + halfX, fromY: midY, toX: midX - halfX, toY: midY };
|
|
6113
|
+
case "right":
|
|
6114
|
+
return { action: "swipe", fromX: midX - halfX, fromY: midY, toX: midX + halfX, toY: midY };
|
|
6115
|
+
}
|
|
6116
|
+
}
|
|
5498
6117
|
|
|
5499
6118
|
// src/scenario/runner.ts
|
|
5500
6119
|
import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync8 } from "node:fs";
|
|
5501
|
-
import { join as
|
|
6120
|
+
import { join as join9 } from "node:path";
|
|
5502
6121
|
async function readUptimeNs2(device) {
|
|
5503
6122
|
try {
|
|
5504
6123
|
const result = await device.shell("cat /proc/uptime");
|
|
@@ -5512,7 +6131,7 @@ async function readUptimeNs2(device) {
|
|
|
5512
6131
|
return void 0;
|
|
5513
6132
|
}
|
|
5514
6133
|
}
|
|
5515
|
-
function
|
|
6134
|
+
function message2(err) {
|
|
5516
6135
|
return err instanceof Error ? err.message : String(err);
|
|
5517
6136
|
}
|
|
5518
6137
|
async function resolvePids2(device, app) {
|
|
@@ -5536,6 +6155,49 @@ async function resolveAppVersion(device, app) {
|
|
|
5536
6155
|
return void 0;
|
|
5537
6156
|
}
|
|
5538
6157
|
}
|
|
6158
|
+
function evaluate2(expect, nodes, app) {
|
|
6159
|
+
const outcomes = [];
|
|
6160
|
+
for (const clause of expect.present ?? []) {
|
|
6161
|
+
const matched = matchSelector(nodes, clause.selector);
|
|
6162
|
+
const min = clause.min ?? 1;
|
|
6163
|
+
const max = clause.max ?? Number.POSITIVE_INFINITY;
|
|
6164
|
+
const ok = matched.length >= min && matched.length <= max;
|
|
6165
|
+
outcomes.push({
|
|
6166
|
+
label: `present: ${describe(clause.selector)}`,
|
|
6167
|
+
ok,
|
|
6168
|
+
actual: matched.length,
|
|
6169
|
+
...ok ? {} : {
|
|
6170
|
+
detail: matched.length < min ? `expected at least ${min}, found ${matched.length} of ${nodes.length} nodes` : `expected at most ${max}, found ${matched.length} of ${nodes.length} nodes`
|
|
6171
|
+
}
|
|
6172
|
+
});
|
|
6173
|
+
}
|
|
6174
|
+
for (const selector of expect.absent ?? []) {
|
|
6175
|
+
const matched = matchSelector(nodes, selector);
|
|
6176
|
+
outcomes.push({
|
|
6177
|
+
label: `absent: ${describe(selector)}`,
|
|
6178
|
+
ok: matched.length === 0,
|
|
6179
|
+
actual: matched.length,
|
|
6180
|
+
...matched.length === 0 ? {} : { detail: `expected none, found ${matched.length} of ${nodes.length} nodes` }
|
|
6181
|
+
});
|
|
6182
|
+
}
|
|
6183
|
+
const wantForeground = expect.foreground ?? true;
|
|
6184
|
+
const owned = nodes.filter((node) => node.bundleName === app).length;
|
|
6185
|
+
const foregroundOk = wantForeground ? owned > 0 : owned === 0;
|
|
6186
|
+
outcomes.push({
|
|
6187
|
+
label: "foreground",
|
|
6188
|
+
ok: foregroundOk,
|
|
6189
|
+
actual: owned,
|
|
6190
|
+
...foregroundOk ? {} : {
|
|
6191
|
+
detail: wantForeground ? `${app} owned no node of ${nodes.length} on screen` : `${app} still owned ${owned} of ${nodes.length} nodes on screen`
|
|
6192
|
+
}
|
|
6193
|
+
});
|
|
6194
|
+
return outcomes;
|
|
6195
|
+
}
|
|
6196
|
+
function failureOf(outcomes) {
|
|
6197
|
+
const failed = outcomes.find((outcome) => !outcome.ok);
|
|
6198
|
+
if (failed === void 0) return void 0;
|
|
6199
|
+
return `expectation failed \u2014 ${failed.label}: ${failed.detail ?? "did not hold"}`;
|
|
6200
|
+
}
|
|
5539
6201
|
function collectOptions(step, app, sceneRoot, ref) {
|
|
5540
6202
|
const { capture } = step;
|
|
5541
6203
|
const has = (name) => capture.collectors.includes(name);
|
|
@@ -5627,10 +6289,11 @@ var ScenarioRunner = class {
|
|
|
5627
6289
|
async runStep(scenario, step, position) {
|
|
5628
6290
|
const startedAtMs = this.now();
|
|
5629
6291
|
const ref = { round: position.round, index: position.index, id: step.id };
|
|
5630
|
-
const sceneRoot =
|
|
6292
|
+
const sceneRoot = join9(this.opts.outDir, step.id, `round-${position.round}`);
|
|
5631
6293
|
const actions = [];
|
|
5632
6294
|
let failure;
|
|
5633
6295
|
let sceneDir;
|
|
6296
|
+
let expectations;
|
|
5634
6297
|
for (const action of step.setup) {
|
|
5635
6298
|
const outcome = await this.perform(scenario.app, action);
|
|
5636
6299
|
actions.push(outcome);
|
|
@@ -5658,7 +6321,22 @@ var ScenarioRunner = class {
|
|
|
5658
6321
|
scene.close();
|
|
5659
6322
|
sceneDir = sceneRoot;
|
|
5660
6323
|
} catch (err) {
|
|
5661
|
-
failure ??=
|
|
6324
|
+
failure ??= message2(err);
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6327
|
+
if (step.expect !== void 0) {
|
|
6328
|
+
try {
|
|
6329
|
+
if (this.device.uiTree === void 0) {
|
|
6330
|
+
throw new OhosPerfError(
|
|
6331
|
+
"the step asserts its screen, but this device cannot dump the UI tree",
|
|
6332
|
+
{ code: "SCENARIO_SELECTOR_NO_TREE" }
|
|
6333
|
+
);
|
|
6334
|
+
}
|
|
6335
|
+
const nodes = await this.device.uiTree();
|
|
6336
|
+
expectations = evaluate2(step.expect, nodes, scenario.app);
|
|
6337
|
+
failure ??= failureOf(expectations);
|
|
6338
|
+
} catch (err) {
|
|
6339
|
+
failure ??= `expectation could not be evaluated: ${message2(err)}`;
|
|
5662
6340
|
}
|
|
5663
6341
|
}
|
|
5664
6342
|
for (const action of step.cleanup) {
|
|
@@ -5676,6 +6354,7 @@ var ScenarioRunner = class {
|
|
|
5676
6354
|
startedAtMs,
|
|
5677
6355
|
durationMs: this.now() - startedAtMs,
|
|
5678
6356
|
actions,
|
|
6357
|
+
...expectations === void 0 ? {} : { expectations },
|
|
5679
6358
|
...failure === void 0 ? {} : { error: failure }
|
|
5680
6359
|
};
|
|
5681
6360
|
}
|
|
@@ -5699,7 +6378,8 @@ var ScenarioRunner = class {
|
|
|
5699
6378
|
};
|
|
5700
6379
|
}
|
|
5701
6380
|
try {
|
|
5702
|
-
const
|
|
6381
|
+
const context = this.device.uiTree === void 0 ? void 0 : { dump: () => this.device.uiTree() };
|
|
6382
|
+
const result = await executeAction(this.device, app, action, context);
|
|
5703
6383
|
return {
|
|
5704
6384
|
action,
|
|
5705
6385
|
...atNs === void 0 ? {} : { atNs },
|
|
@@ -5713,7 +6393,7 @@ var ScenarioRunner = class {
|
|
|
5713
6393
|
...atNs === void 0 ? {} : { atNs },
|
|
5714
6394
|
atMs,
|
|
5715
6395
|
ok: false,
|
|
5716
|
-
error:
|
|
6396
|
+
error: message2(err)
|
|
5717
6397
|
};
|
|
5718
6398
|
}
|
|
5719
6399
|
}
|
|
@@ -5737,7 +6417,7 @@ function testInfoOf(result) {
|
|
|
5737
6417
|
function writeRunFiles(outDir, result) {
|
|
5738
6418
|
mkdirSync9(outDir, { recursive: true });
|
|
5739
6419
|
const write = (name, value) => {
|
|
5740
|
-
writeFileSync8(
|
|
6420
|
+
writeFileSync8(join9(outDir, name), `${JSON.stringify(value, null, 2)}
|
|
5741
6421
|
`);
|
|
5742
6422
|
};
|
|
5743
6423
|
write("testInfo.json", testInfoOf(result));
|
|
@@ -8466,7 +9146,7 @@ var BUNDLE_SO = /^\/proc\/.*\/data\/storage\/.*\/bundle\/(.*\.so|libs\/.*)$/;
|
|
|
8466
9146
|
var BUNDLE_ABC = /^\/proc\/.*\/data\/storage\/.*\/bundle\/.*\.abc$/;
|
|
8467
9147
|
var APP_STORAGE = /^\/proc\/.*\/data\/storage\/(?!.*\/bundle\/.*\.so$)(?!.*\/bundle\/libs\/).*$/;
|
|
8468
9148
|
var ARKTS_SYMBOL = /^([^:]+):\[url:([^:|]+)\|([^|]+)\|([^:|]+)\|([^|]*):(\d+):(\d+)\]$/;
|
|
8469
|
-
function
|
|
9149
|
+
function basename2(filePath) {
|
|
8470
9150
|
const index = filePath.lastIndexOf("/");
|
|
8471
9151
|
return index >= 0 ? filePath.slice(index + 1) : filePath;
|
|
8472
9152
|
}
|
|
@@ -8480,7 +9160,7 @@ function kmpPackage(symbol) {
|
|
|
8480
9160
|
}
|
|
8481
9161
|
function refine(base, symbol) {
|
|
8482
9162
|
if (symbol === null) return base;
|
|
8483
|
-
if (base.category === CATEGORY.APP && base.subCategory !==
|
|
9163
|
+
if (base.category === CATEGORY.APP && base.subCategory !== basename2(base.file)) {
|
|
8484
9164
|
return base;
|
|
8485
9165
|
}
|
|
8486
9166
|
if (base.category === CATEGORY.KMP && symbol.startsWith("kfun:")) {
|
|
@@ -8506,7 +9186,7 @@ function classifyNativePath(filePath, symbol, thread) {
|
|
|
8506
9186
|
if (rule.regex.test(file)) return refine({ ...rule.category, file }, symbol);
|
|
8507
9187
|
}
|
|
8508
9188
|
if (BUNDLE_SO.test(file) || BUNDLE_ABC.test(file)) {
|
|
8509
|
-
const base =
|
|
9189
|
+
const base = basename2(file);
|
|
8510
9190
|
if (BUNDLE_ABC.test(file) && symbol !== null) {
|
|
8511
9191
|
const match = ARKTS_SYMBOL.exec(symbol);
|
|
8512
9192
|
if (match !== null) {
|
|
@@ -8525,13 +9205,13 @@ function classifyNativePath(filePath, symbol, thread) {
|
|
|
8525
9205
|
return {
|
|
8526
9206
|
category: CATEGORY.APP,
|
|
8527
9207
|
categoryName: "APP",
|
|
8528
|
-
subCategory:
|
|
9208
|
+
subCategory: basename2(file),
|
|
8529
9209
|
file
|
|
8530
9210
|
};
|
|
8531
9211
|
}
|
|
8532
|
-
const byBase = EXACT.get(
|
|
9212
|
+
const byBase = EXACT.get(basename2(file));
|
|
8533
9213
|
if (byBase !== void 0) return refine({ ...byBase, file }, symbol);
|
|
8534
|
-
return { category: CATEGORY.SYS_SDK, categoryName: "SYS_SDK", subCategory:
|
|
9214
|
+
return { category: CATEGORY.SYS_SDK, categoryName: "SYS_SDK", subCategory: basename2(file), file };
|
|
8535
9215
|
}
|
|
8536
9216
|
|
|
8537
9217
|
// src/analyze/native-memory.ts
|
|
@@ -14623,8 +15303,8 @@ var CENTRAL_SIGNATURE = 33639248;
|
|
|
14623
15303
|
var LOCAL_SIGNATURE = 67324752;
|
|
14624
15304
|
var ZIP64_SENTINEL = 4294967295;
|
|
14625
15305
|
var ZIP_COMMENT_MAX = 65535;
|
|
14626
|
-
function fail(code,
|
|
14627
|
-
throw new OhosPerfError(
|
|
15306
|
+
function fail(code, message3) {
|
|
15307
|
+
throw new OhosPerfError(message3, { code });
|
|
14628
15308
|
}
|
|
14629
15309
|
function u16(bytes, at) {
|
|
14630
15310
|
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint16(at, true);
|
|
@@ -14776,10 +15456,10 @@ function categorize(extension) {
|
|
|
14776
15456
|
return "other";
|
|
14777
15457
|
}
|
|
14778
15458
|
function extensionOf(path) {
|
|
14779
|
-
const
|
|
14780
|
-
const dot =
|
|
15459
|
+
const basename4 = path.slice(path.lastIndexOf("/") + 1);
|
|
15460
|
+
const dot = basename4.lastIndexOf(".");
|
|
14781
15461
|
if (dot <= 0) return "";
|
|
14782
|
-
return
|
|
15462
|
+
return basename4.slice(dot + 1).toLowerCase();
|
|
14783
15463
|
}
|
|
14784
15464
|
function buildInventory(archive) {
|
|
14785
15465
|
return archive.entries.map((entry) => {
|
|
@@ -14798,10 +15478,10 @@ function buildInventory(archive) {
|
|
|
14798
15478
|
// src/hap/rules.ts
|
|
14799
15479
|
var EXCLUDE_PATTERNS = ["resources/base/.*"];
|
|
14800
15480
|
var KINDS2 = ["filename", "path", "extension", "magic", "content", "combined"];
|
|
14801
|
-
function fail2(ruleId,
|
|
14802
|
-
throw new OhosPerfError(`rule ${JSON.stringify(ruleId)}: ${
|
|
15481
|
+
function fail2(ruleId, message3) {
|
|
15482
|
+
throw new OhosPerfError(`rule ${JSON.stringify(ruleId)}: ${message3}`, { code: "HAP_BAD_RULE" });
|
|
14803
15483
|
}
|
|
14804
|
-
function
|
|
15484
|
+
function basename3(path) {
|
|
14805
15485
|
return path.slice(path.lastIndexOf("/") + 1);
|
|
14806
15486
|
}
|
|
14807
15487
|
function compile(ruleId, source) {
|
|
@@ -14847,7 +15527,7 @@ function matchContent(ruleId, rule, data) {
|
|
|
14847
15527
|
function matchOne(ruleId, rule, file, reader) {
|
|
14848
15528
|
switch (rule.kind) {
|
|
14849
15529
|
case "filename": {
|
|
14850
|
-
const name =
|
|
15530
|
+
const name = basename3(file.path);
|
|
14851
15531
|
for (const item of rule.patterns ?? []) {
|
|
14852
15532
|
const source = typeof item === "string" ? item : item.pattern;
|
|
14853
15533
|
if (compile(ruleId, source).test(name)) return { matched: true, confidence: rule.confidence ?? 1 };
|
|
@@ -14909,7 +15589,7 @@ function matchOne(ruleId, rule, file, reader) {
|
|
|
14909
15589
|
function extractMetadata(ruleId, rule, file, reader) {
|
|
14910
15590
|
const metadata = {};
|
|
14911
15591
|
for (const pattern of rule.metadataPatterns ?? []) {
|
|
14912
|
-
const source = pattern.source === "content" ? new TextDecoder("utf-8").decode(reader.bytes(file.path) ?? new Uint8Array(0)) : pattern.source === "path" ? file.path :
|
|
15592
|
+
const source = pattern.source === "content" ? new TextDecoder("utf-8").decode(reader.bytes(file.path) ?? new Uint8Array(0)) : pattern.source === "path" ? file.path : basename3(file.path);
|
|
14913
15593
|
const match = compile(ruleId, pattern.pattern).exec(source);
|
|
14914
15594
|
const value = match?.[pattern.captureGroup ?? 0];
|
|
14915
15595
|
if (value !== void 0 && value !== "") metadata[pattern.field] = value;
|
|
@@ -16749,6 +17429,7 @@ export {
|
|
|
16749
17429
|
defaultAnalyzers,
|
|
16750
17430
|
dhash,
|
|
16751
17431
|
diffTrees,
|
|
17432
|
+
discoverCases,
|
|
16752
17433
|
encodePng,
|
|
16753
17434
|
escapeHtml,
|
|
16754
17435
|
evidence,
|
|
@@ -16762,10 +17443,12 @@ export {
|
|
|
16762
17443
|
ingestScene,
|
|
16763
17444
|
isUnresolvedSymbol,
|
|
16764
17445
|
isZip,
|
|
17446
|
+
loadCases,
|
|
16765
17447
|
lookupQuery,
|
|
16766
17448
|
markRegions,
|
|
16767
17449
|
matchHapRules,
|
|
16768
17450
|
matchRules,
|
|
17451
|
+
matchSelector,
|
|
16769
17452
|
memoryPlugin,
|
|
16770
17453
|
metric,
|
|
16771
17454
|
nativeEventKind,
|
|
@@ -16782,6 +17465,7 @@ export {
|
|
|
16782
17465
|
parseHitches,
|
|
16783
17466
|
parseProcfsStatus,
|
|
16784
17467
|
parseScenario,
|
|
17468
|
+
parseSelector,
|
|
16785
17469
|
parseSmapsRollup,
|
|
16786
17470
|
queryDefinitions,
|
|
16787
17471
|
readHidumperCapture,
|
|
@@ -16801,6 +17485,7 @@ export {
|
|
|
16801
17485
|
resolveAppIdentity,
|
|
16802
17486
|
resolveAppIpids,
|
|
16803
17487
|
resolveQueryLimit,
|
|
17488
|
+
resolveSelector,
|
|
16804
17489
|
round2HalfEven,
|
|
16805
17490
|
runAnalyzerSections,
|
|
16806
17491
|
runAnalyzers,
|