From patchwork Thu Jun 2 21:06:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 629454 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 3rLK2431FFz9t84 for ; Fri, 3 Jun 2016 06:43: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=vOj0ikoe; 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=SNvVBB2eMyuh3JGp0GUE5AqW8hXB1pkgbP5QgZrZSX0/QHxm/7PQm TLoEzP+WeUcQ/74LpN8QMAKqF4hqHaDHFH8vA4IvxAIWyZGLbILt5oyrU32XgYms cKZhctAePkbHxG8iFO0DVEYL6ETY9P5bNdhWPWySwUIlPWEhSv/lfQ= 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=B0OwOh/iZc6I3e8jfRqQ6XvTfpY=; b=vOj0ikoe6CxbgHhz2qV6 zN/o4NI0IWmWS19JfYifn1zH50QmKlGlF2CBFECXZThYep6UZsf6KZBo9fK1jHYf JFcZcoE1P5538KuvSKvpr3EJ+lTaev8cpnE9GQetmUIqSzf1bkI3FZlgTQzwTXpa R8Rb/sFZzJSO0ZA/GuLH4yk= Received: (qmail 37366 invoked by alias); 2 Jun 2016 20:41:31 -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 36763 invoked by uid 89); 2 Jun 2016 20:41:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=HX-HELO:eggs.gnu.org, Hx-spam-relays-external:208.118.235.92, H*RU:208.118.235.92 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; Thu, 02 Jun 2016 20:41:15 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8ZQV-0002sW-To for gcc-patches@gcc.gnu.org; Thu, 02 Jun 2016 16:41:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52106) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8ZQV-0002sS-Mu for gcc-patches@gcc.gnu.org; Thu, 02 Jun 2016 16:41:11 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 09E302CAB9F for ; Thu, 2 Jun 2016 20:41:11 +0000 (UTC) Received: from c64.redhat.com (vpn-237-222.phx2.redhat.com [10.3.237.222]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u52Kf2X4007154; Thu, 2 Jun 2016 16:41:10 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Bernd Schmidt , Jeff Law , David Malcolm Subject: [PATCH 10/16] Add hash-map-tests.c Date: Thu, 2 Jun 2016 17:06:59 -0400 Message-Id: <1464901625-54547-11-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1464901625-54547-1-git-send-email-dmalcolm@redhat.com> References: <1464874868.11895.41.camel@redhat.com> <1464901625-54547-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 approved an earlier version of this (as unittests/test-hash-map.c): https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03301.html > 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 the tests to gcc/hash-map-tests.c and updates them to the new style. gcc/ChangeLog: * hash-map-tests.c: New file. --- gcc/hash-map-tests.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 gcc/hash-map-tests.c diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c new file mode 100644 index 0000000..b2b9095 --- /dev/null +++ b/gcc/hash-map-tests.c @@ -0,0 +1,88 @@ +/* Unit tests for hash-map.h. + Copyright (C) 2015-2016 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "opts.h" +#include "signop.h" +#include "hash-set.h" +#include "fixed-value.h" +#include "alias.h" +#include "flags.h" +#include "symtab.h" +#include "tree-core.h" +#include "stor-layout.h" +#include "tree.h" +#include "stringpool.h" +#include "selftest.h" + +#if CHECKING_P + +static void +test_map_of_strings_to_int () +{ + hash_map m; + + const char *ostrich = "ostrich"; + const char *elephant = "elephant"; + const char *ant = "ant"; + const char *spider = "spider"; + const char *millipede = "Illacme plenipes"; + const char *eric = "half a bee"; + + /* A fresh hash_map should be empty. */ + ASSERT_EQ (0, m.elements ()); + ASSERT_EQ (NULL, m.get (ostrich)); + + /* Populate the hash_map. */ + ASSERT_EQ (false, m.put (ostrich, 2)); + ASSERT_EQ (false, m.put (elephant, 4)); + ASSERT_EQ (false, m.put (ant, 6)); + ASSERT_EQ (false, m.put (spider, 8)); + ASSERT_EQ (false, m.put (millipede, 750)); + ASSERT_EQ (false, m.put (eric, 3)); + + /* Verify that we can recover the stored values. */ + ASSERT_EQ (6, m.elements ()); + ASSERT_EQ (2, *m.get (ostrich)); + ASSERT_EQ (4, *m.get (elephant)); + ASSERT_EQ (6, *m.get (ant)); + ASSERT_EQ (8, *m.get (spider)); + ASSERT_EQ (750, *m.get (millipede)); + ASSERT_EQ (3, *m.get (eric)); + + /* Verify removing an item. */ + m.remove (eric); + ASSERT_EQ (5, m.elements ()); + ASSERT_EQ (NULL, m.get (eric)); +} + +namespace selftest { + +void +hash_map_tests_c_tests () +{ + test_map_of_strings_to_int (); +} + +} // namespace selftest + +#endif /* CHECKING_P */