From: Jan Vesely Subject: Re: [PATCH libdrm 3/9] tests/hash: misc compilation fixes Date: Mon, 23 Mar 2015 18:42:59 -0400 Message-ID: <1427150579.3547.42.camel@rutgers.edu> References: <1427061825-27470-1-git-send-email-emil.l.velikov@gmail.com> <1427061825-27470-4-git-send-email-emil.l.velikov@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0369167089==" Return-path: Received: from mail-qg0-f43.google.com (mail-qg0-f43.google.com [209.85.192.43]) by gabe.freedesktop.org (Postfix) with ESMTP id 115586E66A for ; Mon, 23 Mar 2015 15:43:01 -0700 (PDT) Received: by qgfa8 with SMTP id a8so169606677qgf.0 for ; Mon, 23 Mar 2015 15:43:00 -0700 (PDT) In-Reply-To: <1427061825-27470-4-git-send-email-emil.l.velikov@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Emil Velikov Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============0369167089== Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-5fOpDr6l4AG3BJ4sOKm+" --=-5fOpDr6l4AG3BJ4sOKm+ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 2015-03-22 at 22:03 +0000, Emil Velikov wrote: > Get the test from completely broken to working like a charm. >=20 > - 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). >=20 > Signed-off-by: Emil Velikov > --- > tests/hash.c | 31 ++++++++++++++----------------- > 1 file changed, 14 insertions(+), 17 deletions(-) >=20 > 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) I think we should use void* for value here. > { > - unsigned long retval =3D 0; > - int retcode =3D drmHashLookup(table, key, &retval); > + unsigned long *retval; > + int retcode =3D drmHashLookup(table, key, (void **)&retval= ); I don't think this is correct. If the entry is found, it stores address to stack variable i in retval, which at this point in iteration incidentally contains the value we are looking for. > =20 > switch (retcode) { > case -1: > printf("Bad magic =3D 0x%08lx:" > " key =3D %lu, expected =3D %lu, returned =3D %lu\n", > - table->magic, key, value, retval); > + table->magic, key, value, *retval); > break; > case 1: > - printf("Not found: key =3D %lu, expected =3D %lu returned =3D %lu\n", > - key, value, retval); > + printf("Not found: key =3D %lu, expected =3D %lu, returned =3D %lu\n", > + key, value, *retval); > break; > case 0: > - if (value !=3D retval) > + if (value !=3D *retval) > printf("Bad value: key =3D %lu, expected =3D %lu, returned =3D %lu\= n", > - key, value, retval); > + key, value, *retval); > break; > default: > printf("Bad retcode =3D %d: key =3D %lu, expected =3D %lu, returned =3D= %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; > =20 > printf("\n***** 256 consecutive integers ****\n"); > table =3D drmHashCreate(); > - for (i =3D 0; i < 256; i++) drmHashInsert(table, i, i); > + for (i =3D 0; i < 256; i++) drmHashInsert(table, i, (void *)&i); This changes the entries inserted. previously it would insert values [0, 256). Now it inserts address of i 256 times. I think we should change the inserted values to be different from the key (offset should be enough), to catch the kind of scenario this tests creates. > for (i =3D 0; i < 256; i++) check_table(table, i, i); > - for (i =3D 256; i >=3D 0; i--) check_table(table, i, i); > compute_dist(table); > drmHashDestroy(table); > =20 > printf("\n***** 1024 consecutive integers ****\n"); > table =3D drmHashCreate(); > - for (i =3D 0; i < 1024; i++) drmHashInsert(table, i, i); > + for (i =3D 0; i < 1024; i++) drmHashInsert(table, i, (void *)&i); > for (i =3D 0; i < 1024; i++) check_table(table, i, i); > - for (i =3D 1024; i >=3D 0; i--) check_table(table, i, i); > compute_dist(table); > drmHashDestroy(table); > =20 > printf("\n***** 1024 consecutive page addresses (4k pages) ****\n"); > table =3D drmHashCreate(); > - for (i =3D 0; i < 1024; i++) drmHashInsert(table, i*4096, i); > + for (i =3D 0; i < 1024; i++) drmHashInsert(table, i*4096, (void *)&i= ); > for (i =3D 0; i < 1024; i++) check_table(table, i*4096, i); > - for (i =3D 1024; i >=3D 0; i--) check_table(table, i*4096, i); > compute_dist(table); > drmHashDestroy(table); > =20 > printf("\n***** 1024 random integers ****\n"); > table =3D drmHashCreate(); > srandom(0xbeefbeef); > - for (i =3D 0; i < 1024; i++) drmHashInsert(table, random(), i); > + for (i =3D 0; i < 1024; i++) drmHashInsert(table, random(), (void *)= &i); > srandom(0xbeefbeef); > for (i =3D 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 =3D drmHashCreate(); > srandom(0xbeefbeef); > - for (i =3D 0; i < 5000; i++) drmHashInsert(table, random(), i); > + for (i =3D 0; i < 5000; i++) drmHashInsert(table, random(), (void *)= &i); > srandom(0xbeefbeef); > for (i =3D 0; i < 5000; i++) check_table(table, random(), i); > srandom(0xbeefbeef); --=20 Jan Vesely --=-5fOpDr6l4AG3BJ4sOKm+ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCgAGBQJVEJbzAAoJEDhUsXb6ZiH/V9cP/jQe/b1yXJ/3MgiiL1gmwLpI 9MoIKyB9WdTX3kLZR7Ho5B67/iZhU4yLUYZYLLLS3CxkK+70a+e/5WkgHopvqQ24 od33iBi7Q7LBAz/tfOUCTS/lDbDDGrlzlYUgyzSjB9v6o9h4zvbjo9RArzSu7AbP fDymffL7YBx2G2N73mmX3zkX0Ub7JqmOWa/8fS94bQmJbjUiumrNR5Jx7fR6HQxC VuX0tLlw2QRaeGGH423D+LNP/JWGwwTcq2EHgT7nL+pK9zdzIxQiUcYWWhgTkmqj pkBcguy6NpwWVEsb49HAAs7vfCwwC5p73SlwrPxlL8k6EfRAmsxpK7htfasMH7N2 jUVvl0aKj0ZKRbB9D8yT4wEcZx4IjPagfGE1Y2/kNF1NU19PQrMPvGk+xiRJ9yKs MnVHZIKyJ9C5r9HmGLlzS1tZ+A997XMF/GCcc3kXd+HFMG1Y6fwcaqxRXNHyXhPf C8TGC30xQk1R/gcbu86dn5FK2Amf1hTB+U6H2t5/V3iXq32Pgrv1RRJzqKaTO+dW sjPnCF371P2/JKgocKD6HrOGVubpxcWI5+4mqMnE89Wru0XVcp483eoCu9BPb0uI GttYc8+PUh1wq6NF075sTtsOhwnaGfXcOqwAagcky5YgfujKqvpg0HD4/6XdZ004 xEURPqqdTxOOTIysiFh4 =zIk0 -----END PGP SIGNATURE----- --=-5fOpDr6l4AG3BJ4sOKm+-- --===============0369167089== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHA6Ly9saXN0 cy5mcmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9kcmktZGV2ZWwK --===============0369167089==--