Skip to content

Commit

Permalink
Fix the dodgy call_sync_on_main_thread tests (emscripten-core#8621)
Browse files Browse the repository at this point in the history
Previously these tests weren't actually checking the right thing. This should fix the logic to what I think the author was trying to do.

Fixes emscripten-core#8620.
  • Loading branch information
VirtualTim authored and belraquib committed Dec 23, 2020
1 parent 0615286 commit 3d8640e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions tests/pthread/call_sync_on_main_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <assert.h>
#include <string.h>

extern void getDomElementInnerHTML(const char *domElement, char *dst, int size);
extern void getDomElementParentInnerHTML(const char *domElement, char *dst, int size);
extern int isThisInWorker(void);
extern int isThisInWorkerOnMainThread(void);
extern int receivesAndReturnsAnInteger(int i);
Expand All @@ -21,13 +21,13 @@ int main()
{
char dst[256];
char name[7] = "resize";
getDomElementInnerHTML(name, dst, sizeof(dst));
getDomElementParentInnerHTML(name, dst, sizeof(dst));
memset(name, 0, sizeof(name)); // Try to uncover if there might be a race condition and above line was not synchronously processed, and we could take name string away.
int inWorker1 = isThisInWorker(); // Build this application with -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1 for this to return 1, otherwise returns 0.
int inWorker2 = isThisInWorkerOnMainThread(); // This should always return 0
int returnedInt = receivesAndReturnsAnInteger(4);
printf("text: \"%s\". inWorker1: %d, inWorker2: %d, returnedInt: %d\n", dst, inWorker1, inWorker2, returnedInt);
assert(!strstr(dst, "Resize canvas"));
assert(strstr(dst, "Resize canvas"));
assert(inWorker1 == PROXY_TO_PTHREAD);
assert(inWorker2 == 0);
assert(returnedInt == 42 + 4);
Expand Down
8 changes: 4 additions & 4 deletions tests/pthread/call_sync_on_main_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ mergeInto(LibraryManager.library, {
// Test accessing a DOM element on the main thread.
// This function returns the inner text of the div by ID "status"
// Because it accesses the DOM, it must be called on the main thread.
getDomElementInnerHTML__proxy: 'sync',
getDomElementInnerHTML__sig: 'viii',
getDomElementInnerHTML: function(domElementId, dst, size) {
getDomElementParentInnerHTML__proxy: 'sync',
getDomElementParentInnerHTML__sig: 'viii',
getDomElementParentInnerHTML: function(domElementId, dst, size) {
var id = UTF8ToString(domElementId);
var text = document.getElementById(id).innerHTML;
var text = document.getElementById(id).parentElement.innerHTML;
stringToUTF8(text, dst, size);
},

Expand Down

0 comments on commit 3d8640e

Please sign in to comment.