All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t 1/5] lib/igt_kms: Don't disable exit handlers around set_vt_mode
@ 2016-02-18 12:39 Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 2/5] tests/kms_mmap_write_crc: Use the right fork helpers Daniel Vetter
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Daniel Vetter @ 2016-02-18 12:39 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Daniel Vetter

This was originally added to work around a race, but then that's
broken now. And set_vt_mode generally never results in a test binary
crash, so overkill.

I want to get rid of this interface since I spotted some abuse.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 lib/igt_kms.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 90c8da7a3772..b483662f792a 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -351,9 +351,7 @@ void kmstest_set_vt_graphics_mode(void)
 
 	igt_install_exit_handler((igt_exit_handler_t) kmstest_restore_vt_mode);
 
-	igt_disable_exit_handler();
 	ret = set_vt_mode(KD_GRAPHICS);
-	igt_enable_exit_handler();
 
 	igt_assert(ret >= 0);
 	orig_vt_mode = ret;
-- 
2.7.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH i-g-t 2/5] tests/kms_mmap_write_crc: Use the right fork helpers
  2016-02-18 12:39 [PATCH i-g-t 1/5] lib/igt_kms: Don't disable exit handlers around set_vt_mode Daniel Vetter
@ 2016-02-18 12:39 ` Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 3/5] gitignore: Add .dirstamp Daniel Vetter
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Vetter @ 2016-02-18 12:39 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Daniel Vetter

For a background task the fork helpers are more appropriate, since we
can explicitly cancel children. Also, anything that does real work is
supposed to be in fixtures.

Cc: Tiago Vignatti <tiago.vignatti@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>

--
Tiago, can you pls check that I haven't broken anythig?

Thanks, Daniel
---
 tests/kms_mmap_write_crc.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/tests/kms_mmap_write_crc.c b/tests/kms_mmap_write_crc.c
index 6984bbd1f000..2e9a282d4293 100644
--- a/tests/kms_mmap_write_crc.c
+++ b/tests/kms_mmap_write_crc.c
@@ -243,6 +243,8 @@ static void run_test(data_t *data)
 	igt_skip("no valid crtc/connector combinations found\n");
 }
 
+struct igt_helper_process hog;
+
 /**
  * fork_cpuhog_helper:
  *
@@ -250,15 +252,9 @@ static void run_test(data_t *data)
  * fill the CPU caches with random information so they can get stalled,
  * provoking incoherency with the GPU most likely.
  */
-static void fork_cpuhog_helper(void) {
-
-	/* TODO: if the parent is about to die before its child, e.g.
-	 * igt_assert_crc_equal() fails, there will be a boring exit handler
-	 * waiting the child to exit also. A workaround is to simply disable that
-	 * handler, buy this needs to be fixed properly in an elegant way. */
-	igt_disable_exit_handler();
-
-	igt_fork(hog, 1) {
+static void fork_cpuhog_helper(void)
+{
+	igt_fork_helper(&hog) {
 		while (1) {
 			usleep(10); /* quite ramdom really. */
 
@@ -297,16 +293,19 @@ int main(int argc, char **argv)
 		igt_require_pipe_crc();
 
 		igt_display_init(&data.display, data.drm_fd);
+
+		fork_cpuhog_helper();
 	}
 
 	igt_info("Using %d rounds for the test\n", ROUNDS);
-	fork_cpuhog_helper();
 
 	for (i = 0; i < ROUNDS; i++)
 		run_test(&data);
 
 	igt_fixture {
 		igt_display_fini(&data.display);
+
+		igt_stop_helper(&hog);
 	}
 
 	igt_exit();
-- 
2.7.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH i-g-t 3/5] gitignore: Add .dirstamp
  2016-02-18 12:39 [PATCH i-g-t 1/5] lib/igt_kms: Don't disable exit handlers around set_vt_mode Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 2/5] tests/kms_mmap_write_crc: Use the right fork helpers Daniel Vetter
@ 2016-02-18 12:39 ` Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 4/5] lib/igt_core: remove igt_disable/enable_exit_handlers Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 5/5] lib: Unit test for exit handler Daniel Vetter
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Vetter @ 2016-02-18 12:39 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Daniel Vetter

autofu apparently adds these files for non-recoursive make. Fallout
from the uwildmat addition.

