test(dfuse): share single-target fixture construction (#17314)

This commit is contained in:
Vincent Koc
2026-12-06 08:09:44 +08:00
committed by GitHub
parent 0f8d2db0fc
commit a024f7af19
+28 -46
View File
@@ -10,6 +10,10 @@ import {
} from "./dfuse.js";
import { dfuseFile, type DfuSeFixture } from "./dfuse.fixture.js";
const singleTarget = (
target: DfuSeFixture["targets"][number],
): DfuSeFixture => ({ targets: [target] });
const decode = (bytes: Uint8Array, chunkSize = 64) => {
const decoder = createDfuSeDecoder(bytes.length);
if (!decoder.ok) throw new Error(decoder.error.message);
@@ -242,47 +246,33 @@ it("recognizes a file only by the DfuSe prefix together with the DFU suffix", ()
it.each([
[
"a target without its signature",
{
targets: [{ alternateSetting: 0, signature: "Tarxet", elements: [] }],
},
singleTarget({ alternateSetting: 0, signature: "Tarxet", elements: [] }),
'byte offset 11: target 0 does not begin with the "Target" signature',
],
[
"an element larger than its target",
{
targets: [
{
alternateSetting: 0,
elements: [{ address: 0, data: [1, 2], declaredSize: 3 }],
},
],
},
singleTarget({
alternateSetting: 0,
elements: [{ address: 0, data: [1, 2], declaredSize: 3 }],
}),
"byte offset 289: target 0 element 0 declares 3 bytes, but its target ends at byte 295",
],
[
"a target larger than the image",
{
targets: [
{
alternateSetting: 0,
declaredSize: 100,
elements: [{ address: 0, data: [1] }],
},
],
},
singleTarget({
alternateSetting: 0,
declaredSize: 100,
elements: [{ address: 0, data: [1] }],
}),
"byte offset 277: target 0 declares 100 bytes, but the image ends at byte 294",
],
[
"fewer elements than the target size",
{
targets: [
{
alternateSetting: 0,
declaredElements: 0,
elements: [{ address: 0, data: [1] }],
},
],
},
singleTarget({
alternateSetting: 0,
declaredElements: 0,
elements: [{ address: 0, data: [1] }],
}),
"byte offset 285: target 0 declares 9 bytes, but its 0 element(s) end 9 bytes earlier",
],
[
@@ -302,27 +292,19 @@ it.each([
],
[
"more elements than the target holds",
{
targets: [
{
alternateSetting: 0,
declaredElements: 2,
elements: [{ address: 0, data: [1] }],
},
],
},
singleTarget({
alternateSetting: 0,
declaredElements: 2,
elements: [{ address: 0, data: [1] }],
}),
"byte offset 294: target 0 element 1 header lies beyond the target's end at byte 294",
],
[
"an element that wraps the address space",
{
targets: [
{
alternateSetting: 0,
elements: [{ address: 0xffff_ffff, data: [1, 2] }],
},
],
},
singleTarget({
alternateSetting: 0,
elements: [{ address: 0xffff_ffff, data: [1, 2] }],
}),
"byte offset 285: target 0 element 0 at 0xffffffff with 2 bytes wraps past 0xffffffff",
],
] as const)("refuses %s with its byte offset", (_name, fixture, message) => {