[PATCH v2 13/15] tests/qtest: Delete previous boot file

Akihiko Odaki posted 15 patches 5 months ago
Maintainers: Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, John Snow <jsnow@redhat.com>, BALATON Zoltan <balaton@eik.bme.hu>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Alexey Kardashevskiy <aik@ozlabs.ru>, David Gibson <david@gibson.dropbear.id.au>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Paolo Bonzini <pbonzini@redhat.com>, David Hildenbrand <david@redhat.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH v2 13/15] tests/qtest: Delete previous boot file
Posted by Akihiko Odaki 5 months ago
A test run may create boot files several times. Delete the previous boot
file before creating a new one.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 tests/qtest/migration-test.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index b7e3406471a6..5c0d669b6df3 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -129,12 +129,23 @@ static char *bootpath;
 #include "tests/migration/aarch64/a-b-kernel.h"
 #include "tests/migration/s390x/a-b-bios.h"
 
+static void bootfile_delete(void)
+{
+    unlink(bootpath);
+    g_free(bootpath);
+    bootpath = NULL;
+}
+
 static void bootfile_create(char *dir, bool suspend_me)
 {
     const char *arch = qtest_get_arch();
     unsigned char *content;
     size_t len;
 
+    if (bootpath) {
+        bootfile_delete();
+    }
+
     bootpath = g_strdup_printf("%s/bootsect", dir);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         /* the assembled x86 boot sector should be exactly one sector large */
@@ -164,13 +175,6 @@ static void bootfile_create(char *dir, bool suspend_me)
     fclose(bootfile);
 }
 
-static void bootfile_delete(void)
-{
-    unlink(bootpath);
-    g_free(bootpath);
-    bootpath = NULL;
-}
-
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's

-- 
2.45.2
Re: [PATCH v2 13/15] tests/qtest: Delete previous boot file
Posted by Thomas Huth 4 months, 3 weeks ago
On 27/06/2024 15.37, Akihiko Odaki wrote:
> A test run may create boot files several times. Delete the previous boot
> file before creating a new one.
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
>   tests/qtest/migration-test.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index b7e3406471a6..5c0d669b6df3 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -129,12 +129,23 @@ static char *bootpath;
>   #include "tests/migration/aarch64/a-b-kernel.h"
>   #include "tests/migration/s390x/a-b-bios.h"
>   
> +static void bootfile_delete(void)
> +{
> +    unlink(bootpath);
> +    g_free(bootpath);
> +    bootpath = NULL;
> +}
> +
>   static void bootfile_create(char *dir, bool suspend_me)
>   {
>       const char *arch = qtest_get_arch();
>       unsigned char *content;
>       size_t len;
>   
> +    if (bootpath) {
> +        bootfile_delete();
> +    }
> +
>       bootpath = g_strdup_printf("%s/bootsect", dir);
>       if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
>           /* the assembled x86 boot sector should be exactly one sector large */
> @@ -164,13 +175,6 @@ static void bootfile_create(char *dir, bool suspend_me)
>       fclose(bootfile);
>   }
>   
> -static void bootfile_delete(void)
> -{
> -    unlink(bootpath);
> -    g_free(bootpath);
> -    bootpath = NULL;
> -}
> -
>   /*
>    * Wait for some output in the serial output file,
>    * we get an 'A' followed by an endless string of 'B's
> 

I think the better fix would be to call bootfile_create() only once from 
main() since we don't have to create the bootfile multiple times, do we?

  Thomas
Re: [PATCH v2 13/15] tests/qtest: Delete previous boot file
Posted by Akihiko Odaki 4 months, 3 weeks ago
On 2024/07/02 16:31, Thomas Huth wrote:
> On 27/06/2024 15.37, Akihiko Odaki wrote:
>> A test run may create boot files several times. Delete the previous boot
>> file before creating a new one.
>>
>> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>> ---
>>   tests/qtest/migration-test.c | 18 +++++++++++-------
>>   1 file changed, 11 insertions(+), 7 deletions(-)
>>
>> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> index b7e3406471a6..5c0d669b6df3 100644
>> --- a/tests/qtest/migration-test.c
>> +++ b/tests/qtest/migration-test.c
>> @@ -129,12 +129,23 @@ static char *bootpath;
>>   #include "tests/migration/aarch64/a-b-kernel.h"
>>   #include "tests/migration/s390x/a-b-bios.h"
>> +static void bootfile_delete(void)
>> +{
>> +    unlink(bootpath);
>> +    g_free(bootpath);
>> +    bootpath = NULL;
>> +}
>> +
>>   static void bootfile_create(char *dir, bool suspend_me)
>>   {
>>       const char *arch = qtest_get_arch();
>>       unsigned char *content;
>>       size_t len;
>> +    if (bootpath) {
>> +        bootfile_delete();
>> +    }
>> +
>>       bootpath = g_strdup_printf("%s/bootsect", dir);
>>       if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
>>           /* the assembled x86 boot sector should be exactly one 
>> sector large */
>> @@ -164,13 +175,6 @@ static void bootfile_create(char *dir, bool 
>> suspend_me)
>>       fclose(bootfile);
>>   }
>> -static void bootfile_delete(void)
>> -{
>> -    unlink(bootpath);
>> -    g_free(bootpath);
>> -    bootpath = NULL;
>> -}
>> -
>>   /*
>>    * Wait for some output in the serial output file,
>>    * we get an 'A' followed by an endless string of 'B's
>>
> 
> I think the better fix would be to call bootfile_create() only once from 
> main() since we don't have to create the bootfile multiple times, do we?

The suspend_me parameter depends on test cases so probably we actually 
need to recreate in such cases.

Regards,
Akihiko Odaki