Skip to contentSkip to conversation

Ensure that file descriptors will be closed on exit

PATCH Superseded Mauro Carvalho Chehab 1 participant 79 messages Sep 1, 2022 – Sep 5, 2022 3 messages not in the archive

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Ensure that file descriptors will be closed on exit

From: Mauro Carvalho Chehab <[email protected]>

GCC is usually smart enough to close devices on exit, but that doesn't work with the logic inside igt_skip(), as it uses longjmp, causing the code to go out of scope. Such scoped variables must be tracked in an outer scope to the skipping subtest.

Change the logic on IGT tests in order to avoid keeping device opened at the end of the test.

Chris Wilson (74):
lib: Introduce typed cleanups
i915/gem_basic: Close device before exit i915/gem_flink_basic: Close device before exit i915/gem_linear_blits: Close device before exit i915/gem_blits: Close device before exit i915/gem_close: Close device before exit i915/gem_create: Close device before exit i915/gem_ctx_engines: Close device before exit i915/gem_ctx_shared: Close device before exit i915/gem_exec_alignment: Close device before exit i915/gem_render_copy: Close device before exit i915/gem_render_copy_redux: Close device before exit i915/gem_media_fill: Close device before exit i915/gem_userptr_blits: Close device before exit i915/gem_workarounds: Close device before exit i915/gem_unref_active_buffers: Close device before exit i915/gem_exec_endless: Close device before exit i915/gem_request_retire: Close device before exit i915/gem_unfence_active_buffers: Close device before exit i915/i915_pciid: Close device before exit
kms_cursor_legacy: Close device before exit
kms_flip: Close device before exit
kms_pipe_crc_basic: Close device before exit
kms_psr: Close device before exit
kms_flip: Close device before exit
kms_force_connector_basic: Close device before exit
dumb_buffer: Close device before exit
kms_atomic: Close device before exit
kms_atomic_interruptible: Close device before exit
kms_atomic_transition: Close device before exit i915/kms_big_fb: Close device before exit i915/kms_ccs: Close device before exit
kms_color: Close device before exit
kms_cursor_crc: Close device before exit i915/kms_big_joiner: Close device before exit i915/kms_cdclk: Close device before exit i915/kms_fence_pin_leak: Close device before exit i915/kms_flip_scaled_crc: Close device before exit i915/kms_flip_tiling: Close device before exit i915/kms_mmap_write_crc: Close device before exit i915/kms_pipe_b_c_ivb: Close device before exit i915/kms_psr2_sf: Close device before exit i915/kms_psr2_su: Close device before exit i915/kms_pwrite_crc: Close device before exit
kms_flip_event_leak: Close device before exit
kms_hdr: Close device before exit
kms_invalid_mode: Close device before exit
kms_lease: Close device before exit
kms_panel_fitting: Close device before exit
kms_plane: Close device before exit
kms_plane_alpha_blend: Close device before exit
kms_plane_cursor: Close device before exit
kms_plane_multiple: Close device before exit
kms_plane_scaling: Close device before exit
kms_properties: Close device before exit
kms_rotation_crc: Close device before exit
kms_sequence: Close device before exit
kms_universal_plane: Close device before exit
kms_vblank: Close device before exit
syncobj_wait: Close device before exit
syncobj_basic: Close device before exit
syncobj_timeline: Close device before exit
drm_import_export: Close device before exit
kms_dp_aux_dev: Close device before exit
kms_hdmi_inject: Close device before exit
kms_3d: Close device before exit
kms_scaling_modes: Close device before exit
kms_dither: Close device before exit
drm_read: Close device before exit
kms_cursor_edge_walk: Close device before exit
kms_plane_lowres: Close device before exit
kms_content_protection: Close device before exit
feature_discovery: Close device before exit i915/i915_pm_dc: Close device before exit

 lib/igt_core.c                          |   6 ++
 lib/igt_core.h                          |   2 +
 lib/igt_types.c                         |  17 +++
 lib/igt_types.h                         |  47 ++++++++
 lib/meson.build                         |   1 +
 lib/tests/bad_subtest_type.c            |  19 ++++
 lib/tests/igt_types.c                   | 136 ++++++++++++++++++++++++
 lib/tests/meson.build                   |   2 +
 tests/drm_import_export.c               |   5 +
 tests/drm_read.c                        |   4 +-
 tests/dumb_buffer.c                     |   4 +
 tests/feature_discovery.c               |   5 +-
 tests/i915/gem_basic.c                  |   8 +-
 tests/i915/gem_blits.c                  |   1 +
 tests/i915/gem_close.c                  |   3 +-
 tests/i915/gem_create.c                 |   3 +-
 tests/i915/gem_ctx_engines.c            |   3 +-
 tests/i915/gem_ctx_shared.c             |   3 +-
 tests/i915/gem_exec_alignment.c         |   3 +-
 tests/i915/gem_exec_endless.c           |   3 +-
 tests/i915/gem_flink_basic.c            |  11 +-
 tests/i915/gem_linear_blits.c           |   3 +-
 tests/i915/gem_media_fill.c             |   1 +
 tests/i915/gem_render_copy.c            |   1 +
 tests/i915/gem_render_copy_redux.c      |   4 +
 tests/i915/gem_request_retire.c         |   5 +-
 tests/i915/gem_unfence_active_buffers.c |   1 +
 tests/i915/gem_unref_active_buffers.c   |   1 +
 tests/i915/gem_userptr_blits.c          |   4 +-
 tests/i915/gem_workarounds.c            |   3 +-
 tests/i915/i915_pciid.c                 |   2 +
 tests/i915/i915_pm_dc.c                 |   1 +
 tests/i915/kms_big_fb.c                 |   1 +
 tests/i915/kms_big_joiner.c             |   1 +
 tests/i915/kms_busy.c                   |   1 +
 tests/i915/kms_ccs.c                    |   4 +-
 tests/i915/kms_cdclk.c                  |   1 +
 tests/i915/kms_fence_pin_leak.c         |   1 +
 tests/i915/kms_flip_scaled_crc.c        |   1 +
 tests/i915/kms_flip_tiling.c            |   1 +
 tests/i915/kms_mmap_write_crc.c         |   1 +
 tests/i915/kms_pipe_b_c_ivb.c           |   1 +
 tests/i915/kms_psr.c                    |   1 +
 tests/i915/kms_psr2_sf.c                |   1 +
 tests/i915/kms_psr2_su.c                |   1 +
 tests/i915/kms_pwrite_crc.c             |   1 +
 tests/kms_3d.c                          |   1 +
 tests/kms_atomic.c                      |   1 +
 tests/kms_atomic_interruptible.c        |   1 +
 tests/kms_atomic_transition.c           |   1 +
 tests/kms_color.c                       |   1 +
 tests/kms_content_protection.c          |   1 +
 tests/kms_cursor_crc.c                  |   1 +
 tests/kms_cursor_edge_walk.c            |   4 +-
 tests/kms_cursor_legacy.c               |   1 +
 tests/kms_dither.c                      |   1 +
 tests/kms_dp_aux_dev.c                  |   1 +
 tests/kms_flip.c                        |   3 +
 tests/kms_flip_event_leak.c             |   1 +
 tests/kms_force_connector_basic.c       |   7 +-
 tests/kms_hdmi_inject.c                 |   1 +
 tests/kms_hdr.c                         |   1 +
 tests/kms_invalid_mode.c                |   1 +
 tests/kms_lease.c                       |   4 +
 tests/kms_panel_fitting.c               |   4 +-
 tests/kms_pipe_crc_basic.c              |   1 +
 tests/kms_plane.c                       |   1 +
 tests/kms_plane_alpha_blend.c           |   1 +
 tests/kms_plane_cursor.c                |   1 +
 tests/kms_plane_lowres.c                |   4 +-
 tests/kms_plane_multiple.c              |   1 +
 tests/kms_plane_scaling.c               |   4 +-
 tests/kms_properties.c                  |   1 +
 tests/kms_rotation_crc.c                |   1 +
 tests/kms_scaling_modes.c               |   4 +-
 tests/kms_sequence.c                    |   4 +
 tests/kms_universal_plane.c             |   1 +
 tests/kms_vblank.c                      |   4 +
 tests/syncobj_basic.c                   |   4 +
 tests/syncobj_timeline.c                |   4 +
 tests/syncobj_wait.c                    |   4 +
 81 files changed, 378 insertions(+), 27 deletions(-)
 create mode 100644 lib/igt_types.c
 create mode 100644 lib/igt_types.h
 create mode 100644 lib/tests/bad_subtest_type.c
 create mode 100644 lib/tests/igt_types.c
Signature · 1 line
2.37.2
#1 lore raw

PATCH 1/74 lib: Introduce typed cleanups

From: Chris Wilson <[email protected]>

Start introducing standard types with automatic cleanup courtesy of gcc's __attribute__((cleanup)). As an example, we start with an fd that will automatically call close() on going out of scope, and crucially before atexit where we will want to check for resource leaks.

