@@ -454,6 +454,73 @@ int main(int argc, char** argv) {
454
454
} ) ;
455
455
}
456
456
457
+ /* test case like this:
458
+ echo "int test(){}" > test.cc
459
+ mkdir o1 o2
460
+ sccache g++ -c -g -gsplit-dwarf test.cc -o test1.o
461
+ sccache g++ -c -g -gsplit-dwarf test.cc -o test1.o --- > cache hit
462
+ sccache g++ -c -g -gsplit-dwarf test.cc -o test2.o --- > cache miss
463
+ strings test2.o |grep test2.dwo
464
+ */
465
+ fn test_split_dwarf_object_generate_output_dir_changes ( compiler : Compiler , tempdir : & Path ) {
466
+ let Compiler {
467
+ name,
468
+ exe,
469
+ env_vars,
470
+ } = compiler;
471
+ trace ! ( "test -g -gsplit-dwarf with different output" ) ;
472
+ zero_stats ( ) ;
473
+ const SRC : & str = "source.c" ;
474
+ write_source ( tempdir, SRC , "int test(){}" ) ;
475
+ let mut args = compile_cmdline ( name, exe. clone ( ) , SRC , "test1.o" , Vec :: new ( ) ) ;
476
+ args. extend ( vec_from ! ( OsString , "-g" ) ) ;
477
+ args. extend ( vec_from ! ( OsString , "-gsplit-dwarf" ) ) ;
478
+ trace ! ( "compile source.c (1)" ) ;
479
+ sccache_command ( )
480
+ . args ( & args)
481
+ . current_dir ( tempdir)
482
+ . envs ( env_vars. clone ( ) )
483
+ . assert ( )
484
+ . success ( ) ;
485
+ get_stats ( |info| {
486
+ assert_eq ! ( 0 , info. stats. cache_hits. all( ) ) ;
487
+ assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
488
+ assert_eq ! ( & 1 , info. stats. cache_misses. get( "C/C++" ) . unwrap( ) ) ;
489
+ } ) ;
490
+ // Compile the same source again to ensure we can get a cache hit.
491
+ trace ! ( "compile source.c (2)" ) ;
492
+ sccache_command ( )
493
+ . args ( & args)
494
+ . current_dir ( tempdir)
495
+ . envs ( env_vars. clone ( ) )
496
+ . assert ( )
497
+ . success ( ) ;
498
+ get_stats ( |info| {
499
+ assert_eq ! ( 1 , info. stats. cache_hits. all( ) ) ;
500
+ assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
501
+ assert_eq ! ( & 1 , info. stats. cache_hits. get( "C/C++" ) . unwrap( ) ) ;
502
+ assert_eq ! ( & 1 , info. stats. cache_misses. get( "C/C++" ) . unwrap( ) ) ;
503
+ } ) ;
504
+ // Compile the same source again with different output
505
+ // to ensure we can force generate new object file.
506
+ let mut args2 = compile_cmdline ( name, exe, SRC , "test2.o" , Vec :: new ( ) ) ;
507
+ args2. extend ( vec_from ! ( OsString , "-g" ) ) ;
508
+ args2. extend ( vec_from ! ( OsString , "-gsplit-dwarf" ) ) ;
509
+ trace ! ( "compile source.c (2)" ) ;
510
+ sccache_command ( )
511
+ . args ( & args2)
512
+ . current_dir ( tempdir)
513
+ . envs ( env_vars. clone ( ) )
514
+ . assert ( )
515
+ . success ( ) ;
516
+ get_stats ( |info| {
517
+ assert_eq ! ( 1 , info. stats. cache_hits. all( ) ) ;
518
+ assert_eq ! ( 2 , info. stats. cache_misses. all( ) ) ;
519
+ assert_eq ! ( & 1 , info. stats. cache_hits. get( "C/C++" ) . unwrap( ) ) ;
520
+ assert_eq ! ( & 2 , info. stats. cache_misses. get( "C/C++" ) . unwrap( ) ) ;
521
+ } ) ;
522
+ }
523
+
457
524
fn test_gcc_clang_no_warnings_from_macro_expansion ( compiler : Compiler , tempdir : & Path ) {
458
525
let Compiler {
459
526
name,
@@ -521,6 +588,7 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_ca
521
588
}
522
589
if compiler. name == "clang" || compiler. name == "gcc" {
523
590
test_gcc_clang_no_warnings_from_macro_expansion ( compiler. clone ( ) , tempdir) ;
591
+ test_split_dwarf_object_generate_output_dir_changes ( compiler. clone ( ) , tempdir) ;
524
592
}
525
593
if compiler. name == "clang++" {
526
594
test_clang_multicall ( compiler. clone ( ) , tempdir) ;
0 commit comments