tests/qtest/ahci: cover the sector count of INITIALIZE DEVICE PARAMETERS
The sector count register of a legacy port is eight bits wide, so ide-test can only reach the lower end of the range the command has to refuse. A register FIS carries a 16 bit count, which leaves AHCI as the only way to ask for a translation of 256 sectors per logical track or more. Ask for 0, 256 and 65535 sectors and expect each to be aborted, then ask for 32 and expect it to be accepted, so that the check cannot pass by refusing everything. 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 15:35 UTC
d6960ecdded35b2d4ef8b23763d19038b2d190b6
1 file changed
+40
tests/qtest/ahci-test.c
+40
@@ -905,6 +905,30 @@ static void ahci_test_flush(AHCIQState *ahci)
905
ahci_test_nondata(ahci, CMD_FLUSH_CACHE);
906
}
907
908
+static void ahci_test_specify(AHCIQState *ahci, uint16_t sectors,
909
+ bool supported)
910
+{
911
+ AHCICommand *cmd;
912
+ uint8_t port;
913
+
914
+ port = ahci_port_select(ahci);
915
+ ahci_port_clear(ahci, port);
916
+
917
+ cmd = ahci_command_create(CMD_INIT_DP);
918
+ ahci_command_set_count(cmd, sectors);
919
+ if (!supported) {
920
+ ahci_command_expect_error(cmd, ATA_ERR_ABRT);
921
+ }
922
+ ahci_command_commit(ahci, cmd, port);
923
+ ahci_command_issue(ahci, cmd);
924
+ if (!supported) {
925
+ ASSERT_BIT_SET(ahci_px_rreg(ahci, port, AHCI_PX_TFD),
926
+ AHCI_PX_TFD_STS_ERR);
927
+ }
928
+ ahci_command_verify(ahci, cmd);
929
+ ahci_command_free(cmd);
930
+}
931
+
932
static void ahci_test_max(AHCIQState *ahci)
933
{
934
RegD2HFIS *d2h = g_malloc0(0x20);
@@ -1012,6 +1036,21 @@ static void test_identify(void)
1036
ahci_shutdown(ahci);
1037
}
1038
1039
+static void test_specify(void)
1040
+{
1041
+ AHCIQState *ahci;
1042
+
1043
+ ahci = ahci_boot_and_enable(NULL);
1044
+
1045
+ /* A register FIS carries 16 bits of count, the legacy ports only eight */
1046
+ ahci_test_specify(ahci, 0, false);
1047
+ ahci_test_specify(ahci, 256, false);
1048
+ ahci_test_specify(ahci, 0xffff, false);
1049
+ ahci_test_specify(ahci, 32, true);
1050
+
1051
+ ahci_shutdown(ahci);
1052
+}
1053
+
1054
/**
1055
* Fragmented DMA test: Perform a standard 4K DMA read/write
1056
* test, but make sure the physical regions are fragmented to
@@ -2220,6 +2259,7 @@ int main(int argc, char **argv)
2259
qtest_add_func("/ahci/migrate/dma/halted", test_migrate_halted_dma);
2260
2261
qtest_add_func("/ahci/max", test_max);
2262
+ qtest_add_func("/ahci/specify", test_specify);
2263
qtest_add_func("/ahci/reset/simple", test_reset);
2264
qtest_add_func("/ahci/reset/pending_callback", test_reset_pending_callback);
2265