---
 lib/igt_core.c               |   6 ++
 lib/igt_core.h               |   2 +
 lib/igt_types.c              |  17 +++++
 lib/igt_types.h              |  47 ++++++++++++
 lib/meson.build              |   1 +
 lib/tests/bad_subtest_type.c |  19 +++++
 lib/tests/igt_types.c        | 136 +++++++++++++++++++++++++++++++++++
 lib/tests/meson.build        |   2 +
 8 files changed, 230 insertions(+)
 create mode 100644 lib/igt_types.c
 create mode 100644 lib/igt_types.h
 create mode 100644 lib/tests/bad_subtest_type.c
 create mode 100644 lib/tests/igt_types.c
lib/igt_core.c +6 -0
index e7425326b7f0..dc6486c841f0 100644
@@ -624,6 +624,12 @@ uint64_t igt_nsec_elapsed(struct timespec *start)
 		(uint64_t)NSEC_PER_SEC*(now.tv_sec - start->tv_sec));
 }
 
+void __igt_assert_in_outer_scope(void)
+{
+	internal_assert(!in_subtest,
+			"must only be called outside of a subtest");
+}
+
 bool __igt_fixture(void)
 {
 	internal_assert(!in_fixture,
lib/igt_core.h +2 -0
index aa98e8ed8deb..f21723dec4bc 100644
@@ -135,6 +135,8 @@ struct _GKeyFile *igt_load_igtrc(void);
  */
 #define IGT_EXIT_ABORT 112
 
+void __igt_assert_in_outer_scope(void);
+
 bool __igt_fixture(void);
 void __igt_fixture_complete(void);
 __noreturn void __igt_fixture_end(void);
lib/igt_types.c new file +17 -0
new file mode 100644
index 000000000000..7416b0fffc04
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: MIT
+/*
+* Copyright © 2022 Intel Corporation
+*/
+
+#include <unistd.h>
+
+#include "igt_types.h"
+
+void igt_cleanup_fd(int *fd)
+{
+	if (!fd || *fd < 0)
+		return;
+
+	close(*fd);
+	*fd = -1;
+}
lib/igt_types.h new file +47 -0

47 lines not on this page · raw message

lib/meson.build +1 -0
index 6910c061e9b9..c85a5b1a0801 100644
@@ -38,6 +38,7 @@ lib_sources = [
 	'igt_sysrq.c',
 	'igt_taints.c',
 	'igt_thread.c',
+	'igt_types.c',
 	'igt_vec.c',
 	'igt_vgem.c',
 	'igt_x86.c',
lib/tests/bad_subtest_type.c new file +19 -0
new file mode 100644
index 000000000000..7f5efdfba8e2
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: MIT
+/*
+* Copyright © 2022 Intel Corporation
+*/
+
+#include "igt_core.h"
+#include "igt_types.h"
+
+igt_main
+{
+	igt_subtest("bad-scoped-variable") {
+		/*
+		 * Not allowed to nest a scoped variable inside a subtest as
+		 * we expect to longjmp out of the subtest on failure/skip
+		 * and automatic cleanup is not invoked for such jmps.
+		 */
+		igt_fd_t(f);
+	}
+}
lib/tests/igt_types.c new file +136 -0

136 lines not on this page · raw message

lib/tests/meson.build +2 -0
index ceaf548b2b2f..d5666c246146 100644
@@ -19,10 +19,12 @@ lib_tests = [
 	'igt_stats',
 	'igt_subtest_group',
 	'igt_thread',
+	'igt_types',
 	'i915_perf_data_alignment',
 ]
 
 lib_fail_tests = [
+	'bad_subtest_type',
 	'igt_no_subtest',
 	'igt_simple_test_subtests',
 	'igt_timeout',
Signature · 1 line
2.37.2

A message that is not in the archive (sent off-list or not yet received): YxB5IMoe9slyOn/[email protected]

#3 lore raw

Re: [igt-dev] [PATCH i-g-t 01/74] lib: Introduce typed cleanups

Quoted 14 lines · On Thu, 1 Sep 2022 12:19:28 +0300 Petri Latvala <[email protected]> wrote:
Quoted 13 lines · Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Start introducing standard types with automatic cleanup courtesy of gcc's __attribute__((cleanup)). As an example, we start with an fd that will automatically call close() on going out of scope, and crucially before atexit where we will want to check for resource leaks.

...

Quoted 5 lines
Quoted 5 lines
lib/igt_types.h new file +5 -0
+void igt_cleanup_fd(int *fd);
+#define igt_fd_t(x__) \
+	int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
+
+#endif /* IGT_TYPES_H */

...

Quoted 3 lines

This fails with clang currently, and might fail with gcc in the future. longjmp is funky.

It is unlikely that gcc would change it, but yeah, there's a possibility.

There's an easy to workaround: just check if CONFIG_CLANG_VERSION is defined, disabling the logic on such case with something like:

/*
* FIXME: on clang, stack variables are lost after setjmp() */
#ifdef CONFIG_CLANG_VERSION
# define igt_fd_t(x__) int x__
#else
# define igt_fd_t(x__) \
int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

This would keep the file descriptors opened on Clang, but it would at least solve for gcc.

Quoted 3 lines

If an automatic (stack) variable is assigned after setjmp(), the longjmp to "before" the assignment has the variable in unspecified state as per the C spec. In the sense that the value can be either.

I see. Yeah, handling undefined behavior cases are complex.

I guess one possible solution would be to define the macro as:

#define igt_fd_t(x__) \
static int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

but I didn't check the C spec to see if this has a defined behavior, nor tested it.

Quoted 6 lines

We've already had to deal with some of this, see the comment at the beginning of runner/runner_tests.c and the sprinkled use of volatile for variables that are declared in subtest_group scope.

(It could be a gcc implementation detail but variables declared in igt_main scope have been fine in testing this curiosity)

Regards,
Mauro

#4 lore raw

Re: [igt-dev] [PATCH i-g-t 01/74] lib: Introduce typed cleanups

Quoted 56 lines · On Thu, 1 Sep 2022 12:56:09 +0200 Mauro Carvalho Chehab…
Quoted 14 lines · On Thu, 1 Sep 2022 12:19:28 +0300 Petri Latvala <[email protected]> wrote:
Quoted 13 lines · Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Start introducing standard types with automatic cleanup courtesy of gcc's __attribute__((cleanup)). As an example, we start with an fd that will automatically call close() on going out of scope, and crucially before atexit where we will want to check for resource leaks.

...

Quoted 5 lines
Quoted 5 lines
lib/igt_types.h new file +5 -0
+void igt_cleanup_fd(int *fd);
+#define igt_fd_t(x__) \
+	int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
+
+#endif /* IGT_TYPES_H */  

...

Quoted 3 lines

This fails with clang currently, and might fail with gcc in the future. longjmp is funky.

It is unlikely that gcc would change it, but yeah, there's a possibility.

There's an easy to workaround: just check if CONFIG_CLANG_VERSION is defined, disabling the logic on such case with something like:

/*
* FIXME: on clang, stack variables are lost after setjmp() */
#ifdef CONFIG_CLANG_VERSION
# define igt_fd_t(x__) int x__
#else
# define igt_fd_t(x__) \
int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

This would keep the file descriptors opened on Clang, but it would at least solve for gcc.

Quoted 3 lines

If an automatic (stack) variable is assigned after setjmp(), the longjmp to "before" the assignment has the variable in unspecified state as per the C spec. In the sense that the value can be either.

I see. Yeah, handling undefined behavior cases are complex.

Quoted 8 lines

I guess one possible solution would be to define the macro as:

#define igt_fd_t(x__) \
static int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

but I didn't check the C spec to see if this has a defined behavior, nor tested it.

Answering myself: this won't work, as the macro uses __cleanup__ atribute, which is only valid for stack-allocated variables:

../tests/i915/gem_request_retire.c:109:2: warning: '__cleanup__' attribute only applies to local variables [-Wignored-attributes]

A solution that would work would be to store a list of file descriptors on a static list and then use it during cleanup time (assuming that clang will still call the cleanup function with longjmp).

Quoted 9 lines
Quoted 6 lines

We've already had to deal with some of this, see the comment at the beginning of runner/runner_tests.c and the sprinkled use of volatile for variables that are declared in subtest_group scope.

(It could be a gcc implementation detail but variables declared in igt_main scope have been fine in testing this curiosity)

Regards,
Mauro

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [igt-dev] [PATCH i-g-t 01/74] lib: Introduce typed cleanups

Quoted 79 lines · On Thu, 1 Sep 2022 14:24:41 +0300 Petri Latvala <[email protected]> wrote:
Quoted 71 lines · Mauro Carvalho Chehab
Quoted 56 lines · On Thu, 1 Sep 2022 12:56:09 +0200 Mauro Carvalho Chehab…
Quoted 14 lines · On Thu, 1 Sep 2022 12:19:28 +0300 Petri Latvala <[email protected]> wrote:
Quoted 13 lines · Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Start introducing standard types with automatic cleanup courtesy of gcc's __attribute__((cleanup)). As an example, we start with an fd that will automatically call close() on going out of scope, and crucially before atexit where we will want to check for resource leaks.

...

Quoted 5 lines
Quoted 5 lines
(quoted diff) +5 -0
+void igt_cleanup_fd(int *fd);
+#define igt_fd_t(x__) \
+	int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
+
+#endif /* IGT_TYPES_H */    

...

Quoted 3 lines

This fails with clang currently, and might fail with gcc in the future. longjmp is funky.

It is unlikely that gcc would change it, but yeah, there's a possibility.

There's an easy to workaround: just check if CONFIG_CLANG_VERSION is defined, disabling the logic on such case with something like:

/*
* FIXME: on clang, stack variables are lost after setjmp() */
#ifdef CONFIG_CLANG_VERSION
# define igt_fd_t(x__) int x__
#else
# define igt_fd_t(x__) \
int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

This would keep the file descriptors opened on Clang, but it would at least solve for gcc.

Quoted 3 lines

If an automatic (stack) variable is assigned after setjmp(), the longjmp to "before" the assignment has the variable in unspecified state as per the C spec. In the sense that the value can be either.

I see. Yeah, handling undefined behavior cases are complex.

Quoted 8 lines

I guess one possible solution would be to define the macro as:

#define igt_fd_t(x__) \
static int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

but I didn't check the C spec to see if this has a defined behavior, nor tested it.

Answering myself: this won't work, as the macro uses __cleanup__ atribute, which is only valid for stack-allocated variables:

Quoted 6 lines

../tests/i915/gem_request_retire.c:109:2: warning: '__cleanup__' attribute only applies to local variables [-Wignored-attributes]

A solution that would work would be to store a list of file descriptors on a static list and then use it during cleanup time (assuming that clang will still call the cleanup function with longjmp).

Quoted 5 lines

Yeah the only thing that helps really is volatile. That is fully specified as per spec for this.

Having said that: What if igt_fd_t just used volatile across the board?

Do you mean folding this change on patch 01/74?

<snip>

lib/igt_types.c +1 -1
index 7416b0fffc04..392f30fcab23 100644
@@ -7,7 +7,7 @@
 
 #include "igt_types.h"
 
-void igt_cleanup_fd(int *fd)
+void igt_cleanup_fd(volatile int *fd)
 {
 	if (!fd || *fd < 0)
 		return;
lib/igt_types.h +2 -2
index 1852026969ae..c4bc01ecdb3b 100644
@@ -40,8 +40,8 @@
 /* Prevent use within the inner scope subtests, it will be broken by igt_skip */
 #define IGT_OUTER_SCOPE_INIT(x) ({ __igt_assert_in_outer_scope(); x; })
 
-void igt_cleanup_fd(int *fd);
+void igt_cleanup_fd(volatile int *fd);
 #define igt_fd_t(x__) \
-	int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
+	volatile int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
 
 #endif /* IGT_TYPES_H */

</snip>

This builds fine, but didn't try yet checking if it will do the right thing.

Regards,
Mauro

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [igt-dev] [PATCH i-g-t 01/74] lib: Introduce typed cleanups

Quoted 121 lines · On Fri, 2 Sep 2022 16:15:27 +0300 Petri Latvala <[email protected]> wrote:
Quoted 120 lines · Mauro Carvalho Chehab
Quoted 79 lines · On Thu, 1 Sep 2022 14:24:41 +0300 Petri Latvala <[email protected]> wrote:
Quoted 71 lines · Mauro Carvalho Chehab
Quoted 56 lines · On Thu, 1 Sep 2022 12:56:09 +0200 Mauro Carvalho Chehab…
Quoted 14 lines · On Thu, 1 Sep 2022 12:19:28 +0300 Petri Latvala <[email protected]> wrote:
Quoted 13 lines · Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Start introducing standard types with automatic cleanup courtesy of gcc's __attribute__((cleanup)). As an example, we start with an fd that will automatically call close() on going out of scope, and crucially before atexit where we will want to check for resource leaks.

...

Quoted 5 lines
Quoted 5 lines
(quoted diff) +5 -0
+void igt_cleanup_fd(int *fd);
+#define igt_fd_t(x__) \
+	int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
+
+#endif /* IGT_TYPES_H */      

...

Quoted 3 lines

This fails with clang currently, and might fail with gcc in the future. longjmp is funky.

It is unlikely that gcc would change it, but yeah, there's a possibility.

There's an easy to workaround: just check if CONFIG_CLANG_VERSION is defined, disabling the logic on such case with something like:

/*
* FIXME: on clang, stack variables are lost after setjmp() */
#ifdef CONFIG_CLANG_VERSION
# define igt_fd_t(x__) int x__
#else
# define igt_fd_t(x__) \
int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

This would keep the file descriptors opened on Clang, but it would at least solve for gcc.

Quoted 3 lines

If an automatic (stack) variable is assigned after setjmp(), the longjmp to "before" the assignment has the variable in unspecified state as per the C spec. In the sense that the value can be either.

I see. Yeah, handling undefined behavior cases are complex.

Quoted 8 lines

I guess one possible solution would be to define the macro as:

#define igt_fd_t(x__) \
static int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
#endif

but I didn't check the C spec to see if this has a defined behavior, nor tested it.

Answering myself: this won't work, as the macro uses __cleanup__ atribute, which is only valid for stack-allocated variables:

Quoted 6 lines

../tests/i915/gem_request_retire.c:109:2: warning: '__cleanup__' attribute only applies to local variables [-Wignored-attributes]

A solution that would work would be to store a list of file descriptors on a static list and then use it during cleanup time (assuming that clang will still call the cleanup function with longjmp).

Quoted 5 lines

Yeah the only thing that helps really is volatile. That is fully specified as per spec for this.

Having said that: What if igt_fd_t just used volatile across the board?

Do you mean folding this change on patch 01/74?

<snip>

lib/igt_types.c +1 -1
index 7416b0fffc04..392f30fcab23 100644
@@ -7,7 +7,7 @@
 
 #include "igt_types.h"
 
-void igt_cleanup_fd(int *fd)
+void igt_cleanup_fd(volatile int *fd)
 {
 	if (!fd || *fd < 0)
 		return;
lib/igt_types.h +2 -2
index 1852026969ae..c4bc01ecdb3b 100644
@@ -40,8 +40,8 @@
 /* Prevent use within the inner scope subtests, it will be broken by igt_skip */
 #define IGT_OUTER_SCOPE_INIT(x) ({ __igt_assert_in_outer_scope(); x; })
 
-void igt_cleanup_fd(int *fd);
+void igt_cleanup_fd(volatile int *fd);
 #define igt_fd_t(x__) \
-	int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
+	volatile int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)
 
 #endif /* IGT_TYPES_H */
Quoted 7 lines
Quoted 4 lines

</snip>

This builds fine, but didn't try yet checking if it will do the right thing.

Yeah, exactly. It should do the right thing, at the cost of zero-to-small performance hit. Whether that's true remains to be seen.

Did a quick test with volatile patch applied on a TGL. It seems it didn't cause any performance hits. It also didn't affect the test results.

So, I'll be submitting a version 2 of this series using volatile.

Regards,
Mauro

--

after renamed from before +32 -32
@@ -1,4 +1,4 @@
- 1.26-g40ec79634da4 (x86_64) (Linux: 5.19.0-drm-50bc22230125+ x86_64)
+ 1.26-g4530a3c6bbf0 (x86_64) (Linux: 5.19.0-drm-50bc22230125+ x86_64)
 
  Subtest load: SKIP (0.002s)
  Subtest basic-auth: SKIP
@@ -12,45 +12,45 @@
  Subtest create-close: SUCCESS (0.000s)
  Subtest create-fd-close: SUCCESS (0.000s)
  Subtest busy: SKIP
- Subtest basic-process: SUCCESS (0.047s)
- Subtest basic-threads: SUCCESS (1.183s)
+ Subtest basic-process: SUCCESS (0.054s)
+ Subtest basic-threads: SUCCESS (1.182s)
  Subtest basic: SUCCESS (0.000s)
  Subtest basic-files: SUCCESS (2.007s)
- Subtest basic: SUCCESS (0.002s)
- Subtest basic: SUCCESS (0.002s)
- Subtest basic: SUCCESS (2.041s)
- Subtest basic-busy: SUCCESS (0.143s)
- Subtest basic-wait: SUCCESS (0.173s)
- Subtest basic-await: SUCCESS (0.378s)
- Subtest nb-await: SUCCESS (0.307s)
- Subtest basic: SUCCESS (4.078s)
+ Subtest basic: SUCCESS (0.003s)
+ Subtest basic: SUCCESS (0.003s)
+ Subtest basic: SUCCESS (2.054s)
+ Subtest basic-busy: SUCCESS (0.145s)
+ Subtest basic-wait: SUCCESS (0.134s)
+ Subtest basic-await: SUCCESS (0.377s)
+ Subtest nb-await: SUCCESS (0.303s)
+ Subtest basic: SUCCESS (4.060s)
  Subtest engines: SKIP
- Subtest basic: SUCCESS (0.042s)
+ Subtest basic: SUCCESS (0.040s)
  Subtest bad-flink: SUCCESS (0.000s)
  Subtest bad-open: SUCCESS (0.000s)
  Subtest basic: SUCCESS (0.000s)
  Subtest double-flink: SUCCESS (0.000s)
  Subtest flink-lifetime: SUCCESS (0.001s)
  Subtest huc-copy: SKIP (0.000s)
- Subtest basic: SUCCESS (0.004s)
+ Subtest basic: SUCCESS (0.005s)
  Subtest basic: SUCCESS (0.000s)
  Subtest basic: SUCCESS (0.000s)
- Subtest basic: SUCCESS (0.032s)
- Subtest basic: SUCCESS (0.021s)
- Subtest basic-all: SUCCESS (1.117s)
+ Subtest basic: SUCCESS (0.022s)
+ Subtest basic: SUCCESS (0.026s)
+ Subtest basic-all: SUCCESS (1.112s)
  Subtest allocator-basic: SKIP
  Subtest allocator-basic-reserve: SKIP
  Subtest safe-alignment: SKIP
- Subtest basic-all: SUCCESS (2.039s)
- Subtest basic-each: SUCCESS (2.079s)
- Subtest basic: SUCCESS (0.014s)
+ Subtest basic-all: SUCCESS (2.289s)
+ Subtest basic-each: SUCCESS (2.123s)
+ Subtest basic: SUCCESS (0.015s)
  Subtest basic: SUCCESS (0.022s)
- SUCCESS (0.059s)
+ SUCCESS (0.055s)
  Subtest busy: SKIP
  Subtest wait: SKIP
  Subtest basic-eu-total: SUCCESS (0.000s)
  Subtest basic-subslice-total: SUCCESS (0.000s)
- Subtest error-state-basic: SUCCESS (0.028s)
+ Subtest error-state-basic: SUCCESS (0.030s)
  SUCCESS (0.001s)
  Subtest addfb25-bad-modifier: SKIP
  Subtest addfb25-framebuffer-vs-set-tiling: SKIP
@@ -124,14 +124,14 @@
  Subtest basic-clone-single-crtc: SKIP
  Subtest basic-brightness: SKIP
  Subtest basic-pci-d3-state: SKIP
- Subtest basic-rte: SKIP (0.001s)
- Subtest basic-api: SUCCESS (0.025s)
+ Subtest basic-rte: SKIP (0.000s)
+ Subtest basic-api: SUCCESS (0.026s)
  Subtest basic-llseek-bad: SUCCESS (0.001s)
- Subtest basic-llseek-size: SUCCESS (0.003s)
+ Subtest basic-llseek-size: SUCCESS (0.002s)
  Subtest basic-with_fd_dup: SUCCESS (0.001s)
  Subtest basic-with_one_bo: SUCCESS (0.001s)
- Subtest basic-with_one_bo_two_files: SUCCESS (0.002s)
- Subtest basic-with_two_bos: SUCCESS (0.002s)
+ Subtest basic-with_one_bo_two_files: SUCCESS (0.001s)
+ Subtest basic-with_two_bos: SUCCESS (0.001s)
  Subtest basic-fence-flip: SKIP
  Subtest basic-fence-mmap: SKIP
  Subtest basic-fence-read: SKIP
@@ -142,11 +142,11 @@
  Subtest setversion: SUCCESS (0.000s)
  Subtest create: SUCCESS (0.000s)
  Subtest debugfs: SUCCESS (0.001s)
- Subtest dmabuf-export: SUCCESS (0.001s)
- Subtest dmabuf-fence: SUCCESS (0.001s)
+ Subtest dmabuf-export: SUCCESS (0.002s)
+ Subtest dmabuf-fence: SUCCESS (0.000s)
  Subtest dmabuf-fence-before: SUCCESS (0.000s)
- Subtest dmabuf-mmap: SUCCESS (0.015s)
- Subtest mmap: SUCCESS (0.014s)
+ Subtest dmabuf-mmap: SUCCESS (0.009s)
+ Subtest mmap: SUCCESS (0.008s)
  Subtest second-client: SUCCESS (0.001s)
- Subtest sysfs: SUCCESS (0.000s)
- Subtest unbind-rebind: SUCCESS (0.960s)
+ Subtest sysfs: SUCCESS (0.001s)
+ Subtest unbind-rebind: SUCCESS (0.979s)

---

If you're curious enough, those are the changesets on my test machine:

4530a3c6bbf0 (HEAD -> master) i915/gem_ctx_isolation: Close device before exit b1d4756a6cab i915/gem_exec_balancer: Close device before exit
df2549ea0cc1 core_auth: Close(master) before exit
4e6e6f5892db i915/i915_pm_dc: Close device before exit
02baa5a498e8 feature_discovery: Close device before exit
46dfbc9ad928 kms_content_protection: Close device before exit
0edd85b18c7f kms_plane_lowres: Close device before exit
562ea35b366b kms_cursor_edge_walk: Close device before exit
152a672d7a1d drm_read: Close device before exit
044ade01e25c kms_dither: Close device before exit
ae20ffcc39f2 kms_scaling_modes: Close device before exit
72e844e0716d kms_3d: Close device before exit
043ac26886cb kms_hdmi_inject: Close device before exit
36cf9798c647 kms_dp_aux_dev: Close device before exit
3aadfa70f159 drm_import_export: Close device before exit
218778762b52 syncobj_timeline: Close device before exit
e0a5c6a3a54c syncobj_basic: Close device before exit
59eaeeb14f8b syncobj_wait: Close device before exit
1213005ddc7e kms_vblank: Close device before exit
fe5bd17d1a71 kms_universal_plane: Close device before exit
c9b5df3b6b03 kms_sequence: Close device before exit
30823b629924 kms_rotation_crc: Close device before exit
74286a7f4b62 kms_properties: Close device before exit
9e52df6f7e44 kms_plane_scaling: Close device before exit
693c0d3b5546 kms_plane_multiple: Close device before exit
ee189b64976c kms_plane_cursor: Close device before exit
950b3d38155e kms_plane_alpha_blend: Close device before exit
4fed026b22fb kms_plane: Close device before exit
d611d7283a2b kms_panel_fitting: Close device before exit
e71281b62517 kms_lease: Close device before exit
eda8b974d91f kms_invalid_mode: Close device before exit
60348f9f2a30 kms_hdr: Close device before exit
5f24d029244c kms_flip_event_leak: Close device before exit
caf47f871b0b i915/kms_pwrite_crc: Close device before exit
fd79af4a5528 i915/kms_psr2_su: Close device before exit
23306e43498f i915/kms_psr2_sf: Close device before exit
0064cdcf8ced i915/kms_pipe_b_c_ivb: Close device before exit
3b6d5b8c0430 i915/kms_mmap_write_crc: Close device before exit
7e503c65c833 i915/kms_flip_tiling: Close device before exit
f38d5c0313ad i915/kms_flip_scaled_crc: Close device before exit
9ab01954d4ed i915/kms_fence_pin_leak: Close device before exit
f1728b91adff i915/kms_cdclk: Close device before exit
89accc090b0f i915/kms_big_joiner: Close device before exit
b54a850c67e9 kms_cursor_crc: Close device before exit
54a5451ca22f kms_color: Close device before exit
da1a768871e1 i915/kms_ccs: Close device before exit
de7a865bb2c5 i915/kms_big_fb: Close device before exit
c1f86be52d1c kms_atomic_transition: Close device before exit
1d54de0d4186 kms_atomic_interruptible: Close device before exit
26ce912981e7 kms_atomic: Close device before exit
2c0b1094771a dumb_buffer: Close device before exit
c502b300dd03 kms_force_connector_basic: Close device before exit
4233e2ae1d38 kms_flip: Close device before exit
006f1e3d93d3 kms_psr: Close device before exit
fc1e25f183ec kms_pipe_crc_basic: Close device before exit
2bf1fb607fd9 kms_flip: Close device before exit
c383167f1ace kms_cursor_legacy: Close device before exit
df752f7cfb9c i915/i915_pciid: Close device before exit
adb9c4547657 i915/gem_unfence_active_buffers: Close device before exit
8e214a2e0b25 i915/gem_request_retire: Close device before exit
19529fdef5cf i915/gem_exec_endless: Close device before exit
3054f0c97b07 i915/gem_unref_active_buffers: Close device before exit
abec97ca8c48 i915/gem_workarounds: Close device before exit
fd2de3209118 i915/gem_userptr_blits: Close device before exit
f9405034e215 i915/gem_media_fill: Close device before exit
9d6df278e077 i915/gem_render_copy_redux: Close device before exit
6d9a4f32dcf8 i915/gem_render_copy: Close device before exit
00b7b0edc00d i915/gem_exec_alignment: Close device before exit
9473d42d97f3 i915/gem_ctx_shared: Close device before exit
0f08a002cbf5 i915/gem_ctx_engines: Close device before exit
da0f52e411f4 i915/gem_create: Close device before exit
e86f970af730 i915/gem_close: Close device before exit
639bb8e53747 i915/gem_blits: Close device before exit
803df363b6db i915/gem_linear_blits: Close device before exit
0ad94b7acc2e i915/gem_flink_basic: Close device before exit
69634ee9d093 i915/gem_basic: Close device before exit
a615ce9c482d lib: Introduce typed cleanups
9b2970a6d495 lib/igt_kms: Choose default mode based on --environment flag from igt_runner c018ce1d1ab8 tests/kms_plane_multiple: Fix assumption about single primary plane 391ac3a06323 tests/amdgpu: add deadlock tests
11f7f3e8ae75 lib/amdgpu: added dispatch tests for gfx and compute
b84a050923b1 lib/amdgpu: added dispatch helper functions
cfc7239bad10 lib/amdgpu: added binary shaders with disassembled annotations ea2ef908a516 lib/amdgpu: improve operations to create commands and misc 0e7eb0bf7b42 tests/kms_cursor_crc: Add max-size test back
397677d03f27 tests/kms_plane_cursor: Convert tests to dynamic
ba61c48dba71 docs: Update report link to fd.o GitLab
ec22200d4c91 runner: Add tests for environment flags
b580bae747f0 runner: Add help for the --environment flag
1e8c7ae5df17 runner: Set requested env vars during execution
f3d848a0b578 runner: Serialize the provided environment flags
66ee80cc5854 runner: Add the --environment flag
01737c4a4577 runner: make the usage function variadic
1096ca21fa7a runner: rename free_settings to clear_settings
9338ab3ec085 replaced /bin/bash shebangs with /bin/sh for BSD compatibility a23e8aed0b54 lib/igt_device_scan: Retry when parent pci device lacks properties 1298b5f0e1b3 igt: Allow overriding the commit hash in the version string 9785abfeda27 lib/chamelium: Use MST Path property to reprobe an MST connector. e01fe99f0069 i915/guc: Disable i915_pm_rps when SLPC is enabled
40ec79634da4 (origin/master, origin/HEAD) tests/i915/kms_big_fb: First async flip discarded on i915

#9 lore raw

PATCH 2/74 i915/gem_basic: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_basic.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tests/i915/gem_basic.c +5 -3
index 17ae190cb2cb..2aa5d850cc10 100644
@@ -25,7 +25,6 @@
  *
  */
 
-#include "igt.h"
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -37,7 +36,10 @@
 #include <sys/ioctl.h>
 
 #include "drm.h"
+
 #include "i915/gem_create.h"
+#include "igt.h"
+#include "igt_types.h"
 
 IGT_TEST_DESCRIPTION("Tests basic gem_create and gem_close IOCTLs");
 
@@ -78,10 +80,10 @@ test_create_fd_close(int fd)
 	close(fd);
 }
 
-int fd;
-
 igt_main
 {
+	igt_fd_t(fd);
+
 	igt_fixture
 		fd = drm_open_driver(DRIVER_INTEL);
 
Signature · 1 line
2.37.2
#10 lore raw

PATCH 3/74 i915/gem_flink_basic: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_flink_basic.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tests/i915/gem_flink_basic.c +8 -3
index 4e207c2ab546..2620bc55daf0 100644
@@ -25,7 +25,6 @@
  *
  */
 
-#include "igt.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -34,8 +33,12 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+
 #include "drm.h"
 
+#include "igt.h"
+#include "igt_types.h"
+
 IGT_TEST_DESCRIPTION("Tests for flink - a way to export a gem object by name");
 
 static void
@@ -152,12 +155,14 @@ test_flink_lifetime(int fd)
 	ret = ioctl(fd2, DRM_IOCTL_GEM_OPEN, &open_struct);
 	igt_assert_eq(ret, 0);
 	igt_assert(open_struct.handle != 0);
-}
 
-int fd;
+	close(fd2);
+}
 
 igt_main
 {
+	igt_fd_t(fd);
+
 	igt_fixture
 		fd = drm_open_driver(DRIVER_INTEL);
 
Signature · 1 line
2.37.2
#11 lore raw

PATCH 4/74 i915/gem_linear_blits: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_linear_blits.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_linear_blits.c +2 -1
index 1fd5b733c3ce..d02751be9232 100644
@@ -47,6 +47,7 @@
 #include "i915/gem.h"
 #include "i915/gem_create.h"
 #include "igt.h"
+#include "igt_types.h"
 
 IGT_TEST_DESCRIPTION("Test doing many blits with a working set larger than the"
 		     " aperture size.");
@@ -236,7 +237,7 @@ igt_main
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	uint64_t count = 0;
 	bool do_relocs;
-	int fd = -1;
+	igt_fd_t(fd);
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
Signature · 1 line
2.37.2
#12 lore raw

PATCH 5/74 i915/gem_blits: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_blits.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/gem_blits.c +1 -0
index 46f157b9367a..24e83b9f512d 100644
@@ -852,5 +852,6 @@ igt_main
 
 	igt_fixture {
 		put_ahnd(device.ahnd);
+		close(device.fd);
 	}
 }
Signature · 1 line
2.37.2
#13 lore raw

PATCH 6/74 i915/gem_close: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_close.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_close.c +2 -1
index ee2d690bfb54..e1ae701c17a1 100644
@@ -24,6 +24,7 @@
 #include "i915/gem.h"
 #include "i915/gem_create.h"
 #include "igt.h"
+#include "igt_types.h"
 
 static int batch_create(int fd)
 {
@@ -125,7 +126,7 @@ static void test_many_handles(int fd)
 
 igt_main
 {
-	int fd = -1;
+	igt_fd_t(fd);
 
 	igt_fixture {
 		/* Create an flink requires DRM_AUTH */
Signature · 1 line
2.37.2
#14 lore raw

PATCH 7/74 i915/gem_create: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_create.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_create.c +2 -1
index d7d2a017223d..f3e5f15408fe 100644
@@ -54,6 +54,7 @@
 #include "intel_chipset.h"
 #include "igt_aux.h"
 #include "igt_dummyload.h"
+#include "igt_types.h"
 #include "igt_x86.h"
 #include "i915/gem.h"
 #include "i915/gem_create.h"
@@ -780,7 +781,7 @@ static void create_ext_cpu_access_big(int fd)
 
 igt_main
 {
-	int fd = -1;
+	igt_fd_t(fd);
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
Signature · 1 line
2.37.2
#15 lore raw

PATCH 8/74 i915/gem_ctx_engines: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_ctx_engines.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_ctx_engines.c +2 -1
index 4b8e51457a8f..b0646516fa6f 100644
@@ -41,6 +41,7 @@
 #include "i915/gem_context.h"
 #include "i915/gem_create.h"
 #include "igt.h"
+#include "igt_types.h"
 #include "sw_sync.h"
 
 #define engine_class(e, n) ((e)->engines[(n)].engine_class)
@@ -593,7 +594,7 @@ static void independent_all(int i915, const intel_ctx_t *ctx)
 igt_main
 {
 	const struct intel_execution_engine2 *e;
-	int i915 = -1;
+	igt_fd_t(i915);
 
 	igt_fixture {
 		i915 = drm_open_driver(DRIVER_INTEL);
Signature · 1 line
2.37.2
#16 lore raw

PATCH 9/74 i915/gem_ctx_shared: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_ctx_shared.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_ctx_shared.c +2 -1
index eb3b024f8e5b..d6b56b72abdc 100644
@@ -42,6 +42,7 @@
 #include "i915/gem_engine_topology.h"
 #include "i915/gem_vm.h"
 #include "igt.h"
+#include "igt_types.h"
 #include "igt_rand.h"
 #include "igt_vgem.h"
 #include "sw_sync.h"
@@ -987,7 +988,7 @@ igt_main
 {
 	const struct intel_execution_engine2 *e;
 	intel_ctx_cfg_t cfg;
-	int i915 = -1;
+	igt_fd_t(i915);
 
 	igt_fixture {
 		i915 = drm_open_driver(DRIVER_INTEL);
Signature · 1 line
2.37.2
#17 lore raw

PATCH 10/74 i915/gem_exec_alignment: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_exec_alignment.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_exec_alignment.c +2 -1
index 3e5f9d52cbed..a9fcd2a747d1 100644
@@ -44,6 +44,7 @@
 #include "i915/gem.h"
 #include "i915/gem_create.h"
 #include "igt.h"
+#include "igt_types.h"
 
 IGT_TEST_DESCRIPTION("Exercises the basic execbuffer using object alignments");
 
@@ -525,7 +526,7 @@ static void single(int fd)
 
 igt_main
 {
-	int fd = -1;
+	igt_fd_t(fd);
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
Signature · 1 line
2.37.2
#18 lore raw

PATCH 11/74 i915/gem_render_copy: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_render_copy.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/gem_render_copy.c +1 -0
index 3da29ec4e316..70b96c8f42ad 100644
@@ -879,5 +879,6 @@ igt_main_args("dac", NULL, help_str, opt_handler, NULL)
 		igt_stop_hang_detector();
 		buf_ops_destroy(data.bops);
 		igt_collection_destroy(set);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#19 lore raw

PATCH 12/74 i915/gem_render_copy_redux: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_render_copy_redux.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/i915/gem_render_copy_redux.c +4 -0
index 525c14d1814d..5e1daccf1801 100644
@@ -233,4 +233,8 @@ igt_main
 			copy_flink(&data);
 		igt_stop_signal_helper();
 	}
+
+	igt_fixture {
+		data_fini(&data);
+	}
 }
Signature · 1 line
2.37.2
#20 lore raw

PATCH 13/74 i915/gem_media_fill: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_media_fill.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/gem_media_fill.c +1 -0
index 1d08df2473d1..e418047c2e74 100644
@@ -173,5 +173,6 @@ igt_main
 	igt_fixture {
 		igt_collection_destroy(set);
 		igt_stop_hang_detector();
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#21 lore raw

PATCH 14/74 i915/gem_userptr_blits: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_userptr_blits.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/i915/gem_userptr_blits.c +3 -1
index 1343b1097aef..6985086694c4 100644
@@ -62,6 +62,7 @@
 #include "i915/gem_create.h"
 #include "igt.h"
 #include "igt_sysfs.h"
+#include "igt_types.h"
 #include "sw_sync.h"
 
 #include "eviction_common.c"
@@ -2299,7 +2300,7 @@ static void test_userfault(int i915)
 
 uint64_t total_ram;
 uint64_t aperture_size;
-int fd, count;
+int count;
 
 static int opt_handler(int opt, int opt_index, void *data)
 {
@@ -2319,6 +2320,7 @@ const char *help_str = "  -c\tBuffer count\n";
 igt_main_args("c:", NULL, help_str, opt_handler, NULL)
 {
 	int size = sizeof(linear);
+	igt_fd_t(fd);
 
 	igt_fixture {
 		unsigned int mmo_max = 0;
Signature · 1 line
2.37.2
#22 lore raw

PATCH 15/74 i915/gem_workarounds: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_workarounds.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_workarounds.c +2 -1
index fc5184925a88..5fb2d73fdd30 100644
@@ -31,6 +31,7 @@
 #include "i915/gem_create.h"
 #include "igt.h"
 #include "igt_device.h"
+#include "igt_types.h"
 
 #define PAGE_SIZE 4096
 #define PAGE_ALIGN(x) ALIGN(x, PAGE_SIZE)
@@ -238,7 +239,6 @@ static void check_workarounds(int fd, enum operation op, unsigned int flags)
 igt_main
 {
 	struct intel_mmio_data mmio_data;
-	int device = -1;
 	const struct {
 		const char *name;
 		enum operation op;
@@ -258,6 +258,7 @@ igt_main
 		{ "-fd", FD },
 		{ }
 	}, *m;
+	igt_fd_t(device);
 
 	igt_fixture {
 		FILE *file;
Signature · 1 line
2.37.2
#23 lore raw

PATCH 16/74 i915/gem_unref_active_buffers: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_unref_active_buffers.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/gem_unref_active_buffers.c +1 -0
index 3b8c981dae62..735c1472038a 100644
@@ -121,4 +121,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
+	close(i915);
 }
Signature · 1 line
2.37.2
#24 lore raw

PATCH 17/74 i915/gem_exec_endless: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_exec_endless.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/i915/gem_exec_endless.c +2 -1
index b83d5a2c1480..2c56cc212036 100644
@@ -28,6 +28,7 @@
 #include "igt.h"
 #include "igt_device.h"
 #include "igt_sysfs.h"
+#include "igt_types.h"
 #include "sw_sync.h"
 
 #define MAX_ENGINES 64
@@ -341,7 +342,7 @@ static void unpin_rps(int sysfs)
 igt_main
 {
 	const struct intel_execution_engine2 *e;
-	int i915 = -1;
+	igt_fd_t(i915);
 
 	igt_skip_on_simulation();
 
Signature · 1 line
2.37.2
#25 lore raw

PATCH 18/74 i915/gem_request_retire: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_request_retire.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tests/i915/gem_request_retire.c +3 -2
index da9d405ed443..9e163bd3af60 100644
@@ -48,6 +48,7 @@
 
 #include "i915/gem.h"
 #include "igt.h"
+#include "igt_types.h"
 
 IGT_TEST_DESCRIPTION("Collection of tests targeting request retirement code"
 		     " paths.");
@@ -103,10 +104,10 @@ test_retire_vma_not_inactive(int fd)
 	put_ahnd(ahnd);
 }
 
-int fd;
-
 igt_main
 {
+	igt_fd_t(fd);
+
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
 		igt_require_gem(fd);
Signature · 1 line
2.37.2
#26 lore raw

PATCH 19/74 i915/gem_unfence_active_buffers: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/gem_unfence_active_buffers.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/gem_unfence_active_buffers.c +1 -0
index 532eed2e76d4..a0a601de241d 100644
@@ -99,4 +99,5 @@ igt_simple_main
 
 	igt_spin_free(i915, spin);
 	put_ahnd(ahnd);
+	close(i915);
 }
Signature · 1 line
2.37.2
#27 lore raw

PATCH 20/74 i915/i915_pciid: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/i915_pciid.c | 2 ++
 1 file changed, 2 insertions(+)
tests/i915/i915_pciid.c +2 -0
index 7de44ff2ff1f..377eec58cf13 100644
@@ -64,4 +64,6 @@ igt_simple_main
 	int intel = drm_open_driver(DRIVER_INTEL);
 
 	igt_assert(has_known_intel_chipset(intel));
+
+	close(intel);
 }
Signature · 1 line
2.37.2
#28 lore raw

PATCH 21/74 kms_cursor_legacy: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_cursor_legacy.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_cursor_legacy.c +1 -0
index 1b69766781c4..1ad92eaae881 100644
@@ -1753,5 +1753,6 @@ igt_main
 		if (intel_psr2_restore)
 			i915_psr2_sel_fetch_restore(display.drm_fd);
 		igt_display_fini(&display);
+		close(display.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#29 lore raw

PATCH 22/74 kms_flip: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_flip.c | 3 +++
 1 file changed, 3 insertions(+)
tests/kms_flip.c +3 -0
index 0567edeaf2ab..5e82f4a2f842 100755
@@ -1877,4 +1877,7 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 			run_pair(tests[i].duration, tests[i].flags);
 	}
 	igt_stop_signal_helper();
+
+	igt_fixture
+		close(drm_fd);
 }
Signature · 1 line
2.37.2
#30 lore raw

PATCH 23/74 kms_pipe_crc_basic: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_pipe_crc_basic.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_pipe_crc_basic.c +1 -0
index 2ff40f72e23e..2985de51c33c 100644
@@ -362,5 +362,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#31 lore raw

PATCH 24/74 kms_psr: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_psr.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_psr.c +1 -0
index 480e2cc77a2b..59f38e20e55f 100644
@@ -592,5 +592,6 @@ igt_main_args("", long_options, help_str, opt_handler, &data)
 		close(data.debugfs_fd);
 		buf_ops_destroy(data.bops);
 		display_fini(&data);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#32 lore raw

PATCH 25/74 kms_flip: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_busy.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_busy.c +1 -0
index 99a07c2aecbd..171ae4ecebff 100644
@@ -436,5 +436,6 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&display);
+		close(display.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#33 lore raw

PATCH 26/74 kms_force_connector_basic: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_force_connector_basic.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tests/kms_force_connector_basic.c +6 -1
index 683d3672056d..6259cec538de 100644
@@ -33,9 +33,9 @@ IGT_TEST_DESCRIPTION("Check the debugfs force connector/edid features work"
 
 static void reset_connectors(void)
 {
-	int drm_fd = 0;
 	drmModeRes *res;
 	drmModeConnector *connector = NULL;
+	int drm_fd;
 
 	drm_fd = drm_open_driver_master(DRIVER_ANY);
 	res = drmModeGetResources(drm_fd);
@@ -54,6 +54,8 @@ static void reset_connectors(void)
 	}
 
 	igt_set_module_param_int(drm_fd, "load_detect_test", 0);
+
+	close(drm_fd);
 }
 
 static int opt_handler(int opt, int opt_index, void *data)
@@ -224,6 +226,9 @@ igt_main_args("", long_opts, help_str, opt_handler, NULL)
 
 			drmModeFreePlane(drm_plane);
 		}
+
+		igt_remove_fb(drm_fd, &xrgb_fb);
+		igt_remove_fb(drm_fd, &argb_fb);
 	}
 
 	igt_describe("Test to check the forced connector state.");
Signature · 1 line
2.37.2
#34 lore raw

PATCH 27/74 dumb_buffer: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/dumb_buffer.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/dumb_buffer.c +4 -0
index 2c6261bd7d75..ded6b809c262 100644
@@ -392,4 +392,8 @@ igt_main
 
 	igt_subtest("create-clear")
 		always_clear(fd, 30);
+
+	igt_fixture {
+		close(fd);
+	}
 }
Signature · 1 line
2.37.2
#35 lore raw

PATCH 28/74 kms_atomic: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_atomic.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_atomic.c +1 -0
index 253829f2bd14..831ba2587292 100644
@@ -1436,5 +1436,6 @@ igt_main
 		igt_remove_fb(display.drm_fd, &fb);
 
 		igt_display_fini(&display);
+		close(display.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#36 lore raw

PATCH 29/74 kms_atomic_interruptible: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_atomic_interruptible.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_atomic_interruptible.c +1 -0
index 038cb2867989..f461a15c9f4c 100644
@@ -349,5 +349,6 @@ igt_main
 	/* TODO: legacy gamma_set/get, object set/getprop, getcrtc, getconnector */
 	igt_fixture {
 		igt_display_fini(&display);
+		close(display.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#37 lore raw

PATCH 30/74 kms_atomic_transition: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_atomic_transition.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_atomic_transition.c +1 -0
index 10b21c929e3b..05c76ebbce9f 100644
@@ -1231,5 +1231,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#38 lore raw

PATCH 31/74 i915/kms_big_fb: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_big_fb.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_big_fb.c +1 -0
index 0c4cd95e7c96..8c7a38160f85 100644
@@ -991,5 +991,6 @@ igt_main
 	igt_fixture {
 		igt_display_fini(&data.display);
 		buf_ops_destroy(data.bops);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#39 lore raw

PATCH 32/74 i915/kms_ccs: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_ccs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/i915/kms_ccs.c +3 -1
index 4df611f77e0c..6721da493af5 100644
@@ -699,6 +699,8 @@ igt_main_args("cs:", NULL, help_str, opt_handler, &data)
 		}
 	}
 
-	igt_fixture
+	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
+	}
 }
Signature · 1 line
2.37.2
#40 lore raw

PATCH 33/74 kms_color: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_color.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_color.c +1 -0
index c202547e59ea..69c180c119df 100644
@@ -1058,5 +1058,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#41 lore raw

PATCH 34/74 kms_cursor_crc: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_cursor_crc.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_cursor_crc.c +1 -0
index 14d4c4ca86c8..1b14d6c205b3 100644
@@ -897,5 +897,6 @@ igt_main
 		}
 
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#42 lore raw

PATCH 35/74 i915/kms_big_joiner: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_big_joiner.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_big_joiner.c +1 -0
index 7d400616f7b5..71b2526d683c 100644
@@ -328,5 +328,6 @@ igt_main
 	igt_fixture {
 		igt_remove_fb(data.drm_fd, &data.fb);
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#43 lore raw

PATCH 36/74 i915/kms_cdclk: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_cdclk.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_cdclk.c +1 -0
index 002b631c4b7e..991a7c507a10 100644
@@ -373,5 +373,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#44 lore raw

PATCH 37/74 i915/kms_fence_pin_leak: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_fence_pin_leak.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_fence_pin_leak.c +1 -0
index 16eb595fd65d..f1eac1c600ad 100644
@@ -229,4 +229,5 @@ igt_simple_main
 
 	buf_ops_destroy(data.bops);
 	igt_display_fini(&data.display);
+	close(data.drm_fd);
 }
Signature · 1 line
2.37.2
#45 lore raw

PATCH 38/74 i915/kms_flip_scaled_crc: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_flip_scaled_crc.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_flip_scaled_crc.c +1 -0
index 764eb70fde31..364f622ba699 100644
@@ -676,5 +676,6 @@ igt_main
 		}
 		kmstest_set_vt_text_mode();
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#46 lore raw

PATCH 39/74 i915/kms_flip_tiling: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_flip_tiling.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_flip_tiling.c +1 -0
index ba9ff46ed150..0d8cc341c0b9 100644
@@ -229,5 +229,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#47 lore raw

PATCH 40/74 i915/kms_mmap_write_crc: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_mmap_write_crc.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_mmap_write_crc.c +1 -0
index a57938b5b8ff..b693c276b2c3 100644
@@ -299,5 +299,6 @@ igt_main_args("n", NULL, NULL, opt_handler, NULL)
 		close(data.drm_fd);
 
 		igt_stop_helper(&hog);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#48 lore raw

PATCH 41/74 i915/kms_pipe_b_c_ivb: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_pipe_b_c_ivb.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_pipe_b_c_ivb.c +1 -0
index 5823ae2a0885..05ac87702077 100644
@@ -291,5 +291,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#49 lore raw

PATCH 42/74 i915/kms_psr2_sf: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_psr2_sf.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_psr2_sf.c +1 -0
index 6612587c6b24..c9e6f2d0862b 100644
@@ -1034,5 +1034,6 @@ igt_main
 	igt_fixture {
 		close(data.debugfs_fd);
 		display_fini(&data);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#50 lore raw

PATCH 43/74 i915/kms_psr2_su: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_psr2_su.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_psr2_su.c +1 -0
index caccf713d86e..6062f9d87186 100644
@@ -335,5 +335,6 @@ igt_main
 	igt_fixture {
 		close(data.debugfs_fd);
 		display_fini(&data);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#51 lore raw

PATCH 44/74 i915/kms_pwrite_crc: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/kms_pwrite_crc.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/kms_pwrite_crc.c +1 -0
index 584e6a19ce9d..7df4b36924fa 100644
@@ -191,4 +191,5 @@ igt_simple_main
 	run_test(&data);
 
 	igt_display_fini(&data.display);
+	close(data.drm_fd);
 }
Signature · 1 line
2.37.2
#52 lore raw

PATCH 45/74 kms_flip_event_leak: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_flip_event_leak.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_flip_event_leak.c +1 -0
index ac201293b334..b3d01aeb24e1 100644
@@ -109,4 +109,5 @@ igt_simple_main
 	igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
 
 	igt_display_fini(&data.display);
+	close(data.drm_fd);
 }
Signature · 1 line
2.37.2
#53 lore raw

PATCH 46/74 kms_hdr: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_hdr.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_hdr.c +1 -0
index e2650f51331f..c18acb60f99e 100644
@@ -615,5 +615,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.fd);
 	}
 }
Signature · 1 line
2.37.2
#54 lore raw

PATCH 47/74 kms_invalid_mode: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_invalid_mode.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_invalid_mode.c +1 -0
index 0ae98a31fcc2..f1c38669860d 100644
@@ -306,5 +306,6 @@ igt_main
 	igt_fixture {
 		igt_display_fini(&data.display);
 		igt_reset_connectors();
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#55 lore raw

PATCH 48/74 kms_lease: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_lease.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/kms_lease.c +4 -0
index 0bf102a6d8f1..4122b0d19a3c 100644
@@ -1287,4 +1287,8 @@ igt_main
 	igt_describe("Tests all the uevent cases");
 	igt_subtest("lease-uevent")
 		lease_uevent(&data);
+
+	igt_fixture {
+		close(data.master.fd);
+	}
 }
Signature · 1 line
2.37.2
#56 lore raw

PATCH 49/74 kms_panel_fitting: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_panel_fitting.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/kms_panel_fitting.c +3 -1
index 478c16bd5f37..2d0590da2ec6 100644
@@ -280,6 +280,8 @@ igt_main
 	igt_subtest_with_dynamic("atomic-fastset")
 		test_panel_fitting(&data, TEST_ATOMIC);
 
-	igt_fixture
+	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
+	}
 }
Signature · 1 line
2.37.2
#57 lore raw

PATCH 50/74 kms_plane: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_plane.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_plane.c +1 -0
index 3cf3cfd3a095..eb943e13f408 100644
@@ -1213,5 +1213,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#58 lore raw

PATCH 51/74 kms_plane_alpha_blend: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_plane_alpha_blend.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_plane_alpha_blend.c +1 -0
index bd064d1e494b..f8660f14e94d 100644
@@ -586,5 +586,6 @@ igt_main
 				    COMMIT_ATOMIC : COMMIT_LEGACY);
 
 		igt_display_fini(&data.display);
+		close(data.gfx_fd);
 	}
 }
