inst_preamble.t (1978B)
1 # 2 # Test that the instrumentation preamble is what we think it is. 3 # 4 use Modern::Perl; 5 use Test::Cmd; 6 use Test::Differences; 7 use Test::More tests => 3; 8 9 10 my $inst = Test::Cmd->new( prog => 'inst/citrun_inst', workdir => '' ); 11 12 $inst->write( "empty.c", "" ); 13 $inst->run( args => "-c empty.c", chdir => $inst->curdir ); 14 15 my $constructor_decl; 16 if ($^O eq "MSWin32") { 17 $constructor_decl = <<EOF ; 18 #pragma section("",read) 19 #define INITIALIZER2_(f,p) \\ 20 static void f(void); \\ 21 __declspec(allocate("")) void (*f##_)(void) = f; \\ 22 __pragma(comment(linker,"")) \\ 23 static void f(void) 24 #define INITIALIZER(f) INITIALIZER2_(f,"") 25 INITIALIZER( init_empty) 26 { 27 citrun_node_add(citrun_major, citrun_minor, &_citrun); 28 } 29 EOF 30 } 31 else { 32 $constructor_decl = <<EOF ; 33 __attribute__((constructor)) static void 34 citrun_constructor() 35 { 36 citrun_node_add(citrun_major, citrun_minor, &_citrun); 37 } 38 EOF 39 } 40 41 # Known good output. 42 my $preamble_good = <<EOF ; 43 #ifdef __cplusplus 44 extern "" { 45 #endif 46 47 #define CITRUN_PATH_MAX 256 48 static const unsigned int citrun_major = 0; 49 static const unsigned int citrun_minor = 0; 50 51 struct citrun_header { 52 char magic[4]; 53 unsigned int major; 54 unsigned int minor; 55 unsigned int pids[3]; 56 unsigned int units; 57 unsigned int loc; 58 char progname[1024]; 59 char cwd[1024]; 60 }; 61 62 struct citrun_node { 63 unsigned int size; 64 char comp_file_path[CITRUN_PATH_MAX]; 65 char abs_file_path[CITRUN_PATH_MAX]; 66 unsigned long long *data; 67 }; 68 69 void citrun_node_add(unsigned int, unsigned int, struct citrun_node *); 70 static struct citrun_node _citrun = { 71 1, 72 "", 73 "", 74 }; 75 76 $constructor_decl 77 #ifdef __cplusplus 78 } 79 #endif 80 #line 1 81 EOF 82 83 # Read and sanitize special preamble file created by citrun_inst. 84 my $preamble; 85 $inst->read( \$preamble, "empty.c.preamble" ); 86 $preamble =~ s/".*"/""/gm; 87 88 eq_or_diff( $preamble, $preamble_good, 'is preamble identical', 89 { context => 3 } ); 90 is( $inst->stderr, '', 'citrun_inst stderr empty' ); 91 is( $? >> 8, 0, 'citrun_inst exit code 0' );