2 * Various tests for emulated CD-ROM drives.
4 * Copyright (c) 2018 Red Hat Inc.
7 * Thomas Huth <thuth@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2
10 * or later. See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
15 #include "boot-sector.h"
16 #include "qapi/qmp/qdict.h"
18 static char isoimage
[] = "cdrom-boot-iso-XXXXXX";
20 static int exec_xorrisofs(const char **args
)
22 gchar
*out_err
= NULL
;
23 gint exit_status
= -1;
26 success
= g_spawn_sync(NULL
, (gchar
**)args
, NULL
,
27 G_SPAWN_SEARCH_PATH
| G_SPAWN_STDOUT_TO_DEV_NULL
,
28 NULL
, NULL
, NULL
, &out_err
, &exit_status
, NULL
);
33 fputs(out_err
, stderr
);
40 static int prepare_image(const char *arch
, char *isoimage
)
42 char srcdir
[] = "cdrom-test-dir-XXXXXX";
43 char *codefile
= NULL
;
45 const char *args
[] = {
46 "xorrisofs", "-quiet", "-l", "-no-emul-boot",
47 "-b", NULL
, "-o", isoimage
, srcdir
, NULL
50 ifh
= mkstemp(isoimage
);
52 perror("Error creating temporary iso image file");
55 if (!g_mkdtemp(srcdir
)) {
56 perror("Error creating temporary directory");
60 if (g_str_equal(arch
, "i386") || g_str_equal(arch
, "x86_64") ||
61 g_str_equal(arch
, "s390x")) {
62 codefile
= g_strdup_printf("%s/bootcode-XXXXXX", srcdir
);
63 ret
= boot_sector_init(codefile
);
68 /* Just create a dummy file */
69 char txt
[] = "empty disc";
70 codefile
= g_strdup_printf("%s/readme.txt", srcdir
);
71 if (!g_file_set_contents(codefile
, txt
, sizeof(txt
) - 1, NULL
)) {
72 fprintf(stderr
, "Failed to create '%s'\n", codefile
);
77 args
[5] = strchr(codefile
, '/') + 1;
78 ret
= exec_xorrisofs(args
);
80 fprintf(stderr
, "xorrisofs failed: %i\n", ret
);
94 * Check that at least the -cdrom parameter is basically working, i.e. we can
95 * see the filename of the ISO image in the output of "info block" afterwards
97 static void test_cdrom_param(gconstpointer data
)
102 qts
= qtest_initf("-M %s -cdrom %s", (const char *)data
, isoimage
);
103 resp
= qtest_hmp(qts
, "info block");
104 g_assert(strstr(resp
, isoimage
) != 0);
109 static void add_cdrom_param_tests(const char **machines
)
112 if (qtest_has_machine(*machines
)) {
113 char *testname
= g_strdup_printf("cdrom/param/%s", *machines
);
114 qtest_add_data_func(testname
, *machines
, test_cdrom_param
);
121 static void test_cdboot(gconstpointer data
)
125 qts
= qtest_initf("-accel kvm -accel tcg -no-shutdown %s%s", (const char *)data
,
127 boot_sector_test(qts
);
131 static void add_x86_tests(void)
133 if (!qtest_has_accel("tcg") && !qtest_has_accel("kvm")) {
134 g_test_skip("No KVM or TCG accelerator available, skipping boot tests");
138 qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot
);
139 if (qtest_has_device("virtio-scsi-ccw")) {
140 qtest_add_data_func("cdrom/boot/virtio-scsi",
141 "-device virtio-scsi -device scsi-cd,drive=cdr "
142 "-blockdev file,node-name=cdr,filename=",
146 * Unstable CI test under load
147 * See https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg05509.html
149 if (g_test_slow() && qtest_has_machine("isapc")) {
150 qtest_add_data_func("cdrom/boot/isapc", "-M isapc "
151 "-drive if=ide,media=cdrom,file=", test_cdboot
);
153 if (qtest_has_device("am53c974")) {
154 qtest_add_data_func("cdrom/boot/am53c974",
155 "-device am53c974 -device scsi-cd,drive=cd1 "
156 "-drive if=none,id=cd1,format=raw,file=",
159 if (qtest_has_device("dc390")) {
160 qtest_add_data_func("cdrom/boot/dc390",
161 "-device dc390 -device scsi-cd,drive=cd1 "
162 "-blockdev file,node-name=cd1,filename=",
165 if (qtest_has_device("lsi53c895a")) {
166 qtest_add_data_func("cdrom/boot/lsi53c895a",
167 "-device lsi53c895a -device scsi-cd,drive=cd1 "
168 "-blockdev file,node-name=cd1,filename=",
171 if (qtest_has_device("megasas")) {
172 qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
173 "-device megasas -device scsi-cd,drive=cd1 "
174 "-blockdev file,node-name=cd1,filename=",
177 if (qtest_has_device("megasas-gen2")) {
178 qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
179 "-device megasas-gen2 -device scsi-cd,drive=cd1 "
180 "-blockdev file,node-name=cd1,filename=",
185 static void add_s390x_tests(void)
187 if (!qtest_has_accel("tcg") && !qtest_has_accel("kvm")) {
188 g_test_skip("No KVM or TCG accelerator available, skipping boot tests");
190 if (!qtest_has_device("virtio-blk-ccw")) {
194 qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot
);
196 if (!qtest_has_device("virtio-scsi-ccw")) {
200 qtest_add_data_func("cdrom/boot/virtio-scsi",
201 "-device virtio-scsi -device scsi-cd,drive=cdr "
202 "-blockdev file,node-name=cdr,filename=", test_cdboot
);
203 qtest_add_data_func("cdrom/boot/with-bootindex",
204 "-device virtio-serial -device virtio-scsi "
205 "-device virtio-blk,drive=d1 "
206 "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
207 "-device virtio-blk,drive=d2,bootindex=1 "
208 "-drive if=none,id=d2,media=cdrom,file=", test_cdboot
);
209 if (qtest_has_device("x-terminal3270")) {
210 qtest_add_data_func("cdrom/boot/without-bootindex",
211 "-device virtio-scsi -device virtio-serial "
212 "-device x-terminal3270 -device virtio-blk,drive=d1 "
213 "-drive driver=null-co,read-zeroes=on,if=none,id=d1 "
214 "-device virtio-blk,drive=d2 "
215 "-drive if=none,id=d2,media=cdrom,file=",
220 int main(int argc
, char **argv
)
223 const char *arch
= qtest_get_arch();
224 const char *xorrisocheck
[] = { "xorrisofs", "-version", NULL
};
226 g_test_init(&argc
, &argv
, NULL
);
228 if (exec_xorrisofs(xorrisocheck
)) {
229 /* xorrisofs not available - so can't run tests */
233 ret
= prepare_image(arch
, isoimage
);
238 if (g_str_equal(arch
, "i386") || g_str_equal(arch
, "x86_64")) {
240 } else if (g_str_equal(arch
, "s390x")) {
242 } else if (g_str_equal(arch
, "ppc64")) {
243 const char *ppcmachines
[] = {
244 "pseries", "mac99", "g3beige", "40p", NULL
246 add_cdrom_param_tests(ppcmachines
);
247 } else if (g_str_equal(arch
, "sparc")) {
248 const char *sparcmachines
[] = {
249 "LX", "SPARCClassic", "SPARCbook", "SS-10", "SS-20", "SS-4",
250 "SS-5", "SS-600MP", "Voyager", "leon3_generic", NULL
252 add_cdrom_param_tests(sparcmachines
);
253 } else if (g_str_equal(arch
, "sparc64")) {
254 const char *sparc64machines
[] = {
255 "niagara", "sun4u", "sun4v", NULL
257 add_cdrom_param_tests(sparc64machines
);
258 } else if (!strncmp(arch
, "mips64", 6)) {
259 const char *mips64machines
[] = {
260 "magnum", "malta", "pica61", NULL
262 add_cdrom_param_tests(mips64machines
);
263 } else if (g_str_equal(arch
, "arm") || g_str_equal(arch
, "aarch64")) {
264 const char *armmachines
[] = {
265 "realview-eb", "realview-eb-mpcore", "realview-pb-a8",
266 "realview-pbx-a9", "versatileab", "versatilepb", "vexpress-a15",
269 add_cdrom_param_tests(armmachines
);
270 if (qtest_has_device("virtio-blk-pci")) {
271 const char *virtmachine
[] = { "virt", NULL
};
272 add_cdrom_param_tests(virtmachine
);
275 const char *nonemachine
[] = { "none", NULL
};
276 add_cdrom_param_tests(nonemachine
);