migration: API to clear bits of guest free pages from the dirty bitmap
[qemu/ar7.git] / tests / cdrom-test.c
blob05611da648a1c7473a4f9f8da2b5319de7e5fde2
1 /*
2 * Various tests for emulated CD-ROM drives.
4 * Copyright (c) 2018 Red Hat Inc.
6 * Author:
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"
14 #include "libqtest.h"
15 #include "boot-sector.h"
16 #include "qapi/qmp/qdict.h"
18 static char isoimage[] = "cdrom-boot-iso-XXXXXX";
20 static int exec_genisoimg(const char **args)
22 gchar *out_err = NULL;
23 gint exit_status = -1;
24 bool success;
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);
29 if (!success) {
30 return -ENOENT;
32 if (out_err) {
33 fputs(out_err, stderr);
34 g_free(out_err);
37 return exit_status;
40 static int prepare_image(const char *arch, char *isoimage)
42 char srcdir[] = "cdrom-test-dir-XXXXXX";
43 char *codefile = NULL;
44 int ifh, ret = -1;
45 const char *args[] = {
46 "genisoimage", "-quiet", "-l", "-no-emul-boot",
47 "-b", NULL, "-o", isoimage, srcdir, NULL
50 ifh = mkstemp(isoimage);
51 if (ifh < 0) {
52 perror("Error creating temporary iso image file");
53 return -1;
55 if (!mkdtemp(srcdir)) {
56 perror("Error creating temporary directory");
57 goto cleanup;
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);
64 if (ret) {
65 goto cleanup;
67 } else {
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);
73 goto cleanup;
77 args[5] = strchr(codefile, '/') + 1;
78 ret = exec_genisoimg(args);
79 if (ret) {
80 fprintf(stderr, "genisoimage failed: %i\n", ret);
83 unlink(codefile);
85 cleanup:
86 g_free(codefile);
87 rmdir(srcdir);
88 close(ifh);
90 return ret;
93 /**
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)
99 QTestState *qts;
100 char *resp;
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);
105 g_free(resp);
106 qtest_quit(qts);
109 static void add_cdrom_param_tests(const char **machines)
111 while (*machines) {
112 char *testname = g_strdup_printf("cdrom/param/%s", *machines);
113 qtest_add_data_func(testname, *machines, test_cdrom_param);
114 g_free(testname);
115 machines++;
119 static void test_cdboot(gconstpointer data)
121 QTestState *qts;
123 qts = qtest_initf("-accel kvm:tcg -no-shutdown %s%s", (const char *)data,
124 isoimage);
125 boot_sector_test(qts);
126 qtest_quit(qts);
129 static void add_x86_tests(void)
131 qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot);
132 qtest_add_data_func("cdrom/boot/virtio-scsi",
133 "-device virtio-scsi -device scsi-cd,drive=cdr "
134 "-blockdev file,node-name=cdr,filename=", test_cdboot);
136 * Unstable CI test under load
137 * See https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg05509.html
139 if (g_test_slow()) {
140 qtest_add_data_func("cdrom/boot/isapc", "-M isapc "
141 "-drive if=ide,media=cdrom,file=", test_cdboot);
143 qtest_add_data_func("cdrom/boot/am53c974",
144 "-device am53c974 -device scsi-cd,drive=cd1 "
145 "-drive if=none,id=cd1,format=raw,file=", test_cdboot);
146 qtest_add_data_func("cdrom/boot/dc390",
147 "-device dc390 -device scsi-cd,drive=cd1 "
148 "-blockdev file,node-name=cd1,filename=", test_cdboot);
149 qtest_add_data_func("cdrom/boot/lsi53c895a",
150 "-device lsi53c895a -device scsi-cd,drive=cd1 "
151 "-blockdev file,node-name=cd1,filename=", test_cdboot);
152 qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
153 "-device megasas -device scsi-cd,drive=cd1 "
154 "-blockdev file,node-name=cd1,filename=", test_cdboot);
155 qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
156 "-device megasas-gen2 -device scsi-cd,drive=cd1 "
157 "-blockdev file,node-name=cd1,filename=", test_cdboot);
160 static void add_s390x_tests(void)
162 qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot);
163 qtest_add_data_func("cdrom/boot/virtio-scsi",
164 "-device virtio-scsi -device scsi-cd,drive=cdr "
165 "-blockdev file,node-name=cdr,filename=", test_cdboot);
168 int main(int argc, char **argv)
170 int ret;
171 const char *arch = qtest_get_arch();
172 const char *genisocheck[] = { "genisoimage", "-version", NULL };
174 g_test_init(&argc, &argv, NULL);
176 if (exec_genisoimg(genisocheck)) {
177 /* genisoimage not available - so can't run tests */
178 return g_test_run();
181 ret = prepare_image(arch, isoimage);
182 if (ret) {
183 return ret;
186 if (g_str_equal(arch, "i386") || g_str_equal(arch, "x86_64")) {
187 add_x86_tests();
188 } else if (g_str_equal(arch, "s390x")) {
189 add_s390x_tests();
190 } else if (g_str_equal(arch, "ppc64")) {
191 const char *ppcmachines[] = {
192 "pseries", "mac99", "g3beige", "40p", "prep", NULL
194 add_cdrom_param_tests(ppcmachines);
195 } else if (g_str_equal(arch, "sparc")) {
196 const char *sparcmachines[] = {
197 "LX", "SPARCClassic", "SPARCbook", "SS-10", "SS-20", "SS-4",
198 "SS-5", "SS-600MP", "Voyager", "leon3_generic", NULL
200 add_cdrom_param_tests(sparcmachines);
201 } else if (g_str_equal(arch, "sparc64")) {
202 const char *sparc64machines[] = {
203 "niagara", "sun4u", "sun4v", NULL
205 add_cdrom_param_tests(sparc64machines);
206 } else if (!strncmp(arch, "mips64", 6)) {
207 const char *mips64machines[] = {
208 "magnum", "malta", "mips", "pica61", NULL
210 add_cdrom_param_tests(mips64machines);
211 } else if (g_str_equal(arch, "arm") || g_str_equal(arch, "aarch64")) {
212 const char *armmachines[] = {
213 "realview-eb", "realview-eb-mpcore", "realview-pb-a8",
214 "realview-pbx-a9", "versatileab", "versatilepb", "vexpress-a15",
215 "vexpress-a9", "virt", NULL
217 add_cdrom_param_tests(armmachines);
218 } else {
219 const char *nonemachine[] = { "none", NULL };
220 add_cdrom_param_tests(nonemachine);
223 ret = g_test_run();
225 unlink(isoimage);
227 return ret;