Skip to content

Commit 55ae367

Browse files
Sai-teja573Kotha Sai Teja
authored andcommitted
Updated Reboot health check -added reboot-health_check.sh and service file and readme
1 parent e6c52e9 commit 55ae367

File tree

4 files changed

+128
-146
lines changed

4 files changed

+128
-146
lines changed
Lines changed: 64 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,91 @@
1-
Overview
1+
# Reboot Health Check Test
22

3-
This script automates a full reboot validation and health check for any embedded Linux system.
4-
It ensures that after each reboot, the system:
3+
This test automates a full reboot validation and health check for an embedded Linux system. It ensures that after a reboot, the system:
54

6-
Boots correctly to shell
7-
8-
Key directories (/proc, /sys, /tmp, /dev) are available
9-
10-
Kernel version is accessible
11-
12-
Networking stack is functional
13-
14-
15-
It supports auto-retry on failures, with configurable maximum retries.
16-
17-
No dependency on cron, systemd, Yocto specifics — purely portable.
5+
- Boots into a stable shell
6+
- Key filesystems (`/proc`, `/sys`, `/tmp`, `/dev`) are accessible
7+
- Kernel version is accessible
8+
- Networking stack is functional
189

10+
This script is useful for validating device boot health as part of CI, flashing, or kernel testing workflows.
1911

2012
---
2113

22-
Features
23-
24-
Automatic setup of a temporary boot hook
14+
## Overview
2515

26-
Reboot and post-boot health validations
16+
The test script performs the following functional checks:
2717

28-
Detailed logs with PASS/FAIL results
18+
1. **Boot Validation**
19+
- Ensures the system boots into a stable shell.
2920

30-
Auto-retry mechanism up to a configurable limit
31-
32-
Safe cleanup of temp files and hooks after success or failure
33-
34-
Color-coded outputs for easy reading
35-
36-
Lightweight and BusyBox compatible
21+
2. **Filesystem Accessibility**
22+
- Confirms that key filesystems (`/proc`, `/sys`, `/tmp`, `/dev`) are accessible.
3723

24+
3. **Kernel Version Check**
25+
- Verifies that the kernel version is accessible.
3826

27+
4. **Networking Stack Verification**
28+
- Checks that the networking stack is functional.
3929

4030
---
41-
42-
Usage
43-
44-
Step 1: Copy the script to your device
45-
46-
scp reboot_health_check_autoretry.sh root@<device_ip>:/tmp/
47-
48-
Step 2: Make it executable
49-
50-
chmod +x /tmp/reboot_health_check_autoretry.sh
51-
52-
Step 3: Run the script
53-
54-
/tmp/reboot_health_check_autoretry.sh
55-
56-
The script will automatically:
57-
58-
Create a flag and self-copy to survive reboot
59-
60-
Setup a temporary /etc/init.d/ hook
61-
62-
Force reboot
63-
64-
On reboot, validate the system
65-
66-
Retry if needed
67-
68-
31+
## Files Used
32+
33+
| File / Path | Description |
34+
|--------------------------------------------------|-----------------------------------------------------------------------------|
35+
| `run.sh` | Main script to execute the reboot validation test |
36+
| `/var/reboot_health/` | Directory to store log and retry-related files |
37+
| `/var/reboot_health/reboot_test.log` | Persistent log file for all test outputs |
38+
| `/var/reboot_health/reboot_retry_count` | File storing number of reboot retries (used internally) |
39+
| `/var/reboot_marker` | Temporary marker to differentiate pre- and post-reboot states |
40+
| `/etc/systemd/system/reboot-health.service` | systemd service file to autostart reboot health check after boot |
41+
| `/var/common/reboot_health_check.sh` | Actual reboot validation script that is called on system boot |
6942

7043
---
7144

72-
Log File
73-
74-
All outputs are stored in /tmp/reboot_test.log
75-
76-
Summarizes all individual tests and overall result
77-
78-
7945

