@@ -33,6 +33,22 @@ class TestConfigChecks(unittest.TestCase):
33
33
# to say.
34
34
maxDiff = 9999
35
35
36
+ def setUp (self ) -> None :
37
+ self .cpp_output = None #type: Optional[str]
38
+
39
+ def tearDown (self ) -> None :
40
+ """Log the preprocessor output to a file, if available and desired.
41
+
42
+ This is intended for debugging. It only happens if the environment
43
+ variable UNITTEST_CONFIG_CHECKS_DEBUG is non-empty.
44
+ """
45
+ if os .getenv ('UNITTEST_CONFIG_CHECKS_DEBUG' ):
46
+ if self .cpp_output is not None :
47
+ basename = os .path .splitext (os .path .basename (sys .argv [0 ]))[0 ]
48
+ filename = f'{ basename } .{ self ._testMethodName } .out.txt'
49
+ with open (filename , 'w' ) as out :
50
+ out .write (self .cpp_output )
51
+
36
52
def user_config_file_name (self , variant : str ) -> str :
37
53
"""Construct a unique temporary file name for a user config header."""
38
54
name = os .path .splitext (os .path .basename (sys .argv [0 ]))[0 ]
@@ -69,6 +85,8 @@ def run_with_config_files(self,
69
85
stdout and stderr.
70
86
"""
71
87
cmd = ['cpp' ]
88
+ if os .getenv ('UNITTEST_CONFIG_CHECKS_DEBUG' ):
89
+ cmd += ['-dD' ]
72
90
if crypto_user_config_file is not None :
73
91
cmd .append (f'-DTF_PSA_CRYPTO_USER_CONFIG_FILE="{ crypto_user_config_file } "' )
74
92
if mbedtls_user_config_file is not None :
@@ -135,8 +153,10 @@ def good_case(self,
135
153
"""
136
154
cp = self .run_with_config (crypto_user_config , mbedtls_user_config ,
137
155
extra_options = extra_options )
156
+ self .cpp_output = cp .stdout
138
157
self .assertEqual (cp .stderr , '' )
139
158
self .assertEqual (cp .returncode , 0 )
159
+ self .cpp_output = None
140
160
141
161
def bad_case (self ,
142
162
crypto_user_config : Optional [str ],
@@ -152,10 +172,12 @@ def bad_case(self,
152
172
"""
153
173
cp = self .run_with_config (crypto_user_config , mbedtls_user_config ,
154
174
extra_options = extra_options )
175
+ self .cpp_output = cp .stdout
155
176
if error is not None :
156
177
self .assertRegex (cp .stderr , error )
157
178
self .assertGreater (cp .returncode , 0 )
158
179
self .assertLess (cp .returncode , 126 )
180
+ self .cpp_output = None
159
181
160
182
def test_nominal (self ) -> None :
161
183
self .good_case (None )
0 commit comments