574176a88d7fc412312e11a274d74cd2f122a0f4Tinderbox User * Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
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 * Individual unit tests
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test");
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews /* relative */
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 /* absolute */
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 { "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 result = dns_name_fromstring2(name1, data[i].name1,
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews result = dns_name_fromstring2(name2, data[i].name2,
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews relation = dns_name_fullcompare(name1, name1, &order, &nlabels);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews /* Some random initializer */
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews relation = dns_name_fullcompare(name1, name2, &order, &nlabels);
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 isc_buffer_init(&source, buf1, sizeof(buf1));
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki isc_buffer_init(&target, buf2, sizeof(buf2));
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_name_towire(name1, 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(name2, cctx, &source), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_CHECK_EQ(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, ISC_FALSE,
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_CHECK(memcmp(target.base, expected, target.used) == 0);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki atf_tc_set_md_var(tc, "descr", "name compression test");
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";
2df63247beeeeaf5fbac23e7bb2e1d2347afc9dbMark Andrews ATF_REQUIRE_EQ(dns_test_begin(NULL, ISC_FALSE), ISC_R_SUCCESS);;
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test 1: NONE */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test2: GLOBAL14 */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test3: ALL */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test4: NONE disabled */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test5: GLOBAL14 disabled */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki /* Test6: ALL disabled */
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki ATF_REQUIRE_EQ(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
bfd4b9e11aa9e8c2b43022a6b7a896b26bd5d7a0Witold Krecicki compress_test(&name1, &name2, &name3, plain, sizeof(plain),
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews atf_tc_set_md_var(tc, "descr", "is trust-anchor-telementry test");
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_CHECK_EQ_MSG(dns_name_istat(name), data[i].istat,
1c8aa38b53a0494fc7d4c3439594d1913987f264Mark Andrews "testing %s - expected %u", data[i].name, data[i].istat);
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 "Benchmark dns_name_fromwire() implementation");
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned char output_data[DNS_NAME_MAXWIRE];
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned int i;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman dns_decompress_setmethods(&dctx, DNS_COMPRESS_NONE);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_init(&source, data, sizeof(data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_init(&target, output_data, sizeof(output_data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman /* Parse 32 million names in each thread */
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman for (i = 0; i < maxval; i++) {
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman isc_buffer_setactive(&source, sizeof(data));
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman (void) dns_name_fromwire(&name, &source, &dctx, 0, &target);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman unsigned int i;
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman for (i = 0; i < nthreads; i++) {
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman result = isc_thread_create(fromwire_thread, NULL, &threads[i]);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman for (i = 0; i < nthreads; i++) {
051197362ba480595c075c95b20e160b980a05c7Mukund Sivaraman result = isc_thread_join(threads[i], NULL);
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman printf("%u dns_name_fromwire() calls, %f seconds, %f calls/second\n",
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#endif /* DNS_BENCHMARK_TESTS */
2457a4b245abd07322b793cdd8dfb184b1add4c4Mukund Sivaraman#endif /* ISC_PLATFORM_USETHREADS */
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#endif /* DNS_BENCHMARK_TESTS */
2457a4b245abd07322b793cdd8dfb184b1add4c4Mukund Sivaraman#endif /* ISC_PLATFORM_USETHREADS */