51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 10723|回复: 14

写了一个功能测试的shell脚本...

[复制链接]

该用户从未签到

发表于 2005-3-22 09:07:39 | 显示全部楼层 |阅读模式
没有通用性...针对我们自己的设备的...

!/bin/sh
#---------------------------------
#1.var
#---------------------------------
#(1)define var
#1.1 usual var
FTPSERV="192.168.10.1"
FTPSERV2="192.168.20.1"
FTPUSER="1"
FTPPASS="111111"
READCSIZE="142516"
RCSIZE="0"
PLATFORM="none"
USBCHK="none"
POWCHK="none"
ETHX=0

#1.2 error var
WANERR="none"
USBERR="none"
POWERR="none"
STAERR="none"
ALAERR="none"
ADSLERR="none"

#---------------------------------
#2 function
#---------------------------------
jecho()
{
        echo -e "\t$1"
}

get_platform()
{
        jecho "lease input a choice\n"
        jecho "1.008"
        jecho "2.108WithADSL"
        jecho "3.108WithoutADSL"
        jecho "4.exit"
        echo -en "\t"       
        read PLATFORM
        case $PLATFORM in
                1)PLATFORM="008";;
                2)PLATFORM="108WithADSL";;
                3)PLATFORM="108WithoutADSL";;
                4)exit;;
                5)PLATFORM="none";jecho "Invalid input,select again";;
        esac
}

check_wan_network()
{
        if [ $IXP1 = "192.168.10.10" ] && [ $MASK = "255.255.255.0" ];then
                jecho "(3)Info:   The Wan interface set to \"$IXP1/$MASK\"..."
        else
                jecho "(3)Error:  Wan interface error"
                WANERR="error";
        fi
}

check_download_readcert()
{
        if [ -f ./readcert ] && [ $RCSIZE -eq $READCSIZE ];then
                jecho "(4)Info:   Download readcert Success"
        else
                jecho "(4)Warningownload readcert failed...now exit"
                exit 1
        fi
}

check_x_property()
{
        if [ -x ./readcert ];then
                jecho "(5)Info:   Get execute property success..."
        else
                jecho "(5)Warning:readcert can't get execute property,exit..."
                exit
        fi
}
       
check_usb()
{
        echo -ne "\tNow,Plase insert a usb key has certificate in it..."
        read -p "ress any key to continue" -s -n 1 && echo
        ./readcert
        jecho "Question(1): Does it display normally?y|n"
        echo -en "\t"
        read USBCHK
       
        case $USBCHK in
                y|yes|Y|YES)
                        jecho "(6)Info:   USBKey success..."
                        USBERR="good";
                        ;;
                n|no|N|NO)
                        jecho "(6)Error:  USBKey error..."
                        USBERR="error";
                        ;;
                *)
                        jecho "(6)Warning:Invalid input,please reinput..."
                        USBERR="none";
                        ;;
        esac
}

check_power_led()
{
jecho "Question(2): Does the power led be right?y|n"
echo -ne "\t"
read POWCHK
        case $POWCHK in
                y|Y|yes|YES)
                        jecho "(7)Info:   Power led seems good..."       
                        POWERR="good"
                        ;;
                n|N|no|NO)
                        jecho "(7)Error:  Power led seems error.."
                        POWERR="error"
                        ;;
                *)
                        jecho "invalid input,please use y or n again."
                        POWERR="none"
                        ;;
        esac
}

check_status_led()
{
jecho "Question(3): Does the status led be right?y|n"
echo -ne "\t"
read STACHK
        case $STACHK in
                y|Y|yes|YES)
                        jecho "(8)Info:   status led seems good..."       
                        STAERR="good"
                        ;;
                n|N|no|NO)
                        jecho "(8)Error:  status led seems error.."
                        STAERR="error"
                        ;;
                *)
                        jecho "invalid input,please use y or n again."
                        STAERR="none"
                        ;;
        esac
}

check_alarm_led()
{
jecho "Question(4): Does the alarm led be right?y|n"
echo -ne "\t"
read ALACHK
        case $ALACHK in
                y|Y|yes|YES)
                        jecho "(9)Info:   alarm led seems good..."       
                        ALAERR="good"
                        ;;
                n|N|no|NO)
                        jecho "(9)Error:  alarm led seems error.."
                        ALAERR="error"
                        ;;
                *)
                        jecho "invalid input,please use y or n again."
                        ALAERR="none"
                        ;;
        esac
}

check_108_wan()
{
        if [ $WANERR = "error" ];then
                jecho "Error()Wan Interface is error..."
        fi
}

check_108_adsl_wan()
{
jecho "check_108_adsl_wan"
#1. WANLED
        WANLEDCHK="none"       
        while [ $WANLEDCHK = "none" ]
        do
        jecho "Question()oes the Wan interface led be right?y|n"
        read WANLEDCHK
                case $WANLEDCHK in
                        y|Y|yes|YES)
                                jecho "()Info:OK,the wan led seems good"
                                WANLEDCHK="good"       
                                ;;
                        n|N|no|NO)
                                jecho "()Error:Maybe it has these errors:"
                                jecho "()Error->108 board ixp1 interface error"
                                jecho "()Error->adsl board error"
                                jecho "()Error->adsl and 108 board error"
                                WANLEDCHK="error"
                                ;;
                        *)
                                jecho "Invalid input,please select y or n"
                                WANLEDCHK="none"
                                ;;
                esac
        done
