From patchwork Thu Mar 26 23:57:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 6102781 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 37DB6BF90F for ; Thu, 26 Mar 2015 23:54:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 32E3D2044C for ; Thu, 26 Mar 2015 23:54:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 26DC02044B for ; Thu, 26 Mar 2015 23:54:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BB87E6EAD3; Thu, 26 Mar 2015 16:54:08 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by gabe.freedesktop.org (Postfix) with ESMTP id D14B46EACD for ; Thu, 26 Mar 2015 16:54:01 -0700 (PDT) Received: by wgra20 with SMTP id a20so81668596wgr.3 for ; Thu, 26 Mar 2015 16:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WYf8UycOhLFkHJG6puoS1I5CB1KYAkkGYxoctHvVmFo=; b=K3tiv/nuZ32khEnURHfntaJSnRYRIvON0rn6bUVfbYJqL3BtTTUFrwGaRcjIIkDCsD IT4MRKt+49YqT5WNo56YXTqOxCIZxbQcvzp0olxuFWpIHKV/mkzul/4iT6KiqKEWtPz8 Y1CJBYoA7I/zGNMYIzeGs5kyaRa0yCpNNeFyTEHT6Cwmo2rBICrk+lEdA0TgU4059ciP 4V3nrJ3eFODDM/a6zvU4ZcukV4CY94jI06oO3x7hydFCKWjco1baXXYGuzz3lLbitfTn SS2hy+p7k09SVDcVIYS5LX1VdIN4U1wx5hoi+mDZ2BrISqC7AMmKW4ufmT+czhb+HMSv tW5w== X-Received: by 10.194.187.46 with SMTP id fp14mr1670577wjc.86.1427414040873; Thu, 26 Mar 2015 16:54:00 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by mx.google.com with ESMTPSA id ey10sm1060338wib.2.2015.03.26.16.53.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 16:54:00 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm v2 2/8] tests/hash: misc compilation fixes Date: Thu, 26 Mar 2015 23:57:05 +0000 Message-Id: <1427414231-11385-2-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.3.1 In-Reply-To: <1427414231-11385-1-git-send-email-emil.l.velikov@gmail.com> References: <1427414231-11385-1-git-send-email-emil.l.velikov@gmail.com> Cc: emil.l.velikov@gmail.com 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: , MIME-Version: 1.0 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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 Get the test from completely broken to working like a charm. - Use the same variable type for both HashInsert and HashLookup. - Use correct storage type for the HashLookup return value. - Remove useless backward iteration of HashLookup(i). v2: - Use void * instead of unsigned long. - Change value to key << 16 | key. Signed-off-by: Emil Velikov --- tests/hash.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/tests/hash.c b/tests/hash.c index 517a667..ee11e23 100644 --- a/tests/hash.c +++ b/tests/hash.c @@ -116,28 +116,28 @@ static void compute_dist(HashTablePtr table) } static void check_table(HashTablePtr table, - unsigned long key, unsigned long value) + unsigned long key, void * value) { - unsigned long retval = 0; - int retcode = drmHashLookup(table, key, &retval); + void *retval; + int retcode = drmHashLookup(table, key, &retval); switch (retcode) { case -1: printf("Bad magic = 0x%08lx:" - " key = %lu, expected = %lu, returned = %lu\n", + " key = %lu, expected = %p, returned = %p\n", table->magic, key, value, retval); break; case 1: - printf("Not found: key = %lu, expected = %lu returned = %lu\n", + printf("Not found: key = %lu, expected = %p, returned = %p\n", key, value, retval); break; case 0: if (value != retval) - printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", + printf("Bad value: key = %lu, expected = %p, returned = %p\n", key, value, retval); break; default: - printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", + printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n", retcode, key, value, retval); break; } @@ -145,52 +145,49 @@ static void check_table(HashTablePtr table, int main(void) { - HashTablePtr table; - int i; + HashTablePtr table; + unsigned long i; printf("\n***** 256 consecutive integers ****\n"); table = drmHashCreate(); - for (i = 0; i < 256; i++) drmHashInsert(table, i, i); - for (i = 0; i < 256; i++) check_table(table, i, i); - for (i = 256; i >= 0; i--) check_table(table, i, i); + for (i = 0; i < 256; i++) drmHashInsert(table, i, (void *)(i << 16 | i)); + for (i = 0; i < 256; i++) check_table(table, i, (void *)(i << 16 | i)); compute_dist(table); drmHashDestroy(table); printf("\n***** 1024 consecutive integers ****\n"); table = drmHashCreate(); - for (i = 0; i < 1024; i++) drmHashInsert(table, i, i); - for (i = 0; i < 1024; i++) check_table(table, i, i); - for (i = 1024; i >= 0; i--) check_table(table, i, i); + for (i = 0; i < 1024; i++) drmHashInsert(table, i, (void *)(i << 16 | i)); + for (i = 0; i < 1024; i++) check_table(table, i, (void *)(i << 16 | i)); compute_dist(table); drmHashDestroy(table); printf("\n***** 1024 consecutive page addresses (4k pages) ****\n"); table = drmHashCreate(); - for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, i); - for (i = 0; i < 1024; i++) check_table(table, i*4096, i); - for (i = 1024; i >= 0; i--) check_table(table, i*4096, i); + for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, (void *)(i << 16 | i)); + for (i = 0; i < 1024; i++) check_table(table, i*4096, (void *)(i << 16 | i)); compute_dist(table); drmHashDestroy(table); printf("\n***** 1024 random integers ****\n"); table = drmHashCreate(); srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) drmHashInsert(table, random(), i); + for (i = 0; i < 1024; i++) drmHashInsert(table, random(), (void *)(i << 16 | i)); srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); + for (i = 0; i < 1024; i++) check_table(table, random(), (void *)(i << 16 | i)); srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); + for (i = 0; i < 1024; i++) check_table(table, random(), (void *)(i << 16 | i)); compute_dist(table); drmHashDestroy(table); printf("\n***** 5000 random integers ****\n"); table = drmHashCreate(); srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) drmHashInsert(table, random(), i); + for (i = 0; i < 5000; i++) drmHashInsert(table, random(), (void *)(i << 16 | i)); srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); + for (i = 0; i < 5000; i++) check_table(table, random(), (void *)(i << 16 | i)); srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); + for (i = 0; i < 5000; i++) check_table(table, random(), (void *)(i << 16 | i)); compute_dist(table); drmHashDestroy(table);