Skip to content

Instantly share code, notes, and snippets.

@bonetechnologies
Created March 16, 2015 17:42
Show Gist options
  • Save bonetechnologies/9d12c3e0bd57e4e024d1 to your computer and use it in GitHub Desktop.
Save bonetechnologies/9d12c3e0bd57e4e024d1 to your computer and use it in GitHub Desktop.
#!/bin/bash
#chris kearney, mentor graphics corporation
SEND_EMAIL_TO="chris_kearney,lee_howard"
export CVSROOT=/wv/sim_cvs
if [ "$(uname)" = "SunOS" ]; then
source /wv/msg/bin/ss5/source_bin.sh
_MAIL=/usr/bin/mailx
_PERL=/bin/perl
elif [ "$(uname)" = "Linux" ]; then
_GREP=/bin/grep
_EGREP=/bin/egrep
_DATE=/bin/date
_CUT=/bin/cut
_WC=/usr/bin/wc
_SED=/bin/sed
_HEAD=/usr/bin/head
_ECHO=/bin/echo
_CVS=/usr/bin/cvs
_AWK=/bin/awk
_MAIL=/bin/mail
_PERL=/usr/bin/perl
else
echo "$(uname) is an unknown platform, exiting now."
exit -2
fi
tmpdir=/tmp/tmp.$$
mkdir $tmpdir
tmpfile=$tmpdir/tmpfile.$$
ParseInput () {
if [ $# -eq 0 ]; then
$_ECHO "Usage: $0 [-d] <slaunch.data> -c <slaunch.cal>"
exit -1;
fi
while [ -n "$1" ] # Parse the command line
do
case $1 in
-[Dd])
SLAUNCH_DATA_FILE=$2;
RUN_DATA_CHECK="1"
shift
;;
-[Mm])
MAIL_RESULT="1"
shift
;;
-[Cc])
SLAUNCH_CAL_FILE=$2;
RUN_CAL_CHECK="1"
shift
;;
-*)
$_ECHO "ERROR: Bad flag \"$1\".";
exit -1;
;;
esac
shift
done
if [ "x$SLAUNCH_DATA_FILE" = "x" ]; then
$_ECHO "ERROR: Must set a slaunch.data file"
exit -1
elif [ ! -f "$SLAUNCH_DATA_FILE" ]; then
$_ECHO "ERROR: $SLAUNCH_DATA_FILE is not accesible or does not exist."
RUN_DATA_CHECK="0"
exit -1
fi
if [ "x$SLAUNCH_CAL_FILE" = "x" ]; then
$_ECHO "ERROR: Must set a slaunch.cal file"
exit -1
elif [ ! -f "$SLAUNCH_CAL_FILE" ]; then
$_ECHO "ERROR: $SLAUNCH_CAL_FILE is not accesible or does not exist."
RUN_CAL_CHECK="0"
exit -1
fi
}
/wv/synp/bin/abortremoval.sh
exitChecker(){
if [ "$1" = "-1" ]; then
rm -rf $tmpdir
$_ECHO -e "ERROR: $2"
if [ "x$MAIL_RESULT" = "x1" ]; then
$_ECHO -e "ERROR: $2" | $_MAIL -s "SLAUNCH - Syntax Errors Found" $SEND_EMAIL_TO
fi
$_ECHO "*** ERROR found exiting now."
exit $1
elif [ "$1" = "0" ]; then
rm -rf $tmpdir
$_ECHO "OK"
exit $1
fi
}
processLine(){
line=`$_ECHO $@ | $_SED -e '/^#/d'`
$_ECHO $line
}
yankDef(){
if [ "$($_ECHO $1 | $_EGREP "(\(|,)$2=>" >>/dev/null;$_ECHO $?)" = "0" ]; then
$_ECHO $($_ECHO $1 | $_SED -e 's/.*'$2'=>"\([^"]*\).*;/\1/')
else
$_ECHO -e "ERROR: $SLAUNCH_DATA_FILE: no $2=> set\n---\n$1\n---"
fi
}
stripit(){
$_ECHO $1 | $_SED 's/:.*$//'
}
ParseInput $*
if [ "$RUN_DATA_CHECK" = "1" ]; then
# Start .data perl syntax check
# Check the .data file, remove lines that start with '=' and "condense" the code.
cat $SLAUNCH_DATA_FILE | $_SED -e '/^#/d' -e '/^$/d' -e '/^=/d' | $_SED -e :a -e '/[^;]$/N; s/\n//; ta' | $_SED -e 's/\t//g' > $tmpfile
exec 3<&0
exec 0< $tmpfile
while read data_line
do
perl_syn=`processLine $data_line | $_PERL -wc 2>&1`
if [ "$?" != "0" ]; then
perl_syn=`$_ECHO $perl_syn | $_SED -e 's/^.*, //' -e 's/ - had.*$//'`
exitChecker "-1" "$SLAUNCH_DATA_FILE: Perl Syntax: $perl_syn\n---\n$data_line\n---"
fi
done
exec 0<&3
# End .data perl syntax check
# a quick hack to check for a next day schedule entry
month=`$_DATE --date='tomorrow' +%m | $_SED 's/^0//'`
day=`$_DATE +%e --date='tomorrow'| $_SED 's/^0//'`
year=`$_DATE --date='tomorrow' +%Y`
cal_date=`$_ECHO "$month.$day.$year" | $_SED 's/ //g'`
cal_recent=`$_GREP -m 1 -n "^$cal_date" $SLAUNCH_CAL_FILE`
if [ "$?" != "0" ]; then
$_ECHO "$0: WARNING: Nothing scheduled for tomorrow. ($cal_date)"
fi
#end next day check
# Look for calender entries for today, or the next three days
month=`$_DATE +%m | $_SED 's/^0//'`
day=`$_DATE +%e | $_SED 's/^0//'`
year=`$_DATE +%Y`
cal_date=`$_ECHO "$month.$day.$year" | $_SED 's/ //g'`
cal_date_orig=`$_ECHO "$month.$day.$year" | $_SED 's/ //g'`
cal_recent=`$_GREP -m 1 -n "^$cal_date" $SLAUNCH_CAL_FILE`
if [ "$?" != "0" ]; then
month=`$_DATE --date='tomorrow' +%m | $_SED 's/^0//'`
day=`$_DATE +%e --date='tomorrow'| $_SED 's/^0//'`
year=`$_DATE --date='tomorrow' +%Y`
cal_date=`$_ECHO "$month.$day.$year" | $_SED 's/ //g'`
cal_recent=`$_GREP -m 1 -n "^$cal_date" $SLAUNCH_CAL_FILE`
if [ "$?" != "0" ]; then
month=`$_DATE --date='2 days' +%m | $_SED 's/^0//'`
day=`$_DATE +%e --date='2 days'| $_SED 's/^0//'`
year=`$_DATE --date='2 days' +%Y`
cal_date=`$_ECHO "$month.$day.$year" | $_SED 's/ //g'`
cal_recent=`$_GREP -m 1 -n "^$cal_date" $SLAUNCH_CAL_FILE`
if [ "$?" != "0" ]; then
month=`$_DATE --date='3 days' +%m | $_SED 's/^0//'`
day=`$_DATE +%e --date='3 days'| $_SED 's/^0//'`
year=`$_DATE --date='3 days' +%Y`
cal_date=`$_ECHO "$month.$day.$year" | $_SED 's/ //g'`
cal_recent=`$_GREP -m 1 -n "^$cal_date" $SLAUNCH_CAL_FILE`
if [ "$?" != "0" ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: No calendar entries found for ( $cal_date_orig - $cal_date )."
fi
fi
fi
fi
cal_recent=`$_ECHO "$cal_recent" | cut -d : -f 1`
# End
# Start .cal perl syntax check
# Check the .cal file, removing the $_DATE lines, and END CALENDER and BEING CALENDER lines, add ; to end of lines.
$_HEAD -n $cal_recent $SLAUNCH_CAL_FILE | $_SED -e '/^$/d' -e '/^[0-9]/d' -e '/^END/d' -e '/^BEGIN/d' -e 's/$/;/' > $tmpfile
exec 3>&0
exec 0< $tmpfile
while read cal_line
do
processLine $cal_line | $_PERL -wc 2> /dev/null
if [ "$?" != "0" ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: Perl syntax: $cal_line"
fi
done
exec 0<&3
# End .cal perl syntax check
# Start build definition .data integrity test
# We now know syntax is correct, now lets check if the build roots are valid.
# Yank back valid CVSTAG's for regr
$_CVS -d /wv/sim_cvs co -d $tmpdir/ regr_home/bin/regr >> /dev/null
$_CVS log $tmpdir/regr >> $tmpdir/regr.log
cvs_head_line=`$_GREP -m 1 -n "keyword substitution:" $tmpdir/regr.log | $_CUT -d : -f 1`
$_HEAD -n $cvs_head_line $tmpdir/regr.log | $_SED -e '/^[^\t]/d' -e '/^$/d' -e 's/^\t//' -e 's/:.*$//' > $tmpdir/regr.log2
# END yank of cvstag
$_GREP "launcher::Build->new" $SLAUNCH_DATA_FILE | $_SED '/^#/d'> $tmpfile
exec 3>&0
exec 0< $tmpfile
while read data_integ_line
do
comma_count=`expr $($_ECHO $data_integ_line | $_SED 's/[^,]//g' | $_WC | $_AWK '{print $3}')`
name=`yankDef "$data_integ_line" "name"`
unix_build_root=`yankDef "$data_integ_line" "unixBuildRoot"`
windows_build_root=`yankDef "$data_integ_line" "windowsBuildRoot"`
build_type=`yankDef "$data_integ_line" "buildType"`
qofr_options=`yankDef "$data_integ_line" "QofROptions"`
test_type=`yankDef "$data_integ_line" "testType"`
cvs_tag=`yankDef "$data_integ_line" "cvsTag"`
#Check for comma count, "CFE" or build defs with "CVSTAG" should have 9 commas. build defs that are CFE and use a cvsTag should have 10 commas
if [ "$($_ECHO $data_integ_line | $_GREP ",cvsTag=>" >>/dev/null;$_ECHO $?)" = "0" -a "$($_ECHO $data_integ_line | $_GREP ",useAltFE=>" >>/dev/null;$_ECHO $?)" = "0" ]; then
comma_count_max=$(expr 10)
elif [ "$($_ECHO $data_integ_line | $_GREP ",cvsTag=>" >>/dev/null;$_ECHO $?)" = "0" -o "$($_ECHO $data_integ_line | $_GREP ",useAltFE=>" >>/dev/null;$_ECHO $?)" = "0" ]; then
comma_count_max=$(expr 9)
else
comma_count_max=$(expr 8)
fi
if [ $comma_count -ne $comma_count_max ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: Incorrect amount of commas ($comma_count found, should be $comma_count_max)\n---\n$data_integ_line\n---"
fi
# end comma check
# lets check to make sure these exist in each individual build def line
if [ "`stripit $name`" = "ERROR" ]; then
name=`$_ECHO $name | $_SED 's/ERROR: //'`
exitChecker "-1" "$name"
fi
if [ "`stripit $unix_build_root`" = "ERROR" ]; then
unix_build_root=`$_ECHO $unix_build_root | $_SED 's/ERROR: //'`
exitChecker "-1" "$unix_build_root"
fi
if [ "`stripit $windows_build_root`" = "ERROR" ]; then
windows_build_root=`$_ECHO "$windows_build_root | $_SED 's/ERROR: //'`
exitChecker "-1" "$windows_build_root"
fi
if [ "`stripit $build_type`" = "ERROR" ]; then
build_type=`$_ECHO $build_type | $_SED 's/ERROR: //'`
exitChecker "-1" "$build_type"
fi
if [ "`stripit $qofr_options`" = "ERROR" ]; then
qofr_options=`$_ECHO $qofr_options | $_SED 's/ERROR: //'`
exitChecker "-1" "$qofr_options"
fi
if [ "`stripit $test_type`" = "ERROR" ]; then
test_type=`$_ECHO "$test_type | $_SED 's/ERROR: //'`
exitChecker "-1" "$test_type"
fi
if [ "`stripit $cvs_tag`" != "ERROR" ]; then
if [ "$($_GREP "$cvs_tag" $tmpdir/regr.log2>>/dev/null;$_ECHO $?)" != "0" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: cvsTag value \"$cvs_tag\" does not exist\n---\n$data_integ_line\n---"
fi
fi
# end
# make sure that the unix build dir exists, if it does, check to make sure the windows build def is valid
windows_build_root_cmp=`$_ECHO $unix_build_root | $_SED -e 's|\/wv|\/\/wv\/dfs|'`
if [ ! -d "$unix_build_root/$name" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: unixBuildRoot does not exist: $unix_build_root/$name\n---\n$data_integ_line\n---"
elif [ "x$windows_build_root" != "x$windows_build_root_cmp" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: windowsBuildroot : $windows_build_root\n---\n$data_integ_line\n---"
fi
#end
if [ "x$build_type" != "xcreationDate=today at 00:00" ]; then
if [ ! -d "$unix_build_root/$name/$build_type" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: buildType does not exist: $unix_build_root/$name/$build_type\n---\n$data_integ_line\n---"
fi
fi
processLine "$qofr_options" | $_GREP -v "completeLaunch" >> /dev/null
if [ "$?" != "1" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: QofROptions missing -completeLaunch flag.\n---\n$data_integ_line\n---"
fi
for i in $(processLine "$qofr_options" | $_SED 's/ -/\n-/g')
do
$_ECHO "$i" | $_EGREP '^blk_' >> /dev/null
if [ "$?" != "1" ]; then
find /wv/sim_cvs/regr_home/lists/ | $_GREP "$i" >> /dev/null
if [ "$?" != "0" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: black list: $i doesnt exist in regr_home\n---\n$data_integ_line\n---"
fi
fi
i=`$_ECHO $i | $_SED 's/blk_.*//'`
if [ "x$i" != "x" ]; then
$_ECHO $i | $_EGREP -v '(-noNFE|-blacklist|-completeLaunch)' >> /dev/null
if [ "$?" != "1" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: $i unknown flag or not a blacklist for QofROptions\n---\n$data_integ_line\n---"
fi
fi
done
if [ "x$test_type" != "xnightly" ]; then
exitChecker "-1" "$SLAUNCH_DATA_FILE: testType is not set to \"nightly\" ($test_type)\n---\n$data_integ_line\n---"
fi
done
exec 0<&3
# End build definition .data integrity test
# Start group .data integrity tests
# cat $SLAUNCH_DATA_FILE | $_SED -e '/^#/d' -e '/^$/d' -e '/^=/d' -e :a -e '/[^;]$/N; s/\n//; ta' -e 's/\t//g' | $_GREP "=launcher::Group->new(" > $tmpfile
# exec 3>&0
# exec 0< $tmpfile
# while read data_integ_line
# do
# $_ECHO $data_integ_line | $_SED -e 's/.*name=>"\([^"]*\).*;/\1/'
# yankDef "$data_integ_line" "name"
# done
# Start .cal integrity test
$_HEAD -n $cal_recent $SLAUNCH_CAL_FILE | $_SED -e '/^#/d' -e '/^$/d' -e '/^[0-9]/d' -e '/^END/d' -e '/^BEGIN/d' -e 's/$/;/' > $tmpfile
exec 3>&0
exec 0< $tmpfile
while read cal_integ_line
do
# does each line start with NightlyStream
start_nightly="`processLine $cal_integ_line | $_SED -e '/^NightlyStream/d' | $_WC -l`"
start_nightly=`expr $start_nightly`
if [ $start_nightly -gt 0 ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: line does not start with \"NightlyStream\"\n---\n$cal_integ_line\n---"
fi
# does "NightlyStream1 Stream1" match, ie: "NightlyStream2 Stream1" causes an error.
# also will detect lines that do not contain an "="
stream_match_one="`processLine $cal_integ_line | $_CUT -d = -f 1 | $_AWK '{ print $1 }'`"
stream_match_two="`processLine $cal_integ_line | $_CUT -d = -f 1 | $_AWK '{ print $2 }'`"
if [ "x`$_ECHO $stream_match_one | $_SED 's/Nightly//'`" != "x$stream_match_two" ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: inconsistent syntax found on line\n---\n$cal_integ_line\n---"
fi
# break down and check the "[$NFE2006a,$b_basic,"RUNONCE"]"'s
for i in $(processLine $cal_integ_line | $_CUT -d = -f 2 | $_SED -e 's/\[\[//' -e 's/\]\]//' -e 's/\[//g' -e's/\],/\n/g')
do
build_def=`$_ECHO "$i" | $_SED 's/;//' | $_AWK -F , '{ print $1 }'`
search_string=`$_ECHO "$build_def=launcher"`
$_GREP "^$search_string" $SLAUNCH_DATA_FILE >/dev/null
if [ "$?" != "0" ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: build def: $build_def does not exist in $SLAUNCH_DATA_FILE\n---\n$cal_integ_line\n---"
fi
block_def=`$_ECHO "$i" | $_SED 's/;//' | $_AWK -F , '{ print $2 }'`
search_string=`$_ECHO "$block_def=launcher"`
$_GREP "^$search_string" $SLAUNCH_DATA_FILE >/dev/null
if [ "$?" != "0" ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: block def: $block_def does not exist in $SLAUNCH_DATA_FILE\n---\n$cal_integ_line\n---"
fi
runonce_def=`$_ECHO "$i" | $_SED -e 's/;//' -e 's/"//g' | $_AWK -F , '{ print $3 }'`
if [ "x$runonce_def" != "xRUNONCE" ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: $runonce_def where RUNONCE\n---\n$cal_integ_line\n---"
fi
runonce_def=`$_ECHO "$i" | $_SED -e 's/;//' | $_AWK -F , '{ print $3 }' | $_SED 's/RUNONCE//'`
if [ "x$runonce_def" != "x\"\"" ]; then
exitChecker "-1" "$SLAUNCH_CAL_FILE: missing quotes on RUNONCE ($runonce_def)\n---\n$cal_integ_line\n---"
fi
done
# end
done
exec 0<&3
# End .cal integrity test
exitChecker 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment