summaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2019-02-19 08:57:12 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2019-02-20 13:58:04 +0100
commit4494052aa3c8f95c2b21acc4a1273fc4431bb71e (patch)
tree64500cbaa1b1767e0e759b2f3cf0481a656ed192 /lib/tests
parent4d0d81a2176227a7432762ae095ba386f3c8aba0 (diff)
lib/tests: Add header for common helpers
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). Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/igt_assert.c9
-rw-r--r--lib/tests/igt_can_fail.c12
-rw-r--r--lib/tests/igt_can_fail_simple.c4
-rw-r--r--lib/tests/igt_exit_handler.c21
-rw-r--r--lib/tests/igt_fork.c9
-rw-r--r--lib/tests/igt_segfault.c9
-rw-r--r--lib/tests/igt_simulation.c9
-rw-r--r--lib/tests/igt_subtest_group.c19
-rw-r--r--lib/tests/igt_tests_common.h38
9 files changed, 71 insertions, 59 deletions
diff --git a/lib/tests/igt_assert.c b/lib/tests/igt_assert.c
index 0082fda1..e3c1ec49 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 56668242..1e3d9558 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 0d9f6dd4..8ff43d15 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 f2997bd1..7546fde6 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 fa5bb770..38c55d11 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 86fee535..bfbbff56 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 2efccac4..3f3cd88f 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 c2364d79..7783d021 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 00000000..9b347a45
--- /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