Update .gitignore files
[openafs.git] / tests / opr / jhash-t.c
1 /*
2  * Copyright (c) 2011 Your File System Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include <afsconfig.h>
26 #include <afs/param.h>
27
28 #include <roken.h>
29 #include <tap/basic.h>
30
31 #include <opr/jhash.h>
32
33 /* Bob Jenkins' lookup3.c comes with a load of self test functions, but
34  * unfortunately, they all use 'hashlittle' (his unaligned hash function). As
35  * we have only got 'hashword' (word aligned arrays) in OpenAFS, we need to roll
36  * our own tests.
37  */
38
39 int
40 main(int argc, char **argv)
41 {
42    plan(8);
43    uint32_t test[] = {3526055646, 2064483663, 3234460805, 3963629775};
44
45    is_int(256, opr_jhash_size(8), "opr_jhash_size returns expected value");
46    is_int(255, opr_jhash_mask(8), "opr_jhash_mask returns expected value");
47
48    is_int(0xdeadbeef, opr_jhash(test, 0, 0), "empty array hashes as expected");
49    is_int(766530906, opr_jhash(test, 4, 0), "simple array works");
50    is_int(3782684773, opr_jhash(test, 4, 1), "changing initval works");
51
52    test[2]++;
53    is_int(1977082159, opr_jhash(test, 4, 0), "modifying value works");
54
55    is_int(1100796964, opr_jhash(test, 1, 0),
56           "single value works through jhash");
57    is_int(1100796964, opr_jhash_int(test[0], 0),
58           "single value works through jhash_int");
59
60    return 0;
61 }