@@ -163,52 +163,61 @@ impl LanguagePlugin for MakePlugin {
163
163
} ) ;
164
164
}
165
165
166
+ // try to clean old log file if any
167
+ let base_test_path = path. join ( "test" ) ;
168
+ let valgrind_log_path = base_test_path. join ( "valgrind.log" ) ;
169
+ let _ = file_util:: remove_file ( & valgrind_log_path) ;
170
+
166
171
// try to run valgrind
167
172
let mut ran_valgrind = true ;
168
173
let valgrind_run = self . run_tests_with_valgrind ( path, true ) ;
169
174
let output = match valgrind_run {
170
175
Ok ( output) => output,
171
- Err ( error) => match error {
172
- MakeError :: Tmc ( TmcError :: Command ( command_error) ) => {
173
- match command_error {
174
- CommandError :: Popen ( _, PopenError :: IoError ( io_error) )
175
- | CommandError :: FailedToRun ( _, PopenError :: IoError ( io_error) )
176
- if io_error. kind ( ) == io:: ErrorKind :: PermissionDenied =>
177
- {
178
- // failed due to lacking permissions, try to clean and rerun
179
- self . clean ( path) ?;
180
- match self . run_tests_with_valgrind ( path, false ) {
181
- Ok ( output) => output,
182
- Err ( err) => {
183
- log:: error!(
176
+ Err ( error) => {
177
+ if let Ok ( valgrind_log) = file_util:: read_file_to_string_lossy ( & valgrind_log_path) {
178
+ log:: warn!( "Failed to run valgrind but a valgrind.log exists: {valgrind_log}" ) ;
179
+ }
180
+ match error {
181
+ MakeError :: Tmc ( TmcError :: Command ( command_error) ) => {
182
+ match command_error {
183
+ CommandError :: Popen ( _, PopenError :: IoError ( io_error) )
184
+ | CommandError :: FailedToRun ( _, PopenError :: IoError ( io_error) )
185
+ if io_error. kind ( ) == io:: ErrorKind :: PermissionDenied =>
186
+ {
187
+ // failed due to lacking permissions, try to clean and rerun
188
+ self . clean ( path) ?;
189
+ match self . run_tests_with_valgrind ( path, false ) {
190
+ Ok ( output) => output,
191
+ Err ( err) => {
192
+ log:: error!(
184
193
"Running with valgrind failed after trying to clean! {}" ,
185
194
err
186
195
) ;
187
- ran_valgrind = false ;
188
- log:: info!( "Running without valgrind" ) ;
189
- self . run_tests_with_valgrind ( path, false ) ?
196
+ ran_valgrind = false ;
197
+ log:: info!( "Running without valgrind" ) ;
198
+ self . run_tests_with_valgrind ( path, false ) ?
199
+ }
190
200
}
191
201
}
192
- }
193
- _ => {
194
- ran_valgrind = false ;
195
- log :: info! ( "Running without valgrind" ) ;
196
- self . run_tests_with_valgrind ( path , false ) ?
202
+ _ => {
203
+ ran_valgrind = false ;
204
+ log :: info! ( "Running without valgrind" ) ;
205
+ self . run_tests_with_valgrind ( path , false ) ?
206
+ }
197
207
}
198
208
}
209
+ MakeError :: RunningTestsWithValgrind ( ..) => {
210
+ ran_valgrind = false ;
211
+ log:: info!( "Running without valgrind" ) ;
212
+ self . run_tests_with_valgrind ( path, false ) ?
213
+ }
214
+ err => {
215
+ log:: warn!( "unexpected error {:?}" , err) ;
216
+ return Err ( err. into ( ) ) ;
217
+ }
199
218
}
200
- MakeError :: RunningTestsWithValgrind ( ..) => {
201
- ran_valgrind = false ;
202
- log:: info!( "Running without valgrind" ) ;
203
- self . run_tests_with_valgrind ( path, false ) ?
204
- }
205
- err => {
206
- log:: warn!( "unexpected error {:?}" , err) ;
207
- return Err ( err. into ( ) ) ;
208
- }
209
- } ,
219
+ }
210
220
} ;
211
- let base_test_path = path. join ( "test" ) ;
212
221
213
222
// fails on valgrind by default
214
223
let fail_on_valgrind_error = match TmcProjectYml :: load_or_default ( path) {
@@ -218,8 +227,7 @@ impl LanguagePlugin for MakePlugin {
218
227
219
228
// valgrind logs are only interesting if fail on valgrind error is on
220
229
let valgrind_log = if ran_valgrind && fail_on_valgrind_error {
221
- let valgrind_path = base_test_path. join ( "valgrind.log" ) ;
222
- Some ( ValgrindLog :: from ( & valgrind_path) ?)
230
+ Some ( ValgrindLog :: from ( & valgrind_log_path) ?)
223
231
} else {
224
232
None
225
233
} ;
0 commit comments