#!/bin/ksh -p # # DTT Checker, a simple test suite for # all DTT's categories. # # Version: 0.60 # # ToDo: rewrite in Perl # # Auhtor: Stefan Parvu ####################################### # Default global vars DTT_PATH=${DTT_HOME:-/opt/DTT} DTT_VER="$(grep Version ${DTT_PATH}/Docs/History |\ tail -1 | awk '{print $5}')" sem=0 sok=0 sskipped=0 sfailed=0 outlog=0 ####################################### ####################################### # Functions # Using in here Ksh functions and not # POSIX like # # Usage function usage { print "Usage:\t${0##*/} [-o filename] [options] [script...] options: \t-A All scripts \t-a apps scripts \t-c cpu scripts \t-d disk scripts \t-e extra scripts \t-l locks scripts \t-m mem scripts \t-n net scripts \t-s system scripts \t-u user scripts \t-r regression \t-q quiet mode" } # # Version function version { print "Version: 0.60" } function print_message { # $1 - Message Id # $2 - The message buffer # ---------------------------------------------- # Message Table # ---------------------------------------------- # Error Class # 1 ERROR Operating system not supported ! # 2 ERROR Not a valid directory ! # 9 FATAL Not a valid test option ! # ------------------------------------------------ # WARNING Class # 10 WARN xxxx # 11 WARN xxxx # ------------------------------------------------ # INFO Class # 20 INFO xxxx # 21 INFO xxxx # ------------------------------------------------ case "$1" in 1) print "Error: Operating system not supported !" exit 1 ;; 2) print "Error: Not a valid directory: $2 !" exit 1 ;; 3) print "Error: Not a valid category: $2 !" exit 1 ;; 5) print "Error: DTrace requires additional \ privileges for user: $2 !" exit 1 ;; 9) print "Fatal: Not a valid test option: $2" exit 1 ;; esac } function print_header { # Make the header print " ################################################## REPORT QA DTraceToolkit ################################################## Date: $(date +"%Y-%m-%d %T") DTraceToolkit version: $DTT_VER Operating System: $(uname -srpv) " } function test_category { # $1 Category # For the following scripts I need kill -INT: # Apps/weblatency.d # Apps/nfswizard.d # Disk/diskhits # Disk/bitesize.d # Disk/hotspot.d # Disk/pathopens.d # Disk/seeksize.d # Disk/iofile.d # Cpu/xcallsbypid.d # Cpu/cpuwalk.d # Cpu/dispqlen.d # Cpu/intbycpu.d # Cpu/inttimes.d # Cpu/intoncpu.d # if [[ ! -d ${DTT_PATH}/$1 ]] then return fi cd ${DTT_PATH}/$1 2>/dev/null print "Category: $1" if (( outlog == 1 )) then print "Category: $1" >> $dtt_log fi if [[ $1 != 'None' ]] then find . -type f | grep -v Readme |\ wc -l | read numberScripts else print "$2" | wc -w | read numberScripts fi print "Number of scripts: $numberScripts" # # log file if (( outlog == 1 )) then print "Number of scripts: $numberScripts" >> $dtt_log fi for file in * do scriptName=${file##*/} if [[ "$scriptName" = 'Readme' ]] then continue fi printf "\r script: $scriptName - running" sleep 1 # if every script has -n then we are ok if [[ "$scriptName" = *.d ]] then if [[ "$scriptName" = guess.d ]] then printf "\r script: $scriptName - skipped \n" # # log file if (( outlog == 1 )) then print " script: $scriptName - skipped " >> $dtt_log fi ((sskipped=sskipped+1)) continue fi ./$scriptName -n 'tick-500ms { exit(0); }' -p $$ > /dev/null 2>&1 if (( $? != 0 )) then printf "\r script: $scriptName - failed \n" # # log file if (( outlog == 1 )) then print " script: $scriptName - failed " >> $dtt_log fi ((sfailed=sfailed+1)) continue else printf "\r script: $scriptName - ok \n" # # log file if (( outlog == 1 )) then print " script: $scriptName - ok " >> $dtt_log fi ((sok=sok+1)) fi else # exceptions for cputimes and cpudist if [[ $scriptName = cputimes || $scriptName = cpudists || \ $scriptName = tcpsnoop || $scriptName = tcptop ]] then ./$scriptName > /dev/null 2>&1 if (( $? != 0 )) then printf "\r script: $scriptName - failed \n" # # log filea if (( outlog == 1 )) then print " script: $scriptName - failed " >> $dtt_log fi ((sfailed=sfailed+1)) continue else printf "\r script: $scriptName - ok \n" # # log file if (( outlog == 1 )) then print " script: $scriptName - ok " >> $dtt_log fi ((sok=sok+1)) continue fi fi ./$scriptName > /dev/null 2>&1 & jobPID=$! sleep 2 # check the jobPID using the NUL signal # sleep enough to make sure a broken command has died... kill -0 $jobPID 2>/dev/null if (( $? != 0 )) then printf "\r script: $scriptName - failed \n" # # log file if (( outlog == 1 )) then print " script: $scriptName - failed " >> $dtt_log fi ((sfailed=sfailed+1)) continue fi # stop the job if kill $jobPID then printf "\r script: $scriptName - ok \n" # # log file if (( outlog == 1 )) then print " script: $scriptName - ok " >> $dtt_log fi ((sok=sok+1)) fi sleep 1 # make sure the script is not running anymore... kill -0 $jobPID 2>/dev/null if (( $? == 0 )) then # the jobPID is alive... # get all childs... kill $(pgrep -P $jobPID | xargs echo) # child(s) must have died... # check again kill -0 $jobPID 2>/dev/null if (( $? != 0 )) then continue else kill $jobPID fi fi fi done print "" # # log file if (( outlog == 1 )) then print "" >> $dtt_log fi } function make_summary { print "################################################## FINAL RESULTS DTT ver: $DTT_VER Passed: $sok Failed: $sfailed Skipped: $sskipped Elapsed time: $1 sec(s) Report generated by: $(/usr/xpg4/bin/id -u -n) ################################################## " } # ############# # MAIN FUNCTION # ############# case "$(uname)" in SunOS) case "$(uname -r)" in 5.1[0-1]) # check in here if the user has DTrace privileges... #printf "\rDTrace privileges - checking" /usr/sbin/dtrace -qn 'BEGIN{trace("Hello world"); exit(0);}' \ > /dev/null 2>&1 if (( $? != 0 )) then #printf "\rDTrace privileges - failed \n" print_message 5 "$(/usr/xpg4/bin/id -u -n)" fi #printf "\rDTrace privileges - ok \n" ;; 5.[6-9]) print_message 1 exit 1 ;; *) print_message 1 exit 1 ;; esac ;; *) print_message 1 ;; esac while getopts ":Aacdehlkmnsuro:vV" arg do case "${arg}" in A) sem=1 print_header if (( outlog == 1 )) then print_header > $dtt_log fi integer start=SECONDS test_category Apps test_category Cpu test_category Disk test_category Extra test_category FS test_category Java test_category JavaScript test_category Locks test_category Kernel test_category Mem test_category Net test_category Perl test_category Php test_category Proc test_category Python test_category Ruby test_category Shell test_category System test_category Tcl test_category User test_category Zones ((elapsed=SECONDS-start)) make_summary $elapsed if (( outlog == 1 )) then make_summary $elapsed >> $dtt_log fi ;; a) sem=1 print_header if (( outlog == 1 )) then print_header > $dtt_log fi integer start=SECONDS test_category Apps ((elapsed=SECONDS-start)) make_summary $elapsed if (( outlog == 1 )) then make_summary $elapsed >> $dtt_log fi ;; c) print_header test_category Cpu make_summary sem=1; ;; d) print_header test_category Disk make_summary sem=1 ;; e) print_header test_category Extra make_summary sem=1 ;; l) print_header test_category Locks make_summary sem=1 ;; k) print_header test_category Kernel make_summary sem=1 ;; h) usage exit 0 ;; m) print_header test_category Mem make_summary sem=1 ;; n) print_header test_category Net make_summary sem=1 ;; s) print_header test_category System make_summary sem=1 ;; u) print_header test_category User make_summary sem=1 ;; r) ;; o) outlog=1 dtt_log=$OPTARG ;; v|V) version exit 0 ;; *) usage exit 1 ;; esac done shift $(($OPTIND - 1)) if (($# != 0)) then # we have individual scripts from command line. Category None... test_category None "$*" # After we have processed everything time to make the final results # generate summary report # make_summary else if ((sem==0)) then usage exit 0 fi # no individual scripts # make_summary "${dir_report}/report_${dir_report}" fi