name_test.c revision 051197362ba480595c075c95b20e160b980a05c7
4ba2689c1f4e0c8c670fc47307d7b46d9da3a45bTinderbox User * Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * Permission to use, copy, modify, and/or distribute this software for any
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * purpose with or without fee is hereby granted, provided that the above
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * copyright notice and this permission notice appear in all copies.
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews * Individual unit tests
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test");
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews unsigned int nlabels;
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),
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 */
59328c76745ee6d2df047e3f072b118258b87cb6Mukund Sivaraman#endif /* DNS_BENCHMARK_TESTS */