Skip to content

[test] Simplify test_pthread_tls. NFC #24658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions test/pthread/test_pthread_c_thread_local.c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
#include <thread>
#include <cstdio>
#include <cassert>
#include <pthread.h>
#include <stdio.h>
#include <assert.h>

thread_local int tls;
thread_local struct {
_Thread_local int tls;
_Thread_local struct {
int a;
double b;
} data = {1, 2};
thread_local int array[10];
_Thread_local int array[10];

void thread(void) {
void* thread_main(void* arg) {
++tls;
data.a = 3;
data.b = 4;
assert(tls == 1);
assert(data.a == 3);
assert(data.b == 4);
assert(array[9] == 0);
return NULL;
}

int main(void) {
array[9] = 1337;
std::thread t(thread);
t.join();
pthread_t t;
pthread_create(&t, NULL, thread_main, NULL);
pthread_join(t, NULL);
assert(tls == 0);
assert(data.a == 1);
assert(data.b == 2);
Expand Down
2 changes: 1 addition & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4068,7 +4068,7 @@ def test_pthread_stack_bounds(self):

# Test that real `thread_local` works.
def test_pthread_tls(self):
self.btest_exit('pthread/test_pthread_tls.cpp', cflags=['-sPROXY_TO_PTHREAD', '-pthread'])
self.btest_exit('pthread/test_pthread_tls.c', cflags=['-sPROXY_TO_PTHREAD', '-pthread'])

# Test that real `thread_local` works in main thread without PROXY_TO_PTHREAD.
def test_pthread_tls_main(self):
Expand Down
14 changes: 7 additions & 7 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2636,13 +2636,6 @@ def test_pthread_thread_local_storage(self):
self.set_setting('INITIAL_MEMORY', '300mb')
self.do_run_in_out_file_test('pthread/test_pthread_thread_local_storage.cpp')

@node_pthreads
@also_with_minimal_runtime
def test_pthread_c_thread_local(self):
if self.get_setting('MINIMAL_RUNTIME') and is_sanitizing(self.cflags):
self.skipTest('MINIMAL_RUNTIME + threads + asan does not work')
self.do_run_in_out_file_test('pthread/test_pthread_c_thread_local.c')

@node_pthreads
def test_pthread_cleanup(self):
self.set_setting('PTHREAD_POOL_SIZE', 4)
Expand Down Expand Up @@ -2714,6 +2707,13 @@ def test_pthread_tls_dylink(self):
self.cflags.append('-Wno-experimental')
self.do_run_in_out_file_test('pthread/test_pthread_tls_dylink.c')

@node_pthreads
@also_with_minimal_runtime
def test_pthread_tls(self):
if self.get_setting('MINIMAL_RUNTIME') and is_sanitizing(self.cflags):
self.skipTest('MINIMAL_RUNTIME + threads + asan does not work')
self.do_runf('pthread/test_pthread_tls.c')

@no_modularize_instance('uses global Module objecgt')
def test_pthread_run_script(self):
shutil.copy(test_file('pthread/foo.js'), '.')
Expand Down