This commit is contained in:
Doug Hoyte
2023-03-06 14:10:39 -05:00
parent 85c26bcb7e
commit 22cbf1708a
2 changed files with 32 additions and 23 deletions

View File

@ -27,9 +27,6 @@ int main() {
XorView x1(idSize); XorView x1(idSize);
XorView x2(idSize); XorView x2(idSize);
std::set<std::string> ids1;
std::set<std::string> ids2;
std::string line; std::string line;
while (std::cin) { while (std::cin) {
std::getline(std::cin, line); std::getline(std::cin, line);
@ -45,15 +42,11 @@ int main() {
if (mode == 1) { if (mode == 1) {
x1.addElem(created, id); x1.addElem(created, id);
ids1.insert(id);
} else if (mode == 2) { } else if (mode == 2) {
x2.addElem(created, id); x2.addElem(created, id);
ids2.insert(id);
} else if (mode == 3) { } else if (mode == 3) {
x1.addElem(created, id); x1.addElem(created, id);
x2.addElem(created, id); x2.addElem(created, id);
ids1.insert(id);
ids2.insert(id);
} else { } else {
throw herr("unexpected mode"); throw herr("unexpected mode");
} }
@ -76,12 +69,10 @@ int main() {
// q and have are returned to client // q and have are returned to client
for (auto &id : have) { for (auto &id : have) {
if (ids1.contains(id)) throw herr("redundant set"); std::cout << "xor,2,HAVE," << to_hex(id) << "\n";
ids1.insert(id);
} }
for (auto &id : need) { for (auto &id : need) {
if (ids2.contains(id)) throw herr("redundant set"); std::cout << "xor,2,NEED," << to_hex(id) << "\n";
ids2.insert(id);
} }
std::cerr << "HAVE " << (have.size() * idSize) << " bytes " std::cerr << "HAVE " << (have.size() * idSize) << " bytes "
<< "NEED " << (need.size() * idSize) << " bytes " << std::endl; << "NEED " << (need.size() * idSize) << " bytes " << std::endl;
@ -95,21 +86,13 @@ int main() {
q = x1.handleQuery(q, have, need); q = x1.handleQuery(q, have, need);
for (auto &id : need) { for (auto &id : need) {
if (ids1.contains(id)) throw herr("redundant set"); std::cout << "xor,1,NEED," << to_hex(id) << "\n";
ids1.insert(id);
} }
for (auto &id : have) { for (auto &id : have) {
if (ids2.contains(id)) throw herr("redundant set"); std::cout << "xor,1,HAVE," << to_hex(id) << "\n";
ids2.insert(id);
} }
} }
} }
if (ids1 != ids2) {
for (const auto &id : ids1) if (!ids2.contains(id)) std::cerr << "In CLIENT not RELAY: " << to_hex(id) << std::endl;
for (const auto &id : ids2) if (!ids1.contains(id)) std::cerr << "In RELAY not CLIENT: " << to_hex(id) << std::endl;
throw herr("mismatch");
}
return 0; return 0;
} }

View File

@ -10,6 +10,9 @@ my $stgen = Session::Token->new(seed => "\x00" x 1024, alphabet => '0123456789ab
while(1) { while(1) {
my $ids1 = {};
my $ids2 = {};
my $pid = open2(my $outfile, my $infile, './test/xor'); my $pid = open2(my $outfile, my $infile, './test/xor');
my $num = rnd(10000) + 1; my $num = rnd(10000) + 1;
@ -21,20 +24,43 @@ while(1) {
} else { } else {
$mode = 3; $mode = 3;
} }
my $created = 1677970534 + rnd($num); my $created = 1677970534 + rnd($num);
my $id = $stgen->get; my $id = $stgen->get;
$ids1->{$id} = 1 if $mode == 1 || $mode == 3;
$ids2->{$id} = 1 if $mode == 2 || $mode == 3;
print $infile "$mode,$created,$id\n"; print $infile "$mode,$created,$id\n";
} }
close($infile); close($infile);
while (<$outfile>) { while (<$outfile>) {
print $_; if (/^xor,(\d),(HAVE|NEED),(\w+)/) {
my ($side, $action, $id) = ($1, $2, $3);
if (($action eq 'HAVE' && $side == 2) || ($action eq 'NEED' && $side == 1)) {
die "duplicate insert of $side,$action,$id" if $ids1->{$id};
$ids1->{$id} = 1;
} elsif (($action eq 'NEED' && $side == 2) || ($action eq 'HAVE' && $side == 1)) {
die "duplicate insert of $side,$action,$id" if $ids2->{$id};
$ids2->{$id} = 1;
}
}
} }
waitpid($pid, 0); waitpid($pid, 0);
my $child_exit_status = $?; my $child_exit_status = $?;
die "failure" if $child_exit_status; die "failure running test harness" if $child_exit_status;
for my $id (keys %$ids1) {
die "$id not in ids2" if !$ids2->{$id};
}
for my $id (keys %$ids2) {
die "$id not in ids1" if !$ids1->{$id};
}
print "\n-----------OK-----------\n"; print "\n-----------OK-----------\n";
} }