Signature · 1 line
2.37.2
#59 lore raw

PATCH 52/74 kms_plane_cursor: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_plane_cursor.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_plane_cursor.c +1 -0
index 73085cc84814..87d5aff5ddf1 100644
@@ -344,5 +344,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#60 lore raw

PATCH 53/74 kms_plane_multiple: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_plane_multiple.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_plane_multiple.c +1 -0
index 1679f7ce12ba..31396da2d0cb 100644
@@ -468,5 +468,6 @@ igt_main_args("", long_options, help_str, opt_handler, NULL)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#61 lore raw

PATCH 54/74 kms_plane_scaling: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_plane_scaling.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/kms_plane_scaling.c +3 -1
index fc8250b5053c..4c621cce8425 100644
@@ -983,6 +983,8 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 	igt_subtest_f("2x-scaler-multi-pipe")
 		test_scaler_with_multi_pipe_plane(&data);
 
-	igt_fixture
+	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
+	}
 }
Signature · 1 line
2.37.2
#62 lore raw

PATCH 55/74 kms_properties: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_properties.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_properties.c +1 -0
index dd5a93aa7a77..2958efaca7ab 100644
@@ -792,5 +792,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&display);
+		close(display.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#63 lore raw

PATCH 56/74 kms_rotation_crc: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_rotation_crc.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_rotation_crc.c +1 -0
index 50869a08a275..db53f5d144ea 100644
@@ -1187,5 +1187,6 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.gfx_fd);
 	}
 }
