Skip to content

Commit

Permalink
Run test_pthread_kill in test_other. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Aug 28, 2024
1 parent 915ca21 commit 602e215
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/pthread/test_pthread_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <emscripten.h>

_Atomic int sharedVar = 0;

Expand All @@ -24,9 +23,8 @@ static void *thread_start(void *arg) {
pthread_exit(0);
}

void BusySleep(double msecs) {
double t0 = emscripten_get_now();
while (emscripten_get_now() < t0 + msecs);
void BusySleep(long msecs) {
usleep(msecs * 1000);
}

int main() {
Expand All @@ -39,8 +37,10 @@ int main() {
// Wait until thread kicks in and sets the shared variable.
while (sharedVar == 0)
BusySleep(10);
printf("thread startd\n");

s = pthread_kill(thr, SIGKILL);
printf("thread killed\n");
assert(s == 0);

// Wait until we see the shared variable stop incrementing. (This is a bit heuristic and hacky)
Expand All @@ -55,7 +55,7 @@ int main() {
sharedVar = 0;

// Wait for a long time, if the thread is still running, it should progress and set sharedVar by this time.
BusySleep(3000);
BusySleep(1000);

// Finally test that the thread is not doing any work and it is dead.
assert(sharedVar == 0);
Expand Down
3 changes: 3 additions & 0 deletions test/pthread/test_pthread_kill.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
thread startd
thread killed
Main: Done. Successfully killed thread. sharedVar: 0
4 changes: 4 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -13412,6 +13412,10 @@ def test_pthread_trap(self):
self.assertContained('sent an error!', output)
self.assertContained('at (test_pthread_trap.wasm.)?thread_main', output, regex=True)

@node_pthreads
def test_pthread_kill(self):
self.do_run_in_out_file_test('pthread/test_pthread_kill.c')

@node_pthreads
def test_emscripten_set_interval(self):
self.do_runf('emscripten_set_interval.c', args=['-pthread', '-sPROXY_TO_PTHREAD'])
Expand Down

0 comments on commit 602e215

Please sign in to comment.