[PATCH i-g-t 1/2] lib: Add support for test child safe exit handlers

Janusz Krzysztofik janusz.krzysztofik at linux.intel.com
Thu Jun 6 14:28:59 UTC 2019


Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik at linux.intel.com>
---
 lib/igt_core.c | 37 ++++++++++++++++++++++++++++++++-----
 lib/igt_core.h |  2 ++
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 9c86d664..4025f3ee 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -1763,7 +1763,6 @@ bool __igt_fork(void)
 		igt_assert(0);
 	case 0:
 		test_child = true;
-		exit_handler_count = 0;
 		reset_helper_process_list();
 		oom_adjust_for_doom();
 		igt_unshare_spins();
@@ -1893,7 +1892,11 @@ static struct {
 	bool installed;
 } orig_sig[MAX_SIGNALS];
 
-static igt_exit_handler_t exit_handler_fn[MAX_EXIT_HANDLERS];
+static struct {
+	igt_exit_handler_t fn;
+	bool child_safe;
+} exit_handler[MAX_EXIT_HANDLERS];
+
 static bool exit_handler_disabled;
 static const struct {
 	int number;
@@ -1956,7 +1959,9 @@ static void call_exit_handlers(int sig)
 	}
 
 	for (i = exit_handler_count - 1; i >= 0; i--)
-		exit_handler_fn[i](sig);
+		if (!test_child || exit_handler[i].child_safe) {
+			exit_handler[i].fn(sig);
+		}
 
 	/* ensure we don't get called twice */
 	exit_handler_count = 0;
@@ -2060,12 +2065,13 @@ void igt_install_exit_handler(igt_exit_handler_t fn)
 	int i;
 
 	for (i = 0; i < exit_handler_count; i++)
-		if (exit_handler_fn[i] == fn)
+		if (exit_handler[i].fn == fn)
 			return;
 
 	igt_assert(exit_handler_count < MAX_EXIT_HANDLERS);
 
-	exit_handler_fn[exit_handler_count] = fn;
+	exit_handler[exit_handler_count].fn = fn;
+	exit_handler[exit_handler_count].child_safe = test_child;
 	exit_handler_count++;
 
 	if (exit_handler_count > 1)
@@ -2088,6 +2094,27 @@ err:
 	igt_assert_f(0, "failed to install the signal handler\n");
 }
 
+/**
+ * igt_set_exit_handler_child_safe:
+ * @fn: exit handler function
+ *
+ * Mark an already installed exit handler function as safe to be called
+ * from a test child.
+ */
+void igt_set_exit_handler_child_safe(igt_exit_handler_t fn)
+{
+	int i;
+
+	for (i = 0; i < exit_handler_count; i++)
+		if (exit_handler[i].fn == fn)
+			break;
+
+	igt_assert(i < exit_handler_count);
+
+	igt_debug("marking exit handler #%d child safe\n", i);
+	exit_handler[i].child_safe = true;
+}
+
 /* simulation enviroment support */
 
 /**
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 88a95ec2..0fc09f06 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -782,6 +782,7 @@ static inline void igt_ignore_warn(bool value)
 } while (0)
 
 /* fork support code */
+extern bool test_child;
 bool __igt_fork(void);
 
 /**
@@ -861,6 +862,7 @@ typedef void (*igt_exit_handler_t)(int sig);
 
 /* reliable atexit helpers, also work when killed by a signal (if possible) */
 void igt_install_exit_handler(igt_exit_handler_t fn);
+void igt_set_exit_handler_child_safe(igt_exit_handler_t fn);
 
 /* helpers to automatically reduce test runtime in simulation */
 bool igt_run_in_simulation(void);
-- 
2.21.0



More information about the Intel-gfx-trybot mailing list