Skip to content

Commit fed9c78

Browse files
authored
Fix spec suite issues (#98)
1 parent d431a3e commit fed9c78

6 files changed

Lines changed: 46 additions & 7 deletions

File tree

‎src/framework/Testee.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ export class Testee { // TODO unified with testbed interface
277277
(testee, req, map) => timeout<object | void>(`sending instruction ${req.type}`, testee.timeout,
278278
testee.bed(step.target ?? Target.supervisor)!.sendRequest(map, req)),
279279
(testee) => testee.run(`Recover: re-initialize ${testee.testbed?.name}`, testee.connector.timeout, async function () {
280+
await testee.shutdown();
280281
await testee.initialize(description.program, description.args ?? []).catch((o) => {
281282
return Promise.reject(o)
282283
});

‎src/messaging/Parsers.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function remoteFunctionResult(result: RemoteFunctionResult): WASM.Value<T
2929
if (result.results.length === 0) {
3030
return nothing;
3131
}
32-
return protocolValue(result.results[result.results.length - 1]);
32+
return protocolValue(result.results[0]);
3333
}
3434

3535
function protocolValue(value: ProtocolValue): WASM.Value<Type> {

‎src/testbeds/Emulator.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ export class Emulator extends Platform {
2020
this.listen();
2121
}
2222

23-
kill(): Promise<void> {
24-
this.connection.child?.kill();
25-
return super.kill();
23+
async kill(): Promise<void> {
24+
const child = this.connection.child;
25+
const closed = child === undefined || child.exitCode !== null || child.signalCode !== null
26+
? Promise.resolve()
27+
: new Promise<void>((resolve) => child.once('close', resolve));
28+
29+
child?.kill();
30+
await super.kill();
31+
await closed;
2632
}
2733

2834
async meta(): Promise<string> {

‎tests/end-to-end/spec.util.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function consume(input: string, cursor: number, regex: RegExp = / /): number {
8181
}
8282

8383
function shouldParseLine(input: string): boolean {
84-
return input.includes('(assert_return') && !input.replace(/\s+/g, '').startsWith(';;');
84+
return input.includes('(assert_return') && input.includes('(invoke') && !input.replace(/\s+/g, '').startsWith(';;');
8585
}
8686

8787
export function parseAsserts(file: string): string[] {
@@ -140,8 +140,8 @@ function parseInteger(hex: string, type: WASM.Integer): WasmInt {
140140
const n: number = parseInt(hex);
141141
return typeof n !== 'bigint' && isNaN(n) ? WasmInt.nan() : typeof n !== 'bigint' && n === Infinity ? WasmInt.infinity() : WasmInt.finite(BigInt(hex));
142142
}
143-
const mask = BigInt(parseInt('0x80' + '00'.repeat(bytes - 1), 16));
144-
let integer = BigInt(parseInt(hex, 16));
143+
const mask = BigInt('0x80' + '00'.repeat(bytes - 1));
144+
let integer = BigInt(hex);
145145
if (integer >= mask) {
146146
integer = integer - mask * 2n;
147147
}

‎tests/unit/interface.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from 'ava';
22
import {Duplex} from 'node:stream';
3+
import {EventEmitter} from 'node:events';
34
import {SubProcess} from '../../src/bridge/SubProcess';
45
import {Message} from '../../src/messaging/Message';
56
import {SourceMap} from '../../src/sourcemap/SourceMap';
@@ -12,6 +13,7 @@ import {
1213
OperationResult
1314
} from '../../src/protocol/vendor/debug';
1415
import {WARDuino} from "../../src/debug/WARDuino";
16+
import {Emulator} from "../../src/testbeds/Emulator";
1517
import {Testee} from "../../src/framework/Testee";
1618
import {EmulatorSpecification} from "../../src/testbeds/TestbedSpecification";
1719

@@ -68,6 +70,23 @@ test('[warduino] start emulator', t => {
6870
t.pass();
6971
});
7072

73+
test('[emulator] shutdown waits for the child process to close', async t => {
74+
const child = Object.assign(new EventEmitter(), {
75+
exitCode: null,
76+
signalCode: null,
77+
kill: () => true
78+
});
79+
const emulator = new Emulator(new SubProcess(new TestChannel(), child as any));
80+
let complete = false;
81+
const shutdown = emulator.kill().then(() => { complete = true; });
82+
83+
await tick();
84+
t.false(complete);
85+
child.emit('close', 0, null);
86+
await shutdown;
87+
t.true(complete);
88+
});
89+
7190
test('[platform] rejects outstanding requests when the connection closes with an error', async t => {
7291
const channel = new TestChannel();
7392
const platform = new TestPlatform(channel);

‎tests/unit/parsing.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ test("[protobuf invoke result] : decodes IEEE-754 float bits", t => {
5555
t.deepEqual(f64, {type: WASM.Float.f64, value: 2.5});
5656
});
5757

58+
test("[protobuf invoke result] : selects the first declared result", t => {
59+
const result = remoteFunctionResultParser(RemoteFunctionResult.encode({
60+
success: true,
61+
results: [
62+
{i32Bits: 77, index: 0},
63+
{f64Bits: 0x401c000000000000n, index: 1}
64+
],
65+
error: Buffer.alloc(0)
66+
}).finish());
67+
68+
t.deepEqual(result, {type: WASM.Integer.i32, value: WasmInt.finite(77n)});
69+
});
70+
5871
test("[protobuf invoke result] : maps void, malformed, and failed responses", t => {
5972
const voidResult = remoteFunctionResultParser(RemoteFunctionResult.encode({success: true, results: [], error: Buffer.alloc(0)}).finish());
6073
t.deepEqual(voidResult, WASM.nothing);

0 commit comments

Comments
 (0)