[RFC i-g-t 2/5] lib/igt_dir_explorer: Add function to recursively read all files in a directory

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri May 16 05:35:13 UTC 2025


On Thu, May 15, 2025 at 11:04:26AM +0200, Peter Senna Tschudin wrote:
> 
> 
> On 5/15/2025 10:51 AM, Zbigniew Kempczyński wrote:
> > On Wed, May 14, 2025 at 07:51:34PM +0200, Peter Senna Tschudin wrote:
> >> Introduces igt_dir_explorer_read_and_discard_all(), a function that
> >> performs a recursive scan of all files within a directory. Each file is
> >> read, and its content is discarded.
> >>
> >> This functionality is utilized in the following tests:
> >> - core_debugfs
> >> - core_debugfs_display_on_off
> >> - core_sysfs
> >>
> >> This addition enhances the ability to efficiently handle directory
> >> traversal and file processing in tests.
> >>
> >> Cc: marcin.bernatowicz at intel.com
> >> Cc: himanshu.girotra at intel.com
> >> Cc: aditya.chauhan at intel.com
> >> Cc: pravalika.gurram at intel.com
> >> Cc: sai.gowtham.ch at intel.com
> >> Cc: ramadevi.gandi at intel.com
> >> Cc: lucas.demarchi at intel.com
> >> Cc: rodrigo.vivi at intel.com
> >> Cc: kamil.konieczny at linux.intel.com
> >> Cc: katarzyna.piecielska at intel.com
> >> Signed-off-by: Peter Senna Tschudin <peter.senna at linux.intel.com>
> >> ---
> >>  lib/igt_dir_explorer.c | 72 ++++++++++++++++++++++++++++++++++++++++++
> >>  lib/igt_dir_explorer.h | 10 ++++++
> >>  lib/meson.build        |  1 +
> >>  3 files changed, 83 insertions(+)
> >>  create mode 100644 lib/igt_dir_explorer.c
> >>  create mode 100644 lib/igt_dir_explorer.h
> >>
> >> diff --git a/lib/igt_dir_explorer.c b/lib/igt_dir_explorer.c
> >> new file mode 100644
> >> index 000000000..d47e08535
> >> --- /dev/null
> >> +++ b/lib/igt_dir_explorer.c
> >> @@ -0,0 +1,72 @@
> >> +// SPDX-License-Identifier: MIT
> >> +/*
> >> + * Copyright © 2025 Intel Corporation
> >> + */
> >> +
> >> +#include <dirent.h>
> >> +#include <fcntl.h>
> >> +
> >> +#include "igt.h"
> >> +#include "igt_dir_explorer.h"
> >> +
> >> +void igt_dir_explorer_read_and_discard_all(int path_fd, int indent)
> > 
> > Just loose thought - if you're doing recursive directory traversal,
> > wouldn't be better to pass function (kind of callback) which would be
> > called for each file/dir entry? I mean single traversal code, and
> > multiple callbacks for different use cases.
> 
> I like the idea. Can you help me create a spec for it?

I would focus to achieve igt_dir_explorer_read_and_discard_all() using
generic traversal/call(backs) functions. Select only fields necessary
to achieve the goal. I'm against overengineering code on the very
beginning. For example I don't see any value in designing multithreading
support in igt code for traversal.

> There is more than
> just what to do. There are cases where we may want to test only specific
> files, and cases where we do not want to test specific files. Ideas:
>  - Accept a callback that performs the action on each file. Read or write
>    for example

In term of callback I really think about call-handler function which gets
filename and decide what to do with it. So from traversal perspective
it is synchronous call.

>  - Accept specification for which files to read, and which not to read.
>  - Maybe an optional blocking callback? do not proceed to the next file
>    until this one returns. This is useful for an async reset for example.

Described above.

>  - Limits? Depth, number of files, wait between reads?
>  - Concurrency? Try read them all at the same time?
>  - Random order for doing the action on the file?

Depth - yes. And include/exclude pattern - this might be very useful
to avoid calling handler for each traversed file/dir. Other things
are unnecessary and I vote against them.

> 
> Which ones of these make sense, and what else can we customize?

> 
> Would it be ok to delay these improvements to a next iteration? There is
> some urgency in solving the issues I created with intel_sysfs_debugfs.

Write something what is simple and work.

--
Zbigniew


More information about the igt-dev mailing list