Android svc命令與自動化/壓力測試
阿新 • • 發佈:2018-11-10
svc指令可用於電源控制, 無線業務控制(modem/wifi/nfc/bt, etc), 等等.
可以不適用按鍵,觸控裝置, 而通過使用svc命令實現這些模組的功能操作,比如wifi的開關:
svc wifi enable //開啟wifi
svc wifi disable //關閉wifi
因此, 對於涉及到這些模組的自動化測試和壓力測試, 都可以使用svc命令, 來解放雙手.
svc位於/system/bin/svc
# which svc
/system/bin/svc
# svc help
Available commands:
help Show information about the subcommands
power Control the power manager
data Control mobile data connectivity
wifi Control the Wi-Fi manager
usb Control Usb state
nfc Control NFC functions
feedback Control feedback state
ebensecure Control ebensecure state
opt Control the operation monitor manager
bluetooth Control Bluetooth service
# svc wifi
Control the Wi-Fi manager
usage: svc wifi [enable|disable]
Turn Wi-Fi on or off.
svc可用於power/data/wifi/usb/nfc/bt等的自動化測試和壓力測試.
下面通過wifi開關/自動重連的壓力測試舉例說明svc的好用之處.
wifi開關/自動重連的壓力測試指令碼:
#!/bin/sh
count_success=0
count_err=0
while true
do
svc wifi disable
sleep 5
svc wifi enable
sleep 20
wlan_status=`wpa_cli -i wlan0 status`
tmp=${wlan_status#*wpa_state=}
wpa_state=${tmp:0:9}
echo "STA status is: $wpa_state"
if [ $wpa_state = "COMPLETED" ];then
count_success=$(($count_success+1))
else
count_err=$(($count_err+1))
fi
echo "====== SUCCESS: $count_success, FAIL: $count_err ========"
done