Signature · 1 line
2.37.2
#64 lore raw

PATCH 57/74 kms_sequence: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_sequence.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/kms_sequence.c +4 -0
index 1655d7d1bc7d..c72857a394c7 100644
@@ -295,4 +295,8 @@ igt_main
 			}
 		}
 	}
+
+	igt_fixture {
+		close(fd);
+	}
 }
Signature · 1 line
2.37.2
#65 lore raw

PATCH 58/74 kms_universal_plane: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_universal_plane.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_universal_plane.c +1 -0
index 3cb6d704a6ef..e23f0f718cd2 100644
@@ -817,5 +817,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#66 lore raw

PATCH 59/74 kms_vblank: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_vblank.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/kms_vblank.c +4 -0
index e65e8522a861..5bd3fefe1440 100644
@@ -550,4 +550,8 @@ igt_main
 	for_each_pipe_static(data.pipe)
 		igt_subtest_group
 			run_subtests_for_pipe(&data);
+
+	igt_fixture {
+		close(fd);
+	}
 }
Signature · 1 line
2.37.2
#67 lore raw

PATCH 60/74 syncobj_wait: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/syncobj_wait.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/syncobj_wait.c +4 -0
index 669d0adfc10d..427b6b1192ad 100644
@@ -912,4 +912,8 @@ igt_main
 
 	igt_subtest("wait-all-interrupted")
 		test_wait_interrupted(fd, WAIT_ALL);
