Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Hard disk geometry test cases. |
| 3 | * |
| 4 | * Copyright (c) 2012 Red Hat Inc. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Markus Armbruster <armbru@redhat.com>, |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 10 | * See the COPYING file in the top-level directory. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * Covers only IDE and tests only CMOS contents. Better than nothing. |
| 15 | * Improvements welcome. |
| 16 | */ |
| 17 | |
Peter Maydell | 681c28a | 2016-02-08 18:08:51 +0000 | [diff] [blame] | 18 | #include "qemu/osdep.h" |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 19 | #include "qemu-common.h" |
| 20 | #include "libqtest.h" |
| 21 | |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 22 | #define ARGV_SIZE 256 |
| 23 | |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 24 | static char *create_test_img(int secs) |
| 25 | { |
| 26 | char *template = strdup("/tmp/qtest.XXXXXX"); |
| 27 | int fd, ret; |
| 28 | |
| 29 | fd = mkstemp(template); |
| 30 | g_assert(fd >= 0); |
| 31 | ret = ftruncate(fd, (off_t)secs * 512); |
| 32 | g_assert(ret == 0); |
| 33 | close(fd); |
| 34 | return template; |
| 35 | } |
| 36 | |
| 37 | typedef struct { |
| 38 | int cyls, heads, secs, trans; |
| 39 | } CHST; |
| 40 | |
| 41 | typedef enum { |
| 42 | mbr_blank, mbr_lba, mbr_chs, |
| 43 | mbr_last |
| 44 | } MBRcontents; |
| 45 | |
| 46 | typedef enum { |
| 47 | /* order is relevant */ |
| 48 | backend_small, backend_large, backend_empty, |
| 49 | backend_last |
| 50 | } Backend; |
| 51 | |
| 52 | static const int img_secs[backend_last] = { |
| 53 | [backend_small] = 61440, |
| 54 | [backend_large] = 8388608, |
| 55 | [backend_empty] = -1, |
| 56 | }; |
| 57 | |
| 58 | static const CHST hd_chst[backend_last][mbr_last] = { |
| 59 | [backend_small] = { |
| 60 | [mbr_blank] = { 60, 16, 63, 0 }, |
| 61 | [mbr_lba] = { 60, 16, 63, 2 }, |
| 62 | [mbr_chs] = { 60, 16, 63, 0 } |
| 63 | }, |
| 64 | [backend_large] = { |
| 65 | [mbr_blank] = { 8322, 16, 63, 1 }, |
| 66 | [mbr_lba] = { 8322, 16, 63, 1 }, |
| 67 | [mbr_chs] = { 8322, 16, 63, 0 } |
| 68 | }, |
| 69 | }; |
| 70 | |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 71 | static char *img_file_name[backend_last]; |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 72 | |
| 73 | static const CHST *cur_ide[4]; |
| 74 | |
| 75 | static bool is_hd(const CHST *expected_chst) |
| 76 | { |
| 77 | return expected_chst && expected_chst->cyls; |
| 78 | } |
| 79 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 80 | static void test_cmos_byte(QTestState *qts, int reg, int expected) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 81 | { |
| 82 | enum { cmos_base = 0x70 }; |
| 83 | int actual; |
| 84 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 85 | qtest_outb(qts, cmos_base + 0, reg); |
| 86 | actual = qtest_inb(qts, cmos_base + 1); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 87 | g_assert(actual == expected); |
| 88 | } |
| 89 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 90 | static void test_cmos_bytes(QTestState *qts, int reg0, int n, |
| 91 | uint8_t expected[]) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 92 | { |
| 93 | int i; |
| 94 | |
| 95 | for (i = 0; i < 9; i++) { |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 96 | test_cmos_byte(qts, reg0 + i, expected[i]); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 100 | static void test_cmos_disk_data(QTestState *qts) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 101 | { |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 102 | test_cmos_byte(qts, 0x12, |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 103 | (is_hd(cur_ide[0]) ? 0xf0 : 0) | |
| 104 | (is_hd(cur_ide[1]) ? 0x0f : 0)); |
| 105 | } |
| 106 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 107 | static void test_cmos_drive_cyl(QTestState *qts, int reg0, |
| 108 | const CHST *expected_chst) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 109 | { |
| 110 | if (is_hd(expected_chst)) { |
| 111 | int c = expected_chst->cyls; |
| 112 | int h = expected_chst->heads; |
| 113 | int s = expected_chst->secs; |
| 114 | uint8_t expected_bytes[9] = { |
| 115 | c & 0xff, c >> 8, h, 0xff, 0xff, 0xc0 | ((h > 8) << 3), |
| 116 | c & 0xff, c >> 8, s |
| 117 | }; |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 118 | test_cmos_bytes(qts, reg0, 9, expected_bytes); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 119 | } else { |
| 120 | int i; |
| 121 | |
| 122 | for (i = 0; i < 9; i++) { |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 123 | test_cmos_byte(qts, reg0 + i, 0); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 128 | static void test_cmos_drive1(QTestState *qts) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 129 | { |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 130 | test_cmos_byte(qts, 0x19, is_hd(cur_ide[0]) ? 47 : 0); |
| 131 | test_cmos_drive_cyl(qts, 0x1b, cur_ide[0]); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 134 | static void test_cmos_drive2(QTestState *qts) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 135 | { |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 136 | test_cmos_byte(qts, 0x1a, is_hd(cur_ide[1]) ? 47 : 0); |
| 137 | test_cmos_drive_cyl(qts, 0x24, cur_ide[1]); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 140 | static void test_cmos_disktransflag(QTestState *qts) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 141 | { |
| 142 | int val, i; |
| 143 | |
| 144 | val = 0; |
| 145 | for (i = 0; i < ARRAY_SIZE(cur_ide); i++) { |
| 146 | if (is_hd(cur_ide[i])) { |
| 147 | val |= cur_ide[i]->trans << (2 * i); |
| 148 | } |
| 149 | } |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 150 | test_cmos_byte(qts, 0x39, val); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 153 | static void test_cmos(QTestState *qts) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 154 | { |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 155 | test_cmos_disk_data(qts); |
| 156 | test_cmos_drive1(qts); |
| 157 | test_cmos_drive2(qts); |
| 158 | test_cmos_disktransflag(qts); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static int append_arg(int argc, char *argv[], int argv_sz, char *arg) |
| 162 | { |
| 163 | g_assert(argc + 1 < argv_sz); |
| 164 | argv[argc++] = arg; |
| 165 | argv[argc] = NULL; |
| 166 | return argc; |
| 167 | } |
| 168 | |
| 169 | static int setup_common(char *argv[], int argv_sz) |
| 170 | { |
| 171 | memset(cur_ide, 0, sizeof(cur_ide)); |
| 172 | return append_arg(0, argv, argv_sz, |
Andreas Färber | 2ad645d | 2013-11-18 17:36:34 +0100 | [diff] [blame] | 173 | g_strdup("-nodefaults")); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static void setup_mbr(int img_idx, MBRcontents mbr) |
| 177 | { |
| 178 | static const uint8_t part_lba[16] = { |
| 179 | /* chs 0,1,1 (lba 63) to chs 0,127,63 (8001 sectors) */ |
| 180 | 0x80, 1, 1, 0, 6, 127, 63, 0, 63, 0, 0, 0, 0x41, 0x1F, 0, 0, |
| 181 | }; |
| 182 | static const uint8_t part_chs[16] = { |
| 183 | /* chs 0,1,1 (lba 63) to chs 7,15,63 (8001 sectors) */ |
| 184 | 0x80, 1, 1, 0, 6, 15, 63, 7, 63, 0, 0, 0, 0x41, 0x1F, 0, 0, |
| 185 | }; |
| 186 | uint8_t buf[512]; |
| 187 | int fd, ret; |
| 188 | |
| 189 | memset(buf, 0, sizeof(buf)); |
| 190 | |
| 191 | if (mbr != mbr_blank) { |
| 192 | buf[0x1fe] = 0x55; |
| 193 | buf[0x1ff] = 0xAA; |
| 194 | memcpy(buf + 0x1BE, mbr == mbr_lba ? part_lba : part_chs, 16); |
| 195 | } |
| 196 | |
| 197 | fd = open(img_file_name[img_idx], O_WRONLY); |
| 198 | g_assert(fd >= 0); |
| 199 | ret = write(fd, buf, sizeof(buf)); |
| 200 | g_assert(ret == sizeof(buf)); |
| 201 | close(fd); |
| 202 | } |
| 203 | |
| 204 | static int setup_ide(int argc, char *argv[], int argv_sz, |
| 205 | int ide_idx, const char *dev, int img_idx, |
Kevin Wolf | b24ec3c | 2018-06-13 11:01:30 +0200 | [diff] [blame] | 206 | MBRcontents mbr) |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 207 | { |
| 208 | char *s1, *s2, *s3; |
| 209 | |
Kevin Wolf | 39c4ae9 | 2015-11-13 14:45:42 +0100 | [diff] [blame] | 210 | s1 = g_strdup_printf("-drive id=drive%d,if=%s", |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 211 | ide_idx, dev ? "none" : "ide"); |
| 212 | s2 = dev ? g_strdup("") : g_strdup_printf(",index=%d", ide_idx); |
| 213 | |
| 214 | if (img_secs[img_idx] >= 0) { |
| 215 | setup_mbr(img_idx, mbr); |
Kevin Wolf | 39c4ae9 | 2015-11-13 14:45:42 +0100 | [diff] [blame] | 216 | s3 = g_strdup_printf(",format=raw,file=%s", img_file_name[img_idx]); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 217 | } else { |
| 218 | s3 = g_strdup(",media=cdrom"); |
| 219 | } |
| 220 | argc = append_arg(argc, argv, argv_sz, |
Kevin Wolf | b24ec3c | 2018-06-13 11:01:30 +0200 | [diff] [blame] | 221 | g_strdup_printf("%s%s%s", s1, s2, s3)); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 222 | g_free(s1); |
| 223 | g_free(s2); |
| 224 | g_free(s3); |
| 225 | |
| 226 | if (dev) { |
| 227 | argc = append_arg(argc, argv, argv_sz, |
| 228 | g_strdup_printf("-device %s,drive=drive%d," |
| 229 | "bus=ide.%d,unit=%d", |
| 230 | dev, ide_idx, |
| 231 | ide_idx / 2, ide_idx % 2)); |
| 232 | } |
| 233 | return argc; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Test case: no IDE devices |
| 238 | */ |
| 239 | static void test_ide_none(void) |
| 240 | { |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 241 | char **argv = g_new0(char *, ARGV_SIZE); |
| 242 | char *args; |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 243 | QTestState *qts; |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 244 | |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 245 | setup_common(argv, ARGV_SIZE); |
| 246 | args = g_strjoinv(" ", argv); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 247 | qts = qtest_init(args); |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 248 | g_strfreev(argv); |
| 249 | g_free(args); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 250 | test_cmos(qts); |
| 251 | qtest_quit(qts); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void test_ide_mbr(bool use_device, MBRcontents mbr) |
| 255 | { |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 256 | char **argv = g_new0(char *, ARGV_SIZE); |
| 257 | char *args; |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 258 | int argc; |
| 259 | Backend i; |
| 260 | const char *dev; |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 261 | QTestState *qts; |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 262 | |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 263 | argc = setup_common(argv, ARGV_SIZE); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 264 | for (i = 0; i < backend_last; i++) { |
| 265 | cur_ide[i] = &hd_chst[i][mbr]; |
| 266 | dev = use_device ? (is_hd(cur_ide[i]) ? "ide-hd" : "ide-cd") : NULL; |
Kevin Wolf | b24ec3c | 2018-06-13 11:01:30 +0200 | [diff] [blame] | 267 | argc = setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 268 | } |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 269 | args = g_strjoinv(" ", argv); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 270 | qts = qtest_init(args); |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 271 | g_strfreev(argv); |
| 272 | g_free(args); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 273 | test_cmos(qts); |
| 274 | qtest_quit(qts); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /* |
| 278 | * Test case: IDE devices (if=ide) with blank MBRs |
| 279 | */ |
| 280 | static void test_ide_drive_mbr_blank(void) |
| 281 | { |
| 282 | test_ide_mbr(false, mbr_blank); |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * Test case: IDE devices (if=ide) with MBRs indicating LBA is in use |
| 287 | */ |
| 288 | static void test_ide_drive_mbr_lba(void) |
| 289 | { |
| 290 | test_ide_mbr(false, mbr_lba); |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * Test case: IDE devices (if=ide) with MBRs indicating CHS is in use |
| 295 | */ |
| 296 | static void test_ide_drive_mbr_chs(void) |
| 297 | { |
| 298 | test_ide_mbr(false, mbr_chs); |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Test case: IDE devices (if=none) with blank MBRs |
| 303 | */ |
| 304 | static void test_ide_device_mbr_blank(void) |
| 305 | { |
| 306 | test_ide_mbr(true, mbr_blank); |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Test case: IDE devices (if=none) with MBRs indicating LBA is in use |
| 311 | */ |
| 312 | static void test_ide_device_mbr_lba(void) |
| 313 | { |
| 314 | test_ide_mbr(true, mbr_lba); |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * Test case: IDE devices (if=none) with MBRs indicating CHS is in use |
| 319 | */ |
| 320 | static void test_ide_device_mbr_chs(void) |
| 321 | { |
| 322 | test_ide_mbr(true, mbr_chs); |
| 323 | } |
| 324 | |
| 325 | static void test_ide_drive_user(const char *dev, bool trans) |
| 326 | { |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 327 | char **argv = g_new0(char *, ARGV_SIZE); |
| 328 | char *args, *opts; |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 329 | int argc; |
| 330 | int secs = img_secs[backend_small]; |
| 331 | const CHST expected_chst = { secs / (4 * 32) , 4, 32, trans }; |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 332 | QTestState *qts; |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 333 | |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 334 | argc = setup_common(argv, ARGV_SIZE); |
Kevin Wolf | b24ec3c | 2018-06-13 11:01:30 +0200 | [diff] [blame] | 335 | opts = g_strdup_printf("%s,%scyls=%d,heads=%d,secs=%d", |
| 336 | dev, trans ? "bios-chs-trans=lba," : "", |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 337 | expected_chst.cyls, expected_chst.heads, |
Markus Armbruster | 856dcba | 2012-07-10 11:12:49 +0200 | [diff] [blame] | 338 | expected_chst.secs); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 339 | cur_ide[0] = &expected_chst; |
Kevin Wolf | b24ec3c | 2018-06-13 11:01:30 +0200 | [diff] [blame] | 340 | argc = setup_ide(argc, argv, ARGV_SIZE, 0, opts, backend_small, mbr_chs); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 341 | g_free(opts); |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 342 | args = g_strjoinv(" ", argv); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 343 | qts = qtest_init(args); |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 344 | g_strfreev(argv); |
| 345 | g_free(args); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 346 | test_cmos(qts); |
| 347 | qtest_quit(qts); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 351 | * Test case: IDE device (if=none) with explicit CHS |
| 352 | */ |
| 353 | static void test_ide_device_user_chs(void) |
| 354 | { |
| 355 | test_ide_drive_user("ide-hd", false); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Test case: IDE device (if=none) with explicit CHS and translation |
| 360 | */ |
| 361 | static void test_ide_device_user_chst(void) |
| 362 | { |
| 363 | test_ide_drive_user("ide-hd", true); |
| 364 | } |
| 365 | |
Markus Armbruster | 4e4e6e3 | 2012-07-10 11:12:52 +0200 | [diff] [blame] | 366 | /* |
| 367 | * Test case: IDE devices (if=ide), but use index=0 for CD-ROM |
| 368 | */ |
| 369 | static void test_ide_drive_cd_0(void) |
| 370 | { |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 371 | char **argv = g_new0(char *, ARGV_SIZE); |
| 372 | char *args; |
Markus Armbruster | 4e4e6e3 | 2012-07-10 11:12:52 +0200 | [diff] [blame] | 373 | int argc, ide_idx; |
| 374 | Backend i; |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 375 | QTestState *qts; |
Markus Armbruster | 4e4e6e3 | 2012-07-10 11:12:52 +0200 | [diff] [blame] | 376 | |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 377 | argc = setup_common(argv, ARGV_SIZE); |
Markus Armbruster | 4e4e6e3 | 2012-07-10 11:12:52 +0200 | [diff] [blame] | 378 | for (i = 0; i <= backend_empty; i++) { |
| 379 | ide_idx = backend_empty - i; |
| 380 | cur_ide[ide_idx] = &hd_chst[i][mbr_blank]; |
Kevin Wolf | b24ec3c | 2018-06-13 11:01:30 +0200 | [diff] [blame] | 381 | argc = setup_ide(argc, argv, ARGV_SIZE, ide_idx, NULL, i, mbr_blank); |
Markus Armbruster | 4e4e6e3 | 2012-07-10 11:12:52 +0200 | [diff] [blame] | 382 | } |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 383 | args = g_strjoinv(" ", argv); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 384 | qts = qtest_init(args); |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 385 | g_strfreev(argv); |
| 386 | g_free(args); |
Thomas Huth | 44c2364 | 2019-05-15 19:43:28 +0200 | [diff] [blame] | 387 | test_cmos(qts); |
| 388 | qtest_quit(qts); |
Markus Armbruster | 4e4e6e3 | 2012-07-10 11:12:52 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 391 | int main(int argc, char **argv) |
| 392 | { |
| 393 | Backend i; |
| 394 | int ret; |
| 395 | |
| 396 | g_test_init(&argc, &argv, NULL); |
| 397 | |
| 398 | for (i = 0; i < backend_last; i++) { |
| 399 | if (img_secs[i] >= 0) { |
| 400 | img_file_name[i] = create_test_img(img_secs[i]); |
| 401 | } else { |
| 402 | img_file_name[i] = NULL; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | qtest_add_func("hd-geo/ide/none", test_ide_none); |
| 407 | qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank); |
| 408 | qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba); |
| 409 | qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs); |
Markus Armbruster | 4e4e6e3 | 2012-07-10 11:12:52 +0200 | [diff] [blame] | 410 | qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0); |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 411 | qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blank); |
| 412 | qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba); |
| 413 | qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs); |
| 414 | qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs); |
| 415 | qtest_add_func("hd-geo/ide/device/user/chst", test_ide_device_user_chst); |
| 416 | |
| 417 | ret = g_test_run(); |
| 418 | |
| 419 | for (i = 0; i < backend_last; i++) { |
Peter Maydell | 0813cbf | 2016-08-05 11:03:12 +0100 | [diff] [blame] | 420 | if (img_file_name[i]) { |
| 421 | unlink(img_file_name[i]); |
Marc-André Lureau | 2c8f869 | 2017-02-05 14:11:56 +0400 | [diff] [blame] | 422 | free(img_file_name[i]); |
Peter Maydell | 0813cbf | 2016-08-05 11:03:12 +0100 | [diff] [blame] | 423 | } |
Markus Armbruster | 0e8a8c8 | 2012-07-10 11:12:30 +0200 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | return ret; |
| 427 | } |