Skip to content

Commit b5f45b4

Browse files
authored
Fix/timeouts (#79)
* Fix uncaught timeout and improve output * Make timeouts count as failures * Fix type error in extract type
1 parent fe087c4 commit b5f45b4

8 files changed

Lines changed: 39 additions & 10 deletions

File tree

src/framework/Testee.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {WASM} from '../sourcemap/Wasm';
1414
import {DummyProxy} from '../testbeds/Emulator';
1515
import {ScenarioResult, Skipped, StepOutcome, SuiteResult} from '../reporter/Results';
1616
import {Verifier} from './Verifier';
17+
import {stringify} from "../util/util";
1718

1819
export function timeout<T>(label: string, time: number, promise: Promise<T>): Promise<T> {
1920
if (time === 0) {
@@ -211,9 +212,10 @@ export class Testee { // TODO unified with testbed interface
211212
}
212213

213214
for (const step of description.steps ?? []) {
215+
const verifier: Verifier = new Verifier(step);
216+
214217
/** Perform the step and check if expectations were met */
215218
await this.step(step.title, testee.timeout, async function () {
216-
const verifier: Verifier = new Verifier(step);
217219
if (testee.bed(step.target ?? Target.supervisor) === undefined) {
218220
testee.states.set(description.title, verifier.error('Cannot run test: no debugger connection.'));
219221
return;
@@ -246,6 +248,10 @@ export class Testee { // TODO unified with testbed interface
246248
previous = actual;
247249
}
248250

251+
testee.states.set(description.title, result);
252+
scenarioResult.add(result);
253+
}).catch((error: Error | string) => {
254+
const result = verifier.error(stringify(error));
249255
testee.states.set(description.title, result);
250256
scenarioResult.add(result);
251257
});

src/framework/Verifier.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export class Verifier {
4545
}
4646

4747
public error(clarification: string): StepOutcome {
48-
const result: StepOutcome = new StepOutcome(this.step);
49-
result.update(Outcome.succeeded);
50-
return result.update(Outcome.error, clarification);
48+
return new StepOutcome(this.step).update(clarification.includes('timeout') ? Outcome.timedout : Outcome.error, clarification);
5149
}
5250

5351
private expectPrimitive<T>(actual: T, expected: T): StepOutcome {

src/messaging/Parsers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ export function signed(value: bigint, bits = 32) {
6868
}
6969

7070
function extractType(object: {value: bigint | number, type: any}): Type {
71-
if (isNaN(<number>object.value)) return WASM.Special.nan;
72-
if (<number>object.value === Infinity) return WASM.Special.infinity;
71+
if (typeof object.value === 'number') {
72+
if (Number.isNaN(object.value)) return WASM.Special.nan;
73+
if (object.value === Infinity) return WASM.Special.infinity;
74+
}
7375
return WASM.typing.get(object.type.toLowerCase()) ?? WASM.Special.unknown;
7476
}
7577

src/reporter/Results.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract class AbstractAggregateResult implements AggregateResult {
7373
}
7474

7575
private failing(): boolean {
76-
return this.subOutcomes.some((outcome) => outcome.outcome === Outcome.failed);
76+
return this.subOutcomes.some((outcome) => outcome.outcome === Outcome.failed || outcome.outcome === Outcome.timedout);
7777
}
7878
}
7979

src/reporter/Style.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface Labels {
2020

2121
success: string;
2222
skipped: string;
23+
timeout: string;
2324
failure: string;
2425
error: string;
2526
}
@@ -68,6 +69,7 @@ export class Plain implements Style {
6869
suiteSkipped: ' SKIPPED ',
6970
success: ' PASS ',
7071
skipped: ' SKIP ',
72+
timeout: ' TIMEOUT ',
7173
failure: ' FAIL ',
7274
error: ' ERROR '
7375
}

src/reporter/describers/Describer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export class StepDescriber extends Describer<StepOutcome> {
3535
case Outcome.uncommenced:
3636
case Outcome.skipped:
3737
return [`${style.colors.skipped(style.labels.skipped)} ${this.item.name}`];
38+
case Outcome.timedout:
39+
return [`${style.colors.failure(style.labels.timeout)} ${this.item.name}`];
3840
case Outcome.error:
3941
case Outcome.failed:
4042
default:

src/util/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ export function find(regex: RegExp, input: string) {
1212
return '';
1313
}
1414
return match[1];
15+
}
16+
17+
export function stringify(chunk: Error | string): string {
18+
return chunk instanceof Error ? chunk.message : chunk;
1519
}

tests/unit/parsing.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import test from 'ava';
2-
import {signed, stateParser} from "../../src/messaging/Parsers";
3-
import {WARDuino} from "../../src";
2+
import {invokeParser, signed, stateParser} from "../../src/messaging/Parsers";
3+
import {Exception, WARDuino} from "../../src";
4+
import {WASM} from "../../src/sourcemap/Wasm";
45
import State = WARDuino.State;
6+
import Type = WASM.Type;
57

68
/**
79
* Check unsigned 32-bit integer to signed conversion
@@ -53,4 +55,17 @@ test('[state parser] : 64-bit integer precision', t => {
5355
const state: State = stateParser(`{\"stack\": [{\"idx\":0,\"type\":\"i32\",\"value\":${value}}]}\n`);
5456
t.true(equality(state.stack?.[0].value, value));
5557
}
56-
});
58+
});
59+
60+
test('[invoke parser] : i64 signed conversion', t => {
61+
const result: WASM.Value<Type> | Exception = invokeParser('{"stack": [{"idx":0,"type":"i64","value":18446744073709551615}]}\n');
62+
63+
if ('text' in result) { // check if exception
64+
t.fail(`Expected parsed value, got exception: ${result.text}`);
65+
return;
66+
}
67+
68+
t.is(result.type, WASM.Integer.i64);
69+
t.is(result.value, -1n);
70+
});
71+

0 commit comments

Comments
 (0)