1 Star 0 Fork 0

Shaco/h3_auto_test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.sh 16.15 KB
一键复制 编辑 原始数据 按行查看 历史
jun 提交于 2024-09-25 13:47 . 添加删除步骤
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
#!/bin/bash
function environment()
{
echo -e "\033[31m配置完后会自动重新启动设备\033[0m"
echo -e "\033[31m安装软件包\033[0m"
sudo apt-get install -y git memtester mbw dmidecode iperf iperf3 cryptsetup
echo -e "\033[31m部署WIFI\033[0m"
sudo cp -R usr /
ls /usr/lib/firmware/xr819
#配置wifi
nmcli dev
nmcli r wifi on
nmcli dev wifi
nmcli dev wifi connect "CSJDZ" password "26519965" ifname wlan0
sleep 5
#配置4G
#rndis模式切换
echo -e "AT+QCFG=\"usbnet\",3\r\n" > /dev/ttyUSB2
#开启网络
echo -e "at+QNETDEVCTL=3,1,1\r\n" > /dev/ttyUSB2
#开启热插拔
echo -e "AT+QSIMDET=1,1\r\n" > /dev/ttyUSB2
#重启命令
echo -e "AT+CFUN=1,1\r\n" > /dev/ttyUSB2
}
function memtest()
{
local test_times=$1 # 接收测试次数作为参数
if [ -z "$test_times" ]; then
test_times=1 # 如果未传入参数,则默认测试 1 次
fi
echo "测试次数为: $test_times"
log_filemem="memtest_$(date +%Y%m%d_%H%M%S).log"
log_filembw="mbwtest_$(date +%Y%m%d_%H%M%S).log"
for i in $(seq 1 $test_times); do
echo -e "\033[31m内存稳定性测试\033[0m"
memtester 100M 1 | tee -a $log_filemem
echo -e "\033[31m内存带宽测试\033[0m"
mbw -q -n 1 100 | tee -a $log_filembw
done
}
function gpioouttest()
{
# 初始化GPIO
echo 18 > /sys/class/gpio/export
echo 21 > /sys/class/gpio/export
echo 19 > /sys/class/gpio/export
echo 8 > /sys/class/gpio/export
echo 9 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio18/direction
echo out > /sys/class/gpio/gpio21/direction
echo out > /sys/class/gpio/gpio19/direction
echo out > /sys/class/gpio/gpio8/direction
echo out > /sys/class/gpio/gpio9/direction
# 初始化按键状态
prev_key1=1
prev_key2=1
prev_key3=1
echo "GPIO循环输出测试开始,按esc退出测试"
while true; do
# 控制LED
echo 1 > /sys/class/gpio/gpio18/value
echo 1 > /sys/class/gpio/gpio21/value
echo 1 > /sys/class/gpio/gpio19/value
# 红灯
echo 0 > /sys/class/gpio/gpio18/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
# 绿灯
echo 1 > /sys/class/gpio/gpio18/value
echo 0 > /sys/class/gpio/gpio21/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
# 蓝灯
echo 1 > /sys/class/gpio/gpio21/value
echo 0 > /sys/class/gpio/gpio19/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
# 控制GPIO
echo 1 > /sys/class/gpio/gpio8/value
echo 1 > /sys/class/gpio/gpio9/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
echo 0 > /sys/class/gpio/gpio8/value
echo 0 > /sys/class/gpio/gpio9/value
read -t 1 -n 1 -s key
if [[ "$key" == $'\e' ]]; then
echo "Exiting..."
break
fi
done
# 清理GPIO
echo "清理GPIO状态"
echo 1 > /sys/class/gpio/gpio18/value
echo 1 > /sys/class/gpio/gpio21/value
echo 1 > /sys/class/gpio/gpio19/value
echo 1 > /sys/class/gpio/gpio8/value
echo 1 > /sys/class/gpio/gpio9/value
echo 18 > /sys/class/gpio/unexport
echo 19 > /sys/class/gpio/unexport
echo 21 > /sys/class/gpio/unexport
echo 8 > /sys/class/gpio/unexport
echo 9 > /sys/class/gpio/unexport
}
function gpiointest()
{
# 初始化GPIO
echo 355 > /sys/class/gpio/export
echo 15 > /sys/class/gpio/export
echo 16 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio355/direction
echo in > /sys/class/gpio/gpio15/direction
echo in > /sys/class/gpio/gpio16/direction
# 初始化按键状态
prev_key1=1
prev_key2=1
prev_key3=1
echo "GPIO输入测试开始,按esc退出测试"
while true; do
# 读取按键状态
key1=$(cat /sys/class/gpio/gpio355/value)
key2=$(cat /sys/class/gpio/gpio15/value)
key3=$(cat /sys/class/gpio/gpio16/value)
# 检查按键状态是否发生变化
if [[ "$key1" != "$prev_key1" ]]; then
echo "Key 1 state changed: $prev_key1 -> $key1"
prev_key1=$key1
fi
if [[ "$key2" != "$prev_key2" ]]; then
echo "Key 2 state changed: $prev_key2 -> $key2"
prev_key2=$key2
fi
if [[ "$key3" != "$prev_key3" ]]; then
echo "Key 3 state changed: $prev_key3 -> $key3"
prev_key3=$key3
fi
# 保存当前终端特性
stty_save=$(stty -g)
# 暂时禁用终端特性
stty -icanon -echo
if read -t 0.01 -n 1 -s key; then
echo "Exiting..."
break
fi
# 恢复终端特性
stty $stty_save
done
# 清理GPIO
echo "清理GPIO状态"
echo 355 > /sys/class/gpio/unexport
echo 15 > /sys/class/gpio/unexport
echo 16 > /sys/class/gpio/unexport
}
function rs485test()
{
# stty -a -F /dev/ttyUSB4
echo -e "hello 485 test:123456789\r\n" > /dev/ttyUSB4
echo -e "hello 485 test:123456789\r\n" > /dev/ttyUSB3
}
function networktest()
{
local test_times=$1 # 接收测试次数作为参数
if [ -z "$test_times" ]; then
test_times=10 # 如果未传入参数,则默认测试 10 次
fi
echo "测试次数为: $test_times"
# 默认参数
test_server="42.123.122.115"
log_dir="network_test_logs"
rm -rf network_test_logs
# 创建日志目录
mkdir -p "$log_dir"
# 获取可用网卡列表及其 IP 地址
available_interfaces=()
interface_ips=()
while IFS= read -r iface; do
ip=$(ip addr show "$iface" | awk '/inet / {print $2}' | cut -d'/' -f1)
if [ -n "$ip" ]; then
available_interfaces+=("$iface")
interface_ips+=("$ip")
fi
done < <(ip addr show | awk '/^[0-9]+: / {print $2}' | tr -d ':' | sed 's/[0-9]*@.*//g' | grep -v 'lo')
# 遍历可用网卡,进行测试
for i in "${!available_interfaces[@]}"; do
interface="${available_interfaces[$i]}"
ip="${interface_ips[$i]}"
log_file="$log_dir/network_test_${interface}_$(date +%Y%m%d_%H%M%S).log"
echo -e "\033[1;34m====== Testing $interface ($ip) ======\033[0m" | tee -a "$log_file"
# 关闭其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface down
fi
done
# 网络测试
echo -e "\033[1;31m网络测试\033[0m" | tee -a "$log_file"
for i in $(seq 10 -1 1); do
echo -ne "\r倒计时 $i 秒" | tee -a "$log_file"
sleep 1
done
echo -e "\n" | tee -a "$log_file"
ping -c $test_times $test_server -I $interface | tee -a "$log_file"
iperf3 -c $test_server -i 1 -t $test_times --connect-timeout 10000 | tee -a "$log_file"
# 恢复其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface up
fi
done
echo -e "\033[1;34m====== $interface ($ip) 测试结束 ======\033[0m\n" | tee -a "$log_file"
done
echo -e "\033[1;32m网络测试已完成,详细结果请查看日志文件夹: $log_dir\033[0m"
echo "ping网络操作,观察每次的时间是否均匀"
}
function networkeasytest()
{
local test_times=$1 # 接收测试次数作为参数
if [ -z "$test_times" ]; then
test_times=20 # 如果未传入参数,则默认测试 10 次
fi
echo "测试次数为: $test_times"
# 默认参数
test_server="47.120.40.219"
log_dir="network_test_logs"
rm -rf network_test_logs
# 创建日志目录
mkdir -p "$log_dir"
# 获取可用网卡列表及其 IP 地址
available_interfaces=()
interface_ips=()
while IFS= read -r iface; do
ip=$(ip addr show "$iface" | awk '/inet / {print $2}' | cut -d'/' -f1)
if [ -n "$ip" ]; then
available_interfaces+=("$iface")
interface_ips+=("$ip")
fi
done < <(ip addr show | awk '/^[0-9]+: / {print $2}' | tr -d ':' | sed 's/[0-9]*@.*//g' | grep -v 'lo')
# 遍历可用网卡,进行测试
for i in "${!available_interfaces[@]}"; do
interface="${available_interfaces[$i]}"
ip="${interface_ips[$i]}"
log_file="$log_dir/network_test_${interface}_$(date +%Y%m%d_%H%M%S).log"
echo -e "\033[1;34m====== Testing $interface ($ip) ======\033[0m" | tee -a "$log_file"
# 关闭其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface down
fi
done
ping -c $test_times $test_server -I $interface | tee -a "$log_file"
# 恢复其他网卡
for other_iface in "${available_interfaces[@]}"; do
if [ "$other_iface" != "$interface" ]; then
ifconfig $other_iface up
fi
done
echo -e "\033[1;34m====== $interface ($ip) 测试结束 ======\033[0m\n" | tee -a "$log_file"
done
echo -e "\033[1;32m网络测试已完成,详细结果请查看日志文件夹: $log_dir\033[0m"
echo "ping网络操作,观察每次的时间是否均匀"
}
function test4G()
{
cat /dev/ttyUSB2 &
#检查SIM状态(查看SIM卡是否就绪)
echo -e "AT+CPIN?\r\n" > /dev/ttyUSB2
#(查看SIM卡注册状态)
echo -e "AT+CREG?\r\n" > /dev/ttyUSB2
#查看SIM卡注册属性
echo -e "AT+COPS?\r\n" > /dev/ttyUSB2
#查看SIM卡信号强度
echo -e "AT+CSQ\r\n" > /dev/ttyUSB2
killall -9 "cat /dev/ttyUSB2"
}
function clean()
{
rm *.log
rm -rf network_test_logs
}
function emmc_mem_resize()
{
echo -e "\033[32mEMMC内存划分\033[0m"
# 修改根文件夹系统大小
sudo e2fsck -f /dev/mmcblk2p1
sudo resize2fs /dev/mmcblk2p1 5500M
# 修改根文件夹系统物理大小
# sudo fuser -k /dev/mmcblk2p1
parted /dev/mmcblk2 resizepart 1 6000MB
sudo e2fsck -f /dev/mmcblk2p1
# 创建分区
yes | sudo parted /dev/mmcblk2 --script mkpart primary ext4 6000MB 6512MB
yes | sudo parted /dev/mmcblk2 --script mkpart primary ext4 6512MB 6612MB
yes | sudo parted /dev/mmcblk2 --script mkpart primary ext4 6612MB 7126MB
# 列出块设备
lsblk
}
function luks_creat()
{
echo -e "\033[32mLUKS分区加密\033[0m"
# 创建加密分区
echo "Creating LUKS encrypted partitions..."
echo -n "手动输入第一个分区信息:1.YES(注意是大写) 2.密码 3.密码"
sudo cryptsetup luksFormat /dev/mmcblk2p2
echo -n "手动输入第二个分区信息:1.YES(注意是大写) 2.密码 3.密码"
sudo cryptsetup luksFormat /dev/mmcblk2p3
echo -n "手动输入第三个分区信息:1.YES(注意是大写) 2.密码 3.密码"
sudo cryptsetup luksFormat /dev/mmcblk2p4
# 解锁分区
echo "Unlocking partitions..."
echo -n "解锁分区1,不用操作"
sudo cryptsetup open /dev/mmcblk2p2 luks1 <<< "123"
echo -n "解锁分区2,不用操作"
sudo cryptsetup open /dev/mmcblk2p3 luks2 <<< "123"
echo -n "解锁分区3,不用操作"
sudo cryptsetup open /dev/mmcblk2p4 luks3 <<< "123"
# 格式化分区
echo "格式化分区..."
sudo mkfs.ext4 /dev/mapper/luks1
sudo mkfs.ext4 /dev/mapper/luks2
sudo mkfs.ext4 /dev/mapper/luks3
# 创建挂载点
echo "创建挂载点..."
sudo mkdir -p /iot
sudo mkdir -p /upgrade
sudo mkdir -p /ww
# # 挂载分区
# echo "Mounting partitions..."
# sudo mount /dev/mapper/luks1 /iot
# sudo mount /dev/mapper/luks2 /upgrade
# sudo mount /dev/mapper/luks3 /ww
# # 卸载分区
# echo "Unmounting partitions..."
# sudo umount /iot
# sudo umount /upgrade
# sudo umount /ww
# # 关闭 LUKS
# echo "Closing LUKS partitions..."
# sudo cryptsetup close luks1
# sudo cryptsetup close luks2
# sudo cryptsetup close luks3
}
function luks_auto_up()
{
echo -e "\033[32mLUKS自动加载\033[0m"
# 生成随机数并保存到变量
RANDOM_PASS=$(dd if=/dev/urandom bs=1 count=1024 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev)
# 将随机数写入文件
echo "$RANDOM_PASS" | sudo tee /etc/luks_pass > /dev/null
sudo chmod 600 /etc/luks_pass
# 修改 /etc/crypttab
echo "更新加密测试..."
echo -e "# <name> <device> <password> <options>\nluks1 /dev/mmcblk2p2 /etc/luks_pass\nluks2 /dev/mmcblk2p3 /etc/luks_pass\nluks3 /dev/mmcblk2p4 /etc/luks_pass" | sudo tee /etc/crypttab > /dev/null
# 添加密钥到 LUKS
echo "Adding keys to LUKS..."
echo -n "更新分区1"
sudo cryptsetup luksAddKey /dev/mmcblk2p2 /etc/luks_pass
echo -n "更新分区2"
sudo cryptsetup luksAddKey /dev/mmcblk2p3 /etc/luks_pass
echo -n "更新分区3"
sudo cryptsetup luksAddKey /dev/mmcblk2p4 /etc/luks_pass
# 修改 /etc/fstab
echo "Updating /etc/fstab..."
echo -e "/dev/mapper/luks1 /iot ext4 defaults 0 0\n/dev/mapper/luks2 /upgrade ext4 defaults 0 0\n/dev/mapper/luks3 /ww ext4 defaults 0 0" | sudo tee -a /etc/fstab > /dev/null
echo "Setup complete."
}
function custom_file()
{
# 解锁分区
echo "Unlocking partitions..."
echo -n "等待分区1打开"
sudo cryptsetup open /dev/mmcblk2p2 luks1 <<< "123"
echo -n "等待分区2打开"
sudo cryptsetup open /dev/mmcblk2p3 luks2 <<< "123"
echo -n "等待分区3打开"
sudo cryptsetup open /dev/mmcblk2p4 luks3 <<< "123"
# 挂载分区
echo "Mounting partitions..."
sudo mount /dev/mapper/luks1 /iot
sudo mount /dev/mapper/luks2 /upgrade
sudo mount /dev/mapper/luks3 /ww
echo -n "部署客户程序,等待拷贝完成,不要操作"
cp -R vlink_g1000_custom/ww /
cp -R vlink_g1000_custom/upgrade /
cp -R vlink_g1000_custom/iot /
reboot
echo -n "部署完成"
}
function filish_clean()
{
rm -rf /root/h3_auto_test
rm -rf /opt/h3_auto_test/vlink_g1000_custom
echo -n "清理完成"
}
function main_menu()
{
# cat /dev/ttyUSB2 &
# cat /dev/ttyUSB3 &
# cat /dev/ttyUSB4 &
# systemctl disable check_all_route.service
# sleep 1
echo -e `date`
cat<<EOF
-----------------------------------
`echo -e "\033[36m >>>硬件测试程序<<<\033[0m"`
`echo -e "\033[35m 0)环境部署\033[0m"`
`echo -e "\033[35m 1)内存测试\033[0m"`
`echo -e "\033[35m 2)测试4G\033[0m"`
`echo -e "\033[35m 3)网络测试\033[0m"`
`echo -e "\033[35m 4)GPIO输出测试\033[0m"`
`echo -e "\033[35m 5)GPIO输入测试\033[0m"`
`echo -e "\033[35m 6)485发送测试\033[0m"`
`echo -e "\033[35m 7)清除日志\033[0m"`
`echo -e "\033[35m 8)内存和网络压力测试(需要大约一个小时)\033[0m"`
`echo -e "\033[35m 9)简易网络测试\033[0m"`
`echo -e "\033[35m 10)加密分区划分(SD卡内运行)\033[0m"`
`echo -e "\033[35m 11)创建luks分区(EMMC启动后运行)\033[0m"`
`echo -e "\033[35m 12)完成测试,清理缓存\033[0m"`
`echo -e "\033[35m Q)退出\033[0m"`
-----------------------------------
EOF
read -p "请输入对应序列号:" num1
case $num1 in
0) environment;;
1) memtest 200;;
2) test4G;;
3) networktest 100;;
4) gpioouttest;;
5) gpiointest;;
6) rs485test;;
7) clean;;
8)
memtest 2
networktest 100
;;
9) networkeasytest;;
10) emmc_mem_resize;;
11)
luks_creat
luks_auto_up
custom_file;;
12) filish_clean;;
Q|q)
# killall -9 "cat"
# systemctl enable check_all_route.service
echo -e "\033[32m--------退出--------- \033[0m"
exit 0
;;
*)
echo -e "\033[31m请输入正确的命令\033[0m"
esac
main_menu
}
while true
do
main_menu
done
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jun626/h3_auto_test.git
[email protected]:jun626/h3_auto_test.git
jun626
h3_auto_test
h3_auto_test
master

搜索帮助