Subversion Repositories Open64

[/] [regression_test/] [lib/] [test_multifile.exp] - Blame information for rev 1943

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1931 hjz
#!/usr/bin/expect -f
2
 
3 1943 hjz
load_lib test_utils.exp
4 1931 hjz
 
5
###############################################################################
6
# Command to test a single case with multiple sources
7
# We assume:
8
#  there is an shell script indicating how to testing the case
9
#  This shell script should return 0 for success while 1 for failure
10
###############################################################################
11
proc CheckOutput { targetfile makefileout errormsg } {
12
    if { ![string equal $targetfile all] } {
13
        puts $makefileout "\tif \[ ! -e $targetfile \]; then \\"
14
        puts $makefileout "\t\techo \"!!!Message:$errormsg (Cannot find output file)!!! \";\\"
15
        puts $makefileout "\t\texit 1;\\"
16
        puts $makefileout "\tfi;"
17
    }
18
}
19
 
20
proc PrintLines { info } {
21
    global summary
22
    set lines [ split $info "\n" ]
23
    foreach line $lines {
24
        puts $summary "        $line"
25
    }
26
}
27
 
28
namespace eval C_CLASS {
29
 
30 1943 hjz
    proc TestMakefile { case caseexe case_out_dir summary checker } {
31 1931 hjz
  global cc cxx fc cflags cxxflags fflags sim #Flags
32
  global curdir
33 1943 hjz
  global C_CLASS::err_compile C_CLASS::err_link C_CLASS::err_build C_CLASS::pass_build #Counters
34
  global C_CLASS::err_runexit C_CLASS::err_runout C_CLASS::err_run C_CLASS::pass_run   #Counters
35 1931 hjz
 
36
  system mkdir -p $case_out_dir
37
  system cp -rf $case/* $case_out_dir
38
 
39
  #Parse and generate Makefile
40
  set makefileout [open $case_out_dir/Makefile w]
41
  set makefilein [open $case/Makefile r]
42
  set targetfile ""
43
  set execute 1
44
  puts $makefileout "CC=$cc"
45
  puts $makefileout "CXX=$cxx"
46
  puts $makefileout "FC=$fc"
47
  puts $makefileout "CFLAGS=$cflags"
48
  puts $makefileout "CXXFLAGS=$cxxflags"
49
  puts $makefileout "FFLAGS=$fflags"
50
  puts $makefileout "TARGET=$case"
51
  puts $makefileout "SIM=$sim"
52
  puts $makefileout ""
53
  set lineno 0
54
  while { [gets $makefilein line] >= 0 } {
55
      set line [string trimright $line]
56
      set commentpos [string first "#" $line]
57
      if { [expr $commentpos == 0] } {
58
    switch -glob $line {
59
        "#NOEXEC" { set execute 0 }
60
    }
61
      }
62
      set lineno [expr $lineno + 1]
63
      if { [expr $commentpos >= 0] } {
64
    set line [string range $line 0 [expr $commentpos - 1]]
65
      }
66
      if { [string is space [string index $line 0]] } { #Parsing command lines
67
    if { [string equal $line ""] } {
68
        if { ![string equal $targetfile ""] } {
69
      CheckOutput $targetfile $makefileout $errormsg
70
      set targetfile ""
71
        }
72
        puts $makefileout $line
73
    } elseif {[string equal [string index $line end] "\\"] || [string equal $targetfile ""]} {
74
        puts $makefileout $line
75
    } else {
76 1943 hjz
        puts $makefileout "$line >& $case_out_dir/$targetfile.ci || (echo \"!!!Message:$errormsg (Makefile:$lineno) !!!\" && exit 1)"
77 1931 hjz
    }
78
      } else {  #Parsing headers
79
    set colonpos [string first ":" $line]
80
    if { [expr $colonpos >= 0] } {
81
        set targetfile [string range $line 0 [expr $colonpos - 1]]
82
        set targetfile [string trimright $targetfile]
83
        if { [string match -nocase "*.o" $targetfile] || [string match -nocase "*.s" $targetfile] } {
84
      set errormsg "\[$targetfile\] Fail at compiling"
85
        } else {
86
      set errormsg "\[$targetfile\] Fail at linking"
87
        }
88
        puts $makefileout $line
89
    } else {
90
        puts $makefileout $line
91
    }
92
      }
93
  }
94
  if { ![string equal $targetfile ""] } {
95
      CheckOutput $targetfile $makefileout $errormsg
96
      set targetfile ""
97
  }
98
  close $makefilein
99
  close $makefileout
100
 
101
  cd $case_out_dir
102
 
103
  set buildres 0
104
  set runres 0
105
  set cmpres 0
106
 
107
  if { [catch {exec make -s} makeresult] } {
108
      incr err_build
109
      set mpos [string first "!!!Message:" $makeresult]
110
      if { [expr $mpos < 0] } {
111
    #Bad Makefile
112
    set buildres -1
113
      } else {
114
    set mpos2 [string first "!!!" $makeresult 11]
115
    set makeresult [string range $makeresult 11 [expr $mpos2 - 1]]
116
    set mpos3 [string first "]" $makeresult]
117
    set buildres -1
118
      }
119
  } else {
120
      incr pass_build
121
      if { $execute == 1 } {
122 1943 hjz
    set rc [catch {exec ./$caseexe > $case_out_dir/$caseexe.run}]
123 1931 hjz
    set runresult ""
124
    if { $rc } {
125
        set runres -1
126
        incr err_run
127
    } else {
128 1943 hjz
        catch {exec cat $case_out_dir/$caseexe.run} runresult
129 1931 hjz
        if { [expr [$checker $runresult] == 1]} {
130
      incr pass_run
131
        } else {
132
      set cmpres 1
133
      incr err_run
134
        }
135
    }
136
      }
137
  }
138
 
139
  Report_TestCase_Result $case $buildres $runres $cmpres
140
  cd $curdir
141
 
142
    }
143
 
144
}