also looking at this
test: exercise full host filesystem recovery
#58
13 files
+644
-5
| @@ -1,12 +1,18 @@ | ||
| 1 | 1 | import { cp, mkdir, readFile, writeFile } from 'node:fs/promises' |
| 2 | 2 | import { join } from 'node:path' |
| 3 | 3 | |
| 4 | /** Actual disposable source repo with explicit stop-reply or configure-output faults. */ | |
| 5 | export async function createHostSourceProject(root: string, options: { fault?: 'stop-session' | 'configure-output' } = {}) { | |
| 4 | /** Actual disposable source repo with explicit faults and optional host-only file padding. */ | |
| 5 | export async function createHostSourceProject(root: string, options: { fault?: 'stop-session' | 'configure-output', imagePadding?: true } = {}) { | |
| 6 | 6 | const project = join(root, 'project') |
| 7 | 7 | await mkdir(project, { mode: 0o700 }) |
| 8 | 8 | await mkdir(join(project, 'firmware'), { mode: 0o700 }) |
| 9 | 9 | await cp(join(import.meta.dir, '../../../firmware/runtime'), join(project, 'firmware/runtime'), { recursive: true }) |
| 10 | if (options.imagePadding) { | |
| 11 | const path = join(project, 'firmware/runtime/src/host.cpp'), source = await readFile(path, 'utf8') | |
| 12 | const entry = 'int main(int argc, char** argv) {' | |
| 13 | if (source.split(entry).length !== 2) throw new Error('Owned host entry no longer matches the large-image fixture') | |
| 14 | await writeFile(path, source.replace(entry, 'struct TestImagePadding { unsigned char first; unsigned char bytes[2 * 1024 * 1024]; unsigned char last; };\nvolatile TestImagePadding test_image_padding{1, {}, 1};\n' + entry + '\n if (test_image_padding.first != 1 || test_image_padding.last != 1) return 2;')) | |
| 15 | } | |
| 10 | 16 | if (options.fault === 'stop-session') { |
| 11 | 17 | const path = join(project, 'firmware/runtime/src/host.cpp'), source = await readFile(path, 'utf8') |
| 12 | 18 | const original = 'drone::encode(runtime.status(now), bytes);' |