42 lines
1.7 KiB
JavaScript
42 lines
1.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { BUTTONS, setButton, mergeFirmware, loadEphemeralSdCard } from '../web/app.js';
|
|
|
|
// Merge - app image is placed at 0x10000 in a 0xFF-erased 16 MB flash with bootloader and partitions.
|
|
const bootloader = new Uint8Array([1, 2, 3]);
|
|
const partitions = new Uint8Array([4, 5, 6]);
|
|
const app = new Uint8Array(1024);
|
|
app[0] = 0xe9;
|
|
const flash = mergeFirmware(app, bootloader, partitions);
|
|
assert.equal(flash.length, 16 * 1024 * 1024);
|
|
assert.deepEqual(flash.slice(0, 3), bootloader);
|
|
assert.deepEqual(flash.slice(0x8000, 0x8003), partitions);
|
|
assert.equal(flash[0x10000], 0xe9);
|
|
assert.equal(flash[0x20000], 0xff);
|
|
assert.throws(() => mergeFirmware(new Uint8Array([0x00]), bootloader, partitions), /0xE9/);
|
|
|
|
const compressedSd = await readFile('web/assets/blank-sd.img.gz');
|
|
const fetchSd = async () => new Response(compressedSd);
|
|
const firstSd = await loadEphemeralSdCard(import.meta.url, fetchSd);
|
|
const secondSd = await loadEphemeralSdCard(import.meta.url, fetchSd);
|
|
assert.equal(firstSd.length, 64 * 1024 * 1024);
|
|
assert.deepEqual(firstSd.slice(510, 512), new Uint8Array([0x55, 0xaa]));
|
|
firstSd[0] ^= 0xff;
|
|
assert.notEqual(firstSd[0], secondSd[0]);
|
|
|
|
const calls = [];
|
|
const module = {
|
|
_xteink_wasm_set_adc: (...args) => calls.push(['adc', ...args]),
|
|
_xteink_wasm_set_gpio: (...args) => calls.push(['gpio', ...args]),
|
|
};
|
|
setButton(module, 'confirm', true);
|
|
setButton(module, 'confirm', false);
|
|
setButton(module, 'power', true);
|
|
setButton(module, 'power', false);
|
|
assert.deepEqual(calls, [
|
|
['adc', BUTTONS.confirm.channel, BUTTONS.confirm.value],
|
|
['adc', BUTTONS.confirm.channel, 4095],
|
|
['gpio', 3, 0],
|
|
['gpio', 3, 1],
|
|
]);
|