All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester
@ 2016-10-11 15:19 Thomas Huth
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script Thomas Huth
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Thomas Huth @ 2016-10-11 15:19 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Paolo Bonzini
  Cc: Sascha Silbe, qemu-trivial, Michael Tsirkin, qemu-ppc,
	Victor Kaplansky, David Gibson

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(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script
  2016-10-11 15:19 [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Thomas Huth
@ 2016-10-11 15:19 ` Thomas Huth
  2016-10-11 15:58   ` Eric Blake
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name Thomas Huth
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Thomas Huth @ 2016-10-11 15:19 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Paolo Bonzini
  Cc: Sascha Silbe, qemu-trivial, Michael Tsirkin, qemu-ppc,
	Victor Kaplansky, David Gibson

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 <thuth@redhat.com>
---
 tests/boot-sector.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/boot-sector.c b/tests/boot-sector.c
index e3193c0..0168fd0 100644
--- a/tests/boot-sector.c
+++ b/tests/boot-sector.c
@@ -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;
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name
  2016-10-11 15:19 [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Thomas Huth
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script Thomas Huth
@ 2016-10-11 15:19 ` Thomas Huth
  2016-10-14  2:50   ` Fam Zheng
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 3/3] tests/boot-sector: Increase time-out to 90 seconds Thomas Huth
  2016-10-11 21:05 ` [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Michael S. Tsirkin
  3 siblings, 1 reply; 8+ messages in thread
From: Thomas Huth @ 2016-10-11 15:19 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Paolo Bonzini
  Cc: Sascha Silbe, qemu-trivial, Michael Tsirkin, qemu-ppc,
	Victor Kaplansky, David Gibson

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.

Reported-by: Sascha Silbe <x-qemu@se-silbe.de>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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(-)

diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index 6ea2b6d..812f830 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -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);
diff --git a/tests/boot-sector.c b/tests/boot-sector.c
index 0168fd0..8399314 100644
--- a/tests/boot-sector.c
+++ b/tests/boot-sector.c
@@ -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;
 }
 
diff --git a/tests/boot-sector.h b/tests/boot-sector.h
index f64b477..35d61c7 100644
--- a/tests/boot-sector.h
+++ b/tests/boot-sector.h
@@ -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);
diff --git a/tests/pxe-test.c b/tests/pxe-test.c
index 5d3ddbe..34282d3 100644
--- a/tests/pxe-test.c
+++ b/tests/pxe-test.c
@@ -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)
 {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 3/3] tests/boot-sector: Increase time-out to 90 seconds
  2016-10-11 15:19 [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Thomas Huth
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script Thomas Huth
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name Thomas Huth
@ 2016-10-11 15:19 ` Thomas Huth
  2016-10-11 21:05 ` [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Michael S. Tsirkin
  3 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2016-10-11 15:19 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Paolo Bonzini
  Cc: Sascha Silbe, qemu-trivial, Michael Tsirkin, qemu-ppc,
	Victor Kaplansky, David Gibson

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.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/boot-sector.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/boot-sector.c b/tests/boot-sector.c
index 8399314..e3880f4 100644
--- a/tests/boot-sector.c
+++ b/tests/boot-sector.c
@@ -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
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script Thomas Huth
@ 2016-10-11 15:58   ` Eric Blake
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Blake @ 2016-10-11 15:58 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Peter Maydell, Paolo Bonzini
  Cc: Victor Kaplansky, Michael Tsirkin, qemu-trivial, qemu-ppc,
	Sascha Silbe, David Gibson

[-- Attachment #1: Type: text/plain, Size: 2025 bytes --]

On 10/11/2016 10:19 AM, Thomas Huth wrote:
> 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 <thuth@redhat.com>
> ---
>  tests/boot-sector.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/boot-sector.c b/tests/boot-sector.c
> index e3193c0..0168fd0 100644
> --- a/tests/boot-sector.c
> +++ b/tests/boot-sector.c
> @@ -72,6 +72,7 @@ static uint8_t boot_sector[0x7e000] = {

The size of 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",

...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.

>                  LOW(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET,
>                  HIGH(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);

Worth reindenting this to match the line above?

>      }
>  
> -    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:
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester
  2016-10-11 15:19 [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Thomas Huth
                   ` (2 preceding siblings ...)
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 3/3] tests/boot-sector: Increase time-out to 90 seconds Thomas Huth
@ 2016-10-11 21:05 ` Michael S. Tsirkin
  2016-10-11 23:25   ` David Gibson
  3 siblings, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2016-10-11 21:05 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Peter Maydell, Paolo Bonzini, Sascha Silbe,
	qemu-trivial, qemu-ppc, Victor Kaplansky, David Gibson

On Tue, Oct 11, 2016 at 05:19:34PM +0200, Thomas Huth wrote:
> 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 <mst@redhat.com>

You can go ahead and merge as I'm offline tomorrow.

> 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(-)
> 
> -- 
> 1.8.3.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester
  2016-10-11 21:05 ` [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Michael S. Tsirkin
@ 2016-10-11 23:25   ` David Gibson
  0 siblings, 0 replies; 8+ messages in thread
From: David Gibson @ 2016-10-11 23:25 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Thomas Huth, qemu-devel, Peter Maydell, Paolo Bonzini,
	Sascha Silbe, qemu-trivial, qemu-ppc, Victor Kaplansky

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

On Wed, Oct 12, 2016 at 12:05:24AM +0300, Michael S. Tsirkin wrote:
> On Tue, Oct 11, 2016 at 05:19:34PM +0200, Thomas Huth wrote:
> > 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 <mst@redhat.com>
> 
> You can go ahead and merge as I'm offline tomorrow.

Done.

> 
> > 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(-)
> > 
> 

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name
  2016-10-11 15:19 ` [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name Thomas Huth
@ 2016-10-14  2:50   ` Fam Zheng
  0 siblings, 0 replies; 8+ messages in thread
From: Fam Zheng @ 2016-10-14  2:50 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Peter Maydell, Paolo Bonzini, Victor Kaplansky,
	Michael Tsirkin, qemu-trivial, qemu-ppc, Sascha Silbe,
	David Gibson

On Tue, 10/11 17:19, Thomas Huth wrote:
> 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.
> 
> Reported-by: Sascha Silbe <x-qemu@se-silbe.de>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Tested-by: Fam Zheng <famz@redhat.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-10-14  2:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-11 15:19 [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Thomas Huth
2016-10-11 15:19 ` [Qemu-devel] [PATCH 1/3] tests/boot-sector: Use minimum length for the Forth boot script Thomas Huth
2016-10-11 15:58   ` Eric Blake
2016-10-11 15:19 ` [Qemu-devel] [PATCH 2/3] tests/boot-sector: Use mkstemp() to create a unique file name Thomas Huth
2016-10-14  2:50   ` Fam Zheng
2016-10-11 15:19 ` [Qemu-devel] [PATCH 3/3] tests/boot-sector: Increase time-out to 90 seconds Thomas Huth
2016-10-11 21:05 ` [Qemu-devel] [PATCH 0/3] Improvements for the boot-sector tester Michael S. Tsirkin
2016-10-11 23:25   ` David Gibson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.