summaryrefslogtreecommitdiffstats
path: root/tapset/test/run.sh
blob: fd43591b0d3f2a229e6094a58d4693bab0d49b93 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function usage {
   echo -ne " \033[1mUsage:\033[0m run stpdir bindir\n"
   echo -ne "   \033[1mstpdir:\033[0m\n"
   echo -ne "\tthe directory containing the stp files\n"
   echo -ne "   \033[1mbindir:\033[0m\n"
   echo -ne "\tthe directory containing the c executables\n"
   exit
}
function cleanup {
   rm -f tmp*
}
function even {
   k=$1
   while [ $k -ne $2 ]; do
      if [ $# -eq 3 ]; then
         echo -ne " " >> $logfile
      else
         echo -ne " " 
      fi
      k=`expr $k + 1`
   done
}
function spit {
   echo -ne "\t\t\tFUNCTION: `echo $1 | cut -d"." -f4`\n" >> $logfile
   echo "Expected output:" >> $logfile
   cat $2 >> $logfile
   echo "Actual output:"   >> $logfile
   cat $1 >> $logfile
   echo -ne "___________________________________" >> $logfile
   echo "___________________________________" >> $logfile
}
function spiteven {
   echo -ne "\t\t\tFUNCTION: `echo $1 | cut -d"." -f4`\n" >> $logfile
   echo -ne "Expected Output:\t\t\t\tActual Output:\n" >> $logfile
   i=1
   lines=`cat $1|wc -l`
   while [ $i -le $lines ]; do
      echo -ne "`head -$i $2|tail -1`"   >> $logfile
      even `head -$i $2|tail -1|wc -m` 49 9
      echo -ne "`head -$i $1|tail -1`\n" >> $logfile
      i=`expr $i + 1`
   done
   echo -ne "___________________________________" >> $logfile
   echo "___________________________________" >> $logfile
}
trap got_trap 1 2 3 6
function got_trap {
   echo -e "\nGot signaled. Cleaning up...\n"
   if [ `ps -A|grep staprun|sed 's/^[ ^t]*//'|cut -d" " -f1 | wc -l` -gt 0 ]
   then
      kill `ps -A|grep staprun|sed 's/^[ ^t]*//'|cut -d" " -f1`
   fi
   if [ `ps -A|grep stap|sed 's/^[ ^t]*//'|cut -d" " -f1 | wc -l` -gt 0 ]
   then
      kill `ps -A|grep stap|sed 's/^[ ^t]*//'|cut -d" " -f1`
   fi
   cleanup
   exit 1
}
function waitforoutput {
   t=0
   while [ `cat $1|wc -l` -eq 0 -a $t -ne 4 ]; do
      sleep 1
      t=`expr $t + 1`
   done
   if [ $t -eq 4 ]; then
      even 1 3
      echo -en "\033[0;36mPROBEMISS\033[0m\n"
      failures=`expr $failures + 1`
      #spit $1 $2
   else
      validate $1 $2
   fi
}
function validate {
   if [ `diff $1 $2|wc -l` -gt 0 ]; then
      even 1 3
      echo -en "\033[0;31mFAIL\033[0m\n"
      failures=`expr $failures + 1`
      if [ `cat $1|wc -l` -eq `cat $2|wc -l` ]; then  
         spiteven $1 $2
      else
         spit $1 $2
      fi
   else
      even 1 3
      echo -en "\033[0;32mPASS\033[0m\n"
   fi
}
# start +++++++++++++++++++++++++++++++++++
stpdir=`echo $1|sed -e 's/\/$//'`
bindir=`echo $2|sed -e 's/\/$//'`
# sanity...
if [[ ! -d $stpdir || ! -d $bindir ]]; then
   echo "Invalid arguments. Try again."
   usage
elif [ `ls $stpdir/*.stp|wc -l` -le 0 ]; then
   echo "No .stp files found in $stpdir"
   exit
elif [ `ls $bindir/|wc -l` -le 0 ]; then
   echo "No executable files found in $bindir"
   exit
elif [ $UID -ne 0 ]; then
   echo "You must be root to do that!"
   exit
elif [ ! -d log ]; then
   mkdir log
fi

total=`ls $stpdir|wc -l`
logfile=log/`date +%m%d%y_%H%M%S`.log
clear
echo -en "Prog\t\tScript"
echo -e "\t\t\t\t Status"

# iterate through script files
ct=1
failures=0
for i in `ls $stpdir`
do
   # create some tmp files for output
   stp_tmpf="tmp.stp.$$.$i"
   c_tmpf="tmp.c.$$.$i"
   echo -ne "$ct/$total:\t"
   if [ $ct -lt 100 ]; then
      echo -ne "\t"
   fi
   echo -ne $i
   #insmod the ko
   stap -DMAXNESTING=10 $stpdir/$i > $stp_tmpf &
   # make sure module is loaded
   pid=""; ast=""
   while [[ "$pid" == "" || "$ast" == "" ]]
   do
      pid=`ps|grep staprun|sed 's/^[ ^t]*//'|cut -d" " -f1`
      ast=`ps|grep stap|sed 's/^[ ^t]*//'|cut -d" " -f1`
      sleep 1
   done
   even `echo $i|wc -m` 30
   echo -n "+++"
   # now we can safely run the user c program
   su -c "./$bindir/e_`echo $i|cut -d"." -f1` > $c_tmpf" krstaffo   
   # kill off stap
   kill $pid
   # give it some breathing room
   waitforoutput $stp_tmpf $c_tmpf
   ct=`expr $ct + 1`
   cleanup
done
echo "Total Failures: $failures/$total"