@@ -193,6 +193,8 @@ const INPUT_FOR_HIP_A: &str = "test_a.hip";
193193const  INPUT_FOR_HIP_B :  & str  = "test_b.hip" ; 
194194const  INPUT_FOR_HIP_C :  & str  = "test_c.hip" ; 
195195const  OUTPUT :  & str  = "test.o" ; 
196+ const  DEV_NULL :  & str  = "/dev/null" ; 
197+ const  DEV_STDOUT :  & str  = "/dev/stdout" ; 
196198
197199// Copy the source files into the tempdir so we can compile with relative paths, since the commandline winds up in the hash key. 
198200fn  copy_to_tempdir ( inputs :  & [ & str ] ,  tempdir :  & Path )  { 
@@ -263,6 +265,120 @@ fn test_basic_compile(compiler: Compiler, tempdir: &Path) {
263265    } ) ; 
264266} 
265267
268+ #[ cfg( unix) ]  
269+ fn  test_basic_compile_into_dev_null ( compiler :  Compiler ,  tempdir :  & Path )  { 
270+     let  Compiler  { 
271+         name, 
272+         exe, 
273+         env_vars, 
274+     }  = compiler; 
275+     println ! ( "test_basic_compile: {}" ,  name) ; 
276+     // Compile a source file. 
277+     copy_to_tempdir ( & [ INPUT ,  INPUT_ERR ] ,  tempdir) ; 
278+ 
279+     let  out_file = tempdir. join ( OUTPUT ) ; 
280+     trace ! ( "compile" ) ; 
281+     sccache_command ( ) 
282+         . args ( compile_cmdline ( name,  & exe,  INPUT ,  DEV_NULL ,  Vec :: new ( ) ) ) 
283+         . current_dir ( tempdir) 
284+         . envs ( env_vars. clone ( ) ) 
285+         . assert ( ) 
286+         . success ( ) ; 
287+     trace ! ( "request stats" ) ; 
288+     get_stats ( |info| { 
289+         assert_eq ! ( 1 ,  info. stats. compile_requests) ; 
290+         assert_eq ! ( 1 ,  info. stats. requests_executed) ; 
291+         assert_eq ! ( 0 ,  info. stats. cache_hits. all( ) ) ; 
292+         assert_eq ! ( 1 ,  info. stats. cache_misses. all( ) ) ; 
293+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get( "C/C++" ) . unwrap( ) ) ; 
294+         let  adv_key = adv_key_kind ( "c" ,  compiler. name ) ; 
295+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get_adv( & adv_key) . unwrap( ) ) ; 
296+     } ) ; 
297+     trace ! ( "compile" ) ; 
298+     fs:: remove_file ( & out_file) . unwrap ( ) ; 
299+     sccache_command ( ) 
300+         . args ( compile_cmdline ( name,  & exe,  INPUT ,  DEV_NULL ,  Vec :: new ( ) ) ) 
301+         . current_dir ( tempdir) 
302+         . envs ( env_vars) 
303+         . assert ( ) 
304+         . success ( ) ; 
305+     assert ! ( fs:: metadata( & out_file) . map( |m| m. len( )  > 0 ) . unwrap( ) ) ; 
306+     trace ! ( "request stats" ) ; 
307+     get_stats ( |info| { 
308+         assert_eq ! ( 2 ,  info. stats. compile_requests) ; 
309+         assert_eq ! ( 2 ,  info. stats. requests_executed) ; 
310+         assert_eq ! ( 1 ,  info. stats. cache_hits. all( ) ) ; 
311+         assert_eq ! ( 1 ,  info. stats. cache_misses. all( ) ) ; 
312+         assert_eq ! ( & 1 ,  info. stats. cache_hits. get( "C/C++" ) . unwrap( ) ) ; 
313+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get( "C/C++" ) . unwrap( ) ) ; 
314+         let  adv_key = adv_key_kind ( "c" ,  compiler. name ) ; 
315+         assert_eq ! ( & 1 ,  info. stats. cache_hits. get_adv( & adv_key) . unwrap( ) ) ; 
316+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get_adv( & adv_key) . unwrap( ) ) ; 
317+     } ) ; 
318+ } 
319+ 
320+ #[ cfg( not( unix) ) ]  
321+ fn  test_basic_compile_into_dev_null ( _:  Compiler ,  _:  & Path )  { 
322+     warn ! ( "Not unix, skipping /dev tests" ) ; 
323+ } 
324+ 
325+ #[ cfg( unix) ]  
326+ fn  test_basic_compile_into_dev_stdout ( compiler :  Compiler ,  tempdir :  & Path )  { 
327+     let  Compiler  { 
328+         name, 
329+         exe, 
330+         env_vars, 
331+     }  = compiler; 
332+     println ! ( "test_basic_compile: {}" ,  name) ; 
333+     // Compile a source file. 
334+     copy_to_tempdir ( & [ INPUT ,  INPUT_ERR ] ,  tempdir) ; 
335+ 
336+     let  out_file = tempdir. join ( OUTPUT ) ; 
337+     trace ! ( "compile" ) ; 
338+     sccache_command ( ) 
339+         . args ( compile_cmdline ( name,  & exe,  INPUT ,  DEV_STDOUT ,  Vec :: new ( ) ) ) 
340+         . current_dir ( tempdir) 
341+         . envs ( env_vars. clone ( ) ) 
342+         . assert ( ) 
343+         . success ( ) ; 
344+     trace ! ( "request stats" ) ; 
345+     get_stats ( |info| { 
346+         assert_eq ! ( 1 ,  info. stats. compile_requests) ; 
347+         assert_eq ! ( 1 ,  info. stats. requests_executed) ; 
348+         assert_eq ! ( 0 ,  info. stats. cache_hits. all( ) ) ; 
349+         assert_eq ! ( 1 ,  info. stats. cache_misses. all( ) ) ; 
350+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get( "C/C++" ) . unwrap( ) ) ; 
351+         let  adv_key = adv_key_kind ( "c" ,  compiler. name ) ; 
352+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get_adv( & adv_key) . unwrap( ) ) ; 
353+     } ) ; 
354+     trace ! ( "compile" ) ; 
355+     fs:: remove_file ( & out_file) . unwrap ( ) ; 
356+     sccache_command ( ) 
357+         . args ( compile_cmdline ( name,  & exe,  INPUT ,  DEV_STDOUT ,  Vec :: new ( ) ) ) 
358+         . current_dir ( tempdir) 
359+         . envs ( env_vars) 
360+         . assert ( ) 
361+         . success ( ) ; 
362+     assert ! ( fs:: metadata( & out_file) . map( |m| m. len( )  > 0 ) . unwrap( ) ) ; 
363+     trace ! ( "request stats" ) ; 
364+     get_stats ( |info| { 
365+         assert_eq ! ( 2 ,  info. stats. compile_requests) ; 
366+         assert_eq ! ( 2 ,  info. stats. requests_executed) ; 
367+         assert_eq ! ( 1 ,  info. stats. cache_hits. all( ) ) ; 
368+         assert_eq ! ( 1 ,  info. stats. cache_misses. all( ) ) ; 
369+         assert_eq ! ( & 1 ,  info. stats. cache_hits. get( "C/C++" ) . unwrap( ) ) ; 
370+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get( "C/C++" ) . unwrap( ) ) ; 
371+         let  adv_key = adv_key_kind ( "c" ,  compiler. name ) ; 
372+         assert_eq ! ( & 1 ,  info. stats. cache_hits. get_adv( & adv_key) . unwrap( ) ) ; 
373+         assert_eq ! ( & 1 ,  info. stats. cache_misses. get_adv( & adv_key) . unwrap( ) ) ; 
374+     } ) ; 
375+ } 
376+ 
377+ #[ cfg( not( unix) ) ]  
378+ fn  test_basic_compile_into_dev_stdout ( _:  Compiler ,  _:  & Path )  { 
379+     warn ! ( "Not unix, skipping /dev tests" ) ; 
380+ } 
381+ 
266382fn  test_noncacheable_stats ( compiler :  Compiler ,  tempdir :  & Path )  { 
267383    let  Compiler  { 
268384        name, 
@@ -629,6 +745,8 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_ca
629745        test_basic_compile ( compiler. clone ( ) ,  tempdir) ; 
630746    } 
631747    test_compile_with_define ( compiler. clone ( ) ,  tempdir) ; 
748+     test_basic_compile_into_dev_null ( compiler. clone ( ) ,  tempdir) ; 
749+     test_basic_compile_into_dev_stdout ( compiler. clone ( ) ,  tempdir) ; 
632750    if  compiler. name  == "cl.exe"  { 
633751        test_msvc_deps ( compiler. clone ( ) ,  tempdir) ; 
634752        test_msvc_responsefile ( compiler. clone ( ) ,  tempdir) ; 
0 commit comments