[PATCH RESEND v1] ktest: Fix Test Failures Due to Missing LOG_FILE Directories

Ayush Jain posted 1 patch 1 year, 3 months ago
There is a newer version of this series
tools/testing/ktest/ktest.pl | 7 +++++++
1 file changed, 7 insertions(+)
[PATCH RESEND v1] ktest: Fix Test Failures Due to Missing LOG_FILE Directories
Posted by Ayush Jain 1 year, 3 months ago
Handle missing parent directories for LOG_FILE path to prevent test
failures. If the parent directories don't exist, create them to ensure
the tests proceed successfully.

Signed-off-by: Ayush Jain <Ayush.jain3@amd.com>
---
 tools/testing/ktest/ktest.pl | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 8c8da966c641..be707cbc56a7 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -4303,6 +4303,13 @@ if (defined($opt{"LOG_FILE"})) {
     if ($opt{"CLEAR_LOG"}) {
 	unlink $opt{"LOG_FILE"};
     }
+	if (! -e $opt{"LOG_FILE"}) {
+		my ($dir) = $opt{"LOG_FILE"} =~ m|^(.*/)|;
+		if ($dir && !-d $dir) {
+			mkpath($dir) or die "Failed to create directories '$dir': $!";
+			print "\nThe log directory $dir did not exist, so it was created.\n";
+		}
+	}
     open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
     LOG->autoflush(1);
 }
-- 
2.34.1
Re: [PATCH RESEND v1] ktest: Fix Test Failures Due to Missing LOG_FILE Directories
Posted by Steven Rostedt 1 year, 2 months ago
On Tue, 28 Jan 2025 05:14:27 +0000
Ayush Jain <Ayush.jain3@amd.com> wrote:

> Handle missing parent directories for LOG_FILE path to prevent test
> failures. If the parent directories don't exist, create them to ensure
> the tests proceed successfully.
> 

Sorry for the late reply. This got lost in my inbox.

> Signed-off-by: Ayush Jain <Ayush.jain3@amd.com>
> ---
>  tools/testing/ktest/ktest.pl | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
> index 8c8da966c641..be707cbc56a7 100755
> --- a/tools/testing/ktest/ktest.pl
> +++ b/tools/testing/ktest/ktest.pl
> @@ -4303,6 +4303,13 @@ if (defined($opt{"LOG_FILE"})) {
>      if ($opt{"CLEAR_LOG"}) {
>  	unlink $opt{"LOG_FILE"};
>      }
> +	if (! -e $opt{"LOG_FILE"}) {

First, please use the same indentation as the file. This isn't kernel code
and doesn't use the kernel indentation.

> +		my ($dir) = $opt{"LOG_FILE"} =~ m|^(.*/)|;

The above has a lot of Perl shortcuts that a normal C programmer would not
understand. Please convert this to:

	if (! -e $opt{"LOG_FILE"} && $opt{"LOG_FILE"} =~ m,^(.*/),) {
		my $dir = $1;


		if (! -d $dir) {
		
Thanks,

-- Steve


> +		if ($dir && !-d $dir) {
> +			mkpath($dir) or die "Failed to create directories '$dir': $!";
> +			print "\nThe log directory $dir did not exist, so it was created.\n";
> +		}
> +	}
>      open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
>      LOG->autoflush(1);
>  }
Re: [PATCH RESEND v1] ktest: Fix Test Failures Due to Missing LOG_FILE Directories
Posted by Jain, Ayush 1 year, 2 months ago
Hello Steven,

Thank you for reviewing,

On 3/5/2025 12:04 AM, Steven Rostedt wrote:
> On Tue, 28 Jan 2025 05:14:27 +0000
> Ayush Jain <Ayush.jain3@amd.com> wrote:
>
>> Handle missing parent directories for LOG_FILE path to prevent test
>> failures. If the parent directories don't exist, create them to ensure
>> the tests proceed successfully.
>>
> Sorry for the late reply. This got lost in my inbox.
>
>> Signed-off-by: Ayush Jain <Ayush.jain3@amd.com>
>> ---
>>  tools/testing/ktest/ktest.pl | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
>> index 8c8da966c641..be707cbc56a7 100755
>> --- a/tools/testing/ktest/ktest.pl
>> +++ b/tools/testing/ktest/ktest.pl
>> @@ -4303,6 +4303,13 @@ if (defined($opt{"LOG_FILE"})) {
>>      if ($opt{"CLEAR_LOG"}) {
>>  	unlink $opt{"LOG_FILE"};
>>      }
>> +	if (! -e $opt{"LOG_FILE"}) {
> First, please use the same indentation as the file. This isn't kernel code
> and doesn't use the kernel indentation.

Sure, will take care of it.

>> +		my ($dir) = $opt{"LOG_FILE"} =~ m|^(.*/)|;
> The above has a lot of Perl shortcuts that a normal C programmer would not
> understand. Please convert this to:
>
> 	if (! -e $opt{"LOG_FILE"} && $opt{"LOG_FILE"} =~ m,^(.*/),) {
> 		my $dir = $1;
>
>
> 		if (! -d $dir) {

Sure, will update this in next version

> 		
> Thanks,
>
> -- Steve
>
>
>> +		if ($dir && !-d $dir) {
>> +			mkpath($dir) or die "Failed to create directories '$dir': $!";
>> +			print "\nThe log directory $dir did not exist, so it was created.\n";
>> +		}
>> +	}
>>      open(LOG, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";
>>      LOG->autoflush(1);
>>  }

Thanks,
Ayush Jain