Skip to content

Commit 217ef19

Browse files
authored
Improve and document the issue with test_stack_varargs* (#7951)
I found out why these fail sometimes - in node.js, we set argv[0] to the native program being run. We allocate that on the stack (I guess to avoid a malloc). And so the filename of the program being run influences how much stack we use. As a result, if a random temp dir is used with a particularly long name, we can error in tests that check for not exceeding a minimal amount of stack usage. Amusingly, in particular this explains why I couldn't see it locally, where I run with EMTEST_SAVE_DIR - that makes it use a standard (short) test dir name, not a random one which might be long... I doubled the amount of stack we allow in those tests (they check that loops don't increase stack space unboundedly), which should make them ok even with a path name of a few K now, and documented it to avoid future confusion should they fail again.
1 parent 5826bcf commit 217ef19

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

tests/core/test_stack_varargs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void func(int i) {
1717
i, i, i, i, i, i, i, i, i, i, i, i, i, i);
1818
}
1919
int main() {
20-
for (int i = 0; i < 2048; i++) func(i);
20+
for (int i = 0; i < 4 * 1024; i++) func(i);
2121
printf("ok!\n");
2222
return 0;
2323
}

tests/test_core.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,21 +1370,29 @@ def test_stack_byval(self):
13701370
self.do_run_in_out_file_test('tests', 'core', 'test_stack_byval')
13711371

13721372
def test_stack_varargs(self):
1373+
# in node.js we allocate argv[0] on the stack, which means the length
1374+
# of the program directory influences how much stack we need, and so
1375+
# long random temp dir names can lead to random failures. The stack
1376+
# size was increased here to avoid that.
13731377
self.set_setting('INLINING_LIMIT', 50)
1374-
self.set_setting('TOTAL_STACK', 4096)
1378+
self.set_setting('TOTAL_STACK', 8 * 1024)
13751379

13761380
self.do_run_in_out_file_test('tests', 'core', 'test_stack_varargs')
13771381

13781382
def test_stack_varargs2(self):
1379-
self.set_setting('TOTAL_STACK', 4096)
1383+
# in node.js we allocate argv[0] on the stack, which means the length
1384+
# of the program directory influences how much stack we need, and so
1385+
# long random temp dir names can lead to random failures. The stack
1386+
# size was increased here to avoid that.
1387+
self.set_setting('TOTAL_STACK', 8 * 1024)
13801388
src = r'''
13811389
#include <stdio.h>
13821390
#include <stdlib.h>
13831391
13841392
void func(int i) {
13851393
}
13861394
int main() {
1387-
for (int i = 0; i < 3072; i++) {
1395+
for (int i = 0; i < 7000; i++) {
13881396
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
13891397
i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
13901398
}
@@ -1401,7 +1409,7 @@ def test_stack_varargs2(self):
14011409
#include <stdlib.h>
14021410
14031411
int main() {
1404-
for (int i = 0; i < 3072; i++) {
1412+
for (int i = 0; i < 7000; i++) {
14051413
int j = printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
14061414
i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
14071415
printf(" (%d)\n", j);
@@ -1437,7 +1445,7 @@ def test_stack_varargs2(self):
14371445
}
14381446
14391447
int main() {
1440-
for (int i = 0; i < 3072; i++) {
1448+
for (int i = 0; i < 7000; i++) {
14411449
int j = printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
14421450
i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
14431451
printf(" (%d)\n", j);

0 commit comments

Comments
 (0)