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