+
+	igt_fixture {
+		close(fd);
+	}
 }
Signature · 1 line
2.37.2
#68 lore raw

PATCH 61/74 syncobj_basic: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/syncobj_basic.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/syncobj_basic.c +4 -0
index 1dce45c918ac..6e20c3411a87 100644
@@ -231,4 +231,8 @@ igt_main
 	igt_subtest("test-valid-cycle")
 		test_valid_cycle(fd);
 
+	igt_fixture {
+		close(fd);
+	}
+
 }
Signature · 1 line
2.37.2
#69 lore raw

PATCH 62/74 syncobj_timeline: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/syncobj_timeline.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/syncobj_timeline.c +4 -0
index 20375cdd38dc..7f5ff6f6cad6 100644
@@ -1536,4 +1536,8 @@ igt_main
 	igt_describe(test_32bits_limit_desc);
 	igt_subtest("32bits-limit")
 		test_32bits_limit(fd);
+
+	igt_fixture {
+		close(fd);
+	}
 }
Signature · 1 line
2.37.2
#70 lore raw

PATCH 63/74 drm_import_export: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/drm_import_export.c | 5 +++++
 1 file changed, 5 insertions(+)
tests/drm_import_export.c +5 -0
index 06245e8bac9f..2dd2f3cb9fff 100644
@@ -296,4 +296,9 @@ igt_main {
 		pthread_join(test_thread_id3, NULL);
 		pthread_join(test_thread_id4, NULL);
 	}
