Skip to content

Commit 6effb0e

Browse files
jinghuithamelvin03
authored andcommitted
Add boot tester workflow
Signed-off-by: jinghuitham <jing.hui.tham@intel.com>
1 parent 75ebad7 commit 6effb0e

File tree

2 files changed

+227
-48
lines changed

2 files changed

+227
-48
lines changed

.github/workflows/boot_tester.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Boot Tester
2+
on:
3+
push:
4+
branches:
5+
- boot_workflow
6+
schedule:
7+
# Run twice a week: Tuesdays at 02:00 UTC and Fridays at 02:00 UTC
8+
- cron: '0 2 * * 2' # Tuesday at 2 AM UTC
9+
- cron: '0 2 * * 5' # Friday at 2 AM UTC
10+
workflow_dispatch: {}
11+
# Allow manual triggering of the workflow
12+
permissions:
13+
contents: read
14+
jobs:
15+
boot-test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Install Earthly
27+
uses: earthly/actions-setup@v1
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
version: "latest" # or pin to a specific version like "v0.8.0"
31+
32+
- name: Install system deps
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install -y qemu-system-x86 ovmf tree jq systemd-ukify mmdebstrap systemd-boot
36+
37+
- name: Set up Go
38+
uses: actions/setup-go@v5
39+
with:
40+
go-version: stable # or a pinned version you know exists
41+
42+
- name: Copy tester script
43+
run: |
44+
if [ ! -f validate.sh ]; then
45+
echo "validate.sh not found!"
46+
exit 1
47+
fi
48+
chmod +x validate.sh
49+
50+
- name: Run build-tester
51+
run: |
52+
echo "Starting validate.sh..."
53+
# Ensure script has access to docker group for Earthly
54+
sudo usermod -aG docker $USER
55+
# Run the validation script
56+
./validate.sh --qemu-test
57+
echo "Build and tests completed."

validate.sh

Lines changed: 170 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,140 @@
11
#!/bin/bash
22
set -e
33
# Expect to be run from the root of the PR branch
4+
5+
# Parse command line arguments
6+
RUN_QEMU_TESTS=false
7+
8+
while [[ $# -gt 0 ]]; do
9+
case $1 in
10+
--qemu-test|--with-qemu)
11+
RUN_QEMU_TESTS=true
12+
shift
13+
;;
14+
-h|--help)
15+
echo "Usage: $0 [--qemu-test|--with-qemu]"
16+
echo " --qemu-test, --with-qemu Run QEMU boot tests after each image build"
17+
echo " -h, --help Show this help message"
18+
exit 0
19+
;;
20+
*)
21+
echo "Unknown option $1"
22+
echo "Use -h or --help for usage information"
23+
exit 1
24+
;;
25+
esac
26+
done
27+
428
echo "Current working dir: $(pwd)"
29+
if [ "$RUN_QEMU_TESTS" = true ]; then
30+
echo "QEMU boot tests will be run after each image build"
31+
else
32+
echo "QEMU boot tests will be skipped"
33+
fi
534

