Improvements for the boot-sector tester
cover Improvements for the boot-sector tester
Here are two patches that try to improve the situation with the slow pxe-test on ppc64 a little bit, and one patch that fixes a potential race condition between tests that run in parallel by using a random filename instead of an invariant one.
Thomas Huth (3):
tests/boot-sector: Use minimum length for the Forth boot script tests/boot-sector: Use mkstemp() to create a unique file name tests/boot-sector: Increase time-out to 90 seconds
tests/bios-tables-test.c | 2 +- tests/boot-sector.c | 25 ++++++++++++++++--------- tests/boot-sector.h | 4 ++-- tests/pxe-test.c | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/3 tests/boot-sector: Use minimum length for the Forth boot script
The pxe-test is quite slow on ppc64 with tcg. We can speed it up a little bit by decreasing the size of the file that has to be loaded via TFTP.
--- tests/boot-sector.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/boot-sector.c +3 -3
@@ -72,6 +72,7 @@ static uint8_t boot_sector[0x7e000] = {int boot_sector_init (const char *fname) {FILE *f =fopen (fname,"w" ); +size_t len =sizeof boot_sector;if (!f) {fprintf (stderr,"Couldn't open \"%s\": %s" , fname,strerror (errno));
@@ -80,13 +81,12 @@ int boot_sector_init(const char *fname)/* For Open Firmware based system, we can use a Forth script instead */ if (strcmp (qtest_get_arch (),"ppc64" ) ==0 ) { -memset (boot_sector,' ' ,sizeof boot_sector); -sprintf ((char *)boot_sector,"\\ Bootscript\n%x %x c! %x %x c!\n" , + len =sprintf ((char *)boot_sector,"\\ Bootscript\n%x %x c! %x %x c!\n" ,LOW (SIGNATURE ),BOOT_SECTOR_ADDRESS +SIGNATURE_OFFSET ,HIGH (SIGNATURE ),BOOT_SECTOR_ADDRESS +SIGNATURE_OFFSET +1 ); } -fwrite (boot_sector,1 ,sizeof boot_sector, f); +fwrite (boot_sector,1 , len, f);fclose (f);return 0 ; }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script
tests/boot-sector.c static uint8_t boot_sector[0x7e000] = {
Quoted 14 lines · Thomas Huth
The pxe-test is quite slow on ppc64 with tcg. We can speed it up a little bit by decreasing the size of the file that has to be loaded via TFTP.
Signed-off-by Thomas Huth <[email protected]>--- tests/boot-sector.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tests/boot-sector.c +0
-0@@ -72,6 +72,7 @@ static uint8_t boot_sector[0x7e000] = {
The size of 0x7e000...
Quoted 8 lines
tests/boot-sector.c +1
-0int boot_sector_init (const char *fname) {FILE *f =fopen (fname,"w" ); +size_t len =sizeof boot_sector;if (!f) {fprintf (stderr,"Couldn't open \"%s\": %s" , fname,strerror (errno));
tests/boot-sector.c int boot_sector_init(const char *fname) · line 84
Quoted 6 lines
tests/boot-sector.c +1
-2@@ -80,13 +81,12 @@ int boot_sector_init(const char *fname)/* For Open Firmware based system, we can use a Forth script instead */ if (strcmp (qtest_get_arch (),"ppc64" ) ==0 ) { -memset (boot_sector,' ' ,sizeof boot_sector); - sprintf((char *)boot_sector, "\\ Bootscript\n%x %x c! %x %x c!\n", + len = sprintf((char *)boot_sector, "\\ Bootscript\n%x %x c! %x %x c!\n",
...is enough to ensure the sprintf() doesn't overflow. Still, I think an snprintf() would be a bit nicer on maintainers to not have to worry about whether overflow is even possible.
tests/boot-sector.c int boot_sector_init(const char *fname) · line 86
Quoted 2 lines
tests/boot-sector.c +0
-0LOW (SIGNATURE ),BOOT_SECTOR_ADDRESS +SIGNATURE_OFFSET , HIGH(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
Worth reindenting this to match the line above?
tests/boot-sector.c int boot_sector_init(const char *fname) · line 89
Quoted 4 lines
tests/boot-sector.c +1
-1} -fwrite (boot_sector,1 ,sizeof boot_sector, f); +fwrite (boot_sector,1 , len, f);
At any rate, the change makes sense, and I can't find anything technically wrong with it, so feel free to add:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/3 tests/boot-sector: Use mkstemp() to create a unique file name
In reply to Thomas HuthThe pxe-test is run for three different targets now (x86_64, i386 and ppc64), and the bios-tables-test is run for two targets (x86_64 and i386). But each of the tests is using an invariant name for the disk image with the boot sector code - so if the tests are running in parallel, there is a race condition that they destroy the disk image of a parallel test program. Let's use mkstemp() to create unique temporary files here instead - and since mkstemp() is returning an integer file descriptor instead of a FILE pointer, we also switch the fwrite() and fclose() to write() and close() instead.
--- tests/bios-tables-test.c | 2 +- tests/boot-sector.c | 17 ++++++++++++----- tests/boot-sector.h | 4 ++-- tests/pxe-test.c | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-)
tests/bios-tables-test.c +1 -1
@@ -112,7 +112,7 @@ typedef struct { g_assert_cmpstr(ACPI_ASSERT_CMP_str, ==, expected); \ }while (0 ) -static const char *disk = "tests/acpi-test-disk.raw"; +static char disk[] = "tests/acpi-test-disk-XXXXXX";static const char *data_dir ="tests/acpi-test-data" ;#ifdef CONFIG_IASL static const char *iasl =stringify (CONFIG_IASL );
tests/boot-sector.c +12 -5
@@ -69,12 +69,13 @@ static uint8_t boot_sector[0x7e000] = { };/* Create boot disk file. */ -int boot_sector_init (const char *fname) +int boot_sector_init (char *fname) { -FILE *f =fopen (fname,"w" ); +int fd, ret;size_t len =sizeof boot_sector; -if (!f) { + fd =mkstemp (fname); +if (fd <0 ) {fprintf (stderr,"Couldn't open \"%s\": %s" , fname,strerror (errno));return 1 ; }
@@ -86,8 +87,14 @@ int boot_sector_init(const char *fname) HIGH(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1); } -fwrite (boot_sector,1 , len, f); -fclose (f); + ret =write (fd, boot_sector, len); +close (fd); + +if (ret != len) { +fprintf (stderr,"Could not write \"%s\"" , fname); +return 1 ; + } +return 0 ; }
tests/boot-sector.h +2 -2
@@ -14,8 +14,8 @@#ifndef TEST_BOOT_SECTOR_H #define TEST_BOOT_SECTOR_H -/* Create boot disk file. */ -int boot_sector_init (const char *fname); +/* Create boot disk file. fname must be a suitable string for mkstemp() */ +int boot_sector_init (char *fname);/* Loop until signature in memory is OK. */ void boot_sector_test (void );
tests/pxe-test.c +1 -1
@@ -19,7 +19,7 @@#define NETNAME "net0" -static const char *disk ="tests/pxe-test-disk.raw" ; +static char disk[] ="tests/pxe-test-disk-XXXXXX" ;static void test_pxe_one (const char *params,bool ipv6) {
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name
Quoted 10 lines · Thomas Huth
The pxe-test is run for three different targets now (
x86_64, i386 and ppc64), and the bios-tables-test is run for two targets (x86_64and i386). But each of the tests is using an invariant name for the disk image with the boot sector code - so if the tests are running in parallel, there is a race condition that they destroy the disk image of a parallel test program. Let's usemkstemp()to create unique temporary files here instead - and sincemkstemp()is returning an integer file descriptor instead of a FILE pointer, we also switch thefwrite()andfclose()towrite()andclose()instead.
Quoted 2 lines
Reported-by Sascha Silbe <[email protected]>Signed-off-by Thomas Huth <[email protected]>
PATCH 3/3 tests/boot-sector: Increase time-out to 90 seconds
In reply to Thomas HuthSince the PXE tester runs rather slow on ppc64 with tcg, there is a chance that we hit the 60 seconds timeout on machines that have a heavy CPU load. So let's increase the timeout to ease the situation.
--- tests/boot-sector.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/boot-sector.c +2 -2
@@ -106,9 +106,9 @@ void boot_sector_test(void)uint16_t signature;int i; -/* Wait at most 1 minute */ +/* Wait at most 90 seconds */ #define TEST_DELAY (1 * G_USEC_PER_SEC / 10) -#define TEST_CYCLES MAX((60 * G_USEC_PER_SEC / TEST_DELAY), 1) +#define TEST_CYCLES MAX((90 * G_USEC_PER_SEC / TEST_DELAY), 1)/* Poll until code has run and modified memory. Once it has we know BIOS * initialization is done. TODO: check that IP reached the halt
Signature · 1 line
1.8.3.1
Quoted 4 lines · Thomas Huth
Here are two patches that try to improve the situation with the slow pxe-test on ppc64 a little bit, and one patch that fixes a potential race condition between tests that run in parallel by using a random filename instead of an invariant one.
You can go ahead and merge as I'm offline tomorrow.
Quoted 13 lines
Thomas Huth (3):
tests/boot-sector: Use minimum length for the Forth boot script tests/boot-sector: Usemkstemp()to create a unique file name tests/boot-sector: Increase time-out to 90 secondstests/bios-tables-test.c | 2 +- tests/boot-sector.c | 25 ++++++++++++++++--------- tests/boot-sector.h | 4 ++-- tests/pxe-test.c | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-)Signature · 1 line
1.8.3.1
Quoted 10 lines · Michael S. Tsirkin
Quoted 4 lines · Thomas Huth
Here are two patches that try to improve the situation with the slow pxe-test on ppc64 a little bit, and one patch that fixes a potential race condition between tests that run in parallel by using a random filename instead of an invariant one.
Reviewed-by Michael S. Tsirkin <[email protected]>You can go ahead and merge as I'm offline tomorrow.
Done.
Quoted 13 lines
Quoted 12 lines
Thomas Huth (3):
tests/boot-sector: Use minimum length for the Forth boot script tests/boot-sector: Usemkstemp()to create a unique file name tests/boot-sector: Increase time-out to 90 secondstests/bios-tables-test.c | 2 +- tests/boot-sector.c | 25 ++++++++++++++++--------- tests/boot-sector.h | 4 ++-- tests/pxe-test.c | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson