From patchwork Fri Oct 6 16:20:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 822548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-463663-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CQ/ARRBG"; dkim-atps=neutral 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 3y7vxj5Zr5z9t48 for ; Sat, 7 Oct 2017 03:20:24 +1100 (AEDT) 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=jvxo/eCoJmyZ2htJo7cTzcyY1fe3sUMz0YDc3Xtek6v81AOtuG1JM dYVJ+pHGrzc4BvWBZPVGfaBYtdDCnkAeYCgab5F0KI1bypleengavnm/qqghvkQ1 DIy1R0LTyB1zwQRjEGJXc2n8G0YrqJtfs/gvurtnIQcHNsmSnZBEZo= 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=s0IzaDnaOS5A+T6zLprZgRdua84=; b=CQ/ARRBGTedjzfPRxLuS U3L+lG5Cln/URDEKlguoO6uSzsChr8vbBEIdiyjVukhzRQOBzA8LcPozb1U61bv9 JngG6u/HSDG/r7lk9D1tz5UMUVBTYafW4KZC0b3M9hoQ0qccchalixRYq5kxcKlU sBAfUebB0xPgBtzcqaziUMQ= Received: (qmail 98308 invoked by alias); 6 Oct 2017 16:20:17 -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 98298 invoked by uid 89); 6 Oct 2017 16:20:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Oct 2017 16:20:15 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01773C04B954; Fri, 6 Oct 2017 16:20:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 01773C04B954 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dmalcolm@redhat.com Received: from c64.redhat.com (ovpn-112-12.phx2.redhat.com [10.3.112.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BF8E5D9C1; Fri, 6 Oct 2017 16:20:12 +0000 (UTC) From: David Malcolm To: =?utf-8?q?Martin_Li=C5=A1ka?= , Jeff Law , gcc-patches@gcc.gnu.org Cc: Jan Hubicka , David Malcolm Subject: [PATCH] Add selftest for vec::reverse Date: Fri, 6 Oct 2017 12:20:33 -0400 Message-Id: <1507306833-12644-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: <82167884-d00e-a87c-9f22-94f5cd6e834d@suse.cz> References: <82167884-d00e-a87c-9f22-94f5cd6e834d@suse.cz> X-IsSubscribed: yes Martin: I noticed that your switch expansion patch added a vec::reverse () method. Here's a proposed selftest for it, mostly to verify that it handles even vs odd lengths (which it does). Only lightly tested; hope this is useful. Dave gcc/ChangeLog: * vec.c (selftest::test_reverse): New function. (selftest::vec_c_tests): Call it. --- gcc/vec.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gcc/vec.c b/gcc/vec.c index d612703..5d70973 100644 --- a/gcc/vec.c +++ b/gcc/vec.c @@ -359,6 +359,43 @@ test_qsort () ASSERT_EQ (10, v.length ()); } +/* Verify that vec::reverse works correctly. */ + +static void +test_reverse () +{ + /* Reversing an empty vec ought to be a no-op. */ + { + auto_vec v; + ASSERT_EQ (0, v.length ()); + v.reverse (); + ASSERT_EQ (0, v.length ()); + } + + /* Verify reversing a vec with even length. */ + { + auto_vec v; + safe_push_range (v, 0, 4); + v.reverse (); + ASSERT_EQ (3, v[0]); + ASSERT_EQ (2, v[1]); + ASSERT_EQ (1, v[2]); + ASSERT_EQ (0, v[3]); + ASSERT_EQ (4, v.length ()); + } + + /* Verify reversing a vec with odd length. */ + { + auto_vec v; + safe_push_range (v, 0, 3); + v.reverse (); + ASSERT_EQ (2, v[0]); + ASSERT_EQ (1, v[1]); + ASSERT_EQ (0, v[2]); + ASSERT_EQ (3, v.length ()); + } +} + /* Run all of the selftests within this file. */ void @@ -374,6 +411,7 @@ vec_c_tests () test_unordered_remove (); test_block_remove (); test_qsort (); + test_reverse (); } } // namespace selftest