mirror of
https://github.com/armbian/autotests.git
synced 2026-01-06 10:31:09 -08:00
Add logging function
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/userconfig
|
||||
/logs
|
||||
|
||||
@@ -9,6 +9,7 @@ Collection of basic auto tests
|
||||
|
||||
To do:
|
||||
|
||||
- make test cases modular
|
||||
- data collecting
|
||||
- make use of existing 3rd party test suites to run extensive testings
|
||||
- run stress test and power cycle n-times
|
||||
|
||||
42
go.sh
42
go.sh
@@ -4,7 +4,7 @@
|
||||
#
|
||||
|
||||
apt install -y -qq expect sshpass &>/dev/null
|
||||
mkdir -p userconfig
|
||||
mkdir -p userconfig logs
|
||||
|
||||
# create sample configuration
|
||||
if [[ ! -f userconfig/configuration.sh ]]; then
|
||||
@@ -14,42 +14,12 @@ fi
|
||||
source userconfig/configuration.sh
|
||||
source lib/functions.sh
|
||||
|
||||
[[ -z $HOST ]] && echo "\$HOST not defined. Exiting." && exit 1
|
||||
[[ -z $HOSTS ]] && echo "\$HOST not defined. Exiting." && exit 1
|
||||
[[ -z $HOST_IPERF ]] && echo "\$HOST_IPERF not defined. Exiting." && exit 1
|
||||
|
||||
display_alert "Try if we can login and send CTRL C" "$HOST" "info"
|
||||
sshpass -p 1234 ssh -o "StrictHostKeyChecking=accept-new" ${USER_ROOT}@${HOST} "\x03" &>/dev/null
|
||||
[[ $? -eq 1 ]] && armbian-first-login
|
||||
|
||||
x=1
|
||||
SUM=0
|
||||
while [ $x -le ${PASSES} ]
|
||||
do
|
||||
while ! ping -c1 $HOST &>/dev/null; do display_alert "Ping failed" "$(date +%R:%S)" "wrn"; done ; START=$(date +%s); display_alert "Host found" "$(date +%R:%S)" "info";
|
||||
|
||||
|
||||
TIMES[$x]=$(date +%s)
|
||||
# if wlan credentials are defined, let's check it first
|
||||
if [[ -n ${WLAN_ID} && $x -eq 1 && -n $(sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "nmcli device | grep wifi") ]]; then
|
||||
check_wlan
|
||||
fi
|
||||
|
||||
display_alert "Stressing [$x] for ${STRESS_TIME}s" "${HOST}" "info";
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "stress -q --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout ${STRESS_TIME}s"
|
||||
display_alert "Rebooting in 5 seconds" "${HOST}" "wrn"
|
||||
sleep 5
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "reboot"
|
||||
sleep 20
|
||||
x=$(( $x + 1 ))
|
||||
|
||||
done
|
||||
|
||||
x=2
|
||||
while [ $x -lt ${PASSES} ]
|
||||
do
|
||||
A=${TIMES[@]:$x:1}
|
||||
x=$(( $x + 1 ))
|
||||
B=${TIMES[@]:$x:1}
|
||||
[[ -z $B ]] && B=$(date +%s)
|
||||
echo $(( $B - $A ))
|
||||
IFS=', ' read -r -a array <<< "$HOSTS"
|
||||
for HOST in "${array[@]}"; do
|
||||
rm logs/${HOST}.log
|
||||
run_tests
|
||||
done
|
||||
|
||||
@@ -10,23 +10,23 @@ display_alert()
|
||||
|
||||
case $3 in
|
||||
err)
|
||||
echo -e "[\e[0;31m error \x1B[0m] $1 $tmp"
|
||||
echo -e "[\e[0;31m error \x1B[0m] $1 $tmp" | tee -a logs/${HOST}.log
|
||||
;;
|
||||
|
||||
wrn)
|
||||
echo -e "[\e[0;35m warn \x1B[0m] $1 $tmp"
|
||||
echo -e "[\e[0;35m warn \x1B[0m] $1 $tmp" | tee -a logs/${HOST}.log
|
||||
;;
|
||||
|
||||
ext)
|
||||
echo -e "[\e[0;32m o.k. \x1B[0m] \e[1;32m$1\x1B[0m $tmp"
|
||||
echo -e "[\e[0;32m o.k. \x1B[0m] \e[1;32m$1\x1B[0m $tmp" | tee -a logs/${HOST}.log
|
||||
;;
|
||||
|
||||
info)
|
||||
echo -e "[\e[0;32m o.k. \x1B[0m] $1 $tmp"
|
||||
echo -e "[\e[0;32m o.k. \x1B[0m] $1 $tmp" | tee -a logs/${HOST}.log
|
||||
;;
|
||||
|
||||
*)
|
||||
echo -e "[\e[0;32m .... \x1B[0m] $1 $tmp"
|
||||
echo -e "[\e[0;32m .... \x1B[0m] $1 $tmp" | tee -a logs/${HOST}.log
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -68,11 +68,9 @@ function armbian-first-login()
|
||||
expect eof
|
||||
")
|
||||
# Disable user creation: send \"\x03\"
|
||||
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "apt -y install jq stress"
|
||||
|
||||
# display output
|
||||
echo "${MAKE_USER}"
|
||||
echo "${MAKE_USER}" | tee -a logs/${HOST}.log
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -80,10 +78,9 @@ function armbian-first-login()
|
||||
function check_wlan
|
||||
{
|
||||
|
||||
# clean keys
|
||||
#ssh-keygen -f "/root/.ssh/known_hosts" -R ${HOST} > /dev/null 2>&1
|
||||
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "nmcli d wifi connect ${WLAN_ID} password ${WLAN_PASS}" &>/dev/null
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "nmcli -t -f UUID,TYPE connection | grep wireless | sed 's/:.*$//' | xargs nmcli con del "
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "nmcli d wifi connect ${WLAN_ID} password ${WLAN_PASS}"
|
||||
sleep 3
|
||||
if [[ $? -eq 0 ]]; then
|
||||
display_alert "Connected to wireless" "${WLAN_ID}"
|
||||
|
||||
@@ -109,10 +106,53 @@ function check_wlan
|
||||
|
||||
# do the test
|
||||
display_alert "Make Ethernet performance test" "${HOST} -> ${HOST_IPERF}"
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "iperf3 -c ${HOST_IPERF} -t 5 -J | jq -r '.intervals' | grep bits_per_second | awk '{print \$2}' | awk '{printf(\"%.0f\n\", \$1)}' | awk '{\$1/=1000000;printf \"%.0f MBits/s\n\",\$1}' | sed -n 'p;n'"
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "iperf3 -c ${HOST_IPERF} -t 5 -J | jq -r '.intervals' | grep bits_per_second | awk '{print \$2}' | awk '{printf(\"%.0f\n\", \$1)}' | awk '{\$1/=1000000;printf \"%.0f MBits/s\n\",\$1}' | sed -n 'p;n'" | tee -a logs/${HOST}.log
|
||||
|
||||
else
|
||||
display_alert "connecting to wireless" "${WLAN_ID}" "err"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
function run_tests
|
||||
{
|
||||
display_alert "Try if we can login and send CTRL C" "$HOST" "info"
|
||||
ssh-keygen -qf "/root/.ssh/known_hosts" -R "${HOST}" > /dev/null 2>&1
|
||||
sshpass -p 1234 ssh -o "StrictHostKeyChecking=accept-new" ${USER_ROOT}@${HOST} "\x03" &>/dev/null
|
||||
[[ $? -eq 1 ]] && armbian-first-login
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "apt -qq -y install jq stress" &>/dev/null
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "armbianmonitor -u" | tee -a logs/${HOST}.log
|
||||
x=1
|
||||
SUM=0
|
||||
while [ $x -le ${PASSES} ]
|
||||
do
|
||||
while ! ping -c1 $HOST &>/dev/null; do display_alert "Ping failed" "$(date +%R:%S)" "wrn"; done ; START=$(date +%s); display_alert "Host found" "$(date +%R:%S)" "info";
|
||||
|
||||
|
||||
TIMES[$x]=$(date +%s)
|
||||
# if wlan credentials are defined, let's check it first
|
||||
if [[ -n ${WLAN_ID} && $x -eq 1 && -n $(sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "nmcli device | grep wifi") ]]; then
|
||||
check_wlan
|
||||
fi
|
||||
|
||||
display_alert "Stressing [$x] for ${STRESS_TIME}s" "${HOST}" "info";
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "stress -q --cpu $(nproc) --io 4 --vm 2 --vm-bytes 128M --timeout ${STRESS_TIME}s"
|
||||
display_alert "Rebooting in 5 seconds" "${HOST}" "wrn"
|
||||
sleep 5
|
||||
sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${HOST} "reboot"
|
||||
sleep 20
|
||||
x=$(( $x + 1 ))
|
||||
|
||||
done
|
||||
|
||||
x=2
|
||||
while [ $x -lt ${PASSES} ]
|
||||
do
|
||||
A=${TIMES[@]:$x:1}
|
||||
x=$(( $x + 1 ))
|
||||
B=${TIMES[@]:$x:1}
|
||||
[[ -z $B ]] && B=$(date +%s)
|
||||
echo $(( $B - $A ))
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user