#!/bin/bash
# Usb_Suspend-Resume.sh:the script could perform only suspend(every 10s) and resume 20s
# Path is the filename of the device usb driver, rep1ace by the actual usb name
path=1-2
# Iteration is the test times, initialized by 1000000000, the value can be revised by user
iteration="1000000000"
# The count of the test times for suspend and resume
count_sus="0"
count_res="0"
count="0"
# Execute the sub suspend and resume - Loop for iteration times
while [ $count -lt $iteration ]
do
# Record date
date "+%Y-%m/%d %H:%M:%S"
# Usb suspend
# Note when the kernel of system over 2.6.35, "level" should be replace by "control"
echo auto > /sys/bus/usb/drivers/usb/$path/power/level
# Idel for 10ms, the usb devices will be auto suspend by system
# Note when the kernel of system over 2.6.38, "autosuspend" should be replace by "autosuspend_delay_ms"
echo 10 > /sys/bus/usb/drivers/usb/$path/power/autosuspend
# Usb Suspend 10s
sleep 10
# Get the state of the device usb
rs=$(cat /sys/bus/usb/drivers/usb/$path/power/runtime_status)
if [ "$rs" = "suspended" ]
then
count_sus=$((count_sus+1))
echo "usb is suspended for $count_sus times"
fi
# Usb resume
# Note when the kernel of system over 2.6.35, "level" should be replace by "control"
echo on > /sys/bus/usb/drivers/usb/$path/power/level
# Usb Suspend 20s
sleep 20
# Get the state of the device usb
res=$(cat /sys/bus/usb/drivers/usb/$path/power/runtime_status)
if [ "$res" = "active" ]
then
count_res=$((count_res+1))
echo "usb is actived for $count_res times"
fi
count=$((count+1))
done
Usb Suspend/Resume
于 2022-09-03 11:12:08 首次发布