2
2
3
3
This tests the output of ``generate_config_checks.py``.
4
4
This can also let us verify what we enforce in the manually written
5
- checks in ``<PROJECT>_check_config.h``.
5
+ checks in ``<PROJECT>_check_config.h`` and ``<PROJECT>_config.c`` .
6
6
"""
7
7
8
8
## Copyright The Mbed TLS Contributors
@@ -29,27 +29,27 @@ class TestConfigChecks(unittest.TestCase):
29
29
PROJECT_SPECIFIC_INCLUDE_DIRECTORIES = [] #type: List[str]
30
30
31
31
# Increase the length of strings that assertion failures are willing to
32
- # print. This is useful for failures where the preprocessor has a lot
32
+ # print. This is useful for failures where the compiler has a lot
33
33
# to say.
34
34
maxDiff = 9999
35
35
36
36
def setUp (self ) -> None :
37
- self .cpp_output = None #type: Optional[str]
37
+ self .cc_output = None #type: Optional[str]
38
38
39
39
def tearDown (self ) -> None :
40
- """Log the preprocessor output to a file, if available and desired.
40
+ """Log the compiler output to a file, if available and desired.
41
41
42
42
This is intended for debugging. It only happens if the environment
43
43
variable UNITTEST_CONFIG_CHECKS_DEBUG is non-empty.
44
44
"""
45
45
if os .getenv ('UNITTEST_CONFIG_CHECKS_DEBUG' ):
46
- # We set self.cpp_output to the preprocessor output before
46
+ # We set self.cc_output to the compiler output before
47
47
# asserting, and set it to None if all the assertions pass.
48
- if self .cpp_output is not None :
48
+ if self .cc_output is not None :
49
49
basename = os .path .splitext (os .path .basename (sys .argv [0 ]))[0 ]
50
50
filename = f'{ basename } .{ self ._testMethodName } .out.txt'
51
51
with open (filename , 'w' ) as out :
52
- out .write (self .cpp_output )
52
+ out .write (self .cc_output )
53
53
54
54
def user_config_file_name (self , variant : str ) -> str :
55
55
"""Construct a unique temporary file name for a user config header."""
@@ -81,12 +81,12 @@ def run_with_config_files(self,
81
81
mbedtls_user_config_file : Optional [str ],
82
82
extra_options : List [str ],
83
83
) -> subprocess .CompletedProcess :
84
- """Run cpp with the given user configuration files.
84
+ """Run cc with the given user configuration files.
85
85
86
86
Return the CompletedProcess object capturing the return code,
87
87
stdout and stderr.
88
88
"""
89
- cmd = ['cpp' ]
89
+ cmd = [os . getenv ( 'CC' , 'cc' ) ]
90
90
if os .getenv ('UNITTEST_CONFIG_CHECKS_DEBUG' ):
91
91
cmd += ['-dD' ]
92
92
if crypto_user_config_file is not None :
@@ -99,7 +99,7 @@ def run_with_config_files(self,
99
99
cmd += ['-Iinclude' ,
100
100
'-I.' ,
101
101
'-I' + os .path .dirname (self .PROJECT_CONFIG_C )]
102
- cmd . append ( self .PROJECT_CONFIG_C )
102
+ cmd += [ '-o' , os . devnull , '-c' , self .PROJECT_CONFIG_C ]
103
103
return subprocess .run (cmd ,
104
104
check = False ,
105
105
encoding = 'utf-8' ,
@@ -111,7 +111,7 @@ def run_with_config(self,
111
111
mbedtls_user_config : Optional [str ] = None ,
112
112
extra_options : Optional [List [str ]] = None ,
113
113
) -> subprocess .CompletedProcess :
114
- """Run cpp with the given content for user configuration files.
114
+ """Run cc with the given content for user configuration files.
115
115
116
116
Return the CompletedProcess object capturing the return code,
117
117
stdout and stderr.
@@ -149,41 +149,41 @@ def good_case(self,
149
149
mbedtls_user_config : Optional [str ] = None ,
150
150
extra_options : Optional [List [str ]] = None ,
151
151
) -> None :
152
- """Run cpp with the given user config(s). Expect no error.
152
+ """Run cc with the given user config(s). Expect no error.
153
153
154
- Pass extra_options on the command line of cpp .
154
+ Pass extra_options on the command line of cc .
155
155
"""
156
156
cp = self .run_with_config (crypto_user_config , mbedtls_user_config ,
157
157
extra_options = extra_options )
158
158
# Assert the error text before the status. That way, if it fails,
159
159
# we see the unexpected error messages in the test log.
160
- self .cpp_output = cp .stdout
160
+ self .cc_output = cp .stdout
161
161
self .assertEqual (cp .stderr , '' )
162
162
self .assertEqual (cp .returncode , 0 )
163
- self .cpp_output = None
163
+ self .cc_output = None
164
164
165
165
def bad_case (self ,
166
166
crypto_user_config : Optional [str ],
167
167
mbedtls_user_config : Optional [str ] = None ,
168
168
error : Optional [Union [str , Pattern ]] = None ,
169
169
extra_options : Optional [List [str ]] = None ,
170
170
) -> None :
171
- """Run cpp with the given user config(s). Expect errors.
171
+ """Run cc with the given user config(s). Expect errors.
172
172
173
- Pass extra_options on the command line of cpp .
173
+ Pass extra_options on the command line of cc .
174
174
175
- If error is given, the standard error from cpp must match this regex.
175
+ If error is given, the standard error from cc must match this regex.
176
176
"""
177
177
cp = self .run_with_config (crypto_user_config , mbedtls_user_config ,
178
178
extra_options = extra_options )
179
- self .cpp_output = cp .stdout
179
+ self .cc_output = cp .stdout
180
180
if error is not None :
181
181
# Assert the error text before the status. That way, if it fails,
182
182
# we see the unexpected error messages in the test log.
183
183
self .assertRegex (cp .stderr , error )
184
184
self .assertGreater (cp .returncode , 0 )
185
185
self .assertLess (cp .returncode , 126 )
186
- self .cpp_output = None
186
+ self .cc_output = None
187
187
188
188
# Nominal case, run first
189
189
def test_01_nominal (self ) -> None :
0 commit comments