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

Ayush Jain posted 1 patch 11 months, 1 week ago
tools/testing/ktest/ktest.pl | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH v3] ktest: Fix Test Failures Due to Missing LOG_FILE Directories
Posted by Ayush Jain 11 months, 1 week 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 | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 8c8da966c641..a5f7fdd0c1fb 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -4303,6 +4303,14 @@ if (defined($opt{"LOG_FILE"})) {
     if ($opt{"CLEAR_LOG"}) {
 	unlink $opt{"LOG_FILE"};
     }
+
+    if (! -e $opt{"LOG_FILE"} && $opt{"LOG_FILE"} =~ m,^(.*/),) {
+        my $dir = $1;
+        if (! -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 v3] ktest: Fix Test Failures Due to Missing LOG_FILE Directories
Posted by Jain, Ayush 10 months, 2 weeks ago
Hello Steven,

Hope you're doing well! Just a quick follow-up on this,
would appreciate your feedback when you get a chance. Let me know if you
need anything from me.

TiA,
Ayush

On 3/7/2025 10:08 AM, Ayush Jain 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.
>
> Signed-off-by: Ayush Jain <Ayush.jain3@amd.com>
> ---
>  tools/testing/ktest/ktest.pl | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
> index 8c8da966c641..a5f7fdd0c1fb 100755
> --- a/tools/testing/ktest/ktest.pl
> +++ b/tools/testing/ktest/ktest.pl
> @@ -4303,6 +4303,14 @@ if (defined($opt{"LOG_FILE"})) {
>      if ($opt{"CLEAR_LOG"}) {
>  	unlink $opt{"LOG_FILE"};
>      }
> +
> +    if (! -e $opt{"LOG_FILE"} && $opt{"LOG_FILE"} =~ m,^(.*/),) {
> +        my $dir = $1;
> +        if (! -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 v3] ktest: Fix Test Failures Due to Missing LOG_FILE Directories
Posted by Steven Rostedt 10 months, 2 weeks ago
On Thu, 27 Mar 2025 15:46:37 +0530
"Jain, Ayush" <ayushjai@amd.com> wrote:

> Hope you're doing well! Just a quick follow-up on this,
> would appreciate your feedback when you get a chance. Let me know if you
> need anything from me.

Ah sorry, I've been traveling and came back to having the merge window
opened, which put me a bit behind.

I'll take a look at it today.

-- Steve