+
+	igt_fixture {
+		close(fd);
+		close(fd1);
+	}
 }
Signature · 1 line
2.37.2
#71 lore raw

PATCH 64/74 kms_dp_aux_dev: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_dp_aux_dev.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_dp_aux_dev.c +1 -0
index d3249fa3d68d..ed9dd510cea6 100644
@@ -134,4 +134,5 @@ igt_simple_main
 	igt_require(valid_connectors);
 
 	drmModeFreeResources(res);
+	close(drm_fd);
 }
Signature · 1 line
2.37.2
#72 lore raw

PATCH 65/74 kms_hdmi_inject: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_hdmi_inject.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_hdmi_inject.c +1 -0
index abae0ab44feb..b6418faf0eaf 100644
@@ -219,5 +219,6 @@ igt_main
 
 	igt_fixture {
 		drmModeFreeConnector(connector);
+		close(drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#73 lore raw

PATCH 66/74 kms_3d: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_3d.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_3d.c +1 -0
index 1488cc146728..c6bef67c1c0f 100644
@@ -111,4 +111,5 @@ igt_simple_main
 	kmstest_force_edid(drm_fd, connector, NULL);
 
 	drmModeFreeConnector(connector);
+	close(drm_fd);
 }
Signature · 1 line
2.37.2
#74 lore raw

PATCH 67/74 kms_scaling_modes: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_scaling_modes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/kms_scaling_modes.c +3 -1
index 8e80189ac6bb..039e4a8d9303 100644
@@ -132,6 +132,8 @@ igt_main
 	igt_subtest_with_dynamic("scaling-mode-none")
 		test_scaling_mode(&data, DRM_MODE_SCALE_NONE);
 
-	igt_fixture
+	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
+	}
 }
