2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Add tests for hash function, and comment dns_rbt_addnode() (#41179)

No CHANGES entry necessary.
This commit is contained in:
Mukund Sivaraman
2016-02-08 14:51:53 +05:30
parent 0c29904b27
commit 614ce1b65f
3 changed files with 154 additions and 16 deletions

View File

@@ -14,8 +14,6 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id$ */
/* ! \file */
#include <config.h>
@@ -25,6 +23,8 @@
#include <stdio.h>
#include <string.h>
#include <isc/hash.h>
#include <isc/crc64.h>
#include <isc/hmacmd5.h>
#include <isc/hmacsha.h>
@@ -1848,10 +1848,111 @@ ATF_TC_BODY(isc_crc64, tc) {
}
}
ATF_TC(isc_hash_function);
ATF_TC_HEAD(isc_hash_function, tc) {
atf_tc_set_md_var(tc, "descr", "Hash function test");
}
ATF_TC_BODY(isc_hash_function, tc) {
unsigned int h1;
unsigned int h2;
UNUSED(tc);
/* Incremental hashing */
h1 = isc_hash_function(NULL, 0, ISC_TRUE, NULL);
h1 = isc_hash_function("This ", 5, ISC_TRUE, &h1);
h1 = isc_hash_function("is ", 3, ISC_TRUE, &h1);
h1 = isc_hash_function("a long test", 12, ISC_TRUE, &h1);
h2 = isc_hash_function("This is a long test", 20,
ISC_TRUE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Immutability of hash function */
h1 = isc_hash_function(NULL, 0, ISC_TRUE, NULL);
h2 = isc_hash_function(NULL, 0, ISC_TRUE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Hash function characteristics */
h1 = isc_hash_function("Hello world", 12, ISC_TRUE, NULL);
h2 = isc_hash_function("Hello world", 12, ISC_TRUE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Case */
h1 = isc_hash_function("Hello world", 12, ISC_FALSE, NULL);
h2 = isc_hash_function("heLLo WorLd", 12, ISC_FALSE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Unequal */
h1 = isc_hash_function("Hello world", 12, ISC_TRUE, NULL);
h2 = isc_hash_function("heLLo WorLd", 12, ISC_TRUE, NULL);
ATF_CHECK(h1 != h2);
}
ATF_TC(isc_hash_function_reverse);
ATF_TC_HEAD(isc_hash_function_reverse, tc) {
atf_tc_set_md_var(tc, "descr", "Reverse hash function test");
}
ATF_TC_BODY(isc_hash_function_reverse, tc) {
unsigned int h1;
unsigned int h2;
UNUSED(tc);
/* Incremental hashing */
h1 = isc_hash_function_reverse(NULL, 0, ISC_TRUE, NULL);
h1 = isc_hash_function_reverse("\000", 1, ISC_TRUE, &h1);
h1 = isc_hash_function_reverse("\003org", 4, ISC_TRUE, &h1);
h1 = isc_hash_function_reverse("\007example", 8, ISC_TRUE, &h1);
h2 = isc_hash_function_reverse("\007example\003org\000", 13,
ISC_TRUE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Immutability of hash function */
h1 = isc_hash_function_reverse(NULL, 0, ISC_TRUE, NULL);
h2 = isc_hash_function_reverse(NULL, 0, ISC_TRUE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Hash function characteristics */
h1 = isc_hash_function_reverse("Hello world", 12, ISC_TRUE, NULL);
h2 = isc_hash_function_reverse("Hello world", 12, ISC_TRUE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Case */
h1 = isc_hash_function_reverse("Hello world", 12, ISC_FALSE, NULL);
h2 = isc_hash_function_reverse("heLLo WorLd", 12, ISC_FALSE, NULL);
ATF_CHECK_EQ(h1, h2);
/* Unequal */
h1 = isc_hash_function_reverse("Hello world", 12, ISC_TRUE, NULL);
h2 = isc_hash_function_reverse("heLLo WorLd", 12, ISC_TRUE, NULL);
ATF_CHECK(h1 != h2);
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
/*
* Tests of hash functions, including isc_hash and the
* various cryptographic hashes.
*/
ATF_TP_ADD_TC(tp, isc_hash_function);
ATF_TP_ADD_TC(tp, isc_hash_function_reverse);
ATF_TP_ADD_TC(tp, isc_hmacmd5);
ATF_TP_ADD_TC(tp, isc_hmacsha1);
ATF_TP_ADD_TC(tp, isc_hmacsha224);
@@ -1865,6 +1966,6 @@ ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_sha384);
ATF_TP_ADD_TC(tp, isc_sha512);
ATF_TP_ADD_TC(tp, isc_crc64);
return (atf_no_error());
}