1*6836bf78Sjruoho /* $NetBSD: t_mi_vector_hash.c,v 1.3 2011/07/07 11:12:18 jruoho Exp $ */
2d6e21947Sjoerg /*-
3d6e21947Sjoerg * Copyright (c) 2009 The NetBSD Foundation, Inc.
4d6e21947Sjoerg * All rights reserved.
5d6e21947Sjoerg *
6d6e21947Sjoerg * This code is derived from software contributed to The NetBSD Foundation
7d6e21947Sjoerg * by Joerg Sonnenberger.
8d6e21947Sjoerg *
9d6e21947Sjoerg * Redistribution and use in source and binary forms, with or without
10d6e21947Sjoerg * modification, are permitted provided that the following conditions
11d6e21947Sjoerg * are met:
12d6e21947Sjoerg *
13d6e21947Sjoerg * 1. Redistributions of source code must retain the above copyright
14d6e21947Sjoerg * notice, this list of conditions and the following disclaimer.
15d6e21947Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
16d6e21947Sjoerg * notice, this list of conditions and the following disclaimer in
17d6e21947Sjoerg * the documentation and/or other materials provided with the
18d6e21947Sjoerg * distribution.
19d6e21947Sjoerg *
20d6e21947Sjoerg * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21d6e21947Sjoerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22d6e21947Sjoerg * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23d6e21947Sjoerg * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24d6e21947Sjoerg * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25d6e21947Sjoerg * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26d6e21947Sjoerg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27d6e21947Sjoerg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28d6e21947Sjoerg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29d6e21947Sjoerg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30d6e21947Sjoerg * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31d6e21947Sjoerg * SUCH DAMAGE.
32d6e21947Sjoerg */
33d6e21947Sjoerg
347afbfeabSjoerg #include <sys/cdefs.h>
35*6836bf78Sjruoho __RCSID("$NetBSD: t_mi_vector_hash.c,v 1.3 2011/07/07 11:12:18 jruoho Exp $");
367afbfeabSjoerg
37d6e21947Sjoerg #include <atf-c.h>
38d6e21947Sjoerg #include <stdlib.h>
39d6e21947Sjoerg #include <string.h>
40d6e21947Sjoerg
41*6836bf78Sjruoho ATF_TC(mi_vector_hash_basic);
ATF_TC_HEAD(mi_vector_hash_basic,tc)42*6836bf78Sjruoho ATF_TC_HEAD(mi_vector_hash_basic, tc)
43d6e21947Sjoerg {
44d6e21947Sjoerg atf_tc_set_md_var(tc, "descr",
45d6e21947Sjoerg "Test mi_vector_hash_vector_hash for consistent results");
46d6e21947Sjoerg }
47d6e21947Sjoerg
48d6e21947Sjoerg static const struct testvector {
49d6e21947Sjoerg const char *vector;
50d6e21947Sjoerg uint32_t hashes[3];
51d6e21947Sjoerg } testv[] = {
52d6e21947Sjoerg { "hello, world", { 0xd38f7f21, 0xbf6be9ab, 0x37a0e989 } },
53d6e21947Sjoerg { "", { 0x9b2ec03d, 0xdb2b69ae, 0xbd49d10d } },
54d6e21947Sjoerg { "a", { 0x9454baa3, 0xb711c708, 0x29eec818 } },
55d6e21947Sjoerg { "ab", { 0x9a5dca90, 0xdd212644, 0x9879ac41 } },
56d6e21947Sjoerg { "abc", { 0x0b91c470, 0x4770cdf5, 0x251e4793 } },
57d6e21947Sjoerg { "abcd", { 0x5f128df3, 0xf5a667a6, 0x5ae61fa5 } },
58d6e21947Sjoerg { "abcde", { 0x4cbae281, 0x799c0ed5, 0x03a96866 } },
59d6e21947Sjoerg { "abcdef", { 0x507a54c8, 0xb6bd06f4, 0xde922732 } },
60d6e21947Sjoerg { "abcdefg", { 0xae2bca5d, 0x61e960ef, 0xb9e6762c } },
61d6e21947Sjoerg { "abcdefgh", { 0xd1021264, 0x87f6988f, 0x053f775e } },
62d6e21947Sjoerg { "abcdefghi", { 0xe380defc, 0xfc35a811, 0x3a7b0a5f } },
63d6e21947Sjoerg { "abcdefghij", { 0x9a504408, 0x70d2e89d, 0xc9cac242 } },
64d6e21947Sjoerg { "abcdefghijk", { 0x376117d0, 0x89f434d4, 0xe52b8e4c } },
65d6e21947Sjoerg { "abcdefghijkl", { 0x92253599, 0x7b6ff99e, 0x0b1b3ea5 } },
66d6e21947Sjoerg { "abcdefghijklm", { 0x92ee6a52, 0x55587d47, 0x3122b031 } },
67d6e21947Sjoerg { "abcdefghijklmn", { 0x827baf08, 0x1d0ada73, 0xfec330e0 } },
68d6e21947Sjoerg { "abcdefghijklmno", { 0x06ab787d, 0xc1ad17c2, 0x11dccf31 } },
69d6e21947Sjoerg { "abcdefghijklmnop", { 0x2cf18103, 0x638c9268, 0xfa1ecf51 } },
70d6e21947Sjoerg };
71d6e21947Sjoerg
ATF_TC_BODY(mi_vector_hash_basic,tc)72*6836bf78Sjruoho ATF_TC_BODY(mi_vector_hash_basic, tc)
73d6e21947Sjoerg {
74d6e21947Sjoerg size_t i, j, len;
75d6e21947Sjoerg uint32_t hashes[3];
76d6e21947Sjoerg char buf[256];
77d6e21947Sjoerg
78d6e21947Sjoerg for (j = 0; j < 8; ++j) {
79d6e21947Sjoerg for (i = 0; i < sizeof(testv) / sizeof(testv[0]); ++i) {
80d6e21947Sjoerg len = strlen(testv[i].vector);
81d6e21947Sjoerg strcpy(buf + j, testv[i].vector);
82d6e21947Sjoerg mi_vector_hash(buf + j, len, 0, hashes);
83d6e21947Sjoerg ATF_CHECK_EQ(hashes[0], testv[i].hashes[0]);
84d6e21947Sjoerg ATF_CHECK_EQ(hashes[1], testv[i].hashes[1]);
85d6e21947Sjoerg ATF_CHECK_EQ(hashes[2], testv[i].hashes[2]);
86d6e21947Sjoerg }
87d6e21947Sjoerg }
88d6e21947Sjoerg }
89d6e21947Sjoerg
ATF_TP_ADD_TCS(tp)90d6e21947Sjoerg ATF_TP_ADD_TCS(tp)
91d6e21947Sjoerg {
92*6836bf78Sjruoho ATF_TP_ADD_TC(tp, mi_vector_hash_basic);
93d6e21947Sjoerg
94d6e21947Sjoerg return atf_no_error();
95d6e21947Sjoerg }
96