Skip to content

Commit 9996395

Browse files
committed
run wasm tests
1 parent b89e409 commit 9996395

7 files changed

Lines changed: 55 additions & 17 deletions

File tree

.github/workflows/c-cpp.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ jobs:
3333
- name: make
3434
run: make test
3535

36-
- name: make em
37-
run: make em
38-
3936
- name: Upload jdcli.js
4037
uses: actions/upload-artifact@v1
4138
with:

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ vg: all
6161
valgrind --suppressions=scripts/valgrind.supp --show-reachable=yes --leak-check=full --gen-suppressions=all ./built/jdcli samples/ex-test.jacs
6262

6363
EMCC_OPTS = $(DEFINES) $(INC) \
64-
-g2 -O1 -s WASM=1 -s MODULARIZE=1 --no-entry -s SINGLE_FILE=0 -s EXPORTED_FUNCTIONS=_malloc,_free --pre-js wasmpre.js
64+
-g2 -O1 -s WASM=1 -s MODULARIZE=1 --no-entry -s SINGLE_FILE=1 -s EXPORTED_FUNCTIONS=_malloc,_free --pre-js wasmpre.js
6565

6666
em:
6767
emcc $(EMCC_OPTS) -o $(BUILT)/jdcli.js $(SRC)
6868

69-
emr: em
70-
node run
69+
test-c: all
70+
./built/jdcli samples/ex-test.jacs
7171

72-
test: all em
73-
./built/jdcli samples/ex-test.jacs
72+
test-em: em
73+
node run samples/ex-test.jacs
74+
75+
test: test-c test-em

hf2/flash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
static jacscriptmgr_cfg_t cfg;
1313

1414
void flash_program(void *dst, const void *src, uint32_t len) {
15+
JD_ASSERT(cfg.program_base != NULL);
1516
ptrdiff_t diff = (uint8_t *)dst - (uint8_t *)cfg.program_base;
1617
JD_ASSERT(((uintptr_t)src & 3) == 0);
1718
JD_ASSERT(0 <= diff && diff + len <= cfg.max_program_size);
@@ -22,6 +23,7 @@ void flash_program(void *dst, const void *src, uint32_t len) {
2223
}
2324

2425
void flash_erase(void *page_addr) {
26+
JD_ASSERT(cfg.program_base != NULL);
2527
ptrdiff_t diff = (uint8_t *)page_addr - (uint8_t *)cfg.program_base;
2628
JD_ASSERT(0 <= diff && diff <= cfg.max_program_size - JD_FLASH_PAGE_SIZE);
2729
JD_ASSERT((diff & (JD_FLASH_PAGE_SIZE - 1)) == 0);

hf2/jd_impl_em.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
static uint64_t cached_devid = 0x1d46a30eef48919;
1111

1212
EM_JS(void, em_send_frame, (void *frame), {
13-
const sz = 12 + HEAP8[frame + 2];
14-
const pkt = HEAP8.slice(frame, frame + sz);
13+
const sz = 12 + (HEAP8[frame + 2] & 0xff);
14+
const pkt = new Uint8Array(HEAP8.slice(frame, frame + sz).buffer);
1515
Module.sendPacket(pkt)
1616
});
1717

1818
EM_JS(double, em_time_now, (void), { return Date.now(); });
1919

20+
int jd_em_frame_received(jd_frame_t *frame);
21+
2022
int jd_em_send_frame(jd_transport_ctx_t *ctx, jd_frame_t *frame) {
2123
em_send_frame(frame);
24+
jd_em_frame_received(frame);
2225
return 0;
2326
}
2427

inc/jd_user_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define JD_CONFIG_STATUS 0
1313
#define JD_CONFIG_CONTROL_FLOOD 0
1414
#define JD_CLIENT 1
15+
#define JD_VERBOSE_ASSERT 1
1516

1617
#define JD_FLASH_PAGE_SIZE 2048
1718

jacdac-c

run.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,47 @@ async function main() {
66
inst.jacsStart()
77
}
88

9-
async function altMain() {
9+
async function runScript(fn) {
1010
const inst = await factory()
11-
11+
const fs = require("fs")
12+
13+
const prog = fs.readFileSync(fn)
14+
1215
// both handlePacket and sendPacket take UInt8Array of the frame
13-
addEventListener("message", ev => inst.handlePacket(ev.data))
14-
inst.sendPacket = pkt => console.log("send", pkt)
15-
inst.jacsSetDeviceId("1122334455667788") // use 8-byte hex-encoded ID, or any string, which will be hashed
16+
// addEventListener("message", ev => inst.handlePacket(ev.data))
17+
// inst.sendPacket = pkt => console.log("send", pkt)
18+
inst.sendPacket = pkt => {
19+
// only react to packets from our device
20+
for (let i = 0; i < 8; ++i)
21+
if (pkt[4 + i] != (i + 1) * 0x11)
22+
return
23+
24+
const idx = pkt[13]
25+
const cmd = pkt[14] | (pkt[15] << 8)
26+
// see if it's "panic event"
27+
if (idx == 2 && (cmd & 0x8000) && (cmd & 0xff) == 0x80) {
28+
const panic_code = pkt[16] | (pkt[16] << 8)
29+
if (panic_code) {
30+
console.log("test failed")
31+
process.exit(1)
32+
} else {
33+
console.log("test OK")
34+
process.exit(0)
35+
}
36+
}
37+
}
38+
inst.jacsSetDeviceId("1122334455667788") // use 8-byte hex-encoded ID (used directly), or any string (hashed)
1639
inst.jacsStart()
40+
inst.jacsDeploy(prog)
41+
setTimeout(() => {
42+
console.log("timeout")
43+
process.exit(2)
44+
}, 2000)
1745
}
1846

19-
main()
47+
process.argv.shift()
48+
process.argv.shift()
49+
if (process.argv[0])
50+
runScript(process.argv[0])
51+
else
52+
main()

0 commit comments

Comments
 (0)