bind9/bin/tests/system/digcomp.pl

118 lines
2.4 KiB
Perl
Raw Normal View History

2000-05-17 18:38:50 -04:00
#!/usr/bin/perl
#
# Copyright (C) 2000, 2001, 2004, 2007, 2012, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
2012-06-28 21:39:47 -04:00
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
2000-05-17 18:38:50 -04:00
2007-06-19 19:47:24 -04:00
# $Id: digcomp.pl,v 1.14 2007/06/19 23:47:00 tbox Exp $
2000-06-22 18:00:42 -04:00
2000-05-17 18:38:50 -04:00
# Compare two files, each with the output from dig, for differences.
# Ignore "unimportant" differences, like ordering of NS lines, TTL's,
# etc...
$lc = 0;
if ($ARGV[0] eq "--lc") {
$lc = 1;
shift;
}
2000-05-17 18:38:50 -04:00
$file1 = $ARGV[0];
$file2 = $ARGV[1];
$count = 0;
$firstname = "";
$status = 0;
$rcode1 = "none";
$rcode2 = "none";
2000-05-17 18:38:50 -04:00
open(FILE1, $file1) || die("open: $file1: $!\n");
2000-05-17 18:38:50 -04:00
while (<FILE1>) {
~ s/\r\n//g;
~ s/\n//g;
if (/^;.+status:\s+(\S+).+$/) {
$rcode1 = $1;
}
next if (/^;/);
if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
$name = $1;
$class = $2;
$type = $3;
$value = $4;
if ($lc) {
$name = lc($name);
$value = lc($value);
}
if ($type eq "SOA") {
$firstname = $name if ($firstname eq "");
if ($name eq $firstname) {
$name = "$name$count";
$count++;
}
}
if ($entry{"$name ; $class.$type ; $value"} ne "") {
$line = $entry{"$name ; $class.$type ; $value"};
print("Duplicate entry in $file1:\n> $_\n< $line\n");
} else {
$entry{"$name ; $class.$type ; $value"} = $_;
}
}
2000-05-17 18:38:50 -04:00
}
close(FILE1);
2000-05-17 18:38:50 -04:00
$printed = 0;
open(FILE2, $file2) || die("open: $file2: $!\n");
2000-05-17 18:38:50 -04:00
while (<FILE2>) {
~ s/\r\n//g;
~ s/\n//g;
if (/^;.+status:\s+(\S+).+$/) {
$rcode2 = $1;
}
next if (/^;/);
if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
$name = $1;
$class = $2;
$type = $3;
$value = $4;
if ($lc) {
$name = lc($name);
$value = lc($value);
}
if (($name eq $firstname) && ($type eq "SOA")) {
$count--;
$name = "$name$count";
}
if ($entry{"$name ; $class.$type ; $value"} ne "") {
$entry{"$name ; $class.$type ; $value"} = "";
} else {
print("Only in $file2 (missing from $file1):\n")
if ($printed == 0);
print("> $_\n");
$printed++;
$status = 1;
}
}
2000-05-17 18:38:50 -04:00
}
close(FILE2);
2000-05-17 18:38:50 -04:00
$printed = 0;
foreach $key (keys(%entry)) {
if ($entry{$key} ne "") {
print("Only in $file1 (missing from $file2):\n")
if ($printed == 0);
print("< $entry{$key}\n");
$status = 1;
$printed++;
}
2000-05-17 18:38:50 -04:00
}
if ($rcode1 ne $rcode2) {
print("< status: $rcode1\n");
print("> status: $rcode2\n");
2000-07-08 12:37:43 -04:00
$status = 1;
}
2000-05-17 18:38:50 -04:00
exit($status);