While at it also exclude stuff generated by make distcheck

Cc: Derek Morton <derek.j.morton@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 .gitignore | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index a438c1c58a07..6204965a0e32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -80,6 +80,7 @@ core
 #
 *.swo
 *.swp
+*.dirstamp
 cscope.*
 TAGS
 build-aux/
@@ -88,5 +89,7 @@ __pycache__
 gtk-doc.make
 gtk-doc.m4
 
+intel-gpu-tools-*/
+
 piglit
 results
-- 
2.7.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH i-g-t 4/5] lib/igt_core: remove igt_disable/enable_exit_handlers
  2016-02-18 12:39 [PATCH i-g-t 1/5] lib/igt_kms: Don't disable exit handlers around set_vt_mode Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 2/5] tests/kms_mmap_write_crc: Use the right fork helpers Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 3/5] gitignore: Add .dirstamp Daniel Vetter
@ 2016-02-18 12:39 ` Daniel Vetter
  2016-02-18 12:39 ` [PATCH i-g-t 5/5] lib: Unit test for exit handler Daniel Vetter
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Vetter @ 2016-02-18 12:39 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Daniel Vetter

No longer needed, and also not really a safe idea.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 lib/igt_core.c | 45 ---------------------------------------------
 lib/igt_core.h |  2 --
 2 files changed, 47 deletions(-)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 8e0bd2e87ecd..26ef0cc8edbf 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -1590,51 +1590,6 @@ err:
 	igt_assert_f(0, "failed to install the signal handler\n");
 }
 
-/**
- * igt_disable_exit_handler:
- *
- * Temporarily disable all exit handlers. Useful for library code doing tricky
- * things.
- */
-void igt_disable_exit_handler(void)
-{
-	sigset_t set;
-	int i;
-
-	if (exit_handler_disabled)
-		return;
-
-	sigemptyset(&set);
-	for (i = 0; i < ARRAY_SIZE(handled_signals); i++)
-		sigaddset(&set, handled_signals[i].number);
-
-	if (sigprocmask(SIG_BLOCK, &set, &saved_sig_mask)) {
-		perror("sigprocmask");
-		return;
-	}
-
-	exit_handler_disabled = true;
-}
-
-/**
- * igt_enable_exit_handler:
- *
- * Re-enable all exit handlers temporarily disabled with
- * igt_disable_exit_handler().
- */
-void igt_enable_exit_handler(void)
-{
-	if (!exit_handler_disabled)
-		return;
-
-	if (sigprocmask(SIG_SETMASK, &saved_sig_mask, NULL)) {
-		perror("sigprocmask");
-		return;
-	}
-
-	exit_handler_disabled = false;
-}
-
 /* simulation enviroment support */
 
 /**
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 8f297e06a068..b3ecb0545916 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -666,8 +666,6 @@ 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_enable_exit_handler(void);
-void igt_disable_exit_handler(void);
 
 /* helpers to automatically reduce test runtime in simulation */
 bool igt_run_in_simulation(void);
-- 
2.7.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH i-g-t 5/5] lib: Unit test for exit handler
  2016-02-18 12:39 [PATCH i-g-t 1/5] lib/igt_kms: Don't disable exit handlers around set_vt_mode Daniel Vetter
                   ` (2 preceding siblings ...)
  2016-02-18 12:39 ` [PATCH i-g-t 4/5] lib/igt_core: remove igt_disable/enable_exit_handlers Daniel Vetter
