Skip to content
Merged
Changes from all 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
70 changes: 52 additions & 18 deletions scripts/verify-signal-recording.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,41 @@ try {
)
).stdout.split(/\r?\n/);
if (nativeHelp.at(-1) === "") nativeHelp.pop();
const nativeCatalogText = (
await execute(
process.env.REA_SIGROK_COMMAND,
["--dont-scan", "--list-supported"],
{ env: environment, timeout: 30000, maxBuffer: 4 * 1024 * 1024 },
)
).stdout;
const catalogHeading = "Supported protocol decoders:\n";
assert.ok(nativeCatalogText.includes(catalogHeading));
// Independent native-output oracle, without importing the production parser.
const nativeCatalog = nativeCatalogText
.split(catalogHeading)[1]
.trim()
.split("\n")
.map((line) => {
const record = line.trimStart();
const separator = record.indexOf(" ");
assert.ok(separator > 0);
return {
id: record.slice(0, separator),
name: record.slice(separator).trimStart(),
};
});
assert.ok(nativeCatalog.length > 0);
for (const input of [
{ query: "uart" },
{},
{ query: "UaRt" },
{ limit: 1 },
{ offset: 1, limit: 2 },
{ limit: null },
{ offset: nativeCatalog.length, limit: 2 },
{ decoder: "uart" },
{ decoder: "uart", query: "BaUd" },
{ decoder: "uart", offset: 50, limit: null },
{ decoder: "uart", query: "[" },
{ query: "rea_no_such_decoder" },
]) {
const started = performance.now();
Expand All @@ -306,23 +335,28 @@ try {
JSON.stringify(response),
),
});
if (input.decoder) {
const matched = nativeHelp
.map((text, i) => ({ line_number: i + 1, text }))
.filter(({ text }) =>
text.toLowerCase().includes((input.query ?? "").toLowerCase()),
);
assert.deepEqual(
report.help_lines,
matched.slice(
input.offset ?? 0,
input.limit === null
? undefined
: (input.offset ?? 0) + (input.limit ?? 50),
),
);
} else if (input.query === "uart")
assert.ok(report.decoders.some(({ id }) => id === "uart"));
const nativeRecords = input.decoder
? nativeHelp.map((text, i) => ({ line_number: i + 1, text }))
: nativeCatalog;
const matched = nativeRecords.filter((record) =>
("text" in record ? record.text : `${record.id} ${record.name}`)
.toLowerCase()
.includes((input.query ?? "").toLowerCase()),
);
const offset = input.offset ?? 0;
const page = matched.slice(
offset,
input.limit === null ? undefined : offset + (input.limit ?? 50),
);
assert.deepEqual(input.decoder ? report.help_lines : report.decoders, page);
assert.deepEqual(input.decoder ? report.decoders : report.help_lines, []);
assert.deepEqual(report.output_window, {
unit: input.decoder ? "help-lines" : "decoders",
examined: nativeRecords.length,
matching: matched.length,
returned: page.length,
has_more: offset + page.length < matched.length,
});
const flags = Object.entries(input).flatMap(([key, value]) =>
value === null ? ["--all"] : [`--${key}`, String(value)],
);
Expand Down
Loading