File indexing completed on 2024-05-12 03:54:29

0001 #!/usr/bin/perl
0002 
0003 if ( @ARGV < 1 ) {
0004   print STDERR "Missing arg: filename\n";
0005   exit 1;
0006 }
0007 
0008 $file = $ARGV[0];
0009 
0010 $file =~ /^(.*)\.[^\.]*$/;
0011 $filebase = $1;
0012 
0013 $header_extension = @ARGV > 1 ? $ARGV[1] : "h";
0014 $source_extension = @ARGV > 2 ? $ARGV[2] : "cpp";
0015 $file_h = "$filebase.$header_extension";
0016 $file_cpp = "$filebase.$source_extension";
0017 
0018 $kcfgc = $file . "c";
0019 
0020 $cmd = "./kconfig_compiler_kf6 $file $kcfgc";
0021 
0022 #print "CMD $cmd\n";
0023 
0024 if ( system( $cmd ) != 0 ) {
0025   print STDERR "Unable to run kconfig_compiler_kf6\n";
0026   exit 1;
0027 }
0028 
0029 checkfile( $file_h );
0030 checkfile( $file_cpp );
0031 
0032 exit 0;
0033 
0034 sub checkfile()
0035 {
0036   my $file = shift;
0037 
0038   $file =~ /\/([^\/]*)$/;
0039   my $filename = $1;
0040 
0041   print "Checking '$filename':\n";
0042 
0043   my @ref;
0044   if ( !open( REF, "$file.ref" ) ) {
0045     print STDERR "Unable to open $file.ref\n";
0046     exit 1;
0047   }
0048   while( <REF> ) {
0049     push @ref, $_;
0050   }
0051   close REF;
0052 
0053   if ( !open( READ, $filename ) ) {
0054     print STDERR "Unable to open $filename\n";
0055     exit 1;
0056   }
0057 
0058   $error = 0;
0059   $i = 0;
0060   $line = 1;
0061   while( <READ> ) {
0062     $out = $_;
0063     $ref = @ref[$i++];
0064 
0065     if ( $out ne $ref ) {
0066       $error++;
0067       print "  Line $line: Expected        : $ref";
0068       print "  Line $line: Compiler output : $out";
0069     }
0070     
0071     $line++;
0072   }
0073 
0074   close READ;
0075 
0076   if ( $error > 0 ) {
0077     print "\n  FAILED: $error errors found.\n";
0078     if ( $error > 5 ) {
0079       system( "diff -u $file.ref $filename" ); 
0080     }
0081     exit 1;
0082   } else {
0083     print "  OK\n";
0084   }
0085 }