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
2 changes: 1 addition & 1 deletion src/framework/Testee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class Testee { // TODO unified with testbed interface
this.name = name;
this.specification = specification;
this.timeout = timeout;
this.connector = new TestbedFactory(connectionTimeout);
this.mapper = new SourceMapFactory();
this.framework = Framework.getImplementation();
this.connector = new TestbedFactory(connectionTimeout, (chunk: Buffer) => this.framework.reporter.debug(chunk.toString()));
}

public bed(target: Target = Target.supervisor): Testbed | void {
Expand Down
8 changes: 4 additions & 4 deletions src/manage/Uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class UploaderFactory {


export abstract class Uploader extends EventEmitter {
abstract upload(compiled: CompileOutput): Promise<Connection>;
abstract upload(compiled: CompileOutput, listener?: (chunk: Buffer) => void): Promise<Connection>;

protected removeTmpDir(tmpdir: string): Promise<void> {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -109,7 +109,7 @@ export class EmulatorUploader extends Uploader {
this.args = args;
}

upload(compiled: CompileOutput, listener?: (chunk: any) => void): Promise<SubProcess> {
upload(compiled: CompileOutput, listener?: (chunk: Buffer) => void): Promise<SubProcess> {
return this.connectSocket(compiled.file, listener);
}

Expand All @@ -118,7 +118,7 @@ export class EmulatorUploader extends Uploader {
return spawn(this.interpreter, _args);
}

private connectSocket(program: string, listener?: (chunk: any) => void): Promise<SubProcess> {
private connectSocket(program: string, listener?: (chunk: Buffer) => void): Promise<SubProcess> {
const that = this;
const process = this.startWARDuino(program);

Expand All @@ -139,7 +139,7 @@ export class EmulatorUploader extends Uploader {
const reader = new ReadlineParser();
process.stdout.pipe(reader);

reader.on('data', (data) => {
reader.on('data', (data: Buffer) => {
if (listener !== undefined) {
listener(data);
}
Expand Down
6 changes: 6 additions & 0 deletions src/reporter/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ export class Reporter {
error(text: string) {
this.output += `error: ${text}\n`;
}

debug(text: string) {
if (this.verboseness === Verbosity.debug) {
console.debug(text);
}
}
}
6 changes: 4 additions & 2 deletions src/testbeds/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ export abstract class Platform extends EventEmitter implements Testbed {

// send request over duplex channel
public sendRequest<R>(map: SourceMap.Mapping, request: Request<R>): Promise<R> {
const message = `${request.type}${request.payload?.(map) ?? ''}\n`;
this.emit(TestbedEvents.Send, message);
return new Promise((resolve, reject) => {
this.requests.push([request, resolve]);
this.connection.channel.write(`${request.type}${request.payload?.(map) ?? ''}\n`, (err: any) => {
if (err !== null) {
this.connection.channel.write(message, (err: Error | null | undefined) => {
if (err !== null && err !== undefined) {
reject(err);
}
});
Expand Down
7 changes: 6 additions & 1 deletion src/testbeds/Testbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export enum TestbedEvents {
OnMessage = 'message',
OnBreakpointHit = 'breakpoint',
OnPushEvent = 'push',
Ready = 'ready'
Ready = 'ready',
Send = 'send'
}

export declare interface Testbed extends EventEmitter {
Expand All @@ -25,4 +26,8 @@ export declare interface Testbed extends EventEmitter {
on(event: TestbedEvents.OnBreakpointHit, listener: (message: Breakpoint) => void): this;

on(event: TestbedEvents.OnPushEvent, listener: (data: string) => void): this;

on(event: TestbedEvents.Ready, listener: (data: string) => void): this;

on(event: TestbedEvents.Send, listener: (data: string) => void): this;
}
20 changes: 14 additions & 6 deletions src/testbeds/TestbedFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Testbed} from './Testbed';
import {Testbed, TestbedEvents} from './Testbed';
import {ARDUINO, EMULATOR, WABT} from '../util/env';
import {CompileOutput, CompilerFactory} from '../manage/Compiler';
import {DummyProxy, Emulator} from './Emulator';
Expand All @@ -13,28 +13,36 @@ export class TestbedFactory {
public readonly timeout: number;
private readonly compilerFactory: CompilerFactory;
private readonly uploaderFactory: UploaderFactory;
private readonly listener?: (chunk: Buffer) => void;

constructor(timeout: number) {
constructor(timeout: number, listener?: (chunk: Buffer) => void) {
this.timeout = timeout;
this.listener = listener;
this.compilerFactory = new CompilerFactory(WABT);
this.uploaderFactory = new UploaderFactory(EMULATOR, ARDUINO);
}

public async initialize(specification: TestbedSpecification, program: string, args: string[]): Promise<Testbed> {
const compiled: CompileOutput = await this.compilerFactory.pickCompiler(program).compile(program).catch((e) => Promise.reject(e));
const connection: Connection = await this.uploaderFactory.pickUploader(specification, args).upload(compiled).catch((e) => Promise.reject(e));
const connection: Connection = await this.uploaderFactory.pickUploader(specification, args).upload(compiled, this.listener).catch((e) => Promise.reject(e));

let testbed: Testbed;
switch (specification.type) {
case PlatformType.arduino:
return new Arduino(connection as Serial);
testbed = new Arduino(connection as Serial);
break;
case PlatformType.emulator:
case PlatformType.emu2emu:
case PlatformType.debug:
return new Emulator(connection as SubProcess);
testbed = new Emulator(connection as SubProcess);
break;
case PlatformType.emuproxy:
return new DummyProxy(connection as SubProcess, specification as ProxySpecification);
testbed = new DummyProxy(connection as SubProcess, specification as ProxySpecification);
break;
default:
return Promise.reject('Platform not implemented.');
}
testbed.on(TestbedEvents.Send, (message: string) => this.listener?.(Buffer.from(message)));
return testbed;
}
}
Loading