#2. ifconfig
ifconfig ixp1 192.168.1.10
ping -c 1 192.168.1.1 >/dev/null 2>&1 && jecho "()Info:adsl and 108 board connect good" || jecho "()Error:adsl and 108 board connect error"
#3. connect adsl line to wan interface
jecho "lease insert adsl line to wan interface,and wait 1 minutes"
while [ $LD5CHK="none" ]
do
jecho "Questionoes ld5 led be right after 1 minutes?"
read LD5CHK
        case $LD5CHCK in
                y|Y|yes|YES)
                        jecho "()Info:OK,the adsl line is good"
                        LD5CHK="good"       
                        ;;
                n|N|no|NO)
                        jecho "()Error:Oh,the adsl line or adsl board seems error"
                        LD5CHK="error"
                        ;;
                *)
                        jecho "Invalid input,Please input y or n"
                        LD5CHK="none"
                        ;;
        esac
done
#4. determine adsl
if [ $WANLEDCHK="good" ] && [ $LD5CHK="good" ];then
        jecho "Error(): ADSL board error"
fi
}

check_108_lan()
{
        X=0
        jecho "Now checking 108 lan..."
        while [ $X -lt 7 ]
        do
                echo -ne "\tPlease connect the eth$X and the ftpserv with ixp0,and press enter"
                read
                if ping -c 1 $FTPSERV2 >/dev/null 2>&1
                then
                        jecho "(10)Info:   eth$X seems good"
                        eval err$X="good"
                else       
                        jecho "(10)Error:  eth$X seems error"
                        eval err$X="error"
                fi
                X=`expr $X + 1`                 
        done
}

check_008_lan()
{
        X=0
        while [ $X -lt 4 ]
        do
                echo -ne "\tPlease connect the lan$X and the ftpserv with ixp0,and press enter"
                read
                if ping -c 1 $FTPSERV2 >/dev/null 2>&1
                then
                        jecho "(10)Info:   eth$X seems good"
                        eval err$X="good"  
                else       
                        jecho "(10)Error:  eth$X seems error"
                        eval err$X="error"
                fi
                X=`expr $X + 1`                 
        done
}

print_led_result()
{
        #led power
        if [ $POWERR = "good" ];then
                jecho "Result(2): Led Power seems good"
        elif [ $POWERR = "error" ];then
                jecho "Result(2): Led Power seems error"
        fi
       
        #led status
        if [ $STAERR = "good" ];then
                jecho "Result(3): Led status seems good"
        elif [ $STAERR = "error" ];then
                jecho "Result(3): Led status seems good"
        fi

        #led alarm
        if [ $ALAERR = "good" ];then
                jecho "Result(4): Led Alarm seems good"
        elif [ $ALAERR = "error" ];then
                jecho "Result(4): Led Alarm seem error"
        fi
}

print_108_lan_result()
{
        Y=0
        while [ $Y -lt 7 ]
        do
                test=`eval 'echo "$err'"$Y"'"'`
                if [ $test = "error" ];then
                        jecho "Result(5): eth$Y seems error"
                elif [ $test = "good" ];then
                        jecho "Result(5): eth$Y seems good"
                else
                        exit
                fi
                Y=`expr $Y + 1`
        done
}                               

print_008_lan_result()
{
        Y=0
        while [ $Y -lt 4 ]
        do
                test=`eval 'echo "$err'"$Y"'"'`
                if [ $test = "error" ];then
                        jecho "Result(5): lan$Y seems error"
                elif [ $test = "good" ];then
                        jecho "Result(5): lan$Y seems good"
                else
                        exit
                fi
                Y=`expr $Y + 1`
        done
}                               

print_lan_result()
{
        if [ $PLATFORM="108WithADSL" ] || [ $PLATFORM="108WithoutADSL" ];then
                print_108_lan_result
        elif [ $PLATFORM="008" ];then
                print_008_lan_result
        else
                exit       
        fi                       
}

print_usb_result()
{
        if [ $USBERR = "error" ];then
                jecho "Result(1):USB interface seems good"
        else
                jecho "Result(1):USB interface seems good"
        fi
}

print_wan_result()
{
        if [ $WANERR="good" ];then
                jecho "Result(6): Wan interface seems good"
        elif [ $WANERR="error" ];then
                jecho "Result(6): Wan interface seems error"
        fi
}

print_008_result()
{
        print_led_result
        print_lan_result
        print_wan_result
}

print_108_result()
{
        print_usb_result
        print_led_result
        print_lan_result
        print_wan_result
}

