Daniel P. Berrangé <[email protected]> writes:
> On Mon, Aug 24, 2026 at 04:24:53PM +0100, Alex Bennée wrote:
>> Add a test case for #3800 where we check that the last sector is
>> properly bounded by the physical media that is inserted.
>>
>> Link: https://gitlab.com/qemu-project/qemu/-/issues/3800
>> AI-used-for: initial draft of test
>
> Wasn't the change in AI policy still pending a new patch
> proposal from Paolo ?
Yes it is, however given I was rushed and am not super familiar with the
fdc qtest code I took a shortcut to get something posted. FWIW it's mostly
as the original prompt created apart from:
- I added the TEST_IMAGE_xxx changes
- I suggested fake_lastsect/fake_getsect naming over the original suggestion
- I asked it to expand the comments on using RESTORE/SAVE after
consulting the datasheet myself when reviewing the code
Think of it as a road test for the proposal...
>
<snip>
>>
>> -#define TEST_IMAGE_SIZE 1440 * 1024
>> +#define TEST_IMAGE_1440KB (1440 * 1024)
>> +#define TEST_IMAGE_720KB (720 * 1024)
>>
<snip>
>>
>> +/*
>> + * Query cur_drv->last_sect using the SAVE command (CMD_SAVE, 0x2e).
>> + * Byte 8 of the 15 result bytes returned by CMD_SAVE holds last_sect.
>> + */
>> +static uint8_t get_lastsect(void)
>> +{
>> + uint8_t res[15];
>> + int i;
>> +
>> + floppy_send(CMD_SAVE);
>> + for (i = 0; i < 15; i++) {
>> + res[i] = floppy_recv();
>> + }
>> + return res[8];
>> +}
>> +
>> +/*
>> + * Attempt to set cur_drv->last_sect directly using the RESTORE command
>> + * (CMD_RESTORE, 0x4e).
>> + * While the 82078 datasheet describes RESTORE for restoring a previously
>> + * saved state, a guest can issue raw RESTORE commands with arbitrary
>> + * parameters without having issued SAVE. Parameter byte 9 is used by the
>> + * controller to restore cur_drv->last_sect.
>> + */
>> +static void fake_lastsect(uint8_t last_sect)
>> +{
>> + floppy_send(CMD_RESTORE);
>> + floppy_send(0); /* fifo[1] */
>> + floppy_send(0); /* fifo[2] */
>> + floppy_send(0); /* fifo[3]: drv0 track */
>> + floppy_send(0); /* fifo[4]: drv1 track */
>> + floppy_send(0); /* fifo[5]: drv2 track */
>> + floppy_send(0); /* fifo[6]: drv3 track */
>> + floppy_send(0); /* fifo[7]: timer0 */
>> + floppy_send(0); /* fifo[8]: timer1 */
>> + floppy_send(last_sect); /* fifo[9]: last_sect */
>> + floppy_send(0); /* fifo[10]: lock/perpendicular */
>> + floppy_send(0); /* fifo[11]: config */
>> + floppy_send(0); /* fifo[12]: precomp_trk */
>> + floppy_send(0); /* fifo[13]: pwrd */
>> + floppy_send(0); /* fifo[14] */
>> + floppy_send(0); /* fifo[15] */
>> + floppy_send(0); /* fifo[16] */
>> + floppy_send(0); /* fifo[17] */
>> +}
>> +
<snip>
>>
>> - /* Create a temporary raw image */
>> + /* Create temporary raw images */
>> fd = g_file_open_tmp("qtest.XXXXXX", &test_image, NULL);
>> g_assert(fd >= 0);
>> - ret = ftruncate(fd, TEST_IMAGE_SIZE);
>> + ret = ftruncate(fd, TEST_IMAGE_1440KB);
>> + g_assert(ret == 0);
>> + close(fd);
>> +
>> + fd = g_file_open_tmp("qtest720.XXXXXX", &test_image_720k, NULL);
>> + g_assert(fd >= 0);
>> + ret = ftruncate(fd, TEST_IMAGE_720KB);
>> g_assert(ret == 0);
>> close(fd);
<snip>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro