@samitouri / QOSamiQemu / commits / d1634ae78d

tests/qtest/ide-test: cover the CHS translation across resets

A translation the guest selected has to survive a software reset and not a hardware one, and the two arrive at the same ide_reset(), so a fix for either direction can break the other. Select a translation, put the drive through a software reset and then through a machine reset, and name the sector each translation picks along the way. The marker read says which translation the device is addressing the disk with, while IDENTIFY DEVICE words 55 and 56 say which one it reports. The machine reset leaves the PCI command register cleared, so the device has to be enabled again before the ports answer. Cc: John Snow <jsnow@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Cc: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Denis V. Lunev <den@openvz.org>

Denis V. Lunev committed Aug 14, 2026 at 18:20 UTC d1634ae78dd4910a37f11c07d313adb7e1bf5c97
1 file changed +46
tests/qtest/ide-test.c
+46
@@ -1639,6 +1639,51 @@ static void test_specify_identify_default(void)
1639 ide_test_quit(qts);
1640 }
1641
1642 +/* A hardware reset reverts the translation (ATA-5 9.1), SRST does not (9.2) */
1643 +static void test_specify_reset(void)
1644 +{
1645 + QTestState *qts;
1646 + QPCIDevice *dev;
1647 + QPCIBar bmdma_bar, ide_bar, ide_bar2;
1648 + uint16_t buf[256];
1649 + char marker[9];
1650 +
1651 + qts = ide_test_start(
1652 + "-blockdev driver=file,node-name=hda,filename=%s "
1653 + "-device ide-hd,drive=hda,bus=ide.0,unit=0 ",
1654 + tmp_path[0]);
1655 + dev = get_pci_device(qts, &bmdma_bar, &ide_bar);
1656 + ide_bar2 = qpci_legacy_iomap(dev, IDE_BASE2);
1657 +
1658 + ide_prepare_markers(qts, dev, ide_bar);
1659 + ide_set_translation(dev, ide_bar, 8, 32);
1660 + ide_read_chs_marker(qts, dev, ide_bar, 0, 1, 1, marker);
1661 + g_assert_cmpstr(marker, ==, CHS_MARKER_CUSTOM);
1662 +
1663 + qpci_io_writeb(dev, ide_bar2, 0, IDE_CTRL_RESET);
1664 + qpci_io_writeb(dev, ide_bar2, 0, 0);
1665 + ide_wait_clear(qts, BSY);
1666 +
1667 + ide_identify_words(dev, ide_bar, buf);
1668 + g_assert_cmpint(buf[55], ==, 8);
1669 + g_assert_cmpint(buf[56], ==, 32);
1670 + ide_read_chs_marker(qts, dev, ide_bar, 0, 1, 1, marker);
1671 + g_assert_cmpstr(marker, ==, CHS_MARKER_CUSTOM);
1672 +
1673 + qtest_qmp_assert_success(qts, "{ 'execute': 'system_reset' }");
1674 + qtest_qmp_eventwait(qts, "RESET");
1675 + qpci_device_enable(dev);
1676 +
1677 + ide_identify_words(dev, ide_bar, buf);
1678 + g_assert_cmpint(buf[55], ==, 16);
1679 + g_assert_cmpint(buf[56], ==, 63);
1680 + ide_read_chs_marker(qts, dev, ide_bar, 0, 1, 1, marker);
1681 + g_assert_cmpstr(marker, ==, CHS_MARKER_DEFAULT);
1682 +
1683 + free_pci_device(dev);
1684 + ide_test_quit(qts);
1685 +}
1686 +
1687 static void test_cdrom_pio(void)
1688 {
1689 cdrom_read_impl(1, CDROM_PIO);
@@ -1714,6 +1759,7 @@ int main(int argc, char **argv)
1759 qtest_add_func("/ide/specify/identify", test_specify_identify);
1760 qtest_add_func("/ide/specify/identify_default",
1761 test_specify_identify_default);
1762 + qtest_add_func("/ide/specify/reset", test_specify_reset);
1763 qtest_add_func("/ide/migration/chs_translation",
1764 test_migrate_chs_translation);
1765 qtest_add_func("/ide/migration/chs_snapshot", test_migrate_chs_snapshot);