[Intel-gfx] [PATCH 2/2] lib/igt.cocci: Add s/assert/igt_assert/

Daniel Vetter daniel.vetter at ffwll.ch
Tue Jul 15 10:23:32 CEST 2014


People use it way too often, and it upsets the test library. The only
valid places to use this is of igt infrastructure self-tests where you
need to check something _without_ all the other abi use checks
igt_fail and friends do. For those tests just #define an internal
assert to hide it.

Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
 lib/igt.cocci          |  7 ++++++
 tests/igt_simulation.c | 68 ++++++++++++++++++++++++++++----------------------
 2 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/lib/igt.cocci b/lib/igt.cocci
index d399496b256f..adebb31c0277 100644
--- a/lib/igt.cocci
+++ b/lib/igt.cocci
@@ -84,3 +84,10 @@ expression pipe;
 + for_each_pipe (display, pipe) {
 ...
 }
+
+// Tests really shouldn't use plain assert!
+@@
+expression E;
+@@
+- assert(E);
++ igt_assert(E);
diff --git a/tests/igt_simulation.c b/tests/igt_simulation.c
index a1aa2f46076b..13b2da9ca172 100644
--- a/tests/igt_simulation.c
+++ b/tests/igt_simulation.c
@@ -34,6 +34,14 @@
 #include "drmtest.h"
 #include "igt_core.h"
 
+/*
+ * We need to hide assert from the cocci igt test refactor spatch.
+ *
+ * IMPORTANT: Test infrastructure tests are the only valid places where using
+ * assert is allowed.
+ */
+#define internal_assert assert
+
 bool simple;
 bool list_subtests;
 bool in_fixture;
@@ -50,7 +58,7 @@ static int do_fork(void)
 
 	switch (pid = fork()) {
 	case -1:
-		assert(0);
+		internal_assert(0);
 	case 0:
 		if (simple) {
 			igt_simple_init(1, argv_run);
@@ -84,7 +92,7 @@ static int do_fork(void)
 		       errno == EINTR)
 			;
 
-		assert(WIFEXITED(status));
+		internal_assert(WIFEXITED(status));
 
 		return WEXITSTATUS(status);
 	}
@@ -94,63 +102,63 @@ int main(int argc, char **argv)
 {
 	/* simple tests */
 	simple = true;
-	assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SKIP);
+	internal_assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SKIP);
 
-	assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
 	/* subtests, list mode */
 	simple = false;
 	list_subtests = true;
 
 	in_fixture = false;
-	assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
-	assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
 	in_fixture = true;
-	assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
-	assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
 	in_fixture = false;
 	in_subtest = true;
-	assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
-	assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
 	/* subtest, run mode */
 	simple = false;
 	list_subtests = false;
 
 	in_fixture = false;
-	assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SKIP);
+	internal_assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SKIP);
 
-	assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
 	in_fixture = true;
-	assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SKIP);
+	internal_assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SKIP);
 
-	assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
 	in_fixture = false;
 	in_subtest = true;
-	assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SKIP);
+	internal_assert(setenv("INTEL_SIMULATION", "1", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SKIP);
 
-	assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
-	assert(do_fork() == IGT_EXIT_SUCCESS);
+	internal_assert(setenv("INTEL_SIMULATION", "0", 1) == 0);
+	internal_assert(do_fork() == IGT_EXIT_SUCCESS);
 
 	return 0;
 }
-- 
2.0.0




More information about the Intel-gfx mailing list