Skip to content

Commit b531cc7

Browse files
committed
Test module upload
1 parent 6e68705 commit b531cc7

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

src/framework/Framework.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class Framework {
7070
await testee.initialize(first.program, first.args ?? []);
7171
});
7272

73-
describe(`Testing on ${testee.name}.`, () => {
73+
describe(`${testee.name}: ${suite.title}`, () => {
7474
// todo add parallelism
7575

7676
// if (!bed.disabled) { // TODO necessary? isn't this done in de test itself?

src/messaging/Message.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Interrupt = WARDuino.Interrupt;
99
import State = WARDuino.State;
1010
import Value = WASM.Value;
1111
import Type = WASM.Type;
12+
import {CompileOutput, CompilerFactory} from '../manage/Compiler';
13+
import {WABT} from '../util/env';
1214

1315
// An acknowledgement returned by the debugger
1416
export interface Ack {
@@ -125,9 +127,14 @@ export namespace Message {
125127
}
126128
}
127129

128-
export function updateModule(program: string): Request<Ack> {
129-
function payload(wasm: Buffer): string {
130-
const w = new Uint8Array(wasm);
130+
export async function uploadFile(program: string): Promise<Request<Ack>> {
131+
let compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(program).compile(program);
132+
return updateModule(compiled.file);
133+
}
134+
135+
export function updateModule(wasm: string): Request<Ack> {
136+
function payload(binary: Buffer): string {
137+
const w = new Uint8Array(binary);
131138
const sizeHex: string = WASM.leb128(w.length);
132139
const sizeBuffer = Buffer.allocUnsafe(4);
133140
sizeBuffer.writeUint32BE(w.length);
@@ -137,7 +144,7 @@ export namespace Message {
137144

138145
return {
139146
type: Interrupt.updateModule,
140-
payload: (map: SourceMap.Mapping) => payload(readFileSync(program)),
147+
payload: (map: SourceMap.Mapping) => payload(readFileSync(wasm)),
141148
parser: (line: string) => {
142149
return ackParser(line, 'CHANGE Module');
143150
}

test/module.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// module regression test
2+
3+
import {EmulatorSpecification, Framework, Kind, Message} from '../src';
4+
import {readdirSync} from 'fs';
5+
6+
const folder: string = process.env.CORESUITE ?? '.';
7+
8+
const framework = Framework.getImplementation();
9+
10+
framework.suite('Test update module functionality');
11+
12+
framework.testee('emulator [:8500]', new EmulatorSpecification(8500));
13+
14+
const files: string[] = readdirSync(folder).filter((file) => file.endsWith('.asserts.wast'));
15+
16+
for (const file of files) {
17+
const module: string = file.replace('.asserts.wast', '.wast');
18+
19+
const request = await Message.uploadFile(folder + module);
20+
framework.test({
21+
title: `Test upload ${module}`,
22+
program: 'test/address.wast',
23+
dependencies: [],
24+
steps: [{
25+
title: `upload ${module}`,
26+
instruction: {kind: Kind.Request, value: request}
27+
}]
28+
});
29+
}
30+
31+
framework.run();

0 commit comments

Comments
 (0)