Skip to content

Commit f2d694c

Browse files
authored
Fix recovery of crashed testbed (#6)
* Use esm with mocha * Test module upload * Shutdown testbeds after test * Fix testbed restart
1 parent 245b5f7 commit f2d694c

File tree

14 files changed

+76
-22
lines changed

14 files changed

+76
-22
lines changed

bin/latch renamed to bin/latch.cjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
* @module bin/latch
99
* @private
1010
*/
11-
1211
const {spawn} = require('child_process');
1312

14-
const args = ['--exit', '--color', '--reporter', `${require('path').dirname(__dirname)}/dist/cjs/framework/MochaReporter.cjs`, '--require', 'ts-node/register', '--ui', 'bdd', ].concat(process.argv.slice(2));
13+
const args = ['--exit', '--color', '--reporter', `${require('path').dirname(__dirname)}/dist/cjs/framework/MochaReporter.cjs`, '--loader=ts-node/esm', '--experimental-specifier-resolution=node', '--require', 'ts-node/register', '--ui', 'bdd' ].concat(process.argv.slice(2));
1514
const proc = spawn('mocha', args, {
1615
stdio: 'inherit'
1716
});
@@ -45,4 +44,4 @@ process.on('SIGINT', () => {
4544
proc.kill('SIGTERM');
4645
}
4746
}
48-
});
47+
});

mocharc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"node-option": [
3+
"experimental-specifier-resolution=node",
4+
"loader=ts-node/esm"
5+
]
6+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "latch",
33
"description": "A testing language for constraint environments",
44
"version": "0.0.1",
5-
"type": "commonjs",
5+
"type": "module",
66
"exports": {
77
"types": "./dist/types/index.d.ts",
88
"require": "./dist/cjs/index.cjs"
@@ -14,7 +14,7 @@
1414
"bin"
1515
],
1616
"bin": {
17-
"latch": "bin/latch"
17+
"latch": "bin/latch.cjs"
1818
},
1919
"scripts": {
2020
"clean": "rm -rf dist",

src/framework/Framework.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class Framework {
7070
await testee.initialize(first.program, first.args ?? []);
7171
});
7272

73-
describe(`Testing on ${testee.name}.`, () => {
73+
describe(`${testee.name}: ${suite.title}`, () => {
7474
// todo add parallelism
7575

7676
// if (!bed.disabled) { // TODO necessary? isn't this done in de test itself?
@@ -86,6 +86,10 @@ export class Framework {
8686
testee.describe(test, this.runs);
8787
});
8888
});
89+
90+
after('Shutdown testbed', async function () {
91+
await testee.shutdown();
92+
});
8993
});
9094
});
9195
}

src/framework/Testee.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {TestScenario} from './scenario/TestScenario';
1313
import {TestbedSpecification} from '../testbeds/TestbedSpecification';
1414
import {Scheduler} from './Scheduler';
1515
import {CompileOutput, CompilerFactory} from '../manage/Compiler';
16-
import {WABT} from '../util/deps';
16+
import {WABT} from '../util/env';
1717

1818
function timeout<T>(label: string, time: number, promise: Promise<T>): Promise<T> {
1919
return Promise.race([promise, new Promise<T>((resolve, reject) => setTimeout(() => reject(`timeout when ${label}`), time))]);
@@ -86,6 +86,10 @@ export class Testee { // TODO unified with testbed interface
8686
});
8787
}
8888

89+
public async shutdown(): Promise<void> {
90+
return this.testbed?.kill();
91+
}
92+
8993
public describe(description: TestScenario, runs: number = 1) {
9094
const testee = this;
9195
const call: SuiteFunction | PendingSuiteFunction = description.skip ? describe.skip : this.suiteFunction;
@@ -107,7 +111,7 @@ export class Testee { // TODO unified with testbed interface
107111
this.timeout(testee.connector.timeout(testee.specification.type));
108112
let compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(description.program).compile(description.program);
109113
try {
110-
await testee.testbed!.sendRequest(new SourceMap.Mapping(), Message.updateModule(compiled.file));
114+
await timeout<Object | void>(`uploading module`, testee.timeout, testee.testbed!.sendRequest(new SourceMap.Mapping(), Message.updateModule(compiled.file)));
111115
} catch (e) {
112116
await testee.initialize(description.program, description.args ?? []);
113117
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Framework} from './framework/Framework';
22

33
export * from './manage/Compiler';
44
export * from './manage/Uploader';
5-
export * from './util/deps';
5+
export * from './util/env';
66
export * from './framework/scenario/Actions';
77
export * from './framework/Testee';
88
export * from './framework/Framework';

src/messaging/Message.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Interrupt = WARDuino.Interrupt;
99
import State = WARDuino.State;
1010
import Value = WASM.Value;
1111
import Type = WASM.Type;
12+
import {CompileOutput, CompilerFactory} from '../manage/Compiler';
13+
import {WABT} from '../util/env';
1214

1315
// An acknowledgement returned by the debugger
1416
export interface Ack {
@@ -125,9 +127,14 @@ export namespace Message {
125127
}
126128
}
127129

128-
export function updateModule(program: string): Request<Ack> {
129-
function payload(wasm: Buffer): string {
130-
const w = new Uint8Array(wasm);
130+
export async function uploadFile(program: string): Promise<Request<Ack>> {
131+
let compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(program).compile(program);
132+
return updateModule(compiled.file);
133+
}
134+
135+
export function updateModule(wasm: string): Request<Ack> {
136+
function payload(binary: Buffer): string {
137+
const w = new Uint8Array(binary);
131138
const sizeHex: string = WASM.leb128(w.length);
132139
const sizeBuffer = Buffer.allocUnsafe(4);
133140
sizeBuffer.writeUint32BE(w.length);
@@ -137,7 +144,7 @@ export namespace Message {
137144

138145
return {
139146
type: Interrupt.updateModule,
140-
payload: (map: SourceMap.Mapping) => payload(readFileSync(program)),
147+
payload: (map: SourceMap.Mapping) => payload(readFileSync(wasm)),
141148
parser: (line: string) => {
142149
return ackParser(line, 'CHANGE Module');
143150
}

src/sourcemap/SourceMapFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {getFileExtension} from '../util/util';
22
import {CompileOutput, CompilerFactory} from '../manage/Compiler';
33
import {AsScriptMapper, WatMapper} from './SourceMapper';
4-
import {WABT} from '../util/deps';
4+
import {WABT} from '../util/env';
55
import {SourceMap} from './SourceMap';
66
import * as path from 'path';
77

src/testbeds/TestbedFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Testbed} from './Testbed';
2-
import {ARDUINO, EMULATOR, WABT} from '../util/deps';
2+
import {ARDUINO, EMULATOR, WABT} from '../util/env';
33
import {CompileOutput, CompilerFactory} from '../manage/Compiler';
44
import {Emulator} from './Emulator';
55
import {UploaderFactory} from '../manage/Uploader';

src/util/deps.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)