test_hash.c: split test_hash_init
[sfrench/cifs-2.6.git] / lib / test_hash.c
index 2b4fe4976cc483d2cc460a11643258b392c64090..032849a48da704d49e50d2b6ee55634e5be16f87 100644 (file)
@@ -158,11 +158,39 @@ test_int_hash(unsigned long long h64, u32 hash_or[2][33])
 
 #define SIZE 256       /* Run time is cubic in SIZE */
 
-static int __init
-test_hash_init(void)
+static int __init test_string_or(void)
 {
        char buf[SIZE+1];
-       u32 string_or = 0, hash_or[2][33] = { { 0, } };
+       u32 string_or = 0;
+       int i, j;
+
+       fill_buf(buf, SIZE, 1);
+
+       /* Test every possible non-empty substring in the buffer. */
+       for (j = SIZE; j > 0; --j) {
+               buf[j] = '\0';
+
+               for (i = 0; i <= j; i++) {
+                       u32 h0 = full_name_hash(buf+i, buf+i, j-i);
+
+                       string_or |= h0;
+               } /* i */
+       } /* j */
+
+       /* The OR of all the hash values should cover all the bits */
+       if (~string_or) {
+               pr_err("OR of all string hash results = %#x != %#x",
+                      string_or, -1u);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int __init test_hash_or(void)
+{
+       char buf[SIZE+1];
+       u32 hash_or[2][33] = { { 0, } };
        unsigned tests = 0;
        unsigned long long h64 = 0;
        int i, j;
@@ -192,7 +220,6 @@ test_hash_init(void)
                                return -EINVAL;
                        }
 
-                       string_or |= h0;
                        h64 = h64 << 32 | h0;   /* For use with hash_64 */
                        if (!test_int_hash(h64, hash_or))
                                return -EINVAL;
@@ -200,12 +227,6 @@ test_hash_init(void)
                } /* i */
        } /* j */
 
-       /* The OR of all the hash values should cover all the bits */
-       if (~string_or) {
-               pr_err("OR of all string hash results = %#x != %#x",
-                       string_or, -1u);
-               return -EINVAL;
-       }
        if (~hash_or[0][0]) {
                pr_err("OR of all __hash_32 results = %#x != %#x",
                        hash_or[0][0], -1u);
@@ -237,6 +258,13 @@ test_hash_init(void)
                }
        }
 
+       pr_notice("%u tests passed.", tests);
+
+       return 0;
+}
+
+static void __init notice_skipped_tests(void)
+{
        /* Issue notices about skipped tests. */
 #ifdef HAVE_ARCH__HASH_32
 #if HAVE_ARCH__HASH_32 != 1
@@ -252,10 +280,24 @@ test_hash_init(void)
 #else
        pr_info("hash_64() has no arch implementation to test.");
 #endif
+}
 
-       pr_notice("%u tests passed.", tests);
+static int __init
+test_hash_init(void)
+{
+       int ret;
 
-       return 0;
+       ret = test_string_or();
+       if (ret < 0)
+               return ret;
+
+       ret = test_hash_or();
+       if (ret < 0)
+               return ret;
+
+       notice_skipped_tests();
+
+       return ret;
 }
 
 static void __exit test_hash_exit(void)