Signature · 1 line
2.37.2
#75 lore raw

PATCH 68/74 kms_dither: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_dither.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_dither.c +1 -0
index 43a25e203ef4..95be6e136c61 100644
@@ -247,5 +247,6 @@ igt_main
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#76 lore raw

PATCH 69/74 drm_read: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/drm_read.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/drm_read.c +3 -1
index 4a966a23b550..36dc623ede13 100644
@@ -46,6 +46,8 @@
 #include <pthread.h>
 #include "drm.h"
 
+#include "igt_types.h"
+
 IGT_TEST_DESCRIPTION("Call read(drm) and see if it behaves.");
 
 static void sighandler(int sig, siginfo_t * info, void *context)
@@ -253,10 +255,10 @@ static void test_short_buffer_wakeup(int in, enum pipe pipe)
 
 igt_main
 {
-	int fd;
 	igt_display_t display;
 	struct igt_fb fb;
 	enum pipe pipe;
+	igt_fd_t(fd);
 
 	igt_fixture {
 		struct sigaction alarm_action = {};
Signature · 1 line
2.37.2
#77 lore raw

PATCH 70/74 kms_cursor_edge_walk: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_cursor_edge_walk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/kms_cursor_edge_walk.c +3 -1
index b75fc216f9f2..74187613276e 100644
@@ -362,6 +362,8 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 		}
 	}
 
