11#! /bin/bash
22set -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+
428echo " 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
635run_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 directory to allow access
55+ echo " Setting permissions for directory: $IMAGE_DIR "
56+ sudo chmod 777 " $IMAGE_DIR "
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
@@ -84,6 +136,15 @@ build_azl3_raw_image() {
84136 # Check for the success message in the output
85137 if echo " $output " | grep -q " image build completed successfully" ; then
86138 echo " AZL3 raw Image build passed."
139+ if [ " $RUN_QEMU_TESTS " = true ]; then
140+ echo " Running QEMU boot test for AZL3 raw image..."
141+ if run_qemu_boot_test " azl3-x86_64-minimal" ; then
142+ echo " QEMU boot test PASSED for AZL3 raw image"
143+ else
144+ echo " QEMU boot test FAILED for AZL3 raw image"
145+ exit 1
146+ fi
147+ fi
87148 else
88149 echo " AZL3 raw Image build failed."
89150 exit 1 # Exit with error if build fails
@@ -109,6 +170,15 @@ build_emt3_raw_image() {
109170 # Check for the success message in the output
110171 if echo " $output " | grep -q " image build completed successfully" ; then
111172 echo " EMT3 raw Image build passed."
173+ if [ " $RUN_QEMU_TESTS " = true ]; then
174+ echo " Running QEMU boot test for EMT3 raw image..."
175+ if run_qemu_boot_test " emt3-x86_64-minimal" ; then
176+ echo " QEMU boot test PASSED for EMT3 raw image"
177+ else
178+ echo " QEMU boot test FAILED for EMT3 raw image"
179+ exit 1
180+ fi
181+ fi
112182 else
113183 echo " EMT3 raw Image build failed."
114184 exit 1 # Exit with error if build fails
@@ -132,8 +202,16 @@ build_elxr12_raw_image() {
132202 output=$( sudo -S ./os-image-composer build image-templates/elxr12-x86_64-minimal-raw.yml 2>&1 )
133203 # Check for the success message in the output
134204 if echo " $output " | grep -q " image build completed successfully" ; then
135-
136205 echo " ELXR12 raw Image build passed."
206+ if [ " $RUN_QEMU_TESTS " = true ]; then
207+ echo " Running QEMU boot test for ELXR12 raw image..."
208+ if run_qemu_boot_test " elxr12-x86_64-minimal" ; then
209+ echo " QEMU boot test PASSED for ELXR12 raw image"
210+ else
211+ echo " QEMU boot test FAILED for ELXR12 raw image"
212+ exit 1
213+ fi
214+ fi
137215 else
138216 echo " ELXR12 raw Image build failed."
139217 exit 1 # Exit with error if build fails
@@ -157,8 +235,16 @@ build_elxr12_immutable_raw_image() {
157235 output=$( sudo -S ./build/os-image-composer build image-templates/elxr12-x86_64-edge-raw.yml 2>&1 )
158236 # Check for the success message in the output
159237 if echo " $output " | grep -q " image build completed successfully" ; then
160-
161238 echo " ELXR12 immutable raw Image build passed."
239+ if [ " $RUN_QEMU_TESTS " = true ]; then
240+ echo " Running QEMU boot test for ELXR12 immutable raw image..."
241+ if run_qemu_boot_test " elxr12-x86_64-edge" ; then
242+ echo " QEMU boot test PASSED for ELXR12 immutable raw image"
243+ else
244+ echo " QEMU boot test FAILED for ELXR12 immutable raw image"
245+ exit 1
246+ fi
247+ fi
162248 else
163249 echo " ELXR12 immutable raw Image build failed."
164250 exit 1 # Exit with error if build fails
@@ -170,8 +256,16 @@ build_emt3_immutable_raw_image() {
170256 output=$( sudo -S ./os-image-composer build image-templates/emt3-x86_64-edge-raw.yml 2>&1 )
171257 # Check for the success message in the output
172258 if echo " $output " | grep -q " image build completed successfully" ; then
173-
174259 echo " EMT3 immutable raw Image build passed."
260+ if [ " $RUN_QEMU_TESTS " = true ]; then
261+ echo " Running QEMU boot test for EMT3 immutable raw image..."
262+ if run_qemu_boot_test " emt3-x86_64-edge" ; then
263+ echo " QEMU boot test PASSED for EMT3 immutable raw image"
264+ else
265+ echo " QEMU boot test FAILED for EMT3 immutable raw image"
266+ exit 1
267+ fi
268+ fi
175269 else
176270 echo " EMT3 immutable raw Image build failed."
177271 exit 1 # Exit with error if build fails
@@ -183,8 +277,16 @@ build_azl3_immutable_raw_image() {
183277 output=$( sudo -S ./build/os-image-composer build image-templates/azl3-x86_64-edge-raw.yml 2>&1 )
184278 # Check for the success message in the output
185279 if echo " $output " | grep -q " image build completed successfully" ; then
186-
187280 echo " AZL3 immutable raw Image build passed."
281+ if [ " $RUN_QEMU_TESTS " = true ]; then
282+ echo " Running QEMU boot test for AZL3 immutable raw image..."
283+ if run_qemu_boot_test " azl3-x86_64-edge" ; then
284+ echo " QEMU boot test PASSED for AZL3 immutable raw image"
285+ else
286+ echo " QEMU boot test FAILED for AZL3 immutable raw image"
287+ exit 1
288+ fi
289+ fi
188290 else
189291 echo " AZL3 immutable raw Image build failed."
190292 exit 1 # Exit with error if build fails
0 commit comments