From patchwork Thu Oct 29 11:01:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Stone X-Patchwork-Id: 7518161 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9A097BEEA4 for ; Thu, 29 Oct 2015 11:02:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 941682076A for ; Thu, 29 Oct 2015 11:02:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id BEEC320A24 for ; Thu, 29 Oct 2015 11:02:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C499E72192; Thu, 29 Oct 2015 04:02:24 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [93.93.135.160]) by gabe.freedesktop.org (Postfix) with ESMTPS id 81E2872192 for ; Thu, 29 Oct 2015 04:01:43 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: daniels) with ESMTPSA id D560660163B From: Daniel Stone To: dri-devel@lists.freedesktop.org Subject: [PATCH igt v7 1/4] lib/tests: Add igt_assert_*() self-tests Date: Thu, 29 Oct 2015 11:01:25 +0000 Message-Id: <1446116488-24901-2-git-send-email-daniels@collabora.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1446116488-24901-1-git-send-email-daniels@collabora.com> References: <1446116488-24901-1-git-send-email-daniels@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure our igt_assert variants are doing something that looks vaguely like the right thing. Signed-off-by: Daniel Stone --- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +}