[igt-dev] [PATCH i-g-t 2/2] runner: Add a unit test that checks for fd leaks

Petri Latvala petri.latvala at intel.com
Tue Oct 2 07:45:42 UTC 2018


Pretty much needed, as proven.

Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
---
 runner/runner_tests.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/runner/runner_tests.c b/runner/runner_tests.c
index 3705d711..37d27123 100644
--- a/runner/runner_tests.c
+++ b/runner/runner_tests.c
@@ -1003,6 +1003,24 @@ igt_main
 		}
 	}
 
+	igt_subtest("file-descriptor-leakage") {
+		int i;
+
+		/*
+		 * This is a build-time test, and it's expected that
+		 * all subtests are normally run. Keep this one at the
+		 * end.
+		 *
+		 * Try to close some number of fds after stderr and
+		 * expect EBADF for each one.
+		 */
+		for (i = 3; i < 400; i++) {
+			errno = 0;
+			igt_assert_neq(close(i), 0);
+			igt_assert_eq(errno, EBADF);
+		}
+	}
+
 	igt_fixture
 		free_settings(&settings);
 }
-- 
2.18.0



More information about the igt-dev mailing list