635
run_qemu_boot_test() {
7-
IMAGE="azl3-default-x86_64.raw" # image file
36+
local IMAGE_PATTERN="$1"
37+
if [ -z "$IMAGE_PATTERN" ]; then
38+
echo "Error: Image pattern not provided to run_qemu_boot_test"
39+
return 1
40+
fi
41+
842
BIOS="/usr/share/OVMF/OVMF_CODE_4M.fd"
943
TIMEOUT=30
1044
SUCCESS_STRING="login:"
1145
LOGFILE="qemu_serial.log"
1246

13-
1447
ORIGINAL_DIR=$(pwd)
15-
# Find image path
16-
FOUND_PATH=$(find . -type f -name "$IMAGE" | head -n 1)
48+
# Find compressed raw image path using pattern, handle permission issues
49+
FOUND_PATH=$(sudo -S find . -type f -name "*${IMAGE_PATTERN}*.raw.gz" 2>/dev/null | head -n 1)
1750
if [ -n "$FOUND_PATH" ]; then
18-
echo "Found image at: $FOUND_PATH"
19-
IMAGE_DIR=$(dirname "$FOUND_PATH") # Extract directory path where image resides
20-
cd "$IMAGE_DIR" # Change to that directory
51+
echo "Found compressed image at: $FOUND_PATH"
52+
IMAGE_DIR=$(dirname "$FOUND_PATH")
53+
54+
# Fix permissions for the tmp directory recursively to allow access
55+
echo "Setting permissions recursively for ./tmp directory"
56+
sudo chmod -R 777 ./tmp
57+
58+
cd "$IMAGE_DIR"
59+
60+
# Extract the .raw.gz file
61+
COMPRESSED_IMAGE=$(basename "$FOUND_PATH")
62+
RAW_IMAGE="${COMPRESSED_IMAGE%.gz}"
63+
echo "Extracting $COMPRESSED_IMAGE to $RAW_IMAGE..."
64+
gunzip -c "$COMPRESSED_IMAGE" > "$RAW_IMAGE"
65+
66+
if [ ! -f "$RAW_IMAGE" ]; then
67+
echo "Failed to extract image!"
68+
cd "$ORIGINAL_DIR"
69+
return 1
70+
fi
71+
72+
IMAGE="$RAW_IMAGE"
2173
else
22-
echo "Image file not found!"
23-
exit 0 #returning exit status 0 instead of 1 until the code is fully debugged ERRRORRR.
74+
echo "Compressed raw image file matching pattern '*${IMAGE_PATTERN}*.raw.gz' not found!"
75+
return 1
2476
fi
2577

2678

2779
echo "Booting image: $IMAGE "
2880
#create log file ,boot image into qemu , return the pass or fail after boot sucess
29-
sudo bash -c 'touch "'$LOGFILE'" && chmod 666 "'$LOGFILE'"
30-
nohup qemu-system-x86_64 \
31-
-m 2048 \
32-
-enable-kvm \
33-
-cpu host \
34-
-drive if=none,file="'$IMAGE'",format=raw,id=nvme0 \
35-
-device nvme,drive=nvme0,serial=deadbeef \
36-
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \
37-
-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \
38-
-nographic \
39-
-serial mon:stdio \
40-
> "'$LOGFILE'" 2>&1 &
41-
42-
qemu_pid=$!
43-
echo "QEMU launched as root with PID $qemu_pid"
44-
echo "Current working dir: $(pwd)"
81+
sudo bash -c "
82+
LOGFILE=\"$LOGFILE\"
83+
SUCCESS_STRING=\"$SUCCESS_STRING\"
84+
IMAGE=\"$IMAGE\"
85+
RAW_IMAGE=\"$RAW_IMAGE\"
86+
ORIGINAL_DIR=\"$ORIGINAL_DIR\"
87+
88+
touch \"\$LOGFILE\" && chmod 666 \"\$LOGFILE\"
89+
nohup qemu-system-x86_64 \\
90+
-m 2048 \\
91+
-enable-kvm \\
92+
-cpu host \\
93+
-drive if=none,file=\"\$IMAGE\",format=raw,id=nvme0 \\
94+
-device nvme,drive=nvme0,serial=deadbeef \\
95+
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \\
96+
-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \\
97+
-nographic \\
98+
-serial mon:stdio \\
99+
> \"\$LOGFILE\" 2>&1 &
100+
101+
qemu_pid=\$!
102+
echo \"QEMU launched as root with PID \$qemu_pid\"
103+
echo \"Current working dir: \$(pwd)\"
45104
46105
# Wait for SUCCESS_STRING or timeout
47-
timeout=30
48-
elapsed=0
49-
while ! grep -q "'$SUCCESS_STRING'" "'$LOGFILE'" && [ $elapsed -lt $timeout ]; do
50-
sleep 1
51-
elapsed=$((elapsed + 1))
52-
done
53-
echo "$elapsed"
54-
kill $qemu_pid
55-
cat "'$LOGFILE'"
56-
57-
if grep -q "'$SUCCESS_STRING'" "'$LOGFILE'"; then
58-
echo "Boot success!"
59-
result=0
60-
else
61-
echo "Boot failed or timed out"
62-
result=0 #setting return value 0 instead of 1 until fully debugged ERRRORRR
63-
fi
64-
exit $result
65-
'
106+
timeout=30
107+
elapsed=0
108+
while ! grep -q \"\$SUCCESS_STRING\" \"\$LOGFILE\" && [ \$elapsed -lt \$timeout ]; do
109+
sleep 1
110+
elapsed=\$((elapsed + 1))
111+
done
112+
echo \"\$elapsed\"
113+
kill \$qemu_pid
114+
cat \"\$LOGFILE\"
115+
116+
if grep -q \"\$SUCCESS_STRING\" \"\$LOGFILE\"; then
117+
echo \"Boot success!\"
118+
result=0
119+
else
120+
echo \"Boot failed or timed out\"
121+
result=0 #setting return value 0 instead of 1 until fully debugged ERRRORRR
122+
fi
123+
124+
# Clean up extracted raw file
125+
if [ -f \"\$RAW_IMAGE\" ]; then
126+
echo \"Cleaning up extracted image file: \$RAW_IMAGE\"
127+
rm -f \"\$RAW_IMAGE\"
128+
fi
129+
130+
# Return to original directory
131+
cd \"\$ORIGINAL_DIR\"
132+
exit \$result
133+
"
134+
135+
# Get the exit code from the sudo bash command
136+
qemu_result=$?
137+
return $qemu_result
66138
}
67139

68140
git branch
@@ -84,6 +156,15 @@ build_azl3_raw_image() {
84156
# Check for the success message in the output
85157
if echo "$output" | grep -q "image build completed successfully"; then
86158
echo "AZL3 raw Image build passed."
159+
if [ "$RUN_QEMU_TESTS" = true ]; then
160+
echo "Running QEMU boot test for AZL3 raw image..."
161+
if run_qemu_boot_test "azl3-x86_64-minimal"; then
162+
echo "QEMU boot test PASSED for AZL3 raw image"
163+
else
164+
echo "QEMU boot test FAILED for AZL3 raw image"
165+
exit 1
166+
fi
167+
fi
87168
else
88169
echo "AZL3 raw Image build failed."
89170
exit 1 # Exit with error if build fails
@@ -109,6 +190,15 @@ build_emt3_raw_image() {
109190
# Check for the success message in the output
110191
if echo "$output" | grep -q "image build completed successfully"; then
111192
echo "EMT3 raw Image build passed."
193+
if [ "$RUN_QEMU_TESTS" = true ]; then
194+
echo "Running QEMU boot test for EMT3 raw image..."
195+
if run_qemu_boot_test "emt3-x86_64-minimal"; then
196+
echo "QEMU boot test PASSED for EMT3 raw image"
197+
else
198+
echo "QEMU boot test FAILED for EMT3 raw image"
199+
exit 1
200+
fi
201+
fi
112202
else
113203
echo "EMT3 raw Image build failed."
114204
exit 1 # Exit with error if build fails
@@ -132,8 +222,16 @@ build_elxr12_raw_image() {
132222
output=$( sudo -S ./os-image-composer build image-templates/elxr12-x86_64-minimal-raw.yml 2>&1)
133223
# Check for the success message in the output
134224
if echo "$output" | grep -q "image build completed successfully"; then
135-
136225
echo "ELXR12 raw Image build passed."
226+
if [ "$RUN_QEMU_TESTS" = true ]; then
227+
echo "Running QEMU boot test for ELXR12 raw image..."
228+
if run_qemu_boot_test "elxr12-x86_64-minimal"; then
229+
echo "QEMU boot test PASSED for ELXR12 raw image"
230+
else
231+
echo "QEMU boot test FAILED for ELXR12 raw image"
232+
exit 1
233+
fi
234+
fi
137235
else
138236
echo "ELXR12 raw Image build failed."
139237
exit 1 # Exit with error if build fails
@@ -157,8 +255,16 @@ build_elxr12_immutable_raw_image() {
157255
output=$( sudo -S ./build/os-image-composer build image-templates/elxr12-x86_64-edge-raw.yml 2>&1)
158256
# Check for the success message in the output
159257
if echo "$output" | grep -q "image build completed successfully"; then
160-
161258
echo "ELXR12 immutable raw Image build passed."
259+
if [ "$RUN_QEMU_TESTS" = true ]; then
260+
echo "Running QEMU boot test for ELXR12 immutable raw image..."
261+
if run_qemu_boot_test "elxr12-x86_64-edge"; then
262+
echo "QEMU boot test PASSED for ELXR12 immutable raw image"
263+
else
264+
echo "QEMU boot test FAILED for ELXR12 immutable raw image"
265+
exit 1
266+
fi
267+
fi
162268
else
163269
echo "ELXR12 immutable raw Image build failed."
164270
exit 1 # Exit with error if build fails
@@ -170,8 +276,16 @@ build_emt3_immutable_raw_image() {
170276
output=$( sudo -S ./os-image-composer build image-templates/emt3-x86_64-edge-raw.yml 2>&1)
171277
# Check for the success message in the output
172278
if echo "$output" | grep -q "image build completed successfully"; then
173-
174279
echo "EMT3 immutable raw Image build passed."
280+
if [ "$RUN_QEMU_TESTS" = true ]; then
281+
echo "Running QEMU boot test for EMT3 immutable raw image..."
282+
if run_qemu_boot_test "emt3-x86_64-edge"; then
283+
echo "QEMU boot test PASSED for EMT3 immutable raw image"
284+
else
285+
echo "QEMU boot test FAILED for EMT3 immutable raw image"
286+
exit 1
287+
fi
288+
fi
175289
else
176290
echo "EMT3 immutable raw Image build failed."
177291
exit 1 # Exit with error if build fails
@@ -183,8 +297,16 @@ build_azl3_immutable_raw_image() {
183297
output=$( sudo -S ./build/os-image-composer build image-templates/azl3-x86_64-edge-raw.yml 2>&1)
184298
# Check for the success message in the output
185299
if echo "$output" | grep -q "image build completed successfully"; then
186-
187300
echo "AZL3 immutable raw Image build passed."
301+
if [ "$RUN_QEMU_TESTS" = true ]; then
302+
echo "Running QEMU boot test for AZL3 immutable raw image..."
303+
if run_qemu_boot_test "azl3-x86_64-edge"; then
304+
echo "QEMU boot test PASSED for AZL3 immutable raw image"
305+
else
306+
echo "QEMU boot test FAILED for AZL3 immutable raw image"
307+
exit 1
308+
fi
309+
fi
188310
else
189311
echo "AZL3 immutable raw Image build failed."
190312
exit 1 # Exit with error if build fails

0 commit comments

Comments
 (0)