Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/pink-jokes-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-management-kit": patch
---

Fix out of memory prediction
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("PredictOutOfMemoryTask", () => {
const result = new PredictOutOfMemoryTask(apiMock, {
installPlan: [
{ bytes: 1324 },
{ bytes: 6559 },
{ bytes: 6496 },
] as unknown as Application[],
}).run();

Expand Down Expand Up @@ -76,8 +76,7 @@ describe("PredictOutOfMemoryTask", () => {
const result = new PredictOutOfMemoryTask(apiMock, {
installPlan: [
{ bytes: 1324 },
{ bytes: 6559 },
{ bytes: 1 },
{ bytes: 6497 },
] as unknown as Application[],
}).run();

Expand All @@ -87,7 +86,7 @@ describe("PredictOutOfMemoryTask", () => {
});
});

it("Success enough memory (recent Nano S, 2kB block size)", () => {
it("Success not enough memory with no remaining block (recent Nano S, 2kB block size)", () => {
// GIVEN
apiMock.getDeviceModel.mockReturnValueOnce({
memorySize: 12 * 1024,
Expand Down Expand Up @@ -119,9 +118,9 @@ describe("PredictOutOfMemoryTask", () => {
// 6x2kB blocks of total memory (12kB total)
// -3*2kB block for firmware (to fit 6kB)
// -3*2kB block for install plan (to fit 6kB)
// = 0 blocks left, enough memory
// = 0 blocks left, not enough memory
expect(result).toStrictEqual({
outOfMemory: false,
outOfMemory: true,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export type PredictOutOfMemoryTaskResult =
error: UnknownDAError;
};

const RESERVED_BLOCKS = 1;

export class PredictOutOfMemoryTask {
private readonly deviceModel: TransportDeviceModel;

Expand Down Expand Up @@ -74,7 +76,8 @@ export class PredictOutOfMemoryTask {

return {
outOfMemory:
currentMemoryBlocksUsage + installPlanBlocksUsage > totalMemoryBlocks,
currentMemoryBlocksUsage + installPlanBlocksUsage >=
totalMemoryBlocks - RESERVED_BLOCKS,
};
Comment thread
paoun-ledger marked this conversation as resolved.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,19 @@ describe("StaticDeviceModelDataSource", () => {
{ firmwareVersion: "2.0.0-rc1", expectedBlockSize: 2 * 1024 },
],
[DeviceModelId.NANO_SP]: [
{ firmwareVersion: "1.0.0", expectedBlockSize: 32 },
{ firmwareVersion: "1.0.0", expectedBlockSize: 512 },
],
[DeviceModelId.NANO_X]: [
{ firmwareVersion: "1.0.0", expectedBlockSize: 4 * 1024 },
],
[DeviceModelId.STAX]: [
{ firmwareVersion: "1.0.0", expectedBlockSize: 32 },
{ firmwareVersion: "1.0.0", expectedBlockSize: 512 },
],
[DeviceModelId.FLEX]: [
{ firmwareVersion: "1.0.0", expectedBlockSize: 32 },
{ firmwareVersion: "1.0.0", expectedBlockSize: 512 },
],
[DeviceModelId.APEX]: [
{ firmwareVersion: "1.0.0", expectedBlockSize: 32 },
{ firmwareVersion: "1.0.0", expectedBlockSize: 512 },
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class StaticDeviceModelDataSource implements DeviceModelDataSource {
bootloaderUsbProductId: 0x0005,
usbOnly: true,
memorySize: 1533 * 1024,
getBlockSize: () => 32,
getBlockSize: () => 512,
masks: [0x33100000],
}),
[DeviceModelId.NANO_X]: new TransportDeviceModel({
Expand Down Expand Up @@ -62,7 +62,7 @@ export class StaticDeviceModelDataSource implements DeviceModelDataSource {
bootloaderUsbProductId: 0x0006,
usbOnly: false,
memorySize: 1533 * 1024,
getBlockSize: () => 32,
getBlockSize: () => 512,
masks: [0x33200000],
bluetoothSpec: [
{
Expand All @@ -80,7 +80,7 @@ export class StaticDeviceModelDataSource implements DeviceModelDataSource {
bootloaderUsbProductId: 0x0007,
usbOnly: false,
memorySize: 1533 * 1024,
getBlockSize: () => 32,
getBlockSize: () => 512,
masks: [0x33300000],
bluetoothSpec: [
{
Expand All @@ -98,7 +98,7 @@ export class StaticDeviceModelDataSource implements DeviceModelDataSource {
bootloaderUsbProductId: 0x0008,
usbOnly: false,
memorySize: 1533 * 1024,
getBlockSize: () => 32,
getBlockSize: () => 512,
masks: [0x33400000],
bluetoothSpec: [
{
Expand Down
Loading