Skip to content

Commit 19eb84f

Browse files
authored
Merge pull request swiftlang#11881 from ndrewh/sanitizers-cherry-picks2
🍒 sanitizers: cherry-pick test stability improvements
2 parents d605f15 + 642b582 commit 19eb84f

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

compiler-rt/test/fuzzer/merge-posix.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ RUN: echo ....U. > %tmp/T2/2
1414
RUN: echo ...Z.. > %tmp/T2/3
1515
RUN: echo ...Z.. > %tmp/T2/4
1616
RUN: echo ....E. > %tmp/T2/5
17-
RUN: echo .....R > %tmp/T2/6
17+
RUN: %python -c "print('.....R' + 'X' * 4096, end='')" > %tmp/T2/6
1818

1919
# Check that we can report an error if file size exceeded
20-
RUN: (ulimit -f 1; not %run %t-FullCoverageSetTest -merge=1 %tmp/T1 %tmp/T2 2>&1 | FileCheck %s --check-prefix=SIGXFSZ)
20+
RUN: (ulimit -f 4; not %run %t-FullCoverageSetTest -merge=1 %tmp/T1 %tmp/T2 2>&1 | FileCheck %s --check-prefix=SIGXFSZ)
2121
SIGXFSZ: ERROR: libFuzzer: file size exceeded
2222

2323
# Check that we honor TMPDIR

compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
#include <assert.h>
77
#include <spawn.h>
88
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
911
#include <sys/wait.h>
1012

13+
extern char **environ;
14+
1115
int main(int argc, char **argv) {
1216
if (argc > 1) {
1317
// CHECK: SPAWNED
@@ -23,11 +27,22 @@ int main(int argc, char **argv) {
2327
argv[0], "2", "3", "4", "2", "3", "4", "2", "3", "4",
2428
"2", "3", "4", "2", "3", "4", "2", "3", "4", NULL,
2529
};
26-
char *const env[] = {
30+
char *env[] = {
2731
"A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B",
2832
"A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", NULL,
2933
};
3034

35+
// When this test runs with a runtime (e.g. ASAN), the spawned process needs
36+
// to use the same runtime search path as the parent. Otherwise, it might
37+
// try to load a runtime that doesn't work and crash before hitting main(),
38+
// failing the test. We technically should forward the variable for the
39+
// current platform, but some platforms have multiple such variables and
40+
// it's quite difficult to plumb this through the lit config.
41+
for (char **e = environ; *e; e++)
42+
if (strncmp(*e, "DYLD_LIBRARY_PATH=", sizeof("DYLD_LIBRARY_PATH=") - 1) ==
43+
0)
44+
env[0] = *e;
45+
3146
pid_t pid;
3247
int s = posix_spawn(&pid, argv[0], &file_actions, &attr, args, env);
3348
assert(!s);

llvm/utils/lit/lit/TestRunner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,8 @@ def executeScriptInternal(
11241124
results = []
11251125
timeoutInfo = None
11261126
shenv = ShellEnvironment(cwd, test.config.environment)
1127+
shenv.env["LIT_CURRENT_TESTCASE"] = test.getFullName()
1128+
11271129
exitCode, timeoutInfo = executeShCmd(
11281130
cmd, shenv, results, timeout=litConfig.maxIndividualTestTime
11291131
)
@@ -1323,11 +1325,13 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
13231325
# run on clang with no real loss.
13241326
command = litConfig.valgrindArgs + command
13251327

1328+
env = dict(test.config.environment)
1329+
env["LIT_CURRENT_TESTCASE"] = test.getFullName()
13261330
try:
13271331
out, err, exitCode = lit.util.executeCommand(
13281332
command,
13291333
cwd=cwd,
1330-
env=test.config.environment,
1334+
env=env,
13311335
timeout=litConfig.maxIndividualTestTime,
13321336
)
13331337
return (out, err, exitCode, None)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Tests that the LIT_CURRENT_TESTCASE variable is set to the name of the currently executing testcase
2+
3+
## Check default environment.
4+
# RUN: bash -c 'echo $LIT_CURRENT_TESTCASE' | FileCheck --match-full-lines %s
5+
#
6+
# CHECK: shtest-env :: env-current-testcase.txt

llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Tests the env command in various scenarios: without arguments, setting, unsetting, and mixing envrionment variables.
2+
# FIXME: All of these tests are broken and will not even call FileCheck.
23

34
## Check default environment.
45
# RUN: env | FileCheck -check-prefix=NO-ARGS %s

llvm/utils/lit/tests/shtest-env-positive.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Test the env command's successful executions.
99

10-
# CHECK: -- Testing: 9 tests{{.*}}
10+
# CHECK: -- Testing: 10 tests{{.*}}
1111

1212
# CHECK: PASS: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
1313
# CHECK: env FOO=1
@@ -39,6 +39,11 @@
3939
# CHECK-NOT: # error:
4040
# CHECK: --
4141

42+
# CHECK: PASS: shtest-env :: env-current-testcase.txt ({{[^)]*}})
43+
# CHECK: # executed command: bash -c 'echo $LIT_CURRENT_TESTCASE'
44+
# CHECK-NOT: # error:
45+
# CHECK: --
46+
4247
# CHECK: PASS: shtest-env :: env-no-subcommand.txt ({{[^)]*}})
4348
# CHECK: env | {{.*}}
4449
# CHECK: # executed command: env
@@ -65,6 +70,6 @@
6570
# CHECK-NOT: # error:
6671
# CHECK: --
6772

68-
# CHECK: Total Discovered Tests: 9
69-
# CHECK: Passed: 9 {{\([0-9]*\.[0-9]*%\)}}
73+
# CHECK: Total Discovered Tests: 10
74+
# CHECK: Passed: 10 {{\([0-9]*\.[0-9]*%\)}}
7075
# CHECK-NOT: {{.}}

0 commit comments

Comments
 (0)