Skip to content

Commit 1277e22

Browse files
authored
[test] Simplify test_pthread_tls. NFC (#24658)
- Convert to C - Run in core tests under node. - Remove redundant test added in #24646
1 parent f2d6185 commit 1277e22

File tree

4 files changed

+19
-52
lines changed

4 files changed

+19
-52
lines changed

test/pthread/test_pthread_c_thread_local.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/pthread/test_pthread_tls.cpp renamed to test/pthread/test_pthread_tls.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
#include <thread>
2-
#include <cstdio>
3-
#include <cassert>
1+
#include <pthread.h>
2+
#include <stdio.h>
3+
#include <assert.h>
44

5-
thread_local int tls;
6-
thread_local struct {
5+
_Thread_local int tls;
6+
_Thread_local struct {
77
int a;
88
double b;
99
} data = {1, 2};
10-
thread_local int array[10];
10+
_Thread_local int array[10];
1111

12-
void thread(void) {
12+
void* thread_main(void* arg) {
1313
++tls;
1414
data.a = 3;
1515
data.b = 4;
1616
assert(tls == 1);
1717
assert(data.a == 3);
1818
assert(data.b == 4);
1919
assert(array[9] == 0);
20+
return NULL;
2021
}
2122

2223
int main(void) {
2324
array[9] = 1337;
24-
std::thread t(thread);
25-
t.join();
25+
pthread_t t;
26+
pthread_create(&t, NULL, thread_main, NULL);
27+
pthread_join(t, NULL);
2628
assert(tls == 0);
2729
assert(data.a == 1);
2830
assert(data.b == 2);

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4068,7 +4068,7 @@ def test_pthread_stack_bounds(self):
40684068

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

40734073
# Test that real `thread_local` works in main thread without PROXY_TO_PTHREAD.
40744074
def test_pthread_tls_main(self):

test/test_core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,13 +2636,6 @@ def test_pthread_thread_local_storage(self):
26362636
self.set_setting('INITIAL_MEMORY', '300mb')
26372637
self.do_run_in_out_file_test('pthread/test_pthread_thread_local_storage.cpp')
26382638

2639-
@node_pthreads
2640-
@also_with_minimal_runtime
2641-
def test_pthread_c_thread_local(self):
2642-
if self.get_setting('MINIMAL_RUNTIME') and is_sanitizing(self.cflags):
2643-
self.skipTest('MINIMAL_RUNTIME + threads + asan does not work')
2644-
self.do_run_in_out_file_test('pthread/test_pthread_c_thread_local.c')
2645-
26462639
@node_pthreads
26472640
def test_pthread_cleanup(self):
26482641
self.set_setting('PTHREAD_POOL_SIZE', 4)
@@ -2714,6 +2707,13 @@ def test_pthread_tls_dylink(self):
27142707
self.cflags.append('-Wno-experimental')
27152708
self.do_run_in_out_file_test('pthread/test_pthread_tls_dylink.c')
27162709

2710+
@node_pthreads
2711+
@also_with_minimal_runtime
2712+
def test_pthread_tls(self):
2713+
if self.get_setting('MINIMAL_RUNTIME') and is_sanitizing(self.cflags):
2714+
self.skipTest('MINIMAL_RUNTIME + threads + asan does not work')
2715+
self.do_runf('pthread/test_pthread_tls.c')
2716+
27172717
@no_modularize_instance('uses global Module objecgt')
27182718
def test_pthread_run_script(self):
27192719
shutil.copy(test_file('pthread/foo.js'), '.')

0 commit comments

Comments
 (0)