runltp脚本

    1. #!/bin/sh  
    2. ################################################################################  
    3. ##                                                                            ##  
    4. ## Copyright (c) International Business Machines  Corp., 2001                 ##  
    5. ##                                                                            ##  
    6. ## This program is free software;  you can redistribute it and#or modify      ##  
    7. ## it under the terms of the GNU General Public License as published by       ##  
    8. ## the Free Software Foundation; either version 2 of the License, or          ##  
    9. ## (at your option) any later version.                                        ##  
    10. ##                                                                            ##  
    11. ## This program is distributed in the hope that it will be useful, but        ##  
    12. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##  
    13. ## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##  
    14. ## for more details.                                                          ##  
    15. ##                                                                            ##  
    16. ## You should have received a copy of the GNU General Public License          ##  
    17. ## along with this program;  if not, write to the Free Software               ##  
    18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##  
    19. ##                                                                            ##  
    20. ################################################################################  
    21. # File: runltp  
    22. #  
    23. # Description:  This script can be used to the tests in the LTP test suite  
    24. #  
    25. # Authors:      Manoj Iyer - manjo@mail.utexas.edu  
    26. #               Robbe Williamson - robbiew@us.ibm.com  
    27. #  
    28. # History:      Oct 07 2003 - Modified - Manoj Iyer  
    29. #               - use functions  
    30. #               - clean up on script exit  
    31. #               - error checking etc.  
    32. #  
    33. #               Oct 08 2003 - Modified - Manoj Iyer  
    34. #               - fixed bug in creating results directory  
    35. #               - all checks should be enlclosed in " " to avoid bash error  
    36. #               - exit with error if ltp-pan is not found in pan directory  
    37. #  
    38. #               Jul 22 2007 - Modified - Ricardo Salveti de Araujo  
    39. #               - added support to put more then one file at CMDLINE (-f)  
    40. #               - added a new option, that the user can pass the address of  
    41. #               the command file, and it'll use wget to get it (-w)  
    42. #               - now -s does the grep at the selected command files (default,  
    43. #               -f or -w)  
    44. #  
    45. #               Jul 23 2007 - Modified - Ricardo Salveti de Araujo  
    46. #               - added flag to get the command file that has all failed tests  
    47. #  
    48. #               Sep 11 2007 - Modified - Subrata Modak  
    49. #               - added option to create Failed File if it is not an absolute path  
    50. #               - added option to create Output File if it is not an absolute path  
    51. #               - added option to create Failed File compulsory, even if user has not mentioned it  
    52. #  
    53. #               Sep 14 2007 - Modified - Ricardo Salveti de Araujo  
    54. #               - cleaning and removing duplicated code  
    55. #  
    56. #               Oct 27 2007 - Modified - Ricardo Salveti de Araujo and Subrata Modak  
    57. #               - better ways to integrate "ltp/tools/genload/stress" with "ltp/runltp"  
    58. #               Nov 24 2007 - Modified - Subrata Modak  
    59. #               - Added a new option to generate output in HTML format also. Also retaining  
    60. #                 the original test format  
    61. #               Nov 28 2007 - Modified - Subrata Modak  
    62. #               - Added a new option to mail back LTP reports  
    63. #               May 19 2008 - Modified - Subrata Modak  
    64. #               - Added capability for default Log file generation  
    65. # Aug 17 2009 - Modified - Subrata Modak  
    66. # - Added Fault Injection generation Capability through -F Option  
    67. #  
    68. #################################################################################  
    69.   
    70.   
    71.   
    72.   
    73.   
    74.   
    75. setup()  
    76. {  
    77. //shell 脚本中的&&和||,commad1&&command2 或者command1 || command2,前者表示“command1执行成功就执行command2”,后者表示“command1执行失败就执行command2”,相当于一个简单的if流程控制语句  
    78.     cd `dirname $0` || \  
    79.     {  
    80. //shell脚本的嵌套执行,有两种方法``和$()引用  
    81.         echo "FATAL: unable to change directory to $(dirname $0)"  
    82.         exit 1  
    83.     }  
    84.     export LTPROOT=${PWD}  
    85.     export TMPBASE="/tmp"  
    86.     export PATH="${PATH}:${LTPROOT}/testcases/bin"  
    87.   
    88.   
    89. //注意中括号的使用,前后要保留空格-d:directory  
    90.     [ -d "$LTPROOT/testcases/bin" ] ||  
    91.     {  
    92.         echo "FATAL: LTP not installed correctly"  
    93.         echo "INFO:  Follow directions in INSTALL!"  
    94.         exit 1  
    95.     }  
    96. #-e:exist  
    97.     [ -e "$LTPROOT/bin/ltp-pan" ] ||  
    98.     {  
    99.         echo "FATAL: Test suite driver 'ltp-pan' not found"  
    100.         echo "INFO:  Follow directions in INSTALL!"  
    101.         exit 1  
    102.     }  
    103. }  
    104.   
    105.   
    106. version_of_ltp()  
    107. {  
    108.     cat "$LTPROOT/Version"  
    109.     exit 0  
    110. }  
    111.   
    112.   
    113. usage()  
    114. {  
    115. //表示打印后面的内容,知道EOF(EOF需要单独在一行),使用EOF的目的是实现多行文件的输出  
    116.     cat <<-EOF >&2  
    117.   
    118.   
    119.     usage: ${0##*/} [ -a EMAIL_TO ] [ -c NUM_PROCS ] [ -C FAILCMDFILE ] [ -d TMPDIR ]  
    120.     [ -D NUM_PROCS,NUM_FILES,NUM_BYTES,CLEAN_FLAG ] -e [ -f CMDFILES(,...) ] [ -g HTMLFILE]  
    121.     [ -i NUM_PROCS ] [ -l LOGFILE ] [ -m NUM_PROCS,CHUNKS,BYTES,HANGUP_FLAG ]  
    122.     -N -n [ -o OUTPUTFILE ] -p -q [ -r LTPROOT ] [ -s PATTERN ] [ -t DURATION ]  
    123.     -v [ -w CMDFILEADDR ] [ -x INSTANCES ] [ -b DEVICE ] [-B DEVICE_FS_TYPE]  
    124. [ -F LOOPS,PERCENTAGE ]  
    125.   
    126.   
    127.     -a EMAIL_TO     EMAIL all your Reports to this E-mail Address  
    128.     -c NUM_PROCS    Run LTP under additional background CPU load  
    129.                     [NUM_PROCS = no. of processes creating the CPU Load by spinning over sqrt()  
    130.                                  (Defaults to 1 when value)]  
    131.     -C FAILCMDFILE  Command file with all failed test cases.  
    132.     -d TMPDIR       Directory where temporary files will be created.  
    133.     -D NUM_PROCS,NUM_FILES,NUM_BYTES,CLEAN_FLAG  
    134.                     Run LTP under additional background Load on Secondary Storage (Seperate by comma)  
    135.                     [NUM_PROCS   = no. of processes creating Storage Load by spinning over write()]  
    136.                     [NUM_FILES   = Write() to these many files (Defaults to 1 when value 0 or undefined)]  
    137.                     [NUM_BYTES   = write these many bytes (defaults to 1GB, when value 0 or undefined)]  
    138.                     [CLEAN_FLAG  = unlink file to which random data written, when value 1]  
    139.     -e              Prints the date of the current LTP release  
    140.     -f CMDFILES     Execute user defined list of testcases (separate with ',')  
    141. -F LOOPS,PERCENTAGE Induce PERCENTAGE Fault in the Kernel Subsystems, and, run each test for LOOPS loop  
    142.     -g HTMLFILE     Create an additional HTML output format  
    143.     -h              Help. Prints all available options.  
    144.     -i NUM_PROCS    Run LTP under additional background Load on IO Bus  
    145.                     [NUM_PROCS   = no. of processes creating IO Bus Load by spinning over sync()]  
    146.     -K DMESG_LOG_DIR  
    147. Log Kernel messages generated for each test cases inside this directory  
    148.     -l LOGFILE      Log results of test in a logfile.  
    149.     -m NUM_PROCS,CHUNKS,BYTES,HANGUP_FLAG  
    150.                     Run LTP under additional background Load on Main memory (Seperate by comma)  
    151.                     [NUM_PROCS   = no. of processes creating main Memory Load by spinning over malloc()]  
    152.                     [CHUNKS      = malloc these many chunks (default is 1 when value 0 or undefined)]  
    153.                     [BYTES       = malloc CHUNKS of BYTES bytes (default is 256MB when value 0 or undefined) ]  
    154.                     [HANGUP_FLAG = hang in a sleep loop after memory allocated, when value 1]  
    155. -M CHECK_TYPE  
    156. [CHECK_TYPE=1 => Full Memory Leak Check tracing children as well]  
    157. [CHECK_TYPE=2 => Thread Concurrency Check tracing children as well]  
    158. [CHECK_TYPE=3 => Full Memory Leak & Thread Concurrency Check tracing children as well]  
    159.     -N              Run all the networking tests.  
    160.     -n              Run LTP with network traffic in background.  
    161.     -o OUTPUTFILE   Redirect test output to a file.  
    162.     -p              Human readable format logfiles.  
    163.     -q              Print less verbose output to screen.  
    164.     -r LTPROOT      Fully qualified path where testsuite is installed.  
    165.     -s PATTERN      Only run test cases which match PATTERN.  
    166.     -S SKIPFILE     Skip tests specified in SKIPFILE  
    167.     -t DURATION     Execute the testsuite for given duration. Examples:  
    168.                       -t 60s = 60 seconds  
    169.                       -t 45m = 45 minutes  
    170.                       -t 24h = 24 hours  
    171.                       -t 2d  = 2 days  
    172.     -T REPETITION   Execute the testsuite for REPETITION no. of times  
    173.     -w CMDFILEADDR  Uses wget to get the user's list of testcases.  
    174.     -x INSTANCES    Run multiple instances of this testsuite.  
    175.     -b DEVICE       Some tests require an unmounted block device  
    176.                     to run correctly.  
    177.     -B DEVICE_FS_TYPE The file system of test block devices.  
    178.   
    179.   
    180.   
    181.   
    182.     example: ${0##*/} -c 2 -i 2 -m 2,4,10240,1 -D 2,10,10240,1 -p -q  -l /tmp/result-log.$$ -o /tmp/result-output.$$ -C /tmp/result-failed.$$ -d ${PWD}  
    183.   
    184.   
    185.   
    186.   
    187. EOF  
    188. exit 0  
    189. }  
    190.   
    191.   
    192. main()  
    193. {  
    194.   //local 表示变量的作用域只在这个函数内部  
    195.     local CMDFILES=""  
    196.     local PRETTY_PRT=""  
    197.     local ALT_DIR_OUT=0  
    198.     local ALT_DIR_RES=0  
    199.     local ALT_HTML_OUT=0  
    200.     local ALT_EMAIL_OUT=0  
    201.     local ALT_DMESG_OUT=0  
    202.     local RUN_NETEST=0  
    203.     local RUN_REPEATED=0  
    204.     local QUIET_MODE=""  
    205.     local NETPIPE=0  
    206.     local GENLOAD=0  
    207.     local MEMSIZE=0  
    208.     local DURATION=""  
    209.     local CMDFILEADDR=""  
    210.     local FAILCMDFILE=""  
    211.     local INJECT_KERNEL_FAULT=""  
    212.     local INJECT_KERNEL_FAULT_PERCENTAGE=""  
    213.     local INJECT_FAULT_LOOPS_PER_TEST=""  
    214.     local VALGRIND_CHECK=""  
    215.     local VALGRIND_CHECK_TYPE=""  
    216.     local LOGFILE_NAME=""  
    217.     local LOGFILE=""  
    218.     local OUTPUTFILE_NAME=""  
    219.     local OUTPUTFILE=""  
    220.     local HTMLFILE_NAME=""  
    221.     local HTMLFILE=""  
    222.     local DMESG_DIR=""  
    223.     local EMAIL_TO=""  
    224.     local TAG_RESTRICT_STRING=""  
    225.     local PAN_COMMAND=""  
    226.     local DEFAULT_FILE_NAME_GENERATION_TIME=`date +"%Y_%b_%d-%Hh_%Mm_%Ss"`  
    227.     local DEVICE_FS_TYPE="ext2"  
    228.     local scenfile=  
    229.   
    230.   
    231. //注意此处的赋值  
    232.     version_date=$(cat "$LTPROOT/Version")  
    233. //循环读取脚本的输入参数,注意”:“表示-a -c等等参数的后面一定要赋值  
    234.     while getopts a:c:C:d:D:f:F:ehi:K:g:l:m:M:Nno:pqr:s:S:t:T:w:x:b:B: arg  
    235.     do  case $arg in  
    236.         a)  EMAIL_TO=$OPTARG  
    237.             ALT_EMAIL_OUT=1;;//这两个;;表示case的分隔符  
    238.         c)//$OPTARG表示对应的-c后面的参数  
    239.             NUM_PROCS=$(($OPTARG))  
    240.             if   [ "$NUM_PROCS" -eq 0 ]; then  
    241.                 # User Did not Define the Value ,or, User Defined Zero,  
    242.                 # hence, prevent from creating infinite processes  
    243.                 NUM_PROCS=1  
    244.             fi  
    245.             $LTPROOT/testcases/bin/genload --cpu $NUM_PROCS >/dev/null 2>&1 &  
    246.             GENLOAD=1 ;;  
    247.   
    248.   
    249.         C)  
    250.             case $OPTARG in  
    251.             /*) 
    252.                 FAILCMDFILE="-C $OPTARG" ;; 
    253.             *) 
    254.                 FAILCMDFILE="-C $LTPROOT/output/$OPTARG" 
    255.                 ALT_DIR_OUT=1 ;; 
    256.             esac ;; 
    257.  
    258.  
    259.         d)  # convert the user path to absolute path. 
    260.  //把相对路径或者符号链接转化为绝对路径 
    261.             export TMPBASE=$(readlink -f ${OPTARG}) ;; 
    262.  
    263.  
    264.         D)  NUM_PROCS=1; NUM_FILES=1; NUM_BYTES=$((1024 * 1024 * 1024)); CLEAN_FLAG=0 
    265.             ARGUMENT_LIST=$OPTARG 
    266.             TOTAL_ARGUMENTS=1 
    267.    //tr 是对一行进行字符串替换的程序,表示把,替换成空格 
    268.             for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '` 
    269.             do 
    270.                 case $TOTAL_ARGUMENTS in 
    271.                     1) NUM_PROCS="$ARGUMENT" ;; 
    272.                     2) NUM_FILES="$ARGUMENT" ;; 
    273.                     3) NUM_BYTES="$ARGUMENT" ;; 
    274.                     4) CLEAN_FLAG="$ARGUMENT" ;; 
    275.                 esac 
    276. //数值计算 
    277.                 TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1` 
    278.             done 
    279.             # just to get the default values if the user passed 0 
    280.             if [ "$NUM_PROCS" -eq 0 ]; then 
    281.                 NUM_PROCS=1 
    282.             fi 
    283.             if [ "$NUM_FILES" -eq 0 ]; then 
    284.                 NUM_FILES=1 
    285.             fi 
    286.             if [ "$NUM_BYTES" -eq 0 ]; then 
    287.                 NUM_BYTES=$((1024 * 1024 * 1024)) 
    288.             fi 
    289.             if [ "$CLEAN_FLAG" -ne 1 ]; then 
    290.                 CLEAN_FLAG=0 
    291.             fi 
    292.             if [ "$CLEAN_FLAG" -eq 1 ]; then 
    293.                 # Do not unlink file in this case 
    294.                 $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \ 
    295.                     $NUM_FILES --hdd-bytes $NUM_BYTES >/dev/null 2>&1 & 
    296.             else 
    297.                 # Cleanup otherwise 
    298.                 $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \ 
    299.                     $NUM_FILES --hdd-bytes $NUM_BYTES --hdd-noclean >/dev/null 2>&1 & 
    300.             fi 
    301.             GENLOAD=1;; 
    302.  
    303.  
    304.         e)  # Print out the version of LTP 
    305.             version_of_ltp 
    306.    ;; 
    307.         f)  # Execute user defined set of testcases. 
    308.             # Can be more then one file, just separate it with ',', like: 
    309.             # -f nfs,commands,/tmp/testfile 
    310.             CMDFILES=$OPTARG;; 
    311. F) INJECT_KERNEL_FAULT=1 
    312. #Seperate out the NO_OF_LOOPS & FAULT_PERCENTAGE 
    313. INJECT_FAULT_LOOPS_PER_TEST=`echo $OPTARG |cut -d',' -f1 | tr -d '\n' | tr -d ' '` 
    314. INJECT_KERNEL_FAULT_PERCENTAGE=`echo $OPTARG |cut -d',' -f2 | tr -d '\n' | tr -d ' '` 
    315. #!表示逻辑取反 
    316. if [ ! $INJECT_FAULT_LOOPS_PER_TEST ]; then 
    317. echo "Loops not properly defined. Resorting to default 5..." 
    318. export INJECT_FAULT_LOOPS_PER_TEST=5 
    319. fi 
    320. if [ ! $INJECT_KERNEL_FAULT_PERCENTAGE ]; then 
    321. echo "Fault Persentage not properly defined. Resorting to default 10..." 
    322. export INJECT_KERNEL_FAULT_PERCENTAGE=10 
    323. fi;; 
    324.         g)  HTMLFILE_NAME="$OPTARG" 
    325.             case $OPTARG in 
    326.             /*) 
    327.                 HTMLFILE="$OPTARG";; 
    328.             *) 
    329.                 HTMLFILE="$LTPROOT/output/$OPTARG";; 
    330.             esac 
    331.             ALT_DIR_OUT=1 
    332.             ALT_HTML_OUT=1;; 
    333.         h)  usage;; 
    334.  
    335.  
    336.         i) 
    337.             NUM_PROCS=$(($OPTARG)) 
    338.             if   [ "$NUM_PROCS" -eq 0 ]; then 
    339.                 # User Did not Define the Value ,or, User Defined Zero, 
    340.                 # hence, prevent from creating infinite processes 
    341.                 NUM_PROCS=1 
    342.             fi 
    343.             $LTPROOT/testcases/bin/genload --io $NUM_PROCS >/dev/null 2>&1 & 
    344.             GENLOAD=1 ;; 
    345.  
    346.  
    347.         K) 
    348.    case $OPTARG in 
    349.           /*) 
    350.     //+%X表示格式化输出成相应的形似 
    351. DMESG_DIR="$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";; 
    352.            *) 
    353.        DMESG_DIR="$LTPROOT/output/$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";; 
    354.    esac 
    355.    #-p:parents 
    356.             mkdir -p $DMESG_DIR 
    357.             ALT_DMESG_OUT=1;; 
    358.         l) 
    359.             LOGFILE_NAME="$OPTARG" 
    360.             case $OPTARG in 
    361.             /*) 
    362.                 LOGFILE="-l $OPTARG" ;; 
    363.             *) 
    364.                 LOGFILE="-l $LTPROOT/results/$OPTARG" 
    365.                 ALT_DIR_RES=1 ;; 
    366.             esac ;; 
    367.  
    368.  
    369.         m)  NUM_PROCS=1; CHUNKS=1; BYTES=$((256 * 1024 * 1024)); HANGUP_FLAG=0 
    370.             ARGUMENT_LIST=$OPTARG 
    371.             TOTAL_ARGUMENTS=1 
    372.             for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '` 
    373.             do 
    374.                 case $TOTAL_ARGUMENTS in 
    375.                     1) NUM_PROCS="$ARGUMENT" ;; 
    376.                     2) CHUNKS="$ARGUMENT" ;; 
    377.                     3) BYTES="$ARGUMENT" ;; 
    378.                     4) HANGUP_FLAG="$ARGUMENT" ;; 
    379.                 esac 
    380.                 TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1` 
    381.             done 
    382.             # just to get the default values if the user passed 0 
    383.             if [ "$NUM_PROCS" -eq 0 ]; then 
    384.                 NUM_PROCS=1 
    385.             fi 
    386.             if [ "$CHUNKS" -eq 0 ]; then 
    387.                 CHUNKS=1 
    388.             fi 
    389.             if [ "$BYTES" -eq 0 ]; then 
    390.                 BYTES=$((256 * 1024 * 1024)) 
    391.             fi 
    392.             if [ "$HANGUP_FLAG" -ne 1 ]; then 
    393.                 HANGUP_FLAG=0 
    394.             fi 
    395.             if [ "$HANGUP_FLAG" -eq 1 ]; then 
    396.                 # Hang in a Sleep loop after memory allocated 
    397.                 $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \ 
    398.                     $CHUNKS --vm-bytes $BYTES --vm-hang >/dev/null 2>&1 & 
    399.             else 
    400.                 # Otherwise Do not Hangup 
    401.                 $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \ 
    402.                     $CHUNKS --vm-bytes $BYTES >/dev/null 2>&1 & 
    403.             fi 
    404.             GENLOAD=1;; 
    405. M) 
    406. VALGRIND_CHECK=1 
    407. VALGRIND_CHECK_TYPE="$OPTARG";; 
    408.  
    409.  
    410.         N)  RUN_NETEST=1;; 
    411.  
    412.  
    413.         n) 
    414.             $LTPROOT/testcases/bin/netpipe.sh 
    415.             NETPIPE=1;; 
    416.  
    417.  
    418.         o)  OUTPUTFILE_NAME="$OPTARG" 
    419.             case $OPTARG in 
    420.             /*) 
    421.                 OUTPUTFILE="-o $OPTARG";; 
    422.             *) 
    423.                 OUTPUTFILE="-o $LTPROOT/output/$OPTARG" 
    424.                 ALT_DIR_OUT=1 ;; 
    425.             esac ;; 
    426.  
    427.  
    428.         p)  PRETTY_PRT=" -p ";; 
    429.  
    430.  
    431.         q)  QUIET_MODE=" -q ";; 
    432.  
    433.  
    434.         r)  LTPROOT=$OPTARG;; 
    435.  
    436.  
    437.         s)  TAG_RESTRICT_STRING=$OPTARG;; 
    438.  
    439.  
    440. S)  case $OPTARG in 
    441.             /*) 
    442.                 SKIPFILE=$OPTARG;; 
    443.             *) 
    444.                 SKIPFILE="$LTPROOT/$OPTARG";; 
    445.             esac ;; 
    446.  
    447.  
    448.         t)  # In case you want to specify the time 
    449.             # to run from the command line 
    450.             # (2m = two minutes, 2h = two hours, etc) 
    451.             DURATION="-t $OPTARG" ;; 
    452.  
    453.  
    454.         T)  # In case you want the testcases to runsequentially RUN_REPEATED times 
    455.             RUN_REPEATED=$OPTARG;; 
    456.  
    457.  
    458.         w)  CMDFILEADDR=$OPTARG;; 
    459.  
    460.  
    461.         x)  # number of ltp's to run 
    462.             cat <<-EOF >&1 
    463.             WARNING: The use of -x can cause unpredictable failures, as a 
    464.                      result of concurrently running multiple tests designed 
    465.                      to be ran exclusively. 
    466.                      Pausing for 10 seconds..." 
    467. EOF 
    468.             sleep 10 
    469.             INSTANCES="-x $OPTARG";; 
    470.         b) DEVICE=$OPTARG;; 
    471.         B) DEVICE_FS_TYPE=$OPTARG;; 
    472.         \?) usage;; 
    473.         esac 
    474.     done 
    475.  
    476.  
    477.     ## It would be nice to create a default log file even if the user has not mentioned 
    478.     if [ ! "$LOGFILE" ]; then                                ## User has not mentioned about Log File name 
    479.        LOGFILE_NAME=$DEFAULT_FILE_NAME_GENERATION_TIME 
    480.        LOGFILE="-l $LTPROOT/results/LTP_RUN_ON-$LOGFILE_NAME.log" 
    481.        ALT_DIR_RES=1 
    482.        PRETTY_PRT=" -p " 
    483.     fi 
    484.  
    485.  
    486.     ## It would be nice if a Failed File is compulsorily created (gives User better Idea of Tests that failed) 
    487.  
    488.  
    489.     if [ ! "$FAILCMDFILE" ]; then                            ## User has not mentioned about Failed File name 
    490.          ALT_DIR_OUT=1 
    491.          if [ ! "$OUTPUTFILE" ]; then             ## User has not mentioned about Output File name either 
    492.             if [ ! "$LOGFILE" ]; then                        ## User has not mentioned about Log File name either 
    493.                FAILED_FILE_NAME=$DEFAULT_FILE_NAME_GENERATION_TIME 
    494.                FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed" 
    495.             else     ## User Fortunately wanted a log file, 
    496.      //当前文件或者文件夹路径的/后面最后一部分 
    497.                FAILED_FILE_NAME=`basename $LOGFILE_NAME`     ## Extract log file name and use it to construct Failed file name 
    498.                FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed" 
    499.             fi 
    500.          else                                                ## User Fortunately wanted a Output file 
    501.                FAILED_FILE_NAME=`basename $OUTPUTFILE_NAME`  ## Extract output file name and use it to construct Failed file name 
    502.                FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed" 
    503.          fi 
    504.     fi 
    505.  
    506.  
    507.     if [ "$ALT_HTML_OUT" -eq 1 ] ; then                      ## User wants the HTML version of the output 
    508.        QUIET_MODE=""                                         ## Suppressing this guy as it will prevent generation of proper output 
    509.                                                              ## which the HTML parser will require 
    510.        if [ ! "$OUTPUTFILE" ]; then                          ## User has not mentioned about the Outputfile name, then we need to definitely generate one 
    511.           OUTPUTFILE_NAME=$DEFAULT_FILE_NAME_GENERATION_TIME 
    512.           OUTPUTFILE="-o $LTPROOT/output/LTP_RUN_ON-$OUTPUTFILE_NAME.output" 
    513.           ALT_DIR_OUT=1 
    514.           if [ ! "$HTMLFILE" ] ; then                        ## User has not mentioned HTML File name, We need to create one 
    515.              HTMLFILE_NAME=`basename $OUTPUTFILE_NAME` 
    516.              HTMLFILE="$LTPROOT/output/$HTMLFILE_NAME.html" 
    517.           fi 
    518.        fi 
    519.     fi 
    520.  
    521.  
    522.     # If we need, create the output directory 
    523.     [ "$ALT_DIR_OUT" -eq 1 ] && \ 
    524.     { 
    525.         [ ! -d $LTPROOT/output ] && \ 
    526.         { 
    527.            echo "INFO: creating $LTPROOT/output directory" 
    528.            mkdir -p $LTPROOT/output || \ 
    529.            { 
    530.                echo "ERROR: failed to create $LTPROOT/output" 
    531.                exit 1 
    532.             } 
    533.         } 
    534.     } 
    535.     # If we need, create the results directory 
    536.     [ "$ALT_DIR_RES" -eq 1 ] && \ 
    537.     { 
    538.         echo "INFO: creating $LTPROOT/results directory" 
    539.         [ ! -d $LTPROOT/results ] && \ 
    540.         { 
    541.            mkdir -p $LTPROOT/results || \ 
    542.            { 
    543.                echo "ERROR: failed to create $LTPROOT/results" 
    544.                exit 1 
    545.             } 
    546.         } 
    547.     } 
    548.  
    549.  
    550.     # Added -m 777 for tests that call tst_tmpdir() and try to 
    551.     #  write to it as user nobody 
    552.     //777 表示任何人都对文件夹能够可读,可写,可执行 
    553.     mkdir -m 777 -p $TMPBASE || \ 
    554.     { 
    555.         echo "FATAL: Unable to make temporary directory $TMPBASE" 
    556.         exit 1 
    557.     } 
    558.     # use mktemp to create "safe" temporary directories 
    559.     export TMPTEMPLATE="${TMPBASE}/ltp-XXXXXXXXXX" 
    560.     //创建临时目录或者文件 
    561.     TMP=`mktemp -d $TMPTEMPLATE` || \ 
    562.     { 
    563.         echo "FATAL: Unable to make temporary directory: $TMP" 
    564.         exit 1 
    565.     } 
    566.     export TMP 
    567.     # To be invoked by tst_tmpdir() 
    568.     # write to it as user nobody 
    569.     export TMPDIR=$TMP 
    570.  
    571.  
    572.     chmod 777 $TMP || \ 
    573.     { 
    574.       echo "unable to chmod 777 $TMP ... aborting" 
    575.       exit 1 
    576.     } 
    577.  
    578.  
    579.     cd $TMP || \ 
    580.     { 
    581.       echo "could not cd ${TMP} ... exiting" 
    582.       exit 1 
    583.     } 
    584.  
    585.  
    586.     [ -n "$INSTANCES" ] && \ 
    587.     { 
    588.       INSTANCES="$INSTANCES -O ${TMP}" 
    589.     } 
    590.  
    591.  
    592.     [ "$RUN_NETEST" -eq 1 ] && \ 
    593.     { 
    594.         [ -z "$RHOST" ] || [ -z "$PASSWD" ] && \ 
    595.         { 
    596.             [ -z "$RHOST" ] && \ 
    597.             { 
    598.                 echo \ 
    599.                 "INFO: Enter RHOST = 'name of the remote host machine'" 
    600.                 echo -n "-> " 
    601. #read value for RHOST from terminal 
    602.                 read RHOST 
    603.             } 
    604.  
    605.  
    606.             [ -z "$PASSWD" ] && \ 
    607.             { 
    608.                 echo " " 
    609.                 echo \ 
    610.                 "INFO: Enter PASSWD = 'root passwd of the remote host machine'" 
    611.                 echo -n "-> " 
    612.                 read PASSWD 
    613.             } 
    614.             export RHOST=$RHOST 
    615.             export PASSWD=$PASSWD 
    616.             echo "WARNING: security of $RHOST may be compromised" 
    617.         } 
    618.     } 
    619.  
    620.  
    621.     # If user does not provide a command file select a default set of testcases 
    622.     # to execute. 
    623.     if [ -z "$CMDFILES" ] && [ -z "$CMDFILEADDR" ] 
    624.     then 
    625.         cat <<-EOF >&1 
    626.  
    627.  
    628.     INFO: no command files were provided. Will execute the following 
    629.           runtest scenario files: 
    630.  
    631.  
    632. `cat $LTPROOT/scenario_groups/default | tr '\012' ' '` 
    633.  
    634.  
    635. EOF 
    636.  
    637.  
    638. SCENARIO_LISTS="$LTPROOT/scenario_groups/default" 
    639.         if [ "$RUN_NETEST" -eq 1 ]; then 
    640.             SCENARIO_LISTS="$SCENARIO_LISTS $LTPROOT/scenario_groups/network" 
    641.         fi 
    642.  
    643.  
    644.     # DO NOT INDENT/DEDENT! 
    645.         if [ -n "$SCENARIO_LISTS" ]; then 
    646.             # Insurance to make sure that the first element in the pipe 
    647.             # completed successfully. 
    648.             cat_ok_sentinel=$TMP/cat_ok.$$ 
    649.    (cat $SCENARIO_LISTS && touch "$cat_ok_sentinel") | \ 
    650.                 while read scenfile; do 
    651.  
    652.  
    653.                     scenfile=${LTPROOT}/runtest/$scenfile 
    654.  
    655.  
    656.                     # Skip over non-existent scenario files; things are 
    657.                     # robust enough now that the build will fail if these 
    658.                     # files don't exist. 
    659.                     [ -f "$scenfile" ] || continue 
    660.  
    661.  
    662.                     cat $scenfile >> "$TMP/alltests" || { 
    663.                         echo "FATAL: unable to append to command file" 
    664.                         rm -Rf "$TMP" 
    665.                         rm -f "$cat_ok_sentinel" 
    666.                         exit 1 
    667.                     } 
    668.  
    669.  
    670.                 done 
    671.  
    672.  
    673.             rm -f "$cat_ok_sentinel" 
    674.  
    675.  
    676.         fi 
    677.     # ^^DO NOT INDENT/DEDENT!^^ 
    678.  
    679.  
    680.     fi 
    681.  
    682.  
    683.     [ -n "$CMDFILES" ] && \ 
    684.     { 
    685.         for scenfile in `echo "$CMDFILES" | tr ',' ' '` 
    686.         do 
    687.             [ -f "$scenfile" ] || scenfile="$LTPROOT/runtest/$scenfile" 
    688.             cat "$scenfile" >> ${TMP}/alltests || \ 
    689.             { 
    690.                 echo "FATAL: unable to create command file" 
    691.                 rm -Rf "$TMP" 
    692.                 exit 1 
    693.             } 
    694.         done 
    695.     } 
    696.  
    697.  
    698.     [ -n "$CMDFILEADDR" ] && \ 
    699.     { 
    700.      // -q:quiet 用于出去干扰信息,-O ouputfilename 
    701.         wget -q "${CMDFILEADDR}" -O ${TMP}/wgetcmdfile 
    702. //判断上一条命令是否执行成功 
    703.         if [ $? -ne 0 ]; then 
    704.             echo "FATAL: error while getting the command file with wget (address $CMDFILEADDR)" 
    705.             exit 1 
    706.         fi 
    707.         cat "${TMP}/wgetcmdfile" >> ${TMP}/alltests || \ 
    708.         { 
    709.             echo "FATAL: unable to create command file" 
    710.             exit 1 
    711.         } 
    712.     } 
    713.  
    714.  
    715.     # The fsx-linux tests use the SCRATCHDEV environment variable as a location 
    716.     # that can be reformatted and run on.  Set SCRATCHDEV if you want to run 
    717.     # these tests.  As a safeguard, this is disabled. 
    718.     unset SCRATCHDEV 
    719.     [ -n "$SCRATCHDEV" ] && \ 
    720.     { 
    721.          cat ${LTPROOT}/runtest/fsx >> ${TMP}/alltests || 
    722.          { 
    723.              echo "FATAL: unable to create  fsx-linux tests command file" 
    724.              exit 1 
    725.          } 
    726.     } 
    727.  
    728.  
    729.     # If enabled, execute only test cases that match the PATTERN 
    730.     if [ -n "$TAG_RESTRICT_STRING" ] 
    731.     then 
    732.         mv -f ${TMP}/alltests ${TMP}/alltests.orig 
    733.    grep $TAG_RESTRICT_STRING ${TMP}/alltests.orig > ${TMP}/alltests #Not worth checking return codes for this case 
    734.     fi 
    735.  
    736.  
    737.     # Blacklist or skip tests if a SKIPFILE was specified with -S 
    738.     if [ -n "$SKIPFILE" ] 
    739.     then 
    740.         for file in $( cat $SKIPFILE ); do 
    741.             sed -i "/^$file[ \t]/d" ${TMP}/alltests 
    742.         done 
    743.     fi 
    744.  
    745.  
    746.     # check for required users and groups 
    747.     ${LTPROOT}/IDcheck.sh || \ 
    748.     { 
    749.         echo "WARNING: required users and groups not present" 
    750.         echo "WARNING: some test cases may fail" 
    751.     } 
    752.  
    753.  
    754.     # display versions of installed software 
    755.     [ -z "$QUIET_MODE" ] && \ 
    756.     { 
    757.         ${LTPROOT}/ver_linux || \ 
    758.         { 
    759.             echo "WARNING: unable to display versions of software installed" 
    760.             exit 1 
    761.     } 
    762.     } 
    763.  
    764.  
    765.     if [ -n "$DEVICE" ]; then 
    766.         sed -i "s|DEVICE|$DEVICE|"  ${TMP}/alltests 
    767.         RC=$? 
    768.     else 
    769.         create_block 
    770.         if [ $? -eq 0 ]; then 
    771.             sed -i "s|DEVICE|$DEVICE|"  ${TMP}/alltests 
    772.             RC=$? 
    773.         else 
    774.             echo "no block device was specified on commandline." 
    775.             echo "Block device could not be created using loopback device" 
    776.             echo "Tests which require block device are disabled." 
    777.             echo "You can specify it with option -b" 
    778.             sed -i "/DEVICE/d"  ${TMP}/alltests 
    779.             RC=$? 
    780.         fi 
    781.     fi 
    782.  
    783.  
    784.     if [ $RC -ne 0 ]; then 
    785.             echo "FATAL: error during processing alltests file by sed" 
    786.             exit 1 
    787.     fi 
    788.  
    789.  
    790.     if [ -n "$DEVICE" ]; then 
    791.         sed -i "s|DEVICE_FS_TYPE|$DEVICE_FS_TYPE|"  ${TMP}/alltests 
    792.     fi 
    793.  
    794.  
    795.     if [ $? -ne 0 ]; then 
    796.         echo "FATAL: error during processing alltests file by sed" 
    797.         exit 1 
    798.     fi 
    799.  
    800.  
    801.     if [ $RUN_REPEATED -gt 1 ]; then # You need to specify at least more than 1 sequential run, else it runs default 
    802.          echo "PAN will run these test cases $RUN_REPEATED times....." 
    803.          echo "Test Tags will be Prepended with ITERATION NO.s....." 
    804.          inc=1 
    805.          sed -e '/^$/ d' -e 's/^[ ,\t]*//' -e '/^#/ d' < ${TMP}/alltests > ${TMP}/alltests.temp ##This removes all newlines, leading spaces, tabs, #  
    806.          sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp > ${TMP}/alltests ## .temp is kept as Base file  
    807.          while [ $inc -lt $RUN_REPEATED ] ; do  
    808.                inc=`expr $inc + 1`  
    809.                sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp >> ${TMP}/alltests #Keep appending with Iteration No.s  
    810.          done  
    811.     fi  
    812.   
    813.   
    814.     [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test start time: $(date)" ; }  
    815.     PAN_COMMAND="${LTPROOT}/bin/ltp-pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \  
    816.     -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE"  
    817.     echo "COMMAND:    $PAN_COMMAND"  
    818.     if [ ! -z "$TAG_RESTRICT_STRING" ] ; then  
    819.       echo "INFO: Restricted to $TAG_RESTRICT_STRING"  
    820.     fi  
    821.     #$PAN_COMMAND #Duplicated code here, because otherwise if we fail, only "PAN_COMMAND" gets output  
    822.   
    823.   
    824.     ## Display the Output/Log/Failed/HTML file names here  
    825.     echo -e "LOG File: \c"  
    826.     echo $LOGFILE | cut -b4-  
    827.   
    828.   
    829.     if [ "$OUTPUTFILE" ]; then  
    830.        echo -e "OUTPUT File: \c"  
    831.        echo $OUTPUTFILE | cut -b4-  
    832.     fi  
    833.   
    834.   
    835.     echo -e "FAILED COMMAND File: \c"  
    836.     echo $FAILCMDFILE | cut -b4-  
    837.   
    838.   
    839.     if [ "$HTMLFILE" ]; then  
    840.        echo "HTML File: $HTMLFILE"  
    841.     fi  
    842.   
    843.   
    844.     echo "Running tests......."  
    845.     test_start_time=$(date)  
    846.   
    847.   
    848. # User wants testing with Kernel Fault Injection  
    849. if [ $INJECT_KERNEL_FAULT ] ; then  
    850. #See if Debugfs is mounted, and  
    851. #Fault Injection Framework available through Debugfs  
    852. use_faultinjection=true  
    853. for debug_subdir in \  
    854. fail_io_timeout \  
    855. fail_make_request \  
    856. fail_page_alloc \  
    857. failslab \  
    858. do  
    859. if [ -d "/sys/kernel/debug/$debug_subdir" ]  
    860. then  
    861. use_faultinjection=true  
    862. break  
    863. fi  
    864. done  
    865. if $use_faultinjection; then  
    866. #If atleast one of the Framework is available  
    867. #Go ahead to Inject Fault & Create required  
    868. #Command Files for LTP run  
    869. echo Running tests with Fault Injection Enabled in the Kernel...  
    870. awk -v LOOPS=$INJECT_FAULT_LOOPS_PER_TEST \  
    871. -v PERCENTAGE=$INJECT_KERNEL_FAULT_PERCENTAGE \  
    872. -f ${LTPROOT}/bin/create_kernel_faults_in_loops_and_probability.awk \  
    873. ${TMP}/alltests > ${TMP}/alltests.tmp  
    874. cp ${TMP}/alltests.tmp ${TMP}/alltests  
    875. rm -rf ${TMP}/alltests.tmp  
    876. else  
    877. echo Fault Injection not enabled in the Kernel..  
    878. echo Running tests normally...  
    879. fi  
    880. fi  
    881.   
    882.   
    883. ## Valgrind Check will work only when Kernel Fault Injection is not expected,  
    884. ## We do not want to test Faults when valgrind is running  
    885. if [ $VALGRIND_CHECK ]; then  
    886. if [ ! $INJECT_KERNEL_FAULT ]; then  
    887. which valgrind || VALGRIND_CHECK_TYPE=XYZ  
    888. case $VALGRIND_CHECK_TYPE in  
    889. [1-3])  
    890. awk -v CHECK_LEVEL=$VALGRIND_CHECK_TYPE \  
    891. -f ${LTPROOT}/bin/create_valgrind_check.awk \  
    892. ${TMP}/alltests $VALGRIND_CHECK_TYPE > \  
    893. ${TMP}/alltests.tmp  
    894. cp ${TMP}/alltests.tmp ${TMP}/alltests  
    895. rm -rf ${TMP}/alltests.tmp  
    896. ;;  
    897. *)  
    898. echo "Invalid Memory Check Type, or, Valgrind is not available"  
    899. ;;  
    900. esac  
    901. fi  
    902. fi  
    903.   
    904.   
    905. if [ $ALT_DMESG_OUT -eq 1 ] ; then  
    906. #We want to print dmesg output for each test,lets do the trick inside the script  
    907. echo Enabling dmesg output logging for each test...  
    908. awk -v DMESG_DIR=$DMESG_DIR \  
    909. -f ${LTPROOT}/bin/create_dmesg_entries_for_each_test.awk \  
    910. ${TMP}/alltests > ${TMP}/alltests.tmp  
    911. cp ${TMP}/alltests.tmp ${TMP}/alltests  
    912. rm -rf ${TMP}/alltests.tmp  
    913. fi  
    914.     # Some tests need to run inside the "bin" directory.  
    915.     cd "${LTPROOT}/testcases/bin"  
    916.     "${LTPROOT}/bin/ltp-pan" $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE  
    917.   
    918.   
    919.     if [ $? -eq 0 ]; then  
    920.       echo "INFO: ltp-pan reported all tests PASS"  
    921.       VALUE=0  
    922.       export LTP_EXIT_VALUE=0;  
    923.     else  
    924.       echo "INFO: ltp-pan reported some tests FAIL"  
    925.       VALUE=1  
    926.       export LTP_EXIT_VALUE=1;  
    927.     fi  
    928.     cd ..  
    929.     echo "LTP Version: $version_date"  
    930.   
    931.   
    932. # $DMESG_DIR is used to cache messages obtained from dmesg after a test run.  
    933. # Proactively reap all of the 0-byte files in $DMESG_DIR as they have zero value  
    934. # and only clutter up the filesystem.  
    935.   
    936.   
    937. if [ $ALT_DMESG_OUT -eq 1 ] ; then  
    938. if ! find "$DMESG_DIR" -size 0 -exec rm {} + ; then  
    939. echo "cd to $DMESG_DIR failed: $?"  
    940. fi  
    941. if [ -n "$(ls "$DMESG_DIR")" ] ; then  
    942. echo "Kernel messages were generated for LTP tests $version_date"  
    943. else  
    944. echo "No Kernel messages were generated for LTP tests $version_date"  
    945. fi  
    946. fi  
    947.   
    948.   
    949.     if [ "$ALT_HTML_OUT" -eq 1 ] ; then        #User wants the HTML output to be created, it then needs to be generated  
    950.        export LTP_VERSION=$version_date  
    951.        export TEST_START_TIME=$test_start_time  
    952.        export TEST_END_TIME=$(date)  
    953.        OUTPUT_DIRECTORY=`echo $OUTPUTFILE | cut -c4-`  
    954.        LOGS_DIRECTORY="$LTPROOT/results"  
    955.        export TEST_OUTPUT_DIRECTORY="$LTPROOT/output"  
    956.        export TEST_LOGS_DIRECTORY=$LOGS_DIRECTORY  
    957.        echo "Generating HTML Output.....!!"  
    958.        ( perl $LTPROOT/bin/genhtml.pl $LTPROOT/bin/html_report_header.txt test_start test_end test_output execution_status $OUTPUT_DIRECTORY  > $HTMLFILE; )  
    959.        echo "Generated HTML Output.....!!"  
    960.        echo "Location: $HTMLFILE";  
    961.   
    962.   
    963.     fi  
    964.   
    965.   
    966.     if [ "$ALT_EMAIL_OUT" -eq 1 ] ; then                      ## User wants reports to be e-mailed  
    967.        if [ [ ! "$HTMLFILE_NAME" ] -o [ ! "$OUTPUTFILE_NAME" ] -o [ ! "$LOGFILE_NAME" ] ] ; then  
    968.           ##User does not have output/logs/html-output, nothing to be mailed in this situation  
    969.           echo "Nothing to be mailed here...."  
    970.        else  
    971.            TAR_FILE_NAME=LTP_RUN_$version_date$DEFAULT_FILE_NAME_GENERATION_TIME.tar  
    972.            if [ "$HTMLFILE_NAME" ] ; then                          ## HTML file Exists  
    973.               if [ "$ALT_HTML_OUT" -ne 1 ] ; then                  ## The HTML file path is absolute and not $LTPROOT/output  
    974.                  mkdir -p $LTPROOT/output                          ## We need to create this Directory  
    975.                  cp $HTMLFILE_NAME $LTPROOT/output/  
    976.               fi  
    977.            fi  
    978.            if [ "$OUTPUTFILE_NAME" ] ; then                        ## Output file exists  
    979.               if [ "$ALT_DIR_OUT" -ne 1 ] ; then                   ## The Output file path is absolute and not $LTPROOT/output  
    980.                  mkdir -p $LTPROOT/output                          ## We need to create this Directory  
    981.                  cp $OUTPUTFILE_NAME $LTPROOT/output/  
    982.               fi  
    983.            fi  
    984.            if [ "$LOGFILE_NAME" ] ; then                           ## Log file exists  
    985.               if [ "$ALT_DIR_RES" -ne 1 ] ; then                   ## The Log file path is absolute and not $LTPROOT/results  
    986.                  mkdir -p $LTPROOT/results                         ## We need to create this Directory  
    987.                  cp $LOGFILE_NAME $LTPROOT/results/  
    988.               fi  
    989.            fi  
    990.            if [ -d $LTPROOT/output ] ; then  
    991.               tar -cf  ./$TAR_FILE_NAME $LTPROOT/output  
    992.               if [ $? -eq 0 ]; then  
    993.                  echo "Created TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/output"  
    994.               else  
    995.                  echo "Cannot Create TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/output"  
    996.               fi  
    997.            fi  
    998.            if [ -d $LTPROOT/results ] ; then  
    999.               tar -uf ./$TAR_FILE_NAME $LTPROOT/results  
    1000.               if [ $? -eq 0 ]; then  
    1001.                  echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/results"  
    1002.               else  
    1003.                  echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/results"  
    1004.               fi  
    1005.            fi  
    1006.            if [ -e $LTPROOT/nohup.out ] ; then                     ## If User would have Chosen nohup to do ltprun  
    1007.               tar -uf ./$TAR_FILE_NAME $LTPROOT/nohup.out  
    1008.               if [ $? -eq 0 ]; then  
    1009.                  echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/nohup.out"  
    1010.               else  
    1011.                  echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/nohup.out"  
    1012.               fi  
    1013.            fi  
    1014.            gzip ./$TAR_FILE_NAME                                     ## gzip this guy  
    1015.            if [ $? -eq 0 ]; then  
    1016.               echo "Gunzipped TAR File: ./$TAR_FILE_NAME"  
    1017.            else  
    1018.               echo "Cannot Gunzip TAR File: ./$TAR_FILE_NAME"  
    1019.            fi  
    1020.            if [ -e /usr/bin/mutt ] ; then                          ## This is a better mail client than others  
    1021.               echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz"  
    1022.               mutt -a ./$TAR_FILE_NAME.gz -s "LTP Reports on $test_start_time" $EMAIL_TO < /dev/null  
    1023.               if [ $? -eq 0 ]; then  
    1024.                  echo "Reports Successfully mailed to: $EMAIL_TO"  
    1025.               else  
    1026.                  echo "Reports cannot be mailed to: $EMAIL_TO"  
    1027.               fi  
    1028.            else ## Use our Ageold mail program  
    1029.               echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz"  
    1030.               uuencode ./$TAR_FILE_NAME.gz $TAR_FILE_NAME.gz | mail  $EMAIL_TO -s "LTP Reports on $test_start_time"  
    1031.               if [ $? -eq 0 ]; then  
    1032.                  echo "Reports Successfully mailed to: $EMAIL_TO"  
    1033.               else  
    1034.                  echo "Reports cannot be mailed to: $EMAIL_TO"  
    1035.               fi  
    1036.            fi  
    1037.        fi  
    1038.     fi  
    1039.   
    1040.   
    1041.     [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test end time: $(date)" ; }  
    1042.   
    1043.   
    1044.     [ "$GENLOAD" -eq 1 ] && { killall -9 genload  >/dev/null 2>&1; }  
    1045.     [ "$NETPIPE" -eq 1 ] && { killall -9 NPtcp  >/dev/null 2>&1; }  
    1046.   
    1047.   
    1048.     [ "$ALT_DIR_OUT" -eq 1 ] || [ "$ALT_DIR_RES" -eq 1 ] && \  
    1049.     {  
    1050.     cat <<-EOF >&1  
    1051.   
    1052.   
    1053.        ###############################################################  
    1054.   
    1055.   
    1056.             Done executing testcases.  
    1057.             LTP Version:  $version_date  
    1058.        ###############################################################  
    1059.   
    1060.   
    1061. EOF  
    1062.     }  
    1063.     exit $VALUE  
    1064. }  
    1065.   
    1066.   
    1067. create_block()  
    1068. {  
    1069.     #create a block device with ext4 filesystem.  
    1070.     dd if=/dev/zero of=${TMP}/test.img bs=1kB count=10240  
    1071.     if [ $? -ne 0 ]; then  
    1072.         echo "Failed to create loopback device image, please check disk space and re-run"  
    1073.         return 1  
    1074.     else  
    1075.         ##search for an unused loop dev  
    1076.         LOOP_DEV=$(losetup -f)  
    1077.         if [ $? -ne 0 ]; then  
    1078.             echo "no unused loop device is found"  
    1079.             return 1  
    1080.         else  
    1081.             ##attach the created file to loop dev.  
    1082.             losetup $LOOP_DEV ${TMP}/test.img  
    1083.             if [ $? -ne 0 ]; then  
    1084.                 echo "losetup failed to create block device"  
    1085.                 return 1  
    1086.             fi  
    1087.             DEVICE=$LOOP_DEV  
    1088.             return 0  
    1089.         fi  
    1090.     fi  
    1091. }  
    1092.   
    1093.   
    1094. cleanup()  
    1095. {  
    1096.     [ "$LOOP_DEV" ] && losetup -d $LOOP_DEV  
    1097.     rm -rf ${TMP}  
    1098. }  
    1099.   
    1100.   
    1101. trap "cleanup" 0  
    1102. setup  
    1103. main "$@"  
    1104.   
    1105.   
    1106. #vim: syntax=sh
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值