summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPavel Hrdina <phrdina@redhat.com>2012-05-24 11:02:30 +0200
committerKevin Wolf <kwolf@redhat.com>2012-05-25 18:23:47 +0200
commit7cd331617a48785faaf2aafe36db5c06285bfed8 (patch)
tree4481e826f89b0e0c4fbf11d28902fbb999d157e7 /tests
parentcfb08fbafcd946341bdf14103293887763802697 (diff)
fdc-test: introduced qtest no_media_on_start and cmos qtest for floppy
As default a guest has always one floppy drive so 0x10 byte in CMOS has to have 0x40 value. Higher 4 bits means that the first floppy drive is 1.44 Mb 3"5 drive and lower 4 bits means the second drive is not present. After the guest starts DSKCHG bit in DIR register should be set. If there is no media in drive, this bit should be set all the time. Because we start the guest without media in drive, we have to swap 'eject' and 'change' in 'test_media_change'. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/fdc-test.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/tests/fdc-test.c b/tests/fdc-test.c
index 5b5dd7481..22d24ac7d 100644
--- a/tests/fdc-test.c
+++ b/tests/fdc-test.c
@@ -63,6 +63,12 @@ char test_image[] = "/tmp/qtest.XXXXXX";
#define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
+static uint8_t base = 0x70;
+
+enum {
+ CMOS_FLOPPY = 0x10,
+};
+
static void floppy_send(uint8_t byte)
{
uint8_t msr;
@@ -108,34 +114,43 @@ static void send_step_pulse(void)
cyl = (cyl + 1) % 4;
}
-static void test_media_change(void)
+static uint8_t cmos_read(uint8_t reg)
{
- uint8_t dir;
+ outb(base + 0, reg);
+ return inb(base + 1);
+}
- /* Media changed bit must be up-to-date after step pulse. Do two SEEKs
- * because we may already happen to be on the right cylinder initially. */
- send_step_pulse();
- send_step_pulse();
- dir = inb(FLOPPY_BASE + reg_dir);
- assert_bit_clear(dir, DSKCHG);
+static void test_cmos(void)
+{
+ uint8_t cmos;
- /* Eject the floppy and check that DSKCHG is set. Reading it out doesn't
- * reset the bit. */
- qmp("{'execute':'eject', 'arguments':{ 'device':'floppy0' }}");
- qmp(""); /* ignore event */
+ cmos = cmos_read(CMOS_FLOPPY);
+ g_assert(cmos == 0x40);
+}
+static void test_no_media_on_start(void)
+{
+ uint8_t dir;
+
+ /* Media changed bit must be set all time after start if there is
+ * no media in drive. */
dir = inb(FLOPPY_BASE + reg_dir);
assert_bit_set(dir, DSKCHG);
dir = inb(FLOPPY_BASE + reg_dir);
assert_bit_set(dir, DSKCHG);
-
+ send_step_pulse();
send_step_pulse();
dir = inb(FLOPPY_BASE + reg_dir);
assert_bit_set(dir, DSKCHG);
dir = inb(FLOPPY_BASE + reg_dir);
assert_bit_set(dir, DSKCHG);
+}
+
+static void test_media_change(void)
+{
+ uint8_t dir;
- /* And then insert it again. DSKCHK should not be reset until a step pulse
+ /* Insert media in drive. DSKCHK should not be reset until a step pulse
* is sent. */
qmp("{'execute':'change', 'arguments':{ 'device':'floppy0', "
"'target': '%s' }}", test_image);
@@ -152,6 +167,22 @@ static void test_media_change(void)
assert_bit_clear(dir, DSKCHG);
dir = inb(FLOPPY_BASE + reg_dir);
assert_bit_clear(dir, DSKCHG);
+
+ /* Eject the floppy and check that DSKCHG is set. Reading it out doesn't
+ * reset the bit. */
+ qmp("{'execute':'eject', 'arguments':{ 'device':'floppy0' }}");
+ qmp(""); /* ignore event */
+
+ dir = inb(FLOPPY_BASE + reg_dir);
+ assert_bit_set(dir, DSKCHG);
+ dir = inb(FLOPPY_BASE + reg_dir);
+ assert_bit_set(dir, DSKCHG);
+
+ send_step_pulse();
+ dir = inb(FLOPPY_BASE + reg_dir);
+ assert_bit_set(dir, DSKCHG);
+ dir = inb(FLOPPY_BASE + reg_dir);
+ assert_bit_set(dir, DSKCHG);
}
int main(int argc, char **argv)
@@ -177,12 +208,12 @@ int main(int argc, char **argv)
/* Run the tests */
g_test_init(&argc, &argv, NULL);
- cmdline = g_strdup_printf("-vnc none "
- "-drive file=%s,if=floppy,cache=writeback ",
- test_image);
+ cmdline = g_strdup_printf("-vnc none ");
qtest_start(cmdline);
qtest_irq_intercept_in(global_qtest, "ioapic");
+ qtest_add_func("/fdc/cmos", test_cmos);
+ qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
qtest_add_func("/fdc/media_change", test_media_change);
ret = g_test_run();