From patchwork Wed Jun 1 21:19:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 628839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rKjLN3XvVz9sCy for ; Thu, 2 Jun 2016 06:55:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=U/8FMqEd; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=Wphm4FyBFlS9sVuZfpw0yFGLwQz2Ktq34Q4+k+/88jiOaeBQEqGFZ VCcHDyCKyvQQgHThIxRhMeVLH3tG+rkfyeMq7746t/JrVBA3goRnAfoAOMd0SZJJ b1Ty+YQLw+irCyyzYo0MYFG4y6fswj9qFlaTX9fMEdMG3/aFAOMVoY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=yJaaX0o1KJig7cLKpD7lv0h4ecU=; b=U/8FMqEdzj+g/OcDg5Q5 ThZjXX4/A2QM8X2Zu6cjGlf4sq9tcdlXRP+9cT230y13l7R1Qeh0i6Sv6wljn1Ra TVvPOAPs74aWwpGtLgxy4W6er+gMK8rD3IuqLr53VBbagr9IFyQZMxK/M5qSxUqR 3Adg3Ik/iaSYbJ/cSyXv6i8= Received: (qmail 28139 invoked by alias); 1 Jun 2016 20:54:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 28035 invoked by uid 89); 1 Jun 2016 20:54:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 spammy=Clear, Hx-languages-length:3741, preapproved, HX-HELO:eggs.gnu.org X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 01 Jun 2016 20:54:17 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8D9X-0007tx-0D for gcc-patches@gcc.gnu.org; Wed, 01 Jun 2016 16:54:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36058) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8D9W-0007tt-OQ for gcc-patches@gcc.gnu.org; Wed, 01 Jun 2016 16:54:10 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CB4A85542 for ; Wed, 1 Jun 2016 20:54:10 +0000 (UTC) Received: from c64.redhat.com (vpn-239-103.phx2.redhat.com [10.3.239.103]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u51Ks4WQ027176; Wed, 1 Jun 2016 16:54:09 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Bernd Schmidt , Jeff Law , David Malcolm Subject: [PATCH 07/21] Add selftests to bitmap.c Date: Wed, 1 Jun 2016 17:19:49 -0400 Message-Id: <1464816003-35862-8-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1464816003-35862-1-git-send-email-dmalcolm@redhat.com> References: <1447952699-40820-1-git-send-email-dmalcolm@redhat.com> <1464816003-35862-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-IsSubscribed: yes Jeff pre-approved the plugin version of this (as a new file unittests/test-bitmap.c): https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03284.html with: > OK if/when prereqs are approved. Minor twiddling if we end up moving it > elsewhere or standardizing/reducing header files is pre-approved. This version moves them to bitmap.c One issue: how to express: TEST (bitmap_test, gc_alloc) in a ChangeLog entry. I've chosen to write it as (bitmap_test, gc_alloc) since that has the greatest chance of being found via grep. gcc/ChangeLog: * bitmap.c: Include "selftest.h". (bitmap_test, gc_alloc): New selftest. (bitmap_test, set_range): New selftest. (bitmap_test, clear_bit_in_middle): New selftest. (bitmap_test, copying): New selftest. (bitmap_test, bitmap_single_bit_set_p): New selftest. --- gcc/bitmap.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/gcc/bitmap.c b/gcc/bitmap.c index 0c05512..7db7c68 100644 --- a/gcc/bitmap.c +++ b/gcc/bitmap.c @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "bitmap.h" +#include "selftest.h" /* Memory allocation statistics purpose instance. */ mem_alloc_description bitmap_mem_desc; @@ -2162,5 +2163,96 @@ debug (const bitmap_head *ptr) fprintf (stderr, "\n"); } +#if CHECKING_P +namespace { + +/* Freshly-created bitmaps ought to be empty. */ + +TEST (bitmap_test, gc_alloc) +{ + bitmap b = bitmap_gc_alloc (); + EXPECT_TRUE (bitmap_empty_p (b)); +} + +/* Verify bitmap_set_range. */ + +TEST (bitmap_test, set_range) +{ + bitmap b = bitmap_gc_alloc (); + EXPECT_TRUE (bitmap_empty_p (b)); + + bitmap_set_range (b, 7, 5); + EXPECT_FALSE (bitmap_empty_p (b)); + EXPECT_EQ (5, bitmap_count_bits (b)); + + /* Verify bitmap_bit_p at the boundaries. */ + EXPECT_FALSE (bitmap_bit_p (b, 6)); + EXPECT_TRUE (bitmap_bit_p (b, 7)); + EXPECT_TRUE (bitmap_bit_p (b, 11)); + EXPECT_FALSE (bitmap_bit_p (b, 12)); +} + +/* Verify splitting a range into two pieces using bitmap_clear_bit. */ + +TEST (bitmap_test, clear_bit_in_middle) +{ + bitmap b = bitmap_gc_alloc (); + + /* Set b to [100..200]. */ + bitmap_set_range (b, 100, 100); + EXPECT_EQ (100, bitmap_count_bits (b)); + + /* Clear a bit in the middle. */ + bool changed = bitmap_clear_bit (b, 150); + EXPECT_TRUE (changed); + EXPECT_EQ (99, bitmap_count_bits (b)); + EXPECT_TRUE (bitmap_bit_p (b, 149)); + EXPECT_FALSE (bitmap_bit_p (b, 150)); + EXPECT_TRUE (bitmap_bit_p (b, 151)); +} + +/* Verify bitmap_copy. */ + +TEST (bitmap_test, copying) +{ + bitmap src = bitmap_gc_alloc (); + bitmap_set_range (src, 40, 10); + + bitmap dst = bitmap_gc_alloc (); + EXPECT_FALSE (bitmap_equal_p (src, dst)); + bitmap_copy (dst, src); + EXPECT_TRUE (bitmap_equal_p (src, dst)); + + /* Verify that we can make them unequal again... */ + bitmap_set_range (src, 70, 5); + EXPECT_FALSE (bitmap_equal_p (src, dst)); + + /* ...and that changing src after the copy didn't affect + the other: */ + EXPECT_FALSE (bitmap_bit_p (dst, 70)); +} + +/* Verify bitmap_single_bit_set_p. */ +TEST (bitmap_test, bitmap_single_bit_set_p) +{ + bitmap b = bitmap_gc_alloc (); + + EXPECT_FALSE (bitmap_single_bit_set_p (b)); + + bitmap_set_range (b, 42, 1); + EXPECT_TRUE (bitmap_single_bit_set_p (b)); + EXPECT_EQ (42, bitmap_first_set_bit (b)); + + bitmap_set_range (b, 1066, 1); + EXPECT_FALSE (bitmap_single_bit_set_p (b)); + EXPECT_EQ (42, bitmap_first_set_bit (b)); + + bitmap_clear_range (b, 0, 100); + EXPECT_TRUE (bitmap_single_bit_set_p (b)); + EXPECT_EQ (1066, bitmap_first_set_bit (b)); +} + +} // anon namespace +#endif /* CHECKING_P */ #include "gt-bitmap.h"