summaryrefslogtreecommitdiffstats
path: root/korundum/rubylib/rbkconfig_compiler/checkkcfg.pl
blob: 2eddbeee61b2be5c550013d726197d65ed5b0262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl

if ( @ARGV != 1 ) {
  print STDERR "Missing arg: filename\n";
  exit 1;
}

$file = $ARGV[0];

$file =~ /^(.*)\.[^\.]*$/;
$filebase = $1;

$file_h = "$filebase.h";
$file_cpp = "$filebase.cpp";

$kcfgc = $file . "c";

$cmd = "./kconfig_compiler $file $kcfgc";

#print "CMD $cmd\n";

if ( system( $cmd ) != 0 ) {
  print STDERR "Unable to run kconfig_compiler\n";
  exit 1;
}

checkfile( $file_h );
checkfile( $file_cpp );

exit 0;

sub checkfile()
{
  my $file = shift;

  $file =~ /\/([^\/]*)$/;
  my $filename = $1;

  print "Checking '$filename':\n";

  my @ref;
  if ( !open( REF, "$file.ref" ) ) {
    print STDERR "Unable to open $file.ref\n";
    exit 1;
  }
  while( <REF> ) {
    push @ref, $_;
  }
  close REF;

  if ( !open( READ, $filename ) ) {
    print STDERR "Unable to open $filename\n";
    exit 1;
  }

  $error = 0;
  $i = 0;
  $line = 1;
  while( <READ> ) {
    $out = $_;
    $ref = @ref[$i++];

    if ( $out ne $ref ) {
      $error++;
      print "  Line $line: Expected        : $ref";
      print "  Line $line: Compiler output : $out";
    }
    
    $line++;
  }

  close READ;

  if ( $error > 0 ) {
    print "\n  FAILED: $error errors found.\n";
    if ( $error > 5 ) {
      system( "diff -u $file.ref $filename" ); 
    }
    exit 1;
  } else {
    print "  OK\n";
  }
}