[igt-dev] [PATCH i-g-t 1/5] lib/tests: Add header for common helpers
Daniel Vetter
daniel.vetter at ffwll.ch
Tue Feb 19 07:57:12 UTC 2019
Start with internal_assert, more will follow. While at it, use
internal_assert everywhere (except where we check exit status, those
will get dedicated assert checks).
Signed-off-by: Daniel Vetter <daniel.vetter at intel.com>
---
lib/tests/igt_assert.c | 9 +-------
lib/tests/igt_can_fail.c | 12 +++++------
lib/tests/igt_can_fail_simple.c | 4 ++--
lib/tests/igt_exit_handler.c | 21 +++++++++---------
lib/tests/igt_fork.c | 9 +-------
lib/tests/igt_segfault.c | 9 +-------
lib/tests/igt_simulation.c | 9 +-------
lib/tests/igt_subtest_group.c | 19 +++++++++--------
lib/tests/igt_tests_common.h | 38 +++++++++++++++++++++++++++++++++
9 files changed, 71 insertions(+), 59 deletions(-)
create mode 100644 lib/tests/igt_tests_common.h
diff --git a/lib/tests/igt_assert.c b/lib/tests/igt_assert.c
index 0082fda14851..e3c1ec49daf2 100644
--- a/lib/tests/igt_assert.c
+++ b/lib/tests/igt_assert.c
@@ -22,7 +22,6 @@
*
*/
-#include <assert.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
@@ -36,13 +35,7 @@
#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
+#include "igt_tests_common.h"
char test[] = "test";
char *argv_run[] = { test };
diff --git a/lib/tests/igt_can_fail.c b/lib/tests/igt_can_fail.c
index 566682422b64..1e3d9558728f 100644
--- a/lib/tests/igt_can_fail.c
+++ b/lib/tests/igt_can_fail.c
@@ -22,23 +22,23 @@
*
*/
-#include <assert.h>
#include "igt_core.h"
+#include "igt_tests_common.h"
igt_main
{
- assert(igt_can_fail() == false);
+ internal_assert(igt_can_fail() == false);
igt_fixture {
- assert(igt_can_fail());
+ internal_assert(igt_can_fail());
}
- assert(igt_can_fail() == false);
+ internal_assert(igt_can_fail() == false);
igt_subtest("subtest") {
- assert(igt_can_fail());
+ internal_assert(igt_can_fail());
}
- assert(igt_can_fail() == false);
+ internal_assert(igt_can_fail() == false);
}
diff --git a/lib/tests/igt_can_fail_simple.c b/lib/tests/igt_can_fail_simple.c
index 0d9f6dd4076c..8ff43d15fa6b 100644
--- a/lib/tests/igt_can_fail_simple.c
+++ b/lib/tests/igt_can_fail_simple.c
@@ -22,11 +22,11 @@
*
*/
-#include <assert.h>
#include "igt_core.h"
+#include "igt_tests_common.h"
igt_simple_main
{
- assert(igt_can_fail());
+ internal_assert(igt_can_fail());
}
diff --git a/lib/tests/igt_exit_handler.c b/lib/tests/igt_exit_handler.c
index f2997bd13633..7546fde6d6f8 100644
--- a/lib/tests/igt_exit_handler.c
+++ b/lib/tests/igt_exit_handler.c
@@ -21,19 +21,20 @@
* IN THE SOFTWARE.
*/
-#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "igt_core.h"
+#include "igt_tests_common.h"
+
int test;
int pipes[2];
static void exit_handler1(int sig)
{
- assert(test == 1);
+ internal_assert(test == 1);
test++;
}
@@ -42,12 +43,12 @@ static void exit_handler2(int sig)
char tmp = 1;
/* ensure exit handlers are called in reverse */
- assert(test == 0);
+ internal_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);
+ internal_assert(write(pipes[1], &tmp, 1) == 1);
}
enum test_type {
@@ -67,7 +68,7 @@ static int testfunc(enum test_type test_type)
int status;
char tmp = 0;
- assert(pipe2(pipes, O_NONBLOCK) == 0);
+ internal_assert(pipe2(pipes, O_NONBLOCK) == 0);
pid = fork();
@@ -100,10 +101,10 @@ static int testfunc(enum test_type test_type)
igt_exit();
}
- assert(waitpid(pid, &status, 0) != -1);
+ internal_assert(waitpid(pid, &status, 0) != -1);
- assert(read(pipes[0], &tmp, 1) == 1);
- assert(tmp == 1);
+ internal_assert(read(pipes[0], &tmp, 1) == 1);
+ internal_assert(tmp == 1);
return status;
}
@@ -112,9 +113,9 @@ int main(int argc, char **argv)
{
int status;
- assert(testfunc(SUC) == 0);
+ internal_assert(testfunc(SUC) == 0);
- assert(testfunc(NORMAL) == 0);
+ internal_assert(testfunc(NORMAL) == 0);
status = testfunc(FAIL);
assert(WIFEXITED(status) && WEXITSTATUS(status) == 1);
diff --git a/lib/tests/igt_fork.c b/lib/tests/igt_fork.c
index fa5bb7701c09..38c55d11f7ec 100644
--- a/lib/tests/igt_fork.c
+++ b/lib/tests/igt_fork.c
@@ -22,7 +22,6 @@
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
@@ -32,13 +31,7 @@
#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
+#include "igt_tests_common.h"
char test[] = "test";
char *argv_run[] = { test };
diff --git a/lib/tests/igt_segfault.c b/lib/tests/igt_segfault.c
index 86fee5354d67..bfbbff564fac 100644
--- a/lib/tests/igt_segfault.c
+++ b/lib/tests/igt_segfault.c
@@ -38,19 +38,12 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
-#include <assert.h>
#include <errno.h>
#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
+#include "igt_tests_common.h"
bool simple;
bool runa;
diff --git a/lib/tests/igt_simulation.c b/lib/tests/igt_simulation.c
index 2efccac4e390..3f3cd88fd058 100644
--- a/lib/tests/igt_simulation.c
+++ b/lib/tests/igt_simulation.c
@@ -28,19 +28,12 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
-#include <assert.h>
#include <errno.h>
#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
+#include "igt_tests_common.h"
bool simple;
bool list_subtests;
diff --git a/lib/tests/igt_subtest_group.c b/lib/tests/igt_subtest_group.c
index c2364d799f36..7783d021e5a2 100644
--- a/lib/tests/igt_subtest_group.c
+++ b/lib/tests/igt_subtest_group.c
@@ -22,9 +22,10 @@
*
*/
-#include <assert.h>
#include "igt_core.h"
+#include "igt_tests_common.h"
+
igt_main
{
bool t1 = false;
@@ -41,7 +42,7 @@ igt_main
}
igt_subtest("not-run") {
- assert(0);
+ internal_assert(0);
}
igt_subtest_group {
@@ -49,35 +50,35 @@ igt_main
* restore to "run testcases" when an outer
* group is already in SKIP state. */
igt_subtest("still-not-run") {
- assert(0);
+ internal_assert(0);
}
}
}
igt_subtest("run") {
t1 = true;
- assert(1);
+ internal_assert(1);
}
}
igt_subtest_group {
igt_fixture {
- assert(t2 == 0);
+ internal_assert(t2 == 0);
t2 = 1;
}
igt_subtest("run-again") {
- assert(t2 == 1);
+ internal_assert(t2 == 1);
t2 = 2;
}
igt_fixture {
- assert(t2 == 2);
+ internal_assert(t2 == 2);
t2 = 3;
}
}
- assert(t1);
- assert(t2 == 3);
+ internal_assert(t1);
+ internal_assert(t2 == 3);
}
diff --git a/lib/tests/igt_tests_common.h b/lib/tests/igt_tests_common.h
new file mode 100644
index 000000000000..9b347a4565d9
--- /dev/null
+++ b/lib/tests/igt_tests_common.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2019 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.
+ *
+ */
+
+#ifndef IGT_LIB_TESTS_COMMON_H
+#define IGT_LIB_TESTS_COMMON_H
+
+#include <assert.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
+
+#endif
--
2.20.1
More information about the igt-dev
mailing list