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 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
@@ -54,14 +106,23 @@ run_qemu_boot_test() {
54106 kill $qemu_pid
55107 cat "' $LOGFILE ' "
56108
57- if grep -q "' $SUCCESS_STRING ' " "' $LOGFILE ' "; then
109+ if grep -q "$SUCCESS_STRING" "$LOGFILE"; then
58110 echo "Boot success!"
59111 result=0
60112 else
61113 echo "Boot failed or timed out"
62114 result=0 #setting return value 0 instead of 1 until fully debugged ERRRORRR
63- fi
64- exit $result
115+ fi
116+
117+ # Clean up extracted raw file
118+ if [ -f "$RAW_IMAGE" ]; then
119+ echo "Cleaning up extracted image file: $RAW_IMAGE"
120+ rm -f "$RAW_IMAGE"
121+ fi
122+
123+ # Return to original directory
124+ cd "$ORIGINAL_DIR"
125+ return $result
65126 '
66127}
67128
@@ -84,6 +145,15 @@ build_azl3_raw_image() {
84145 # Check for the success message in the output
85146 if echo " $output " | grep -q " image build completed successfully" ; then
86147 echo " AZL3 raw Image build passed."
148+ if [ " $RUN_QEMU_TESTS " = true ]; then
149+ echo " Running QEMU boot test for AZL3 raw image..."
150+ if run_qemu_boot_test " azl3-x86_64-minimal" ; then
151+ echo " QEMU boot test PASSED for AZL3 raw image"
152+ else
153+ echo " QEMU boot test FAILED for AZL3 raw image"
154+ exit 1
155+ fi
156+ fi
87157 else
88158 echo " AZL3 raw Image build failed."
89159 exit 1 # Exit with error if build fails
@@ -109,6 +179,15 @@ build_emt3_raw_image() {
109179 # Check for the success message in the output
110180 if echo " $output " | grep -q " image build completed successfully" ; then
111181 echo " EMT3 raw Image build passed."
182+ if [ " $RUN_QEMU_TESTS " = true ]; then
183+ echo " Running QEMU boot test for EMT3 raw image..."
184+ if run_qemu_boot_test " emt3-x86_64-minimal" ; then
185+ echo " QEMU boot test PASSED for EMT3 raw image"
186+ else
187+ echo " QEMU boot test FAILED for EMT3 raw image"
188+ exit 1
189+ fi
190+ fi
112191 else
113192 echo " EMT3 raw Image build failed."
114193 exit 1 # Exit with error if build fails
@@ -132,8 +211,16 @@ build_elxr12_raw_image() {
132211 output=$( sudo -S ./os-image-composer build image-templates/elxr12-x86_64-minimal-raw.yml 2>&1 )
133212 # Check for the success message in the output
134213 if echo " $output " | grep -q " image build completed successfully" ; then
135-
136214 echo " ELXR12 raw Image build passed."
215+ if [ " $RUN_QEMU_TESTS " = true ]; then
216+ echo " Running QEMU boot test for ELXR12 raw image..."
217+ if run_qemu_boot_test " elxr12-x86_64-minimal" ; then
218+ echo " QEMU boot test PASSED for ELXR12 raw image"
219+ else
220+ echo " QEMU boot test FAILED for ELXR12 raw image"
221+ exit 1
222+ fi
223+ fi
137224 else
138225 echo " ELXR12 raw Image build failed."
139226 exit 1 # Exit with error if build fails
@@ -157,8 +244,16 @@ build_elxr12_immutable_raw_image() {
157244 output=$( sudo -S ./build/os-image-composer build image-templates/elxr12-x86_64-edge-raw.yml 2>&1 )
158245 # Check for the success message in the output
159246 if echo " $output " | grep -q " image build completed successfully" ; then
160-
161247 echo " ELXR12 immutable raw Image build passed."
248+ if [ " $RUN_QEMU_TESTS " = true ]; then
249+ echo " Running QEMU boot test for ELXR12 immutable raw image..."
250+ if run_qemu_boot_test " elxr12-x86_64-edge" ; then
251+ echo " QEMU boot test PASSED for ELXR12 immutable raw image"
252+ else
253+ echo " QEMU boot test FAILED for ELXR12 immutable raw image"
254+ exit 1
255+ fi
256+ fi
162257 else
163258 echo " ELXR12 immutable raw Image build failed."
164259 exit 1 # Exit with error if build fails
@@ -170,8 +265,16 @@ build_emt3_immutable_raw_image() {
170265 output=$( sudo -S ./os-image-composer build image-templates/emt3-x86_64-edge-raw.yml 2>&1 )
171266 # Check for the success message in the output
172267 if echo " $output " | grep -q " image build completed successfully" ; then
173-
174268 echo " EMT3 immutable raw Image build passed."
269+ if [ " $RUN_QEMU_TESTS " = true ]; then
270+ echo " Running QEMU boot test for EMT3 immutable raw image..."
271+ if run_qemu_boot_test " emt3-x86_64-edge" ; then
272+ echo " QEMU boot test PASSED for EMT3 immutable raw image"
273+ else
274+ echo " QEMU boot test FAILED for EMT3 immutable raw image"
275+ exit 1
276+ fi
277+ fi
175278 else
176279 echo " EMT3 immutable raw Image build failed."
177280 exit 1 # Exit with error if build fails
@@ -183,8 +286,16 @@ build_azl3_immutable_raw_image() {
183286 output=$( sudo -S ./build/os-image-composer build image-templates/azl3-x86_64-edge-raw.yml 2>&1 )
184287 # Check for the success message in the output
185288 if echo " $output " | grep -q " image build completed successfully" ; then
186-
187289 echo " AZL3 immutable raw Image build passed."
290+ if [ " $RUN_QEMU_TESTS " = true ]; then
291+ echo " Running QEMU boot test for AZL3 immutable raw image..."
292+ if run_qemu_boot_test " azl3-x86_64-edge" ; then
293+ echo " QEMU boot test PASSED for AZL3 immutable raw image"
294+ else
295+ echo " QEMU boot test FAILED for AZL3 immutable raw image"
296+ exit 1
297+ fi
298+ fi
188299 else
189300 echo " AZL3 immutable raw Image build failed."
190301 exit 1 # Exit with error if build fails
0 commit comments