All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Stone <daniels@collabora.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH igt v7 1/4] lib/tests: Add igt_assert_*() self-tests
Date: Thu, 29 Oct 2015 11:03:55 +0000	[thread overview]
Message-ID: <1446116638-25348-2-git-send-email-daniels@collabora.com> (raw)
In-Reply-To: <1446116638-25348-1-git-send-email-daniels@collabora.com>

Make sure our igt_assert variants are doing something that looks vaguely
like the right thing.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 lib/tests/Makefile.sources |   1 +
 lib/tests/igt_simple.c     | 173 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 174 insertions(+)
 create mode 100644 lib/tests/igt_simple.c

diff --git a/lib/tests/Makefile.sources b/lib/tests/Makefile.sources
index 58ae36b..fe5df6e 100644
--- a/lib/tests/Makefile.sources
+++ b/lib/tests/Makefile.sources
@@ -10,6 +10,7 @@ check_PROGRAMS = \
 	igt_timeout \
 	igt_invalid_subtest_name \
 	igt_segfault \
+	igt_simple \
 	$(NULL)
 
 check_SCRIPTS = \
diff --git a/lib/tests/igt_simple.c b/lib/tests/igt_simple.c
new file mode 100644
index 0000000..306b1fb
--- /dev/null
+++ b/lib/tests/igt_simple.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright © 2015 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.
+ *
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <float.h>
+#include <limits.h>
+#include <math.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.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
+
+char test[] = "test";
+char *argv_run[] = { test };
+void (*test_to_run)(void) = NULL;
+
+/*
+ * A really tedious way of making sure we execute every negative test, and that
+ * they all really fail.
+ */
+#define CHECK_NEG(x) { \
+	igt_subtest_f("XFAIL_simple_%d", __LINE__) { \
+		(*exec_before)++; \
+		x; \
+		raise(SIGBUS); \
+	} \
+	exec_total++; \
+}
+
+static int do_fork(void)
+{
+	int pid, status;
+	int argc;
+
+	switch (pid = fork()) {
+	case -1:
+		internal_assert(0);
+	case 0:
+		argc = 1;
+		igt_simple_init(argc, argv_run);
+		test_to_run();
+		igt_exit();
+	default:
+		while (waitpid(pid, &status, 0) == -1 &&
+		       errno == EINTR)
+			;
+
+		if(WIFSIGNALED(status))
+			return WTERMSIG(status) + 128;
+
+		return WEXITSTATUS(status);
+	}
+}
+
+static void test_cmpint_negative(void)
+{
+	int *exec_before = calloc(1, sizeof(int));
+	int exec_total = 0;
+
+	CHECK_NEG(igt_assert_eq(INT_MIN, INT_MAX));
+
+	CHECK_NEG(igt_assert_eq_u32(0xfffffffeUL, 0xffffffffUL));
+
+	CHECK_NEG(igt_assert_eq_u64(0xfffeffffffffffffULL, 0xffffffffffffffffULL));
+	CHECK_NEG(igt_assert_eq_u64(0xfffffffeffffffffULL, 0xffffffffffffffffULL));
+	CHECK_NEG(igt_assert_eq_u64(0xfffffffffffeffffULL, 0xffffffffffffffffULL));
+
+	CHECK_NEG(igt_assert_eq_double(0.0, DBL_MAX));
+	CHECK_NEG(igt_assert_eq_double(DBL_MAX, nexttoward(DBL_MAX, 0.0)));
+
+	if (*exec_before != exec_total)
+		raise(SIGSEGV);
+}
+
+static void test_cmpint(void)
+{
+	igt_assert_eq(0, 0);
+	igt_assert_eq(INT_MAX, INT_MAX);
+	igt_assert_eq(INT_MAX, INT_MAX);
+	igt_assert_neq(INT_MIN, INT_MAX);
+
+	igt_assert_eq_u32(0, 0);
+	igt_assert_eq_u32(0xffffffffUL, 0xffffffffUL);
+	igt_assert_neq_u32(0xfffffffeUL, 0xffffffffUL);
+
+	igt_assert_eq_u64(0, 0);
+	igt_assert_eq_u64(0xffffffffffffffffULL, 0xffffffffffffffffULL);
+	igt_assert_neq_u64(0xfffffffffffffffeULL, 0xffffffffffffffffULL);
+
+	igt_assert_eq_double(0.0, 0.0);
+	igt_assert_eq_double(DBL_MAX, DBL_MAX);
+	igt_assert_neq_double(0.0, DBL_MAX);
+}
+
+static void test_fd_negative(void)
+{
+	int *exec_before = calloc(1, sizeof(int));
+	int exec_total = 0;
+
+	CHECK_NEG(igt_assert_fd(-1));
+	CHECK_NEG(igt_assert_fd(INT_MIN));
+
+	if (*exec_before != exec_total)
+		raise(SIGSEGV);
+}
+
+static void test_fd(void)
+{
+	igt_assert_fd(0);
+	igt_assert_fd(1);
+	igt_assert_fd(INT_MAX);
+}
+
+igt_main
+{
+	int ret;
+
+	igt_subtest("igt_cmpint")
+		test_cmpint();
+
+	/*
+	 * The awkward subtest dance here is because we really want to use
+	 * subtests in our negative tests, to ensure we actually execute all
+	 * the subtests. But we can't begin a subtest within a subtest, and
+	 * we inherit the state from the parent, so ...
+	 */
+	test_to_run = test_cmpint_negative;
+	ret = do_fork();
+	igt_subtest("igt_cmpint_negative")
+		internal_assert(ret == IGT_EXIT_FAILURE);
+
+	igt_subtest("igt_assert_fd")
+		test_fd();
+
+	test_to_run = test_fd_negative;
+	ret = do_fork();
+	igt_subtest("igt_assert_fd_negative")
+		internal_assert(ret == IGT_EXIT_FAILURE);
+}
-- 
2.5.0

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

  reply	other threads:[~2015-10-29 11:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-29 11:03 [PATCH igt v7 0/4] Assert tests, atomic, multi-blob Daniel Stone
2015-10-29 11:03 ` Daniel Stone [this message]
2015-11-17 17:34   ` [PATCH igt v7 1/4] lib/tests: Add igt_assert_*() self-tests Daniel Vetter
2015-10-29 11:03 ` [PATCH igt v7 2/4] tests: Run igt.cocci Daniel Stone
2015-10-29 11:03 ` [PATCH igt v7 3/4] tests/core_prop_blob: Add multiple blobs per connection Daniel Stone
2015-10-29 11:03 ` [PATCH igt v7 4/4] kms_atomic: Add basic atomic modesetting tests Daniel Stone
  -- strict thread matches above, loose matches on Subject: below --
2015-10-29 11:01 [PATCH igt v7 0/4] Assert tests, atomic, multi-blob Daniel Stone
2015-10-29 11:01 ` [PATCH igt v7 1/4] lib/tests: Add igt_assert_*() self-tests Daniel Stone
2015-10-29 10:31 [PATCH igt v7 0/4] Assert tests, atomic, multi-blob Daniel Stone
2015-10-29 10:31 ` [PATCH igt v7 1/4] lib/tests: Add igt_assert_*() self-tests Daniel Stone
2015-10-29 12:36   ` Thomas Wood

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=1446116638-25348-2-git-send-email-daniels@collabora.com \
    --to=daniels@collabora.com \
    --cc=intel-gfx@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 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.