Skip to contentSkip to conversation

Improvements for the boot-sector tester

PATCH In review Thomas Huth 5 participants 8 messages Oct 11, 2016 – Oct 14, 2016

lore
Share & tools
lore
#0 lore raw

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
#3 lore raw

PATCH 2/3 tests/boot-sector: Use mkstemp() to create a unique file name

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_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
index 6ea2b6d..812f830 100644
@@ -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
index 0168fd0..8399314 100644
@@ -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
index f64b477..35d61c7 100644
@@ -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
index 5d3ddbe..34282d3 100644
@@ -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
#1 lore raw

PATCH 1/3 tests/boot-sector: Use minimum length for the Forth boot script

In reply to 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.

---
 tests/boot-sector.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/boot-sector.c +3 -3
index e3193c0..0168fd0 100644
@@ -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
#5 lore raw

PATCH 3/3 tests/boot-sector: Increase time-out to 90 seconds

In reply to Thomas Huth

Since 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
index 8399314..e3880f4 100644
@@ -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
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script

In reply to Thomas Huth

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.

---
 tests/boot-sector.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/boot-sector.c +0 -0
index e3193c0..0168fd0 100644
@@ -72,6 +72,7 @@ static uint8_t boot_sector[0x7e000] = {

The size of 0x7e000...

Quoted 8 lines
tests/boot-sector.c +1 -0
 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));

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 -0
                 LOW(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
Reviewed-by on the v1 series
#6 lore raw
In reply to Thomas Huth
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: 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
#7 lore raw
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.

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: 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 · 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
Tested-by on v1 2/3
#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name

In reply to Thomas Huth
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_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.

Quoted 2 lines