aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_browser.py4
-rw-r--r--tests/worker_api_3_main.cpp44
-rw-r--r--tests/worker_api_3_worker.cpp25
3 files changed, 73 insertions, 0 deletions
diff --git a/tests/test_browser.py b/tests/test_browser.py
index 62d3f257..3bceeda8 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -1757,6 +1757,10 @@ void *getBindBuffer() {
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')
+ def test_worker_api_3(self):
+ Popen([PYTHON, EMCC, path_from_root('tests', 'worker_api_3_worker.cpp'), '-o', 'worker.js', '-s', 'BUILD_AS_WORKER=1', '-s', 'EXPORTED_FUNCTIONS=["_one"]']).communicate()
+ self.btest('worker_api_3_main.cpp', expected='5')
+
def test_emscripten_async_wget2(self):
self.btest('http.cpp', expected='0', args=['-I' + path_from_root('tests')])
diff --git a/tests/worker_api_3_main.cpp b/tests/worker_api_3_main.cpp
new file mode 100644
index 00000000..595f99b9
--- /dev/null
+++ b/tests/worker_api_3_main.cpp
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <assert.h>
+#include <emscripten.h>
+
+int w1;
+
+bool sawCalls[] = { false, false, false, false };
+
+void c1(char *data, int size, void *arg) {
+ assert((int)arg == 97);
+ assert(size >= sizeof(int));
+
+ int *x = (int*)data;
+ printf("c1: %d\n", x[0]);
+
+ if (*x >= 0 && *x < 4) {
+ // Calls should have happened in order.
+ sawCalls[*x] = true; // Note the call with current param was made
+ for (int i = 0; i < *x - 1; ++i) {
+ if (!sawCalls[i]) {
+ // If we were called out of order, fail this and all following calls.
+ sawCalls[*x] = false;
+ break;
+ }
+ }
+ } else {
+ assert(*x == 4);
+ // This is the last call. All prior calls should have occurred.
+ int result = 1; // Final call occurred.
+ for (int i = 0; i < 4; ++i)
+ if (sawCalls[i]) result++;
+ REPORT_RESULT();
+ }
+}
+
+int main() {
+ w1 = emscripten_create_worker("worker.js");
+
+ int x[1] = { 0 };
+ emscripten_call_worker(w1, "one", (char*)x, sizeof(x), c1, (void*)97);
+
+ return 0;
+}
+
diff --git a/tests/worker_api_3_worker.cpp b/tests/worker_api_3_worker.cpp
new file mode 100644
index 00000000..db14377a
--- /dev/null
+++ b/tests/worker_api_3_worker.cpp
@@ -0,0 +1,25 @@
+#include <assert.h>
+#include <emscripten.h>
+
+extern "C" {
+
+// Respond with 0, 1, 2, 3 each with finalResponse=false, and 4 with
+// finalResponse=true.
+void one(char *data, int size) {
+ int *x = (int*)data;
+
+ if (*x == 0) {
+ // Respond 0, 1, 2, 3
+ for (int i = 0; i < 4; ++i) {
+ *x = i;
+ emscripten_worker_respond_provisionally(data, size);
+ }
+ }
+
+ // Respond 4
+ *x = 4;
+ emscripten_worker_respond(data, size);
+}
+
+}
+