-	igt_fixture
+	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
+	}
 }
Signature · 1 line
2.37.2
#78 lore raw

PATCH 71/74 kms_plane_lowres: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_plane_lowres.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/kms_plane_lowres.c +3 -1
index f37dbd16ac03..bb6cffac0911 100644
@@ -334,6 +334,8 @@ igt_main
 			run_test(&data, subtests[i].modifier);
 	}
 
-	igt_fixture
+	igt_fixture {
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
+	}
 }
Signature · 1 line
2.37.2
#79 lore raw

PATCH 72/74 kms_content_protection: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/kms_content_protection.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_content_protection.c +1 -0
index 3041f1cddf8b..095cc94b446b 100644
@@ -839,5 +839,6 @@ igt_main
 	igt_fixture {
 		test_content_protection_cleanup();
 		igt_display_fini(&data.display);
+		close(data.drm_fd);
 	}
 }
Signature · 1 line
2.37.2
#80 lore raw

PATCH 73/74 feature_discovery: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/feature_discovery.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tests/feature_discovery.c +3 -2
index 1978ce890de2..d369812ae614 100644
@@ -29,15 +29,16 @@
 #include "igt_kms.h"
 #include "igt_psr.h"
 #include "igt_sysfs.h"
+#include "igt_types.h"
 
-static int fd;
-static int debugfs_fd;
 static igt_display_t display;
 
 IGT_TEST_DESCRIPTION("A metatest that checks for \"features\" presence. "
 		     "The subtests here should only skip or pass, "
 		     "anything else means we have a serious problem.");
 igt_main {
+	igt_fd_t(debugfs_fd);
+	igt_fd_t(fd);
 
 	igt_fixture {
 		fd = drm_open_driver_master(DRIVER_ANY);
Signature · 1 line
2.37.2
#81 lore raw

PATCH 74/74 i915/i915_pm_dc: Close device before exit

In reply to Mauro Carvalho Chehab

From: Chris Wilson <[email protected]>

Close the device fd before we check for leaks during the atexit handlers.

---
 tests/i915/i915_pm_dc.c | 1 +
 1 file changed, 1 insertion(+)
tests/i915/i915_pm_dc.c +1 -0
index f664a2a2c14b..c7090f589de2 100644
@@ -552,6 +552,7 @@ int main(int argc, char *argv[])
 		close(data.debugfs_fd);
 		close(data.msr_fd);
 		display_fini(&data);
+		close(data.drm_fd);
 	}
 
 	igt_exit();
Signature · 1 line
2.37.2