From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: IGT development <igt-dev@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Subject: [igt-dev] [PATCH i-g-t 1/6] lib/tests: Add header for common helpers
Date: Fri, 15 Feb 2019 10:54:43 +0100 [thread overview]
Message-ID: <20190215095448.13196-1-daniel.vetter@ffwll.ch> (raw)
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@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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2019-02-15 9:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-15 9:54 Daniel Vetter [this message]
2019-02-15 9:54 ` [igt-dev] [PATCH i-g-t 2/6] lib/tests: add internal_assert_wexited/wsignaled Daniel Vetter
2019-02-15 9:54 ` [igt-dev] [PATCH i-g-t 3/6] tests: drop invalid name build checks Daniel Vetter
2019-02-15 9:54 ` [igt-dev] [PATCH i-g-t 4/6] lib/tests: Convert no_exit tests into positive tests Daniel Vetter
2019-02-15 9:54 ` [igt-dev] [PATCH i-g-t 5/6] lib/tests: Add testcase for nonexisting subtest name Daniel Vetter
2019-02-15 9:54 ` [igt-dev] [PATCH i-g-t 6/6] lib/core_auth: mount namespace magic to make the test work everywhere Daniel Vetter
2019-02-15 15:48 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,1/6] lib/tests: Add header for common helpers Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190215095448.13196-1-daniel.vetter@ffwll.ch \
--to=daniel.vetter@ffwll.ch \
--cc=daniel.vetter@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox