diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/runner.py | 2 | ||||
-rw-r--r-- | tests/worker_api_2_main.cpp | 29 | ||||
-rw-r--r-- | tests/worker_api_2_worker.cpp | 17 |
3 files changed, 45 insertions, 3 deletions
diff --git a/tests/runner.py b/tests/runner.py index e5b8d13a..b0f4f507 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -9119,7 +9119,7 @@ elif 'browser' in str(sys.argv): self.btest('worker_api_main.cpp', expected='566') def test_worker_api_2(self): - Popen(['python', EMCC, path_from_root('tests', 'worker_api_2_worker.cpp'), '-o', 'worker.js', '-s', 'BUILD_AS_WORKER=1', '-O2', '--minify', '0', '-s', 'EXPORTED_FUNCTIONS=["_one", "_two"]']).communicate() + Popen(['python', EMCC, path_from_root('tests', 'worker_api_2_worker.cpp'), '-o', 'worker.js', '-s', 'BUILD_AS_WORKER=1', '-O2', '--minify', '0', '-s', 'EXPORTED_FUNCTIONS=["_one", "_two", "_three", "_four"]']).communicate() self.btest('worker_api_2_main.cpp', args=['-O2', '--minify', '0'], expected='11') pids_to_clean = [] diff --git a/tests/worker_api_2_main.cpp b/tests/worker_api_2_main.cpp index 4824cf74..da24a43b 100644 --- a/tests/worker_api_2_main.cpp +++ b/tests/worker_api_2_main.cpp @@ -17,6 +17,28 @@ Info x[3] = { { 22, 3.159, 97, 2.1828 }, int stage = 1; +int c3_7 = 0, c3_8 = 0; + +void c3(char *data, int size, void *arg) { // tests calls different in different workers. + int calls = *((int*)data); + printf("%d: %d\n", (int)arg, calls); + if ((int)arg == 7) { + assert(c3_7 == 0); + c3_7++; + assert(calls == 5); + } else { + assert((int)arg == 8); + assert(c3_8 == 0); + c3_8++; + assert(calls == 1); + } + if (c3_7 && c3_7) { // note: racey, responses from 2 workers here + emscripten_destroy_worker(w1); + int result = 11; + REPORT_RESULT(); + } +} + void c2(char *data, int size, void *arg) { // tests queuing up several messages, each with different data assert((int)arg == stage); Info *x2 = (Info*)data; @@ -31,8 +53,11 @@ void c2(char *data, int size, void *arg) { // tests queuing up several messages, assert(x2[0].d == x[i].d-1); if (stage == 5) { - int result = 11; - REPORT_RESULT(); + int w2 = emscripten_create_worker("worker.js"); + emscripten_call_worker(w2, "three", NULL, 0, NULL, (void*)6); // bump calls in new worker, once + + emscripten_call_worker(w1, "four", NULL, 0, c3, (void*)7); + emscripten_call_worker(w2, "four", NULL, 0, c3, (void*)8); } stage++; } diff --git a/tests/worker_api_2_worker.cpp b/tests/worker_api_2_worker.cpp index 6db704a5..d7033bc4 100644 --- a/tests/worker_api_2_worker.cpp +++ b/tests/worker_api_2_worker.cpp @@ -8,13 +8,17 @@ struct Info { double d; }; +int calls = 0; // global state that is not in all workers + extern "C" { void one(char *data, int size) { + calls++; emscripten_worker_respond(data, size); } void two(char *data, int size) { + calls++; Info *x = (Info*)data; x[0].i++; x[0].f--; @@ -23,5 +27,18 @@ void two(char *data, int size) { emscripten_worker_respond(data, size); } +void three(char *data, int size) { + assert(data == 0); + assert(size == 0); + calls++; + // no response +} + +void four(char *data, int size) { + assert(data == 0); + assert(size == 0); + emscripten_worker_respond((char*)&calls, sizeof(calls)); +} + } |