Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions stress/error_hooks/001-check-ethernet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

me=$(basename "$0")
echo "checking $me"

# check wire interface
# find the first ethernet interface (eno* or eth*)
interface=$(ip link show | awk -F: '$2 ~ /eno|eth/ {print $2; exit}' | tr -d ' ')
if [ -z "$interface" ]; then
echo "Skipping $me: No ethernet interface found"
exit 0 # Not an error, just skip
fi

# check if the interface is present
if ip link show "$interface" &>/dev/null; then
echo "Interface $interface found"
else
echo "Error: Interface $interface not found"
exit 1
fi

#run the command to check if the interface is present
err=$(ip a | grep "$interface")
21 changes: 21 additions & 0 deletions stress/error_hooks/002-check-wifi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

me=$(basename "$0")
echo "checking $me"

interface=$(ip link show | awk -F: '$2 ~ /wlp/ {print $2; exit}' | tr -d ' ')

if [ -z "$interface" ]; then
echo "Error: No Wi-Fi interface found"
exit 1
fi

# check if the wifi is up

if ip link show "$interface" | grep -q "state UP"; then
echo "Wi-Fi interface $interface is UP"
exit 0
else
echo "Error: Wi-Fi interface $interface found but not UP"
exit 1
fi
32 changes: 32 additions & 0 deletions stress/error_hooks/003-check-image-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

me=$(basename "$0")
echo "checking $me"

# load OS version information

if [ -f /etc/os-release ]; then
image_version=$(grep "^VERSION=" /etc/os-release | cut -d= -f2 | tr -d '"')
os_name=$(grep "^NAME=" /etc/os-release | cut -d= -f2 | tr -d '"')
elif [ -f /etc/issue ]; then
image_version=$(head -n 1 /etc/issue | awk '{print $NF}')
os_name=$(head -n 1 /etc/issue | awk '{$NF=""; print $0}')
else
echo "Error: Cannot determine OS version"
exit 1
fi

echo "Detected OS: $os_name"
echo "Detected Version: $image_version"

# except image version
expected_version="24.04"

# check if the image version matches the expected version
if [[ "$image_version" == *"$expected_version"* ]]; then
echo "Image version check PASSED"
exit 0
else
echo "Error: Expected version $expected_version but found $image_version"
exit 1
fi
18 changes: 18 additions & 0 deletions stress/error_hooks/004-check-audio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
me=$(basename "$0")
echo "checking $me"

# check output audio device
if ! aplay -l | grep -i "card" &>/dev/null; then
echo "Error: No audio output device found"
exit 1
fi

# check microphone input device
if ! arecord -l | grep -i "card" &>/dev/null; then
echo "Error: No audio input device (mic) found"
exit 1
fi

echo "Audio input/output devices detected"
exit 0
29 changes: 29 additions & 0 deletions stress/error_hooks/005-check-mipi7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
me=$(basename "$0")
echo "checking $me"

status=0

# check dmesg for mipi-related errors
mipi_keywords="mipi dsi"
dmesg_output=$(dmesg | grep -i "$mipi_keywords")

if echo "$dmesg_output" | grep -iE "fail|error|timeout"; then
echo "[ERROR] MIPI related errors detected:"
echo "$dmesg_output"
status=1
else
echo "No MIPI dmesg errors found"
fi

# check if MIPI interface is present
mipi_interface="mipi_video0" # can be changed to /dev/videoX、ethX

if ip link show "$mipi_interface" &>/dev/null; then
echo "MIPI interface $mipi_interface found"
else
echo "[ERROR] MIPI interface $mipi_interface not found"
status=1
fi

exit $status
96 changes: 54 additions & 42 deletions stress/setup-reboot-stress-mipi.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
#!/bin/bash

if [ ! "$EUID" -ne 0 ]
then echo "Please do not run as root"
if [ ! "$EUID" -ne 0 ]; then
echo "Please do not run as root"
exit
fi

