From patchwork Sun Mar 22 22:03:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 6067801 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 1FC719F2A9 for ; Sun, 22 Mar 2015 22:00:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2EB312022D for ; Sun, 22 Mar 2015 22:00:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2F25D2024C for ; Sun, 22 Mar 2015 22:00:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 681B86E3CC; Sun, 22 Mar 2015 15:00:47 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com [74.125.82.42]) by gabe.freedesktop.org (Postfix) with ESMTP id C48026E3C7 for ; Sun, 22 Mar 2015 15:00:43 -0700 (PDT) Received: by wgs2 with SMTP id 2so24976059wgs.1 for ; Sun, 22 Mar 2015 15:00:43 -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=oEBc2G+7CEGUz2IhfuWDUIhTRHfA20aop+/vBQkDXWA=; b=zzlWBGR+hpmJiexntQCSl4sfQZboCdqBxwa2yyROBVU4jtJ/uHyWgmjKdU06897BBt /6Oa3rI5U+0L38ApgjU7OxYWYeR+1pSg58IiWLafhrZkrVxt9UIc96LZz4T+foQr34wU rLbdcE7gyM+l9DA3G7dETWUvjmKjzfrXP4Elf9ZNxa+1oM99Yx9Zw+wMk/lMRQHu+8va DyUxitz/PtfT3jStDPuIW8f2VMi1ZUaMdoouvNq6MYOyk+qi2Ny7X9upzPgQn1yoQKVK 1t8uLe+Oe9x0/YB756fkSC3w3sJZm45g/6KNn7i0teYCabbQ6LlEW7y4DTilAnWJNsGx nM5Q== X-Received: by 10.194.185.68 with SMTP id fa4mr175781676wjc.111.1427061643193; Sun, 22 Mar 2015 15:00:43 -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 dq8sm8281654wib.9.2015.03.22.15.00.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Mar 2015 15:00:42 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 3/9] tests/hash: misc compilation fixes Date: Sun, 22 Mar 2015 22:03:39 +0000 Message-Id: <1427061825-27470-4-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.3.1 In-Reply-To: <1427061825-27470-1-git-send-email-emil.l.velikov@gmail.com> References: <1427061825-27470-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). Signed-off-by: Emil Velikov --- tests/hash.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/tests/hash.c b/tests/hash.c index d57d2dc..902919f 100644 --- a/tests/hash.c +++ b/tests/hash.c @@ -139,27 +139,27 @@ static void compute_dist(HashTablePtr table) static void check_table(HashTablePtr table, unsigned long key, unsigned long value) { - unsigned long retval = 0; - int retcode = drmHashLookup(table, key, &retval); + unsigned long *retval; + int retcode = drmHashLookup(table, key, (void **)&retval); switch (retcode) { case -1: printf("Bad magic = 0x%08lx:" " key = %lu, expected = %lu, returned = %lu\n", - table->magic, key, value, retval); + table->magic, key, value, *retval); break; case 1: - printf("Not found: key = %lu, expected = %lu returned = %lu\n", - key, value, retval); + printf("Not found: key = %lu, expected = %lu, returned = %lu\n", + key, value, *retval); break; case 0: - if (value != retval) + if (value != *retval) printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", - key, value, retval); + key, value, *retval); break; default: printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", - retcode, key, value, retval); + retcode, key, value, *retval); break; } } @@ -167,36 +167,33 @@ static void check_table(HashTablePtr table, int main(void) { HashTablePtr table; - int i; + 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++) drmHashInsert(table, i, (void *)&i); for (i = 0; i < 256; i++) check_table(table, i, i); - for (i = 256; i >= 0; i--) check_table(table, i, 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++) drmHashInsert(table, i, (void *)&i); for (i = 0; i < 1024; i++) check_table(table, i, i); - for (i = 1024; i >= 0; i--) check_table(table, i, 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++) drmHashInsert(table, i*4096, (void *)&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); 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); srandom(0xbeefbeef); for (i = 0; i < 1024; i++) check_table(table, random(), i); srandom(0xbeefbeef); @@ -207,7 +204,7 @@ int main(void) 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); srandom(0xbeefbeef); for (i = 0; i < 5000; i++) check_table(table, random(), i); srandom(0xbeefbeef);