3
3
# You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
"""ffpuppet helpers tests"""
5
5
6
- from contextlib import suppress
7
6
from os import getpid
8
7
from pathlib import Path
9
8
from subprocess import CalledProcessError
26
25
27
26
def test_helpers_01 (tmp_path ):
28
27
"""test _configure_sanitizers()"""
29
-
30
- def parse (opt_str ):
31
- opts = {}
32
- for entry in SanitizerOptions .re_delim .split (opt_str ):
33
- with suppress (ValueError ):
34
- key , value = entry .split ("=" , maxsplit = 1 )
35
- opts [key ] = value
36
- return opts
37
-
38
28
# test with empty environment
39
- env = {}
40
- env = _configure_sanitizers (env , tmp_path , "blah" )
29
+ env = _configure_sanitizers ({}, tmp_path , "blah" )
41
30
assert "ASAN_OPTIONS" in env
42
- asan_opts = parse (env ["ASAN_OPTIONS" ])
43
- assert "external_symbolizer_path" not in asan_opts
44
- assert "detect_leaks" in asan_opts
45
- assert asan_opts ["detect_leaks" ] == "false"
46
- assert asan_opts ["log_path" ] == "'blah'"
31
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
32
+ assert opts .get ("external_symbolizer_path" ) is None
33
+ assert opts .get ("detect_leaks" ) == "false"
34
+ assert opts .get ("log_path" ) == "'blah'"
47
35
assert "LSAN_OPTIONS" in env
48
36
assert "UBSAN_OPTIONS" in env
49
37
# test with presets environment
50
- env = {
51
- "ASAN_OPTIONS" : "detect_leaks=true" ,
52
- "LSAN_OPTIONS" : "a=1" ,
53
- "UBSAN_OPTIONS" : "" ,
54
- }
55
- env = _configure_sanitizers (env , tmp_path , "blah" )
38
+ env = _configure_sanitizers (
39
+ {
40
+ "ASAN_OPTIONS" : "detect_leaks=true" ,
41
+ "LSAN_OPTIONS" : "a=1" ,
42
+ "UBSAN_OPTIONS" : "" ,
43
+ },
44
+ tmp_path ,
45
+ "blah" ,
46
+ )
56
47
assert "ASAN_OPTIONS" in env
57
- asan_opts = parse (env ["ASAN_OPTIONS" ])
58
- assert "detect_leaks" in asan_opts
59
- assert asan_opts ["detect_leaks" ] == "true"
48
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
49
+ assert opts .get ("detect_leaks" ) == "true"
60
50
assert "LSAN_OPTIONS" in env
61
51
assert "UBSAN_OPTIONS" in env
62
- ubsan_opts = parse (env ["UBSAN_OPTIONS" ])
63
- assert "print_stacktrace" in ubsan_opts
52
+ opts = SanitizerOptions (env ["UBSAN_OPTIONS" ])
53
+ assert opts . get ( "print_stacktrace" ) is not None
64
54
# test suppression file
65
55
sup = tmp_path / "test.sup"
66
56
sup .touch ()
67
- env = {"ASAN_OPTIONS" : f"suppressions='{ sup } '" }
68
- env = _configure_sanitizers (env , tmp_path , "blah" )
69
- asan_opts = parse (env ["ASAN_OPTIONS" ])
70
- assert "suppressions" in asan_opts
57
+ env = _configure_sanitizers (
58
+ {"ASAN_OPTIONS" : f"suppressions='{ sup } '" }, tmp_path , "blah"
59
+ )
60
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
61
+ assert opts .get ("suppressions" ) is not None
71
62
# test overwrite log_path
72
- env = {
73
- "ASAN_OPTIONS" : "log_path='overwrite'" ,
74
- "TSAN_OPTIONS" : "log_path='overwrite'" ,
75
- "UBSAN_OPTIONS" : "log_path='overwrite'" ,
76
- }
77
- env = _configure_sanitizers (env , tmp_path , "blah" )
63
+ env = _configure_sanitizers (
64
+ {
65
+ "ASAN_OPTIONS" : "log_path='overwrite'" ,
66
+ "TSAN_OPTIONS" : "log_path='overwrite'" ,
67
+ "UBSAN_OPTIONS" : "log_path='overwrite'" ,
68
+ },
69
+ tmp_path ,
70
+ "blah" ,
71
+ )
78
72
assert "ASAN_OPTIONS" in env
79
- asan_opts = parse (env ["ASAN_OPTIONS" ])
80
- assert asan_opts [ "log_path" ] == "'blah'"
73
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
74
+ assert opts . get ( "log_path" ) == "'blah'"
81
75
assert "UBSAN_OPTIONS" in env
82
- ubsan_opts = parse (env ["UBSAN_OPTIONS" ])
83
- assert ubsan_opts [ "log_path" ] == "'blah'"
76
+ opts = SanitizerOptions (env ["UBSAN_OPTIONS" ])
77
+ assert opts . get ( "log_path" ) == "'blah'"
84
78
# test missing suppression file
85
- env = {"ASAN_OPTIONS" : "suppressions=not_a_file" }
86
79
with raises (AssertionError , match = "missing suppressions file" ):
87
- _configure_sanitizers (env , tmp_path , "blah" )
80
+ _configure_sanitizers (
81
+ {"ASAN_OPTIONS" : "suppressions=not_a_file" }, tmp_path , "blah"
82
+ )
88
83
# unquoted path containing ':'
89
- env = {"ASAN_OPTIONS" : "strip_path_prefix=x:\\ foo\\ bar" }
90
- with raises (AssertionError , match = r"\(strip_path_prefix\) must be quoted" ):
91
- _configure_sanitizers (env , tmp_path , "blah" )
84
+ with raises (ValueError , match = r"\(strip_path_prefix\) must be quoted" ):
85
+ _configure_sanitizers (
86
+ {"ASAN_OPTIONS" : "strip_path_prefix=x:\\ foo\\ bar" }, tmp_path , "blah"
87
+ )
92
88
# multiple options
93
89
options = (
94
90
"opt1=1" ,
@@ -100,34 +96,29 @@ def parse(opt_str):
100
96
"opt7='/with space/'" ,
101
97
"opt8='x:\\ with a space\\ or two'" ,
102
98
)
103
- env = {"ASAN_OPTIONS" : ":" .join (options )}
104
- env = _configure_sanitizers (env , tmp_path , "blah" )
105
- asan_opts = parse (env ["ASAN_OPTIONS" ])
99
+ env = _configure_sanitizers ({"ASAN_OPTIONS" : ":" .join (options )}, tmp_path , "blah" )
100
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
106
101
for key , value in (x .split (sep = "=" , maxsplit = 1 ) for x in options ):
107
- assert asan_opts [ key ] == value
102
+ assert opts . get ( key ) == value
108
103
# test using packaged llvm-symbolizer
109
104
llvm_sym_packed = tmp_path / LLVM_SYMBOLIZER
110
105
llvm_sym_packed .touch ()
111
- env = {"ASAN_OPTIONS" : ":" .join (options )}
112
- env = _configure_sanitizers (env , tmp_path , "blah" )
113
- asan_opts = parse (env ["ASAN_OPTIONS" ])
114
- assert "external_symbolizer_path" in asan_opts
115
- assert asan_opts ["external_symbolizer_path" ].strip ("'" ) == str (llvm_sym_packed )
106
+ env = _configure_sanitizers ({"ASAN_OPTIONS" : ":" .join (options )}, tmp_path , "blah" )
107
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
108
+ assert opts .get ("external_symbolizer_path" ).strip ("'" ) == str (llvm_sym_packed )
116
109
# test malformed option pair
117
- env = {"ASAN_OPTIONS" : "a=b=c:x" }
118
- env = _configure_sanitizers (env , tmp_path , "blah" )
119
- asan_opts = parse (env ["ASAN_OPTIONS" ])
120
- assert asan_opts ["a" ] == "b=c"
121
- assert "x" not in asan_opts
110
+ env = _configure_sanitizers ({"ASAN_OPTIONS" : "a=b=c:malformed" }, tmp_path , "blah" )
111
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
112
+ assert opts .get ("a" ) == "b=c"
113
+ assert "malformed" not in str (opts )
122
114
# test ASAN_SYMBOLIZER_PATH
123
115
(tmp_path / "a" ).mkdir ()
124
116
llvm_sym_a = tmp_path / "a" / "llvm-symbolizer"
125
117
llvm_sym_a .touch ()
126
118
env = {"ASAN_SYMBOLIZER_PATH" : str (llvm_sym_a )}
127
119
env = _configure_sanitizers (env , tmp_path , "blah" )
128
- asan_opts = parse (env ["ASAN_OPTIONS" ])
129
- assert "external_symbolizer_path" in asan_opts
130
- assert asan_opts ["external_symbolizer_path" ].strip ("'" ) == str (llvm_sym_a )
120
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
121
+ assert opts .get ("external_symbolizer_path" ).strip ("'" ) == str (llvm_sym_a )
131
122
# test ASAN_SYMBOLIZER_PATH override by ASAN_OPTIONS=external_symbolizer_path
132
123
(tmp_path / "b" ).mkdir ()
133
124
llvm_sym_b = tmp_path / "b" / "llvm-symbolizer"
@@ -137,9 +128,8 @@ def parse(opt_str):
137
128
"ASAN_OPTIONS" : f"external_symbolizer_path='{ llvm_sym_b } '" ,
138
129
}
139
130
env = _configure_sanitizers (env , tmp_path , "blah" )
140
- asan_opts = parse (env ["ASAN_OPTIONS" ])
141
- assert "external_symbolizer_path" in asan_opts
142
- assert asan_opts ["external_symbolizer_path" ].strip ("'" ) == str (llvm_sym_b )
131
+ opts = SanitizerOptions (env ["ASAN_OPTIONS" ])
132
+ assert opts .get ("external_symbolizer_path" ).strip ("'" ) == str (llvm_sym_b )
143
133
144
134
145
135
def test_helpers_02 (tmp_path ):
0 commit comments