# Set up environment
chmod +x ./bin/*
./bin/env-setup.sh
if [ $? -ne 0 ]; then
echo '\033[0;31mError: ENV setup failed\033[0m'
exit 1
echo -e '\033[0;31mError: ENV setup failed\033[0m'
exit 1
fi

user=$(whoami)
STRESS_COUNT=50

if [ ! -d ~/.stress_config ]; then
mkdir ~/.stress_config
mkdir -p ~/.stress_config
echo "$STRESS_COUNT" > ~/.stress_config/count_reboot
echo "$STRESS_COUNT" > ~/.stress_config/count_reboot_total
echo 0 > ~/.stress_config/count_error
echo "reboot" > ~/.stress_config/method
echo "$user" > ~/.stress_config/owner
echo 1 > ~/.stress_config/err_stop

# Run error_hooks before setting up the service
echo "[INFO] Running error_hooks for MIPI stress preparation..."
hook_failed=0
for hook in "$HOME/hugh_script/stress/error_hooks/"*.sh; do
echo "[HOOK] Executing $hook"
bash "$hook"
result=$?
if [ $result -ne 0 ]; then
echo "[ERROR] Hook $hook failed"
hook_failed=1
fi
done

if [ "$hook_failed" -ne 0 ]; then
echo -e "\033[0;31m[ERROR] One or more hooks failed. Aborting setup.\033[0m"
exit 1
fi
echo "$STRESS_COUNT" > ~/.stress_config/count_reboot
echo "$STRESS_COUNT" > ~/.stress_config/count_reboot_total
echo 0 > ~/.stress_config/count_error
#setup systemd service

# setup systemd service
sudo bash -c "cat >/etc/systemd/system/shutdown_stress.service" <<"EOF"
[Unit]
Description=shutdown_stress service
#After=network.target
After=plymouth-quit-wait.service
StartLimitIntervalSec=10

[Service]
Type=simple
Restart=on-failure
#After=network-online.target
RestartSec=15
Environment=DISPLAY=:0
User=THE_USER
ExecStart=/usr/bin/bash /usr/bin/run_shutdown_stress

[Install]
WantedBy=multi-user.target

EOF

# replace placeholder
sudo sed -i s/"User=THE_USER"/"User=$user"/g /etc/systemd/system/shutdown_stress.service
sudo systemctl enable shutdown_stress.service

#setup runtime script
# setup runtime script
sudo bash -c "cat >/usr/bin/run_shutdown_stress" <<"EOF"
#!/bin/bash
count_file=~/.stress_config/count_reboot
Expand All @@ -58,49 +77,42 @@ count_total=$(cat $count_file_total)
count_error=$(cat $count_file_error)
THE_ERR="switch camera to host failed"
output_message=""
#-1=detected
#0 =do no
#1 =shutown
service_status=0 # 0=do nothing,
service_status=0
STRESS_BOOT_WAKEUP_DELAY=60

# device=$(ip a | grep "$target_device")
err_m=$(sudo dmesg | grep "$THE_ERR")
err_vsc=$(sudo dmesg | grep "vsc" | grep "failed")
if [ ! "$count" -gt 0 ]; then
#Show Report and exit

if [ -n "$err_m" ]; then
count_error=$((count_error + 1))
fi

output_message="Finished stress $count_total times"
zenity --info --text="$output_message" --title="Info"
sudo systemctl disable shutdown_stress.service
sudo systemctl stop shutdown_stress.service
exit 0
if [ ! "$count" -gt 0 ]; then
if [ -n "$err_m" ]; then
count_error=$((count_error + 1))
fi
output_message="Finished stress $count_total times"
zenity --info --text="$output_message" --title="Info"
sudo systemctl disable shutdown_stress.service
sudo systemctl stop shutdown_stress.service
exit 0
elif [[ -n "$err_m" || -n "$err_vsc" ]]; then
output_message="Err detected!"
service_status=-1
count_error=$((count_error + 1))
echo "$err_m" >> "$count_file_log"
echo "$err_vsc" >> "$count_file_log"
echo $count_error > $count_file_error
output_message="Err detected!"
service_status=-1
count_error=$((count_error + 1))
echo "$err_m" >> "$count_file_log"
echo "$err_vsc" >> "$count_file_log"
echo $count_error > $count_file_error
else
output_message="shutdown stress ($count/$count_total), will shutdown soon "
service_status=1
output_message="shutdown stress ($count/$count_total), will shutdown soon"
service_status=1
fi

count=$((count - 1))
echo $count > $count_file

zenity --info --text="$output_message" --title="Info"&
sleep 10

#sudo rtcwake --mode off -s "$STRESS_BOOT_WAKEUP_DELAY"
sudo reboot

EOF

sudo chown $user:$user /usr/bin/run_shutdown_stress
sudo chmod 700 /usr/bin/run_shutdown_stress

echo "[INFO] setup-reboot-stress-mipi.sh completed"
62 changes: 43 additions & 19 deletions stress/setup-shutdown-stress-only.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
#!/bin/bash

#Prerequisite
#1. Setup visuo for the user without typing password
#1. Setup visudo for the user without typing password
#2. sudo apt install rtcwake zenity

if [ ! "$EUID" -ne 0 ]
then echo "Please do not run as root"
if [ ! "$EUID" -ne 0 ]; then
echo "Please do not run as root"
exit
fi

user=$(whoami)
STRESS_COUNT=50

mkdir ~/.stress_config
mkdir -p ~/.stress_config
echo "$STRESS_COUNT" > ~/.stress_config/count_reboot
echo "$STRESS_COUNT" > ~/.stress_config/count_reboot_total
echo 0 > ~/.stress_config/count_error
#setup systemd service
echo "shutdown" > ~/.stress_config/method
echo "$user" > ~/.stress_config/owner
echo 0 > ~/.stress_config/err_stop

# Run error_hooks before setting up the service
echo "[INFO] Running error_hooks before setting up shutdown stress..."
hook_failed=0
for hook in "$HOME/hugh_script/stress/error_hooks/"*.sh; do
echo "[HOOK] Executing $hook"
bash "$hook"
result=$?
if [ $result -ne 0 ]; then
echo "[ERROR] Hook $hook failed"
hook_failed=1
fi
done

if [ "$hook_failed" -ne 0 ]; then
echo -e "\033[0;31m[ERROR] One or more hooks failed. Aborting setup.\033[0m"
exit 1
fi

#setup systemd service
sudo bash -c "cat >/etc/systemd/system/shutdown_stress.service" <<"EOF"
[Unit]
Description=shutdown_stress service
Expand All @@ -31,11 +54,12 @@ RestartSec=15
Environment=DISPLAY=:0
User=THE_USER
ExecStart=/usr/bin/bash /usr/bin/run_shutdown_stress

[Install]
WantedBy=multi-user.target

EOF

sudo sed -i s/"User=THE_USER"/"User=$user"/g /etc/systemd/system/shutdown_stress.service
sudo systemctl enable shutdown_stress.service

Expand All @@ -48,22 +72,21 @@ count=$(cat $count_file)
count_total=$(cat $count_file_total)
output_message=""
#-1=detected
#0 =do no
#1 =shutown
service_status=0 # 0=do nothing,
#0 =do nothing
#1 =shutdown
service_status=0
STRESS_BOOT_WAKEUP_DELAY=60

if [ ! "$count" -gt 0 ]; then
#Show Report and exit

output_message="Finished stress $count_total times"
#zenity --info --text="$output_message" --title="Info"
sudo systemctl disable shutdown_stress.service
sudo systemctl stop shutdown_stress.service
exit 0
#Show Report and exit
output_message="Finished stress $count_total times"
#zenity --info --text="$output_message" --title="Info"
sudo systemctl disable shutdown_stress.service
sudo systemctl stop shutdown_stress.service
exit 0
else
output_message="shutdown stress ($count/$count_total), will shutdown soon "
service_status=1
output_message="shutdown stress ($count/$count_total), will shutdown soon"
service_status=1
fi

count=$((count - 1))
Expand All @@ -74,8 +97,9 @@ sleep 10

sudo rtcwake --mode off -s "$STRESS_BOOT_WAKEUP_DELAY"


EOF

sudo chown $user:$user /usr/bin/run_shutdown_stress
sudo chmod 700 /usr/bin/run_shutdown_stress

echo "[INFO] setup-shutdown-stress-only.sh completed"
Loading