a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews/*
574176a88d7fc412312e11a274d74cd2f122a0f4Tinderbox User * Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews/* $Id$ */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews/*! \file */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews#include <config.h>
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <stdlib.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <string.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <unistd.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews#include <atf-c.h>
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <isc/buffer.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <isc/commandline.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <isc/mem.h>
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#include <isc/os.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <isc/print.h>
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman#include <isc/thread.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <isc/util.h>
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki#include <dns/compress.h>
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews#include <dns/name.h>
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews#include <dns/fixedname.h>
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews#include "dnstest.h"
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews/*
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * Individual unit tests
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark AndrewsATF_TC(fullcompare);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark AndrewsATF_TC_HEAD(fullcompare, tc) {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test");
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews}
a266ab205bfd1c510022e2cd2a8cb62988242593Mark AndrewsATF_TC_BODY(fullcompare, tc) {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_fixedname_t fixed1;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_fixedname_t fixed2;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_name_t *name1;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_name_t *name2;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_namereln_t relation;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews int i;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews isc_result_t result;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews struct {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews const char *name1;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews const char *name2;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_namereln_t relation;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews int order;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews unsigned int nlabels;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews } data[] = {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews /* relative */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "", "", dns_namereln_equal, 0, 0 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "foo", "", dns_namereln_subdomain, 1, 0 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "", "foo", dns_namereln_contains, -1, 0 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "foo", "bar", dns_namereln_none, 4, 0 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "bar", "foo", dns_namereln_none, -4, 0 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "bar.foo", "foo", dns_namereln_subdomain, 1, 1 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "foo", "bar.foo", dns_namereln_contains, -1, 1 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "baz.bar.foo", "bar.foo", dns_namereln_subdomain, 1, 2 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "bar.foo", "baz.bar.foo", dns_namereln_contains, -1, 2 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "foo.example", "bar.example", dns_namereln_commonancestor,
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews 4, 1 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews /* absolute */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { ".", ".", dns_namereln_equal, 0, 1 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "foo.", "bar.", dns_namereln_commonancestor, 4, 1 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "bar.", "foo.", dns_namereln_commonancestor, -4, 1 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "foo.example.", "bar.example.", dns_namereln_commonancestor,
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews 4, 2 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "bar.foo.", "foo.", dns_namereln_subdomain, 1, 2 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "foo.", "bar.foo.", dns_namereln_contains, -1, 2 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "baz.bar.foo.", "bar.foo.", dns_namereln_subdomain, 1, 3 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { "bar.foo.", "baz.bar.foo.", dns_namereln_contains, -1, 3 },
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews { NULL, NULL, dns_namereln_none, 0, 0 }
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews };
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews UNUSED(tc);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_fixedname_init(&fixed1);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews name1 = dns_fixedname_name(&fixed1);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_fixedname_init(&fixed2);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews name2 = dns_fixedname_name(&fixed2);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews for (i = 0; data[i].name1 != NULL; i++) {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews int order = 3000;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews unsigned int nlabels = 3000;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews if (data[i].name1[0] == 0) {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_fixedname_init(&fixed1);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews } else {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews result = dns_name_fromstring2(name1, data[i].name1,
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews NULL, 0, NULL);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews }
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews if (data[i].name2[0] == 0) {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews dns_fixedname_init(&fixed2);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews } else {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews result = dns_name_fromstring2(name2, data[i].name2,
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews NULL, 0, NULL);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews }
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews relation = dns_name_fullcompare(name1, name1, &order, &nlabels);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(relation, dns_namereln_equal);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(order, 0);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(nlabels, name1->labels);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews /* Some random initializer */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews order = 3001;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews nlabels = 3001;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews relation = dns_name_fullcompare(name1, name2, &order, &nlabels);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(relation, data[i].relation);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(order, data[i].order);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_REQUIRE_EQ(nlabels, data[i].nlabels);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews }
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews}
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecickistatic void
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecickicompress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned char *expected, unsigned int length,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_t *cctx, dns_decompress_t *dctx)
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki{
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki isc_buffer_t source;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki isc_buffer_t target;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_t name;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned char buf1[1024];
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned char buf2[1024];
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki isc_buffer_init(&source, buf1, sizeof(buf1));
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki isc_buffer_init(&target, buf2, sizeof(buf2));
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_name_towire(name1, cctx, &source), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_CHECK_EQ(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_CHECK_EQ(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_CHECK_EQ(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki isc_buffer_setactive(&source, source.used);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_init(&name, NULL);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &target) == ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &target) == ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &target) == ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &target) == ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_invalidate(dctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_CHECK_EQ(target.used, length);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_CHECK(memcmp(target.base, expected, target.used) == 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki}
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold KrecickiATF_TC(compression);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold KrecickiATF_TC_HEAD(compression, tc) {
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki atf_tc_set_md_var(tc, "descr", "name compression test");
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki}
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold KrecickiATF_TC_BODY(compression, tc) {
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned int allowed;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_t cctx;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_t dctx;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_t name1;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_t name2;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_t name3;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki isc_region_t r;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned char plain1[] = "\003yyy\003foo";
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned char plain2[] = "\003bar\003yyy\003foo";
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned char plain3[] = "\003xxx\003bar\003foo";
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki unsigned char plain[] = "\003yyy\003foo\0\003bar\003yyy\003foo\0\003"
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki "bar\003yyy\003foo\0\003xxx\003bar\003foo";
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
2df63247beeeeaf5fbac23e7bb2e1d2347afc9dbMark Andrews ATF_REQUIRE_EQ(dns_test_begin(NULL, ISC_FALSE), ISC_R_SUCCESS);;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_init(&name1, NULL);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki r.base = plain1;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki r.length = sizeof(plain1);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_fromregion(&name1, &r);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_init(&name2, NULL);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki r.base = plain2;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki r.length = sizeof(plain2);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_fromregion(&name2, &r);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_init(&name3, NULL);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki r.base = plain3;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki r.length = sizeof(plain3);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_name_fromregion(&name3, &r);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test 1: NONE */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki allowed = DNS_COMPRESS_NONE;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_setmethods(&cctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_setmethods(&dctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &cctx, &dctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_rollback(&cctx, 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_invalidate(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test2: GLOBAL14 */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki allowed = DNS_COMPRESS_GLOBAL14;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_setmethods(&cctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_setmethods(&dctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &cctx, &dctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_rollback(&cctx, 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_invalidate(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test3: ALL */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki allowed = DNS_COMPRESS_ALL;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_setmethods(&cctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_setmethods(&dctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &cctx, &dctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_rollback(&cctx, 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_invalidate(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test4: NONE disabled */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki allowed = DNS_COMPRESS_NONE;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_setmethods(&cctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_disable(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_setmethods(&dctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &cctx, &dctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_rollback(&cctx, 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_invalidate(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test5: GLOBAL14 disabled */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki allowed = DNS_COMPRESS_GLOBAL14;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_setmethods(&cctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_disable(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_setmethods(&dctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &cctx, &dctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_rollback(&cctx, 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_invalidate(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test6: ALL disabled */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki allowed = DNS_COMPRESS_ALL;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_setmethods(&cctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_disable(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_setmethods(&dctx, allowed);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki &cctx, &dctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_rollback(&cctx, 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_compress_invalidate(&cctx);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_test_end();
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki}
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark AndrewsATF_TC(istat);
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark AndrewsATF_TC_HEAD(istat, tc) {
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews atf_tc_set_md_var(tc, "descr", "is trust-anchor-telementry test");
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews}
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark AndrewsATF_TC_BODY(istat, tc) {
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews dns_fixedname_t fixed;
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews dns_name_t *name;
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews isc_result_t result;
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews size_t i;
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews struct {
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews const char *name;
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews isc_boolean_t istat;
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews } data[] = {
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { ".", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234", ISC_TRUE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_TA-1234", ISC_TRUE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "+TA-1234", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_fa-1234", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_td-1234", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta_1234", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-g234", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1h34", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-12i4", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-123j", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234-abcf", ISC_TRUE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234-abcf-ED89", ISC_TRUE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-12345-abcf-ED89", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-.example", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234.example", ISC_TRUE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234-abcf.example", ISC_TRUE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234-abcf-ED89.example", ISC_TRUE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-12345-abcf-ED89.example", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234-abcfe-ED89.example", ISC_FALSE },
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews { "_ta-1234-abcf-EcD89.example", ISC_FALSE }
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews };
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews dns_fixedname_init(&fixed);
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews name = dns_fixedname_name(&fixed);
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews for (i = 0; i < sizeof(data)/sizeof(data[0]); i++) {
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews result = dns_name_fromstring(name, data[i].name, 0, NULL);
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews ATF_CHECK_EQ_MSG(dns_name_istat(name), data[i].istat,
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews "testing %s - expected %u", data[i].name, data[i].istat);
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews }
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews}
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews
2457a4b245abd07322b793cdd8dfb184b1add4c4Mukund Sivaraman#ifdef ISC_PLATFORM_USETHREADS
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#ifdef DNS_BENCHMARK_TESTS
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman/*
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman * XXXMUKS: Don't delete this code. It is useful in benchmarking the
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman * name parser, but we don't require it as part of the unit test runs.
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman */
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund SivaramanATF_TC(benchmark);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund SivaramanATF_TC_HEAD(benchmark, tc) {
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman atf_tc_set_md_var(tc, "descr",
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman "Benchmark dns_name_fromwire() implementation");
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman}
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaramanstatic void *
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaramanfromwire_thread(void *arg) {
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned int maxval = 32000000;
f6ea3eaf82dfafc4cd3d4a3449fe74ac797b469bEvan Hunt isc_uint8_t data[] = {
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman 3, 'w', 'w', 'w',
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e',
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman 7, 'i', 'n', 'v', 'a', 'l', 'i', 'd',
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman 0
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman };
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned char output_data[DNS_NAME_MAXWIRE];
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_t source, target;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned int i;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_decompress_t dctx;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman UNUSED(arg);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_decompress_setmethods(&dctx, DNS_COMPRESS_NONE);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_init(&source, data, sizeof(data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_add(&source, sizeof(data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_init(&target, output_data, sizeof(output_data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman /* Parse 32 million names in each thread */
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman for (i = 0; i < maxval; i++) {
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_name_t name;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_clear(&source);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_clear(&target);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_add(&source, sizeof(data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_setactive(&source, sizeof(data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_name_init(&name, NULL);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman (void) dns_name_fromwire(&name, &source, &dctx, 0, &target);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman }
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman return (NULL);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman}
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund SivaramanATF_TC_BODY(benchmark, tc) {
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_result_t result;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned int i;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_time_t ts1, ts2;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman double t;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned int nthreads;
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman isc_thread_t threads[32];
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman UNUSED(tc);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman debug_mem_record = ISC_FALSE;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman result = dns_test_begin(NULL, ISC_TRUE);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman result = isc_time_now(&ts1);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman nthreads = ISC_MIN(isc_os_ncpus(), 32);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman nthreads = ISC_MAX(nthreads, 1);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman for (i = 0; i < nthreads; i++) {
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman result = isc_thread_create(fromwire_thread, NULL, &threads[i]);
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman }
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman for (i = 0; i < nthreads; i++) {
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman result = isc_thread_join(threads[i], NULL);
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman }
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman result = isc_time_now(&ts2);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman t = isc_time_microdiff(&ts2, &ts1);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman printf("%u dns_name_fromwire() calls, %f seconds, %f calls/second\n",
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman nthreads * 32000000, t / 1000000.0,
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman (nthreads * 32000000) / (t / 1000000.0));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_test_end();
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman}
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#endif /* DNS_BENCHMARK_TESTS */
2457a4b245abd07322b793cdd8dfb184b1add4c4Mukund Sivaraman#endif /* ISC_PLATFORM_USETHREADS */
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews/*
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * Main
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark AndrewsATF_TP_ADD_TCS(tp) {
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews ATF_TP_ADD_TC(tp, fullcompare);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_TP_ADD_TC(tp, compression);
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews ATF_TP_ADD_TC(tp, istat);
2457a4b245abd07322b793cdd8dfb184b1add4c4Mukund Sivaraman#ifdef ISC_PLATFORM_USETHREADS
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#ifdef DNS_BENCHMARK_TESTS
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman ATF_TP_ADD_TC(tp, benchmark);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#endif /* DNS_BENCHMARK_TESTS */
2457a4b245abd07322b793cdd8dfb184b1add4c4Mukund Sivaraman#endif /* ISC_PLATFORM_USETHREADS */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews return (atf_no_error());
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews}