[SeaBIOS] Re: [PATCH v7 8/8] hd-geo-test: Add tests for lchs override
On 9/26/19 6:00 AM, Philippe Mathieu-Daudé wrote: > On 9/25/19 1:06 PM, Sam Eiderman wrote: >> From: Sam Eiderman >> >> Add QTest tests to check the logical geometry override option. >> >> The tests in hd-geo-test are out of date - they only test IDE and do not >> test interesting MBRs. >> >> I added a few helper functions which will make adding more tests easier. >> >> QTest's fw_cfg helper functions support only legacy fw_cfg, so I had to >> read the new fw_cfg layout on my own. >> >> Creating qcow2 disks with specific size and MBR layout is currently >> unused - we only use a default empty MBR. >> >> Reviewed-by: Karl Heubaum >> Reviewed-by: Arbel Moshe >> Signed-off-by: Sam Eiderman >> --- >> tests/Makefile.include | 2 +- >> tests/hd-geo-test.c| 589 + >> 2 files changed, 590 insertions(+), 1 deletion(-) >> >> diff --git a/tests/Makefile.include b/tests/Makefile.include >> index 479664f899..a5b92fea6a 100644 >> --- a/tests/Makefile.include >> +++ b/tests/Makefile.include >> @@ -780,7 +780,7 @@ tests/ide-test$(EXESUF): tests/ide-test.o >> $(libqos-pc-obj-y) >> tests/ahci-test$(EXESUF): tests/ahci-test.o $(libqos-pc-obj-y) >> qemu-img$(EXESUF) >> tests/ipmi-kcs-test$(EXESUF): tests/ipmi-kcs-test.o >> tests/ipmi-bt-test$(EXESUF): tests/ipmi-bt-test.o >> -tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o >> +tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o $(libqos-obj-y) >> tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y) >> tests/boot-serial-test$(EXESUF): tests/boot-serial-test.o $(libqos-obj-y) >> tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ >> diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c >> index 62eb624726..458de99c31 100644 >> --- a/tests/hd-geo-test.c >> +++ b/tests/hd-geo-test.c >> @@ -17,7 +17,12 @@ >> >> #include "qemu/osdep.h" >> #include "qemu-common.h" >> +#include "qemu/bswap.h" >> +#include "qapi/qmp/qlist.h" >> #include "libqtest.h" >> +#include "libqos/fw_cfg.h" >> +#include "libqos/libqos.h" >> +#include "standard-headers/linux/qemu_fw_cfg.h" >> >> #define ARGV_SIZE 256 >> >> @@ -388,6 +393,575 @@ static void test_ide_drive_cd_0(void) >> qtest_quit(qts); >> } >> >> +typedef struct { >> +bool active; >> +uint32_t head; >> +uint32_t sector; >> +uint32_t cyl; >> +uint32_t end_head; >> +uint32_t end_sector; >> +uint32_t end_cyl; >> +uint32_t start_sect; >> +uint32_t nr_sects; >> +} MBRpartitions[4]; >> + >> +static MBRpartitions empty_mbr = { {false, 0, 0, 0, 0, 0, 0, 0, 0}, >> + {false, 0, 0, 0, 0, 0, 0, 0, 0}, >> + {false, 0, 0, 0, 0, 0, 0, 0, 0}, >> + {false, 0, 0, 0, 0, 0, 0, 0, 0} }; >> + >> +static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors) >> +{ >> +const char *template = "/tmp/qtest.XX"; >> +char *raw_path = strdup(template); >> +char *qcow2_path = strdup(template); >> +char cmd[100 + 2 * PATH_MAX]; >> +uint8_t buf[512]; >> +int i, ret, fd, offset; >> +uint64_t qcow2_size = sectors * 512; >> +uint8_t status, parttype, head, sector, cyl; >> +char *qemu_img_path; >> +char *qemu_img_abs_path; >> + >> +offset = 0xbe; >> + >> +for (i = 0; i < 4; i++) { >> +status = mbr[i].active ? 0x80 : 0x00; >> +g_assert(mbr[i].head < 256); >> +g_assert(mbr[i].sector < 64); >> +g_assert(mbr[i].cyl < 1024); >> +head = mbr[i].head; >> +sector = mbr[i].sector + ((mbr[i].cyl & 0x300) >> 2); >> +cyl = mbr[i].cyl & 0xff; >> + >> +buf[offset + 0x0] = status; >> +buf[offset + 0x1] = head; >> +buf[offset + 0x2] = sector; >> +buf[offset + 0x3] = cyl; >> + >> +parttype = 0; >> +g_assert(mbr[i].end_head < 256); >> +g_assert(mbr[i].end_sector < 64); >> +g_assert(mbr[i].end_cyl < 1024); >> +head = mbr[i].end_head; >> +sector = mbr[i].end_sector + ((mbr[i].end_cyl & 0x300) >> 2); >> +cyl = mbr[i].end_cyl & 0xff; >> + >> +buf[offset + 0x4] = parttype; >> +buf[offset + 0x5] = head; >> +buf[offset + 0x6] = sector; >> +buf[offset + 0x7] = cyl; >> + >> +(*(uint32_t *)&buf[offset + 0x8]) = cpu_to_le32(mbr[i].start_sect); >> +(*(uint32_t *)&buf[offset + 0xc]) = cpu_to_le32(mbr[i].nr_sects); >> + >> +offset += 0x10; >> +} >> + >> +fd = mkstemp(raw_path); >> +g_assert(fd); >> +close(fd); >> + >> +fd = open(raw_path, O_WRONLY); >> +g_assert(fd >= 0); >> +ret = write(fd, buf, sizeof(buf)); >> +g_assert(ret == sizeof(buf)); >> +close(fd); >> + >> +fd = mkstemp(qcow2_path); >> +g_assert(fd); >> +close(fd); >> + >> +qemu_img_path = getenv("QTEST_QEMU_IMG"); >> +g_assert(qemu_img_path); >> +qemu_img_abs_path = realpath(qemu_img_path, NULL); >> +
[SeaBIOS] Re: [PATCH v7 8/8] hd-geo-test: Add tests for lchs override
On 9/25/19 1:06 PM, Sam Eiderman wrote: > From: Sam Eiderman > > Add QTest tests to check the logical geometry override option. > > The tests in hd-geo-test are out of date - they only test IDE and do not > test interesting MBRs. > > I added a few helper functions which will make adding more tests easier. > > QTest's fw_cfg helper functions support only legacy fw_cfg, so I had to > read the new fw_cfg layout on my own. > > Creating qcow2 disks with specific size and MBR layout is currently > unused - we only use a default empty MBR. > > Reviewed-by: Karl Heubaum > Reviewed-by: Arbel Moshe > Signed-off-by: Sam Eiderman > --- > tests/Makefile.include | 2 +- > tests/hd-geo-test.c| 589 + > 2 files changed, 590 insertions(+), 1 deletion(-) > > diff --git a/tests/Makefile.include b/tests/Makefile.include > index 479664f899..a5b92fea6a 100644 > --- a/tests/Makefile.include > +++ b/tests/Makefile.include > @@ -780,7 +780,7 @@ tests/ide-test$(EXESUF): tests/ide-test.o > $(libqos-pc-obj-y) > tests/ahci-test$(EXESUF): tests/ahci-test.o $(libqos-pc-obj-y) > qemu-img$(EXESUF) > tests/ipmi-kcs-test$(EXESUF): tests/ipmi-kcs-test.o > tests/ipmi-bt-test$(EXESUF): tests/ipmi-bt-test.o > -tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o > +tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o $(libqos-obj-y) > tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y) > tests/boot-serial-test$(EXESUF): tests/boot-serial-test.o $(libqos-obj-y) > tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ > diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c > index 62eb624726..458de99c31 100644 > --- a/tests/hd-geo-test.c > +++ b/tests/hd-geo-test.c > @@ -17,7 +17,12 @@ > > #include "qemu/osdep.h" > #include "qemu-common.h" > +#include "qemu/bswap.h" > +#include "qapi/qmp/qlist.h" > #include "libqtest.h" > +#include "libqos/fw_cfg.h" > +#include "libqos/libqos.h" > +#include "standard-headers/linux/qemu_fw_cfg.h" > > #define ARGV_SIZE 256 > > @@ -388,6 +393,575 @@ static void test_ide_drive_cd_0(void) > qtest_quit(qts); > } > > +typedef struct { > +bool active; > +uint32_t head; > +uint32_t sector; > +uint32_t cyl; > +uint32_t end_head; > +uint32_t end_sector; > +uint32_t end_cyl; > +uint32_t start_sect; > +uint32_t nr_sects; > +} MBRpartitions[4]; > + > +static MBRpartitions empty_mbr = { {false, 0, 0, 0, 0, 0, 0, 0, 0}, > + {false, 0, 0, 0, 0, 0, 0, 0, 0}, > + {false, 0, 0, 0, 0, 0, 0, 0, 0}, > + {false, 0, 0, 0, 0, 0, 0, 0, 0} }; > + > +static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors) > +{ > +const char *template = "/tmp/qtest.XX"; > +char *raw_path = strdup(template); > +char *qcow2_path = strdup(template); > +char cmd[100 + 2 * PATH_MAX]; > +uint8_t buf[512]; > +int i, ret, fd, offset; > +uint64_t qcow2_size = sectors * 512; > +uint8_t status, parttype, head, sector, cyl; > +char *qemu_img_path; > +char *qemu_img_abs_path; > + > +offset = 0xbe; > + > +for (i = 0; i < 4; i++) { > +status = mbr[i].active ? 0x80 : 0x00; > +g_assert(mbr[i].head < 256); > +g_assert(mbr[i].sector < 64); > +g_assert(mbr[i].cyl < 1024); > +head = mbr[i].head; > +sector = mbr[i].sector + ((mbr[i].cyl & 0x300) >> 2); > +cyl = mbr[i].cyl & 0xff; > + > +buf[offset + 0x0] = status; > +buf[offset + 0x1] = head; > +buf[offset + 0x2] = sector; > +buf[offset + 0x3] = cyl; > + > +parttype = 0; > +g_assert(mbr[i].end_head < 256); > +g_assert(mbr[i].end_sector < 64); > +g_assert(mbr[i].end_cyl < 1024); > +head = mbr[i].end_head; > +sector = mbr[i].end_sector + ((mbr[i].end_cyl & 0x300) >> 2); > +cyl = mbr[i].end_cyl & 0xff; > + > +buf[offset + 0x4] = parttype; > +buf[offset + 0x5] = head; > +buf[offset + 0x6] = sector; > +buf[offset + 0x7] = cyl; > + > +(*(uint32_t *)&buf[offset + 0x8]) = cpu_to_le32(mbr[i].start_sect); > +(*(uint32_t *)&buf[offset + 0xc]) = cpu_to_le32(mbr[i].nr_sects); > + > +offset += 0x10; > +} > + > +fd = mkstemp(raw_path); > +g_assert(fd); > +close(fd); > + > +fd = open(raw_path, O_WRONLY); > +g_assert(fd >= 0); > +ret = write(fd, buf, sizeof(buf)); > +g_assert(ret == sizeof(buf)); > +close(fd); > + > +fd = mkstemp(qcow2_path); > +g_assert(fd); > +close(fd); > + > +qemu_img_path = getenv("QTEST_QEMU_IMG"); > +g_assert(qemu_img_path); > +qemu_img_abs_path = realpath(qemu_img_path, NULL); > +g_assert(qemu_img_abs_path); > + > +ret = snprintf(cmd, sizeof(cmd), > + "%s convert -f raw -O qcow2 %s %s > /dev/null", > + qemu_img_abs_path, > +