From patchwork Thu Oct 29 10:31:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Stone X-Patchwork-Id: 7518061 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1253D9F327 for ; Thu, 29 Oct 2015 10:31:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A0FB209D8 for ; Thu, 29 Oct 2015 10:31:52 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 075C3207C8 for ; Thu, 29 Oct 2015 10:31:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E39B96E535; Thu, 29 Oct 2015 03:31:48 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by gabe.freedesktop.org (Postfix) with ESMTPS id C460B6E59A for ; Thu, 29 Oct 2015 03:31:38 -0700 (PDT) Received: by wikq8 with SMTP id q8so279691488wik.1 for ; Thu, 29 Oct 2015 03:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fooishbar_org.20150623.gappssmtp.com; s=20150623; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=cwn8hqyx2KNjrP/o0ca33+Do4P7qtbz6bT6n4gfVZEU=; b=IIyAus58pNgsq5gLEhSwHeMoMQLh07BLBZnyA5eWOTxE3H9Cp9Sf3pfK7oXghT1wEe XmAXe3ZrF/ast2JOfPA2U08/T6A2GtNosrzWm7nADnEV7kCmEkwrXAu2e/a9RuaJppjX w1kfcjo9mVBiA5cEGhJol98d2vIgE+3FzaQJm+Ijq/PPEC01CIlJwRVeRQex+1egvHtg 81TjVzQyATS2we0LIcAWCFbUOJieofqP7eFJB35Dn02h4VTT7L5vLO+CeapFD3msuvmh Pbq64YVrM9Q8eeA9vr7+mgnTWCp2/A2Mvc50ojQIl9chzIgEzsWuf8zhjaYGR6yJZaa5 9sHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; bh=cwn8hqyx2KNjrP/o0ca33+Do4P7qtbz6bT6n4gfVZEU=; b=DIZyNnF07IUdYgqeQMjiP+25CIhK3vohC2XKLSZzdb/vDb8wPdoVeuPVpCwriJZ7Jy sJZze3AM/mEFTARxmv5Dsdks+H0Yjz2VEpD/FlEyVjxS1Af5V6oyO4P41wdKfLb/5REF x9h44R8JRcVs5Rwz3IE3z2YA1HeBXtPApZG5FB9PBg34/gXGOEhJt1aU70vzxCSbPt2I 8iGzcmtfXWY/cxZeSqNo0UCh94oyWNriECO7kELNuzQH1WLFYnpbO6kbwuMB9fZrWaNX an2mXCUF+MVk5CdWiwjLO+1/H9yDXetsOBFm1kbv8a1nJy2Hw7W60ZxSBVVGrowSP2d/ deIg== X-Gm-Message-State: ALoCoQkqiMxwdJowAduMeXEksXlxcdQtVvV7feohfsyyRg37jrzQxMbGrgIktSw336SFXhGeL0GS X-Received: by 10.194.179.234 with SMTP id dj10mr1276023wjc.52.1446114697398; Thu, 29 Oct 2015 03:31:37 -0700 (PDT) Received: from fxhe.lan (93-97-222-139.zone5.bethere.co.uk. [93.97.222.139]) by smtp.gmail.com with ESMTPSA id vr10sm1044426wjc.38.2015.10.29.03.31.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2015 03:31:36 -0700 (PDT) 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 10:31:16 +0000 Message-Id: <1446114679-6844-2-git-send-email-daniels@collabora.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1446114679-6844-1-git-send-email-daniels@collabora.com> References: <1446114679-6844-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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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); +}