8046
---
81-
82-
Configuration
83-
84-
Modify these inside the script if needed:
85-
86-
47+
## Service setup:
48+
1. Copy the `reboot-health.service` file to:
49+
Enable the service:
50+
systemctl`enable reboot-health.service`
8751
---
8852

89-
Pass/Fail Criteria
90-
91-
9253
---
54+
## Manual Run Instructions:
9355

94-
Limitations
95-
96-
Requires basic /bin/sh shell (ash, bash, dash supported)
97-
98-
Needs writable /tmp/ and /etc/init.d/
99-
100-
Does not rely on systemd, cron, or external daemons
101-
102-
56+
1. **make the script excuetable**
57+
`chmod +x run.sh`
10358

59+
2. **Run the test using:**
60+
`./run-test.sh Reboot_health_check`
10461
---
10562

106-
Cleanup
107-
108-
Script automatically:
109-
110-
Removes temporary boot hook
111-
112-
Deletes self-copy after successful completion
113-
114-
Cleans retry counters
115-
116-
117-
You don't need to manually intervene.
118-
119-
12063
---
121-
122-
Example Run Output
123-
124-
2025-04-26 19:45:20 [START] Reboot Health Test Started
125-
2025-04-26 19:45:21 [STEP] Preparing system for reboot test...
126-
2025-04-26 19:45:23 [INFO] System will reboot now to perform validation.
127-
(reboots)
128-
129-
2025-04-26 19:46:10 [STEP] Starting post-reboot validation...
130-
2025-04-26 19:46:11 [PASS] Boot flag detected. System reboot successful.
131-
2025-04-26 19:46:12 [PASS] Shell is responsive.
132-
2025-04-26 19:46:12 [PASS] Directory /proc exists.
133-
2025-04-26 19:46:12 [PASS] Directory /sys exists.
134-
2025-04-26 19:46:12 [PASS] Directory /tmp exists.
135-
2025-04-26 19:46:12 [PASS] Directory /dev exists.
136-
2025-04-26 19:46:12 [PASS] Kernel version: 6.6.65
137-
2025-04-26 19:46:13 [PASS] Network stack active (ping localhost successful).
138-
2025-04-26 19:46:13 [OVERALL PASS] Reboot + Health Check successful!
64+
## Sample output:
65+
```text
66+
[2025-05-22 18:11:00] [START] Reboot Health Test Started
67+
[2025-05-22 18:11:00] [INFO] Reboot marker not found. Rebooting now...
68+
Rebooting...
69+
70+
...system reboots...
71+
72+
[2025-05-22 18:11:10] [START] Reboot Health Test Started
73+
[2025-05-22 18:11:10] [PASS] System booted successfully and root shell obtained.
74+
[2025-05-22 18:11:10] [OVERALL PASS] Reboot + Health Check successful!
75+
```
76+
---
77+
---
78+
## Notes:
79+
```text
80+
The device takes approximately 10 seconds to reach shell after reboot.
81+
Log file is persistent and accumulates output from all runs.
82+
You can manually clear logs using:
83+
`rm -f /var/reboot_health/reboot_test.log`
84+
```
85+
---
86+
## License:
87+
```text
88+
SPDX-License-Identifier: BSD-3-Clause-Clear
89+
(C) Qualcomm Technologies, Inc. and/or its subsidiaries.
90+
```
13991

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Reboot Health Check Service
3+
After=default.target
4+
5+
[Service]
6+
Type=simple
7+
ExecStart=/var/common/reboot_health_check
8+
StandardOutput=tty
9+
StandardError=tty
10+
Restar=no
11+
12+
13+
[Install]
14+
WantedBy=multi-user.target
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
LOG_FILE="/var/reboot_test.log"
4+
MARKER="/var/reboot_marker"
5+
6+
echo "[START] Reboot Health Test Started" > $LOG_FILE
7+
8+
if [ "$(whoami)" = "root" ]; then
9+
if [ ! -f "$MARKER" ]; then
10+
echo "[INFO] Reboot marker not found. Rebooting now..." >> $LOG_FILE
11+
touch "$MARKER"
12+
sleep 2
13+
reboot -f
14+
else
15+
echo "[PASS] System booted successfully and root shell obtained." >> $LOG_FILE
16+
echo "[OVERALL PASS] Reboot + Health Check successful!" >> $LOG_FILE
17+
rm -f "$MARKER"
18+
fi
19+
cat $LOG_FILE
20+
exit 0
21+
else
22+
echo "[FAIL] Root shell not available!" >> $LOG_FIle
23+
cat $LOG_FILE
24+
exit 1
25+
fi
Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
##!/bin/sh
22

33
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
44
# SPDX-License-Identifier: BSD-3-Clause-Clear
@@ -38,49 +38,40 @@ res_file="./$TESTNAME.res"
3838
log_info "-----------------------------------------------------------------------------------------"
3939
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
4040
log_info "=== Test Initialization ==="
41-
41+
4242
# Directory for health check files
4343
HEALTH_DIR="/var/reboot_health"
44+
LOG_FILE="$HEALTH_DIR/reboot_test.log"
4445
RETRY_FILE="$HEALTH_DIR/reboot_retry_count"
46+
MARKER_FILE="/var/reboot_marker"
4547
MAX_RETRIES=3
46-
48+
4749
# Make sure health directory exists
4850
mkdir -p "$HEALTH_DIR"
49-
51+
5052
# Initialize retry count if not exist
5153
if [ ! -f "$RETRY_FILE" ]; then
5254
echo "0" > "$RETRY_FILE"
5355
fi
54-
55-
# Read current retry count
56-
RETRY_COUNT=$(cat "$RETRY_FILE")
57-
58-
log_info "--------------------------------------------"
59-
log_info "Boot Health Check Started - $(date)"
60-
log_info "Current Retry Count: $RETRY_COUNT"
61-
62-
# Health Check: You can expand this check
63-
if [ "$(whoami)" = "root" ]; then
64-
log_pass "System booted successfully and root shell obtained."
65-
log_info "Test Completed Successfully after $RETRY_COUNT retries."
66-
67-
# Optional: clean retry counter after success
68-
echo "0" > "$RETRY_FILE"
69-
56+
57+
# Timestamp function
58+
timestamp() {
59+
date '+%Y-%m-%d %H:%M:%S'
60+
}
61+
62+
echo "[`timestamp`] [START] Reboot Health Test Started" >> "$LOG_FILE"|tee -a "$LOG_FILE"
63+
64+
# Reboot logic
65+
if [ ! -f "$MARKER_FILE" ]; then
66+
echo "[`timestamp`] [INFO] Reboot marker not found. Rebooting now..." >> "$LOG_FILE"
67+
echo "Rebooting"
68+
touch "$MARKER_FILE"
69+
reboot
7070
exit 0
7171
else
72-
log_fail "Root shell not available!"
73-
74-
RETRY_COUNT=$((RETRY_COUNT + 1))
75-
echo "$RETRY_COUNT" > "$RETRY_FILE"
76-
77-
if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then
78-
log_error "[ERROR] Maximum retries ($MAX_RETRIES) reached. Stopping test."
79-
exit 1
80-
else
81-
log_info "Rebooting system for retry #$RETRY_COUNT..."
82-
sync
83-
sleep 2
84-
reboot -f
85-
fi
72+
# Post-reboot actions
73+
rm -f "$MARKER_FILE"
74+
echo "[`timestamp`] [PASS] System booted successfully and root shell obtained." >> "$LOG_FILE"
75+
echo "[`timestamp`] [OVERALL PASS] Reboot + Health Check successful!" >> "$LOG_FILE"
8676
fi
77+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"

0 commit comments

Comments
 (0)