Skip to content

Commit 245b5f7

Browse files
committed
Restructure suite x testee relationship
1 parent 124b45f commit 245b5f7

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

src/framework/Framework.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,49 @@ import {TestbedSpecification} from '../testbeds/TestbedSpecification';
77
export interface Suite {
88
title: string;
99
tests: TestScenario[];
10+
testees: Testee[];
1011
}
1112

1213
interface DependenceTree {
1314
test: TestScenario;
1415
children: DependenceTree[];
1516
}
1617

18+
export interface TesteeOptions {
19+
disabled?: boolean;
20+
timeout?: number;
21+
connectionTimout?: number;
22+
}
23+
1724
export class Framework {
1825
private static implementation: Framework;
1926

20-
private testees: Testee[] = [];
21-
private suites: Suite[] = [];
27+
private testSuites: Suite[] = [];
2228

2329
public runs: number = 1;
2430

2531
private constructor() {
2632
}
2733

2834
private currentSuite(): Suite {
29-
return this.suites[this.suites.length - 1];
35+
return this.testSuites[this.testSuites.length - 1];
3036
}
3137

32-
public testee(name: string, specification: TestbedSpecification, scheduler: Scheduler = new HybridScheduler(), disabled: boolean = false) {
33-
const testee = new Testee(name, specification, scheduler);
34-
if (disabled) {
38+
public testee(name: string, specification: TestbedSpecification, scheduler: Scheduler = new HybridScheduler(), options: TesteeOptions = {}) {
39+
const testee = new Testee(name, specification, scheduler, options.timeout ?? 2000, options.connectionTimout ?? 5000);
40+
if (options.disabled) {
3541
testee.skipall();
3642
}
3743

38-
this.testees.push(testee);
44+
this.currentSuite().testees.push(testee);
3945
}
4046

41-
public platforms(): Testee[] {
42-
return this.testees;
47+
public suites(): Suite[] {
48+
return this.testSuites;
4349
}
4450

4551
public suite(title: string) {
46-
this.suites.push({title: title, tests: []});
52+
this.testSuites.push({title: title, tests: [], testees: []});
4753
}
4854

4955
public test(test: TestScenario) {
@@ -55,8 +61,8 @@ export class Framework {
5561
}
5662

5763
public run(cores: number = 1) { // todo remove cores
58-
this.suites.forEach((suite: Suite) => {
59-
this.testees.forEach((testee: Testee) => {
64+
this.testSuites.forEach((suite: Suite) => {
65+
suite.testees.forEach((testee: Testee) => {
6066
const order: TestScenario[] = testee.scheduler.schedule(suite);
6167
const first: TestScenario = order[0];
6268
before('Initialize testbed', async function () {

src/framework/MochaReporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {MochaOptions, reporters, Runner, Suite, Test} from 'mocha';
22
import {Reporter} from './Reporter';
3-
import {Framework} from './Framework';
3+
import {Framework, Suite as LatchSuite} from './Framework';
44
import {Archiver} from './Archiver';
55
import {Testee} from './Testee';
66
import color = reporters.Base.color;
@@ -80,7 +80,7 @@ class MochaReporter extends reporters.Base {
8080
console.log(color('suite', '%s==================='), this.indent());
8181

8282
const names: string[] = [];
83-
Framework.getImplementation().platforms().forEach((platform: Testee) => names.push(platform.name));
83+
Framework.getImplementation().suites().forEach((suite: LatchSuite) => suite.testees.forEach((platform: Testee) => names.push(platform.name)));
8484
names.forEach((name: string) => this.archiver.extend('platforms', name));
8585
console.log(color('suite', '%sPlatforms %s'), this.indent(), names.join(', '));
8686

src/framework/Testee.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ export class Testee { // TODO unified with testbed interface
6969

7070
public testbed?: Testbed;
7171

72-
constructor(name: string, specification: TestbedSpecification, scheduler: Scheduler, timeout: number = 2000) {
72+
constructor(name: string, specification: TestbedSpecification, scheduler: Scheduler, timeout: number, connectionTimeout: number) {
7373
this.name = name;
7474
this.specification = specification;
7575
this.scheduler = scheduler;
7676
this.timeout = timeout;
77-
this.connector = new TestbedFactory();
77+
this.connector = new TestbedFactory(connectionTimeout);
7878
this.mapper = new SourceMapFactory();
7979
this.framework = Framework.getImplementation();
8080
}

src/testbeds/TestbedFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class TestbedFactory {
1414
private readonly compilerFactory: CompilerFactory;
1515
private readonly uploaderFactory: UploaderFactory;
1616

17-
constructor(timeout: number = 5000) {
17+
constructor(timeout: number) {
1818
this.defaultTimeout = timeout;
1919
this.compilerFactory = new CompilerFactory(WABT);
2020
this.uploaderFactory = new UploaderFactory(EMULATOR, ARDUINO);

test/test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
import {ArduinoSpecification, EmulatorSpecification, Expected, Framework, Kind, Message, Step} from '../src';
1+
import {ArduinoSpecification, EmulatorSpecification, Expected, Framework, Invoker, Kind, Message, Step, WASM} from '../src';
22
import dump = Message.dump;
33
import stepOver = Message.stepOver;
44

55
const framework = Framework.getImplementation();
66

7-
framework.testee('emulator [:8500]', new EmulatorSpecification(8500));
8-
framework.testee('emulator [:8520]', new EmulatorSpecification(8520));
9-
framework.testee('esp wrover', new ArduinoSpecification('/dev/ttyUSB0', 'esp32:esp32:esp32wrover'));
7+
framework.suite('Test Wasm spec'); // must be called first
108

11-
framework.suite('Test Latch performance in CI');
9+
framework.testee('emulator [:8500]', new EmulatorSpecification(8500));
1210

1311
const steps: Step[] = [];
1412

13+
// ✔ ((invoke "8u_good1" (i32.const 0)) (i32.const 97))
14+
steps.push(new Invoker('8u_good1', [{value: 0, type: WASM.Type.i32}] as WASM.Value[], 97));
15+
16+
// ✔ ((invoke "8u_good3" (i32.const 0)) (i32.const 98))
17+
steps.push(new Invoker('8u_good3', [{value: 0, type: WASM.Type.i32}] as WASM.Value[], 98));
18+
1519
framework.test({
1620
title: `Test with address_0.wast`,
1721
program: 'test/address.wast',
1822
dependencies: [],
1923
steps: steps
2024
});
2125

26+
framework.suite('Test Debugger interface');
27+
framework.testee('emulator [:8520]', new EmulatorSpecification(8520));
28+
// framework.testee('esp wrover', new ArduinoSpecification('/dev/ttyUSB0', 'esp32:esp32:esp32wrover'));
29+
30+
2231
framework.test({
2332
title: 'Test STEP OVER',
2433
program: 'test/call.wast',

0 commit comments

Comments
 (0)