From patchwork Thu Mar 26 23:57:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 6102751 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 190F2BF910 for ; Thu, 26 Mar 2015 23:54:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A33DF20450 for ; Thu, 26 Mar 2015 23:54:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7F4402044B for ; Thu, 26 Mar 2015 23:54:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8AF116EACF; Thu, 26 Mar 2015 16:54:04 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by gabe.freedesktop.org (Postfix) with ESMTP id BA5EC6EACF for ; Thu, 26 Mar 2015 16:54:02 -0700 (PDT) Received: by wibgn9 with SMTP id gn9so9399608wib.1 for ; Thu, 26 Mar 2015 16:54:02 -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=RIBByi9DN8c314kI4qN81gbNZWlQ6CBPSfngYDXjuLY=; b=EwriaQqf3qaSutjZcNuMwD3H9GakTICl6CBLOmh5vrU7PpobDwVOH+BZwN/Na1PIHE UMfwFhbxgK8Wv6bGQom/AM+sVXN+8LNairsyzuI3w5TEsUAFgs86Q8VmSO+lmCcdwxTa tCig+kIT7I7bPU/108iQ+7fCg3tfquhe61Ckarc5KlqRpc12wJ8uVsaIV1c/i2MNLiDt b4saAnnywGKeyjPIyro4PdYd52TeNnAoAnncSQUwY0ZYrjjsaWOA9BDGQx6JelmKt/pp Ut6sVrQp67nf+2TJhgPlHuv/X/23RlbVGFtHgCcnS1Nvs/bkcBsJS3XZJZJ05Tm6r0ni 4rwA== X-Received: by 10.194.193.69 with SMTP id hm5mr33162063wjc.43.1427414042068; Thu, 26 Mar 2015 16:54:02 -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.54.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 16:54:01 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm v2 3/8] tests/hash: style fixes Date: Thu, 26 Mar 2015 23:57:06 +0000 Message-Id: <1427414231-11385-3-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 v2: Rebase on earlier changes. Keep count initialisation as is. Signed-off-by: Emil Velikov Reviewed-by: Jan Vesely --- tests/hash.c | 90 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/tests/hash.c b/tests/hash.c index ee11e23..1543c86 100644 --- a/tests/hash.c +++ b/tests/hash.c @@ -80,21 +80,25 @@ static int dist[DIST_LIMIT]; static void clear_dist(void) { int i; - for (i = 0; i < DIST_LIMIT; i++) dist[i] = 0; + for (i = 0; i < DIST_LIMIT; i++) + dist[i] = 0; } static int count_entries(HashBucketPtr bucket) { int count = 0; - for (; bucket; bucket = bucket->next) ++count; + for (; bucket; bucket = bucket->next) + ++count; return count; } static void update_dist(int count) { - if (count >= DIST_LIMIT) ++dist[DIST_LIMIT-1]; - else ++dist[count]; + if (count >= DIST_LIMIT) + ++dist[DIST_LIMIT-1]; + else + ++dist[count]; } static void compute_dist(HashTablePtr table) @@ -103,43 +107,45 @@ static void compute_dist(HashTablePtr table) HashBucketPtr bucket; printf("Entries = %ld, hits = %ld, partials = %ld, misses = %ld\n", - table->entries, table->hits, table->partials, table->misses); + table->entries, table->hits, table->partials, table->misses); clear_dist(); for (i = 0; i < HASH_SIZE; i++) { - bucket = table->buckets[i]; - update_dist(count_entries(bucket)); + bucket = table->buckets[i]; + update_dist(count_entries(bucket)); } for (i = 0; i < DIST_LIMIT; i++) { - if (i != DIST_LIMIT-1) printf("%5d %10d\n", i, dist[i]); - else printf("other %10d\n", dist[i]); + if (i != DIST_LIMIT-1) + printf("%5d %10d\n", i, dist[i]); + else + printf("other %10d\n", dist[i]); } } static void check_table(HashTablePtr table, - unsigned long key, void * value) + unsigned long key, void * value) { void *retval; int retcode = drmHashLookup(table, key, &retval); switch (retcode) { case -1: - printf("Bad magic = 0x%08lx:" - " key = %lu, expected = %p, returned = %p\n", - table->magic, key, value, retval); - break; + printf("Bad magic = 0x%08lx:" + " key = %lu, expected = %p, returned = %p\n", + table->magic, key, value, retval); + break; case 1: - printf("Not found: key = %lu, expected = %p, returned = %p\n", - key, value, retval); - break; + 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 = %p, returned = %p\n", - key, value, retval); - break; + if (value != retval) + printf("Bad value: key = %lu, expected = %p, returned = %p\n", + key, value, retval); + break; default: - printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n", - retcode, key, value, retval); - break; + printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n", + retcode, key, value, retval); + break; } } @@ -150,44 +156,56 @@ int main(void) printf("\n***** 256 consecutive integers ****\n"); table = drmHashCreate(); - 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)); + 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, (void *)(i << 16 | i)); - for (i = 0; i < 1024; i++) check_table(table, i, (void *)(i << 16 | 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, (void *)(i << 16 | i)); - for (i = 0; i < 1024; i++) check_table(table, i*4096, (void *)(i << 16 | 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(), (void *)(i << 16 | 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(), (void *)(i << 16 | 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(), (void *)(i << 16 | 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(), (void *)(i << 16 | 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(), (void *)(i << 16 | 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(), (void *)(i << 16 | i)); + for (i = 0; i < 5000; i++) + check_table(table, random(), (void *)(i << 16 | i)); compute_dist(table); drmHashDestroy(table);