From: Ondřej Surý Date: Mon, 19 Aug 2024 09:01:08 +0000 (+0200) Subject: Allow TTL skew in the badcache print unit test X-Git-Tag: v9.21.1~30^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=7860b6519dcb862629ba37305cc55f12b7974ce0;p=thirdparty%2Fbind9.git Allow TTL skew in the badcache print unit test If the machine running the job is extra loaded (or extra slow), the print test in the badcache unit test would fail because the TTL would be 59 (possibly even lower) and the test expects the badcache.out to only have TTL 60. Refactor the test to check for the expected strings and check whether the TTL is in the expected range. --- diff --git a/tests/dns/badcache_test.c b/tests/dns/badcache_test.c index f7151b73fdf..0c81c7ac02c 100644 --- a/tests/dns/badcache_test.c +++ b/tests/dns/badcache_test.c @@ -43,20 +43,6 @@ #include -static uint32_t -crc32(const uint8_t *buf, size_t size) { - uint32_t crc; - crc = 0xFFFFFFFF; - while (size--) { - crc = crc ^ *buf++; - for (size_t j = 0; j < 8; j++) { - uint32_t mask = -(crc & 1); - crc = (crc >> 1) ^ (0xedb88320 & mask); - } - } - return (~crc); -} - #define BADCACHE_TEST_FLAG 1 << 3 ISC_LOOP_TEST_IMPL(basic) { @@ -135,8 +121,14 @@ ISC_LOOP_TEST_IMPL(print) { isc_stdtime_t expire = now + 60; uint32_t flags = BADCACHE_TEST_FLAG; FILE *file = NULL; - uint8_t buf[4096]; + char buf[4096]; size_t len; + char *pos; + char *endptr; + const char *part1 = ";\n; badcache\n;\n; example.com/A [ttl "; + const char *part2 = "]\n; example.com/AAAA [ttl "; + const char *part3 = "]\n"; + long ttl; dns_name_fromstring(name, "example.com.", NULL, 0, NULL); @@ -153,8 +145,27 @@ ISC_LOOP_TEST_IMPL(print) { assert_int_equal(len, 68); fclose(file); - /* Calculated as crc32 ./badcache.out */ - assert_int_equal(crc32(buf, len), 0x7c96678f); + pos = buf; + assert_memory_equal(pos, part1, strlen(part1)); + pos += strlen(part1); + + ttl = strtol(pos, &endptr, 0); + assert_ptr_not_equal(pos, endptr); + assert_true(ttl >= 0 && ttl <= 60); + pos = endptr; + + assert_memory_equal(pos, part2, strlen(part2)); + pos += strlen(part2); + + ttl = strtol(pos, &endptr, 0); + assert_ptr_not_equal(pos, endptr); + assert_true(ttl >= 0 && ttl <= 60); + pos = endptr; + + assert_memory_equal(pos, part3, strlen(part3)); + pos += strlen(part3); + + assert_int_equal(pos - buf, len); dns_badcache_destroy(&bc);