[1/2] igt/gem_fd_exhaustion: Actually test error handling on fd exhaustion

Submitted by Karol Krol on Feb. 27, 2018, 2:30 p.m.

Details

Message ID 20180227143044.10497-1-karol.krol@intel.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Karol Krol Feb. 27, 2018, 2:30 p.m.
Long time ago, there was an issue with driver crashing due to lack of
error handling on struct file creation (gem_create()). We're unable to hit
this scenario, because dup() does not creat flip. Let's replace dup() with
open() and assert that error is returned on exhaustion.

Signed-off-by: Karol Krol <karol.krol@intel.com>
---
 tests/gem_fd_exhaustion.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/tests/gem_fd_exhaustion.c b/tests/gem_fd_exhaustion.c
index 0969f9c6..6750444e 100644
--- a/tests/gem_fd_exhaustion.c
+++ b/tests/gem_fd_exhaustion.c
@@ -65,7 +65,7 @@  igt_simple_main
 		igt_drop_root();
 
 		for (int i = 0; ; i++) {
-			int leak = dup(fd);
+			int leak = open("/dev/null", O_RDONLY);
 			uint32_t handle;
 
 			if (__gem_create(fd, 4096, &handle) == 0)
@@ -73,6 +73,8 @@  igt_simple_main
 
 			if (leak < 0) {
 				igt_info("fd exhaustion after %i rounds.\n", i);
+				igt_assert(__gem_create(fd, 4096,
+							&handle) == -ENFILE);
 				break;
 			}
 		}

Comments

Chris Wilson Feb. 27, 2018, 2:41 p.m.
Quoting Karol Krol (2018-02-27 14:30:43)
> Long time ago, there was an issue with driver crashing due to lack of
> error handling on struct file creation (gem_create()). We're unable to hit
> this scenario, because dup() does not creat flip. Let's replace dup() with
> open() and assert that error is returned on exhaustion.
> 
> Signed-off-by: Karol Krol <karol.krol@intel.com>
> ---
>  tests/gem_fd_exhaustion.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/gem_fd_exhaustion.c b/tests/gem_fd_exhaustion.c
> index 0969f9c6..6750444e 100644
> --- a/tests/gem_fd_exhaustion.c
> +++ b/tests/gem_fd_exhaustion.c
> @@ -65,7 +65,7 @@ igt_simple_main
>                 igt_drop_root();
>  
>                 for (int i = 0; ; i++) {
> -                       int leak = dup(fd);
> +                       int leak = open("/dev/null", O_RDONLY);
>                         uint32_t handle;
>  
>                         if (__gem_create(fd, 4096, &handle) == 0)
> @@ -73,6 +73,8 @@ igt_simple_main
>  
>                         if (leak < 0) {
>                                 igt_info("fd exhaustion after %i rounds.\n", i);
> +                               igt_assert(__gem_create(fd, 4096,
> +                                                       &handle) == -ENFILE);

No. It can fail for a variety of reasons (ENOMEM is an easy one), so you
cannot mandate it always fails with ENFILE.
-Chris