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
1 change: 1 addition & 0 deletions src/framework/Testee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export class Testee { // TODO unified with testbed interface
(testee, req, map) => timeout<object | void>(`sending instruction ${req.type}`, testee.timeout,
testee.bed(step.target ?? Target.supervisor)!.sendRequest(map, req)),
(testee) => testee.run(`Recover: re-initialize ${testee.testbed?.name}`, testee.connector.timeout, async function () {
await testee.shutdown();
await testee.initialize(description.program, description.args ?? []).catch((o) => {
return Promise.reject(o)
});
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/Parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function remoteFunctionResult(result: RemoteFunctionResult): WASM.Value<T
if (result.results.length === 0) {
return nothing;
}
return protocolValue(result.results[result.results.length - 1]);
return protocolValue(result.results[0]);
}

function protocolValue(value: ProtocolValue): WASM.Value<Type> {
Expand Down
12 changes: 9 additions & 3 deletions src/testbeds/Emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ export class Emulator extends Platform {
this.listen();
}

kill(): Promise<void> {
this.connection.child?.kill();
return super.kill();
async kill(): Promise<void> {
const child = this.connection.child;
const closed = child === undefined || child.exitCode !== null || child.signalCode !== null
? Promise.resolve()
: new Promise<void>((resolve) => child.once('close', resolve));

child?.kill();
await super.kill();
await closed;
}

async meta(): Promise<string> {
Expand Down
6 changes: 3 additions & 3 deletions tests/end-to-end/spec.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function consume(input: string, cursor: number, regex: RegExp = / /): number {
}

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

export function parseAsserts(file: string): string[] {
Expand Down Expand Up @@ -140,8 +140,8 @@ function parseInteger(hex: string, type: WASM.Integer): WasmInt {
const n: number = parseInt(hex);
return typeof n !== 'bigint' && isNaN(n) ? WasmInt.nan() : typeof n !== 'bigint' && n === Infinity ? WasmInt.infinity() : WasmInt.finite(BigInt(hex));
}
const mask = BigInt(parseInt('0x80' + '00'.repeat(bytes - 1), 16));
let integer = BigInt(parseInt(hex, 16));
const mask = BigInt('0x80' + '00'.repeat(bytes - 1));
let integer = BigInt(hex);
if (integer >= mask) {
integer = integer - mask * 2n;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/interface.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from 'ava';
import {Duplex} from 'node:stream';
import {EventEmitter} from 'node:events';
import {SubProcess} from '../../src/bridge/SubProcess';
import {Message} from '../../src/messaging/Message';
import {SourceMap} from '../../src/sourcemap/SourceMap';
Expand All @@ -12,6 +13,7 @@ import {
OperationResult
} from '../../src/protocol/vendor/debug';
import {WARDuino} from "../../src/debug/WARDuino";
import {Emulator} from "../../src/testbeds/Emulator";
import {Testee} from "../../src/framework/Testee";
import {EmulatorSpecification} from "../../src/testbeds/TestbedSpecification";

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

test('[emulator] shutdown waits for the child process to close', async t => {
const child = Object.assign(new EventEmitter(), {
exitCode: null,
signalCode: null,
kill: () => true
});
const emulator = new Emulator(new SubProcess(new TestChannel(), child as any));
let complete = false;
const shutdown = emulator.kill().then(() => { complete = true; });

await tick();
t.false(complete);
child.emit('close', 0, null);
await shutdown;
t.true(complete);
});

test('[platform] rejects outstanding requests when the connection closes with an error', async t => {
const channel = new TestChannel();
const platform = new TestPlatform(channel);
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/parsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ test("[protobuf invoke result] : decodes IEEE-754 float bits", t => {
t.deepEqual(f64, {type: WASM.Float.f64, value: 2.5});
});

test("[protobuf invoke result] : selects the first declared result", t => {
const result = remoteFunctionResultParser(RemoteFunctionResult.encode({
success: true,
results: [
{i32Bits: 77, index: 0},
{f64Bits: 0x401c000000000000n, index: 1}
],
error: Buffer.alloc(0)
}).finish());

t.deepEqual(result, {type: WASM.Integer.i32, value: WasmInt.finite(77n)});
});

test("[protobuf invoke result] : maps void, malformed, and failed responses", t => {
const voidResult = remoteFunctionResultParser(RemoteFunctionResult.encode({success: true, results: [], error: Buffer.alloc(0)}).finish());
t.deepEqual(voidResult, WASM.nothing);
Expand Down
Loading