@ 2016-02-18 12:39 ` Daniel Vetter
  3 siblings, 0 replies; 5+ messages in thread
From: Daniel Vetter @ 2016-02-18 12:39 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Daniel Vetter

Checks that
- exit handlers are run only once, even when registered multiple
  times.
- run in reverse order
- actually run for all ways a test could exit.

This is prep work to extend exit handlers to also work in a subtest
aware way.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 lib/tests/.gitignore         |   1 +
 lib/tests/Makefile.sources   |   1 +
 lib/tests/igt_exit_handler.c | 128 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 lib/tests/igt_exit_handler.c

diff --git a/lib/tests/.gitignore b/lib/tests/.gitignore
index a4f10805a304..661386a38dc8 100644
--- a/lib/tests/.gitignore
+++ b/lib/tests/.gitignore
@@ -1,6 +1,7 @@
 # Please keep sorted alphabetically
 igt_assert
 igt_fork_helper
+igt_exit_handler
 igt_invalid_subtest_name
 igt_list_only
 igt_no_exit
diff --git a/lib/tests/Makefile.sources b/lib/tests/Makefile.sources
index 777b9c19b9f3..09baeb127d22 100644
--- a/lib/tests/Makefile.sources
+++ b/lib/tests/Makefile.sources
@@ -11,6 +11,7 @@ check_PROGRAMS = \
 	igt_invalid_subtest_name \
 	igt_segfault \
 	igt_assert \
+	igt_exit_handler \
 	$(NULL)
 
 check_SCRIPTS = \
diff --git a/lib/tests/igt_exit_handler.c b/lib/tests/igt_exit_handler.c
new file mode 100644
index 000000000000..d1b5a8891739
--- /dev/null
+++ b/lib/tests/igt_exit_handler.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "igt_core.h"
+
+int test;
+int pipes[2];
+
+static void exit_handler1(int sig)
+{
+	assert(test == 1);
+	test++;
+}
+
+static void exit_handler2(int sig)
+{
+	char tmp = 1;
+
+	/* ensure exit handlers are called in reverse */
+	assert(test == 0);
+	test++;
+
+	/* we need to get a side effect to the parent to make sure exit handlers
+	 * actually run. */
+	assert(write(pipes[1], &tmp, 1) == 1);
+}
+
+enum test_type {
+	SUC,
+	NORMAL,
+	FAIL,
+	SKIP,
+	SIG
+};
+
+static int testfunc(enum test_type test_type)
+{
+	char prog[] = "igt_no_exit";
+	char *fake_argv[] = {prog};
+	int fake_argc = 1;
+	pid_t pid;
+	int status;
+	char tmp = 0;
+
+	assert(pipe2(pipes, O_NONBLOCK) == 0);
+
+	pid = fork();
+
+	if (pid == 0) {
+		igt_subtest_init(fake_argc, fake_argv);
+
+		igt_fixture {
+			/* register twice, should only be called once */
+			igt_install_exit_handler(exit_handler1);
+			igt_install_exit_handler(exit_handler1);
+
+			igt_install_exit_handler(exit_handler2);
+		}
+
+		igt_subtest("subtest") {
+			switch (test_type) {
+			case SUC:
+				igt_success();
+			case FAIL:
+				igt_fail(1);
+			case SKIP:
+				igt_skip("skip");
+			case NORMAL:
+				break;
+			case SIG:
+				raise(SIGTERM);
+			}
+		}
+
+		igt_exit();
+	}
+
+	assert(waitpid(pid, &status, 0) != -1);
+
+	assert(read(pipes[0], &tmp, 1) == 1);
+	assert(tmp == 1);
+
+	return status;
+}
+
+int main(int argc, char **argv)
+{
+	int status;
+
+	assert(testfunc(SUC) == 0);
+
+	assert(testfunc(NORMAL) == 0);
+
+	status = testfunc(FAIL);
+	assert(WIFEXITED(status) && WEXITSTATUS(status) == 1);
+
+	status = testfunc(SKIP);
+	assert(WIFEXITED(status) && WEXITSTATUS(status) == IGT_EXIT_SKIP);
+
+	status = testfunc(SIG);
+	assert(WIFSIGNALED(status) && WTERMSIG(status) == SIGTERM);
+}
-- 
2.7.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-18 12:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-18 12:39 [PATCH i-g-t 1/5] lib/igt_kms: Don't disable exit handlers around set_vt_mode Daniel Vetter
2016-02-18 12:39 ` [PATCH i-g-t 2/5] tests/kms_mmap_write_crc: Use the right fork helpers Daniel Vetter
2016-02-18 12:39 ` [PATCH i-g-t 3/5] gitignore: Add .dirstamp Daniel Vetter
2016-02-18 12:39 ` [PATCH i-g-t 4/5] lib/igt_core: remove igt_disable/enable_exit_handlers Daniel Vetter
2016-02-18 12:39 ` [PATCH i-g-t 5/5] lib: Unit test for exit handler Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.