Skip to content

Commit 4679796

Browse files
authored
Add pthread+memgrowth tests to test_other.py. NFC (#24682)
Previously these tests were only being run in the browser. This is in preparation for fixing #24287.
1 parent 8f12acf commit 4679796

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

test/pthread/test_pthread_memory_growth.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ EM_JS(void, js_assert_final_heap_state, (bool isWorker, const char* buffer, int
3838

3939
#define FINAL_HEAP_SIZE (64 * 1024 * 1024)
4040

41-
static char *alloc_beyond_initial_heap()
42-
{
41+
char *alloc_beyond_initial_heap() {
4342
char *buffer = malloc(FINAL_HEAP_SIZE);
4443
assert(buffer);
4544
// Write value at the end of the buffer to check that any thread can access addresses beyond the initial heap size.
@@ -50,24 +49,21 @@ static char *alloc_beyond_initial_heap()
5049

5150
const char *_Atomic buffer = NULL;
5251

53-
static void assert_final_heap_state(bool is_worker)
54-
{
52+
void assert_final_heap_state(bool is_worker) {
5553
assert(buffer != NULL);
5654
assert(*buffer == 42);
5755
js_assert_final_heap_state(is_worker, buffer, FINAL_HEAP_SIZE);
5856
}
5957

60-
static void *thread_start(void *arg)
61-
{
58+
void *thread_start(void *arg) {
6259
assert_initial_heap_state(true);
6360
// allocate more memory than we currently have, forcing a growth
6461
buffer = alloc_beyond_initial_heap();
6562
assert_final_heap_state(true);
6663
return NULL;
6764
}
6865

69-
int main()
70-
{
66+
int main() {
7167
assert_initial_heap_state(false);
7268

7369
pthread_t thr;

test/pthread/test_pthread_memory_growth_mainthread.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,22 @@ _Atomic enum state {
4444

4545
const char *_Atomic buffer;
4646

47-
static void assert_initial_heap_state(bool is_worker)
48-
{
47+
void assert_initial_heap_state(bool is_worker) {
4948
assert(state == INITIAL_STATE);
5049
assert(buffer == NULL);
5150
js_assert_initial_heap_state(is_worker);
5251
}
5352

5453
#define FINAL_HEAP_SIZE (64 * 1024 * 1024)
5554

56-
static void assert_final_heap_state(bool is_worker)
57-
{
55+
void assert_final_heap_state(bool is_worker) {
5856
assert(state == FINAL_STATE);
5957
assert(buffer != NULL);
6058
assert(*buffer == 42);
6159
js_assert_final_heap_state(is_worker, buffer, FINAL_HEAP_SIZE);
6260
}
6361

64-
static void *thread_start(void *arg)
65-
{
62+
void *thread_start(void *arg) {
6663
assert_initial_heap_state(true);
6764
// Tell main thread that we checked the initial state and it can allocate.
6865
state = THREAD_CHECKED_INITIAL_STATE;
@@ -73,8 +70,7 @@ static void *thread_start(void *arg)
7370
return NULL;
7471
}
7572

76-
static char *alloc_beyond_initial_heap()
77-
{
73+
char *alloc_beyond_initial_heap() {
7874
char *buffer = malloc(FINAL_HEAP_SIZE);
7975
assert(buffer);
8076
// Write value at the end of the buffer to check that any thread can access addresses beyond the initial heap size.
@@ -83,13 +79,13 @@ static char *alloc_beyond_initial_heap()
8379
return buffer;
8480
}
8581

86-
int main()
87-
{
82+
int main() {
83+
// Check initial state in both threads before allocating more memory.
84+
assert_initial_heap_state(false);
85+
8886
pthread_t thr;
8987
int res = pthread_create(&thr, NULL, thread_start, NULL);
9088
assert(res == 0);
91-
// Check initial state in both threads before allocating more memory.
92-
assert_initial_heap_state(false);
9389
while (state != THREAD_CHECKED_INITIAL_STATE);
9490

9591
// allocate more memory than we currently have, forcing a growth

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4739,7 +4739,7 @@ def test_minimal_runtime_hello_thread(self, opts):
47394739
# Tests memory growth in pthreads mode, but still on the main thread.
47404740
@parameterized({
47414741
'': ([], 1),
4742-
'proxy': (['-sPROXY_TO_PTHREAD'], 2),
4742+
'proxy': (['-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'], 2),
47434743
})
47444744
@no_2gb('uses INITIAL_MEMORY')
47454745
@no_4gb('uses INITIAL_MEMORY')

test/test_other.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14281,6 +14281,28 @@ def test_pthread_trap(self):
1428114281
def test_pthread_kill(self):
1428214282
self.do_run_in_out_file_test('pthread/test_pthread_kill.c')
1428314283

14284+
# Tests memory growth in pthreads mode, but still on the main thread.
14285+
@node_pthreads
14286+
@parameterized({
14287+
'': ([], 1),
14288+
'proxy': (['-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'], 2),
14289+
})
14290+
def test_pthread_growth_mainthread(self, cflags, pthread_pool_size):
14291+
self.set_setting('PTHREAD_POOL_SIZE', pthread_pool_size)
14292+
self.do_runf('pthread/test_pthread_memory_growth_mainthread.c', cflags=['-Wno-pthreads-mem-growth', '-pthread', '-sALLOW_MEMORY_GROWTH', '-sINITIAL_MEMORY=32MB', '-sMAXIMUM_MEMORY=256MB'] + cflags)
14293+
14294+
# Tests memory growth in a pthread.
14295+
@node_pthreads
14296+
@parameterized({
14297+
'': ([],),
14298+
'assert': (['-sASSERTIONS'],),
14299+
'proxy': (['-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME'], 2),
14300+
'minimal': (['-sMINIMAL_RUNTIME', '-sMODULARIZE', '-sEXPORT_NAME=MyModule'],),
14301+
})
14302+
def test_pthread_growth(self, cflags, pthread_pool_size = 1):
14303+
self.set_setting('PTHREAD_POOL_SIZE', pthread_pool_size)
14304+
self.do_runf('pthread/test_pthread_memory_growth.c', cflags=['-Wno-pthreads-mem-growth', '-pthread', '-sALLOW_MEMORY_GROWTH', '-sINITIAL_MEMORY=32MB', '-sMAXIMUM_MEMORY=256MB'] + cflags)
14305+
1428414306
@node_pthreads
1428514307
def test_emscripten_set_interval(self):
1428614308
self.do_runf('emscripten_set_interval.c', args=['-pthread', '-sPROXY_TO_PTHREAD'])

0 commit comments

Comments
 (0)