Skip to content

Commit 16dc866

Browse files
authored
Convert test_dylink_pthread_static_data to C (#24502)
In an effort to reproduce the flakiness and fix #24500 this change makes the test build a lot faster. For some reason the C++ lambda expression was adding over a second to the compiler time on `main.cpp`. This change makes the test go from 2.8 seconds 1.4 seconds on my machine.
1 parent b76426b commit 16dc866

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

test/test_other.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,45 +2146,47 @@ def test_dylink_pthread_static_data(self):
21462146
# the memory is zero-initialized only once (and not once per thread).
21472147
# * The global object must have a constructor to make sure that it is
21482148
# constructed only once (and not once per thread).
2149-
create_file('side.cpp', r'''
2150-
struct Data {
2151-
Data() : value(42) {}
2152-
int value;
2153-
} data;
2154-
int * get_address() {
2155-
return &data.value;
2149+
create_file('side.c', r'''
2150+
int value = 0;
2151+
2152+
__attribute__((constructor)) void ctor(void) {
2153+
value = 42;
2154+
}
2155+
2156+
int* get_address() {
2157+
return &value;
21562158
}
21572159
''')
2158-
self.run_process([
2159-
EMCC,
2160-
'-o', 'side.wasm',
2161-
'side.cpp',
2162-
'-pthread', '-Wno-experimental',
2163-
'-sSIDE_MODULE'])
2160+
self.run_process([EMCC, '-o', 'side.wasm', 'side.c', '-pthread', '-Wno-experimental', '-sSIDE_MODULE'])
21642161

2165-
create_file('main.cpp', r'''
2162+
create_file('main.c', r'''
2163+
#include <assert.h>
21662164
#include <stdio.h>
2167-
#include <thread>
2168-
int * get_address();
2169-
int main(void) {
2170-
*get_address() = 123;
2171-
std::thread([]{
2172-
printf("%d\n", *get_address());
2173-
}).join();
2174-
return 0;
2165+
#include <pthread.h>
2166+
2167+
int* get_address();
2168+
2169+
void* thread_main(void* arg) {
2170+
assert(*get_address() == 123);
2171+
printf("%d\n", *get_address());
2172+
return NULL;
2173+
}
2174+
2175+
int main() {
2176+
assert(*get_address() == 42);
2177+
*get_address() = 123;
2178+
pthread_t t;
2179+
pthread_create(&t, NULL, thread_main, NULL);
2180+
pthread_join(t, NULL);
2181+
return 0;
21752182
}
21762183
''')
21772184

2178-
self.do_runf(
2179-
'main.cpp',
2180-
'123',
2181-
emcc_args=[
2182-
'-pthread', '-Wno-experimental',
2183-
'-sPROXY_TO_PTHREAD',
2184-
'-sEXIT_RUNTIME',
2185-
'-sMAIN_MODULE=2',
2186-
'side.wasm',
2187-
])
2185+
self.do_runf('main.c', '123', emcc_args=['-pthread', '-Wno-experimental',
2186+
'-sPROXY_TO_PTHREAD',
2187+
'-sEXIT_RUNTIME',
2188+
'-sMAIN_MODULE=2',
2189+
'side.wasm'])
21882190

21892191
def test_dylink_pthread_warning(self):
21902192
err = self.expect_fail([EMCC, '-Werror', '-sMAIN_MODULE', '-pthread', test_file('hello_world.c')])

0 commit comments

Comments
 (0)