print_108_adsl_result()
{
        print_usb_result
        print_led_result
        print_lan_result
        print_wan_result
}

#3 test
#3.1 get platform
echo -e "\n\n"
jecho "--===Welcome to sunyard vpn autotest program===--"
echo -e "\n\n"
while [ $PLATFORM = "none" ]
do
        get_platform
done
jecho "Here's Test steps----->"
echo -e "\n"
jecho "(1)Info:   You have select $PLATFORM"
jecho "(2)Warninglease make sure the ftpserver hasn't got a firewall running"
jecho "please connect the wan and the ftpserv"

#3.2 Network setting
ifconfig ixp1 192.168.10.10 netmask 255.255.255.0
IXP1=`ifconfig ixp1 | grep "inet" | cut -d: -f2 | awk '{print $1}'`
MASK=`ifconfig ixp1 | grep "Mask" | cut -d: -f4`
check_wan_network

#3.3 Download readcert
if [ $PLATFORM = "108WithADSL" ] && [ $PLATFORM = "108WithoutADSL" ];then
wget ftp://$FTPUSER\"\"FTPPASS@$FTPSERV/readcert >/dev/null 2>&1
RCSIZE=`ls -l ./readcert | awk '{print $5}'`
check_download_readcert
chmod +x ./readcert
check_x_property

#3.insert usb key and check
while [ $USBERR = "none" ]
do
check_usb
done
fi


#3.2 led test
#3.2.1 power led
while [ $POWERR = "none" ]
do
check_power_led
done

#3.2.2 status led
while [ $STAERR = "none" ]
do
ledflicker 1
check_status_led
done

#3.2.3 alarm led

while [ $ALAERR = "none" ]
do
ledflicker 2
check_alarm_led
done

#3.2.4 108 test
#if [ $PLATFORM="108WithADSL" ] && [ $PLATFORM="108WithoutADSL" ];then
#ledonoff on 1 red
#ledonoff on 2 red
#ledonoff on 3 red
#jecho "Does status alarm and power be red?"
#read LEDRED
#fi       

#3.3 wan test
if [ $WANERR = "error" ];then
        if [ $PLATFORM = "008" ] || [ $PLATFORM = "108WithoutADSL" ];then
                check_108_wan
        elif [ $PLATFORM = "108WithADSL" ];then
                check_108_adsl_wan
        else
                jecho "invalid platform..."
                exit 1
        fi
fi

#3.4 lan test
ifconfig ixp1 down
ifconfig | grep -q "ixp1" && jecho "ixp1 down failed" || jecho "ixp1 down success"
ifconfig ixp0 192.168.20.11 netmask 255.255.255.0                                        #should check if the ip is ok
if [ $PLATFORM = "008" ];then
        check_008_lan                                                                        #complete
elif [ $PLATFORM = "108WithADSL" ] || [ $PLATFORM = "108WithoutADSL" ];then
        check_108_lan                                                                        #complete
else
        jecho "invalid platform..."
        exit 2
fi

#3.5 rtc test
jecho "(11)Info:   Now time set to 101010102005,Please save and check after it reboot"
date 101010102005 >/dev/null 2>&1
hwclock -w
jecho "(11)Info:   Please wait while save the configuration"
bkcon

#4.0 Test Result
echo -e "\n\n"  
jecho "-------------Here's the result------------"
echo ""
if [ $PLATFORM = "008" ];then
        print_008_result
elif [ $PLATFORM = "108WithoutADSL" ];then
        print_108_result
elif [ $PLATFORM = "108WithADSL" ];then
        print_108_adsl_result
fi

该用户从未签到

发表于 2005-11-11 10:28:49 | 显示全部楼层
学海无涯啊啊
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2006-3-8 11:16:48 | 显示全部楼层
什么注释都没有,贴出来有何意义!:(
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2006-8-22 12:29:21 | 显示全部楼层

xie的专业点好不

不懂
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2006-9-4 18:31:41 | 显示全部楼层
估计过段时间你都不知道这个干什么用的了
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2008-3-10 17:08:55 | 显示全部楼层
so long and without comments????
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2008-8-5 16:30:45 | 显示全部楼层
没有注释
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2008-8-20 09:46:53 | 显示全部楼层
看不懂
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2008-9-2 16:54:42 | 显示全部楼层
加紧学习。
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2008-9-3 13:39:38 | 显示全部楼层
楼主想说明什么问题呢?
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2008-12-30 16:40:21 | 显示全部楼层
居然一点没有注释 看了一段看不太下去
你想大家帮忙优化还是怎么样呢?
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2009-1-4 11:54:21 | 显示全部楼层
只是想贴出来让大家看看长不长呀 多少加点注释,太难懂了- -
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2015-11-4 10:00:45 | 显示全部楼层
虽然不知道代码写的什么,但只懂得里面的语法
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2015-11-12 17:27:42 | 显示全部楼层
终于看完了~~~
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2016-10-10 20:56:57 | 显示全部楼层
嘿嘿,回个贴表明我来过。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-3-29 17:36 , Processed in 0.082406 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表