From 22cbf1708abe75f419935fcb79b8119c0c0475c7 Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Mon, 6 Mar 2023 14:10:39 -0500 Subject: [PATCH] wip --- test/xor.cpp | 25 ++++--------------------- test/xorTest.pl | 30 ++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/test/xor.cpp b/test/xor.cpp index c7209ca..d112bc2 100644 --- a/test/xor.cpp +++ b/test/xor.cpp @@ -27,9 +27,6 @@ int main() { XorView x1(idSize); XorView x2(idSize); - std::set ids1; - std::set ids2; - std::string line; while (std::cin) { std::getline(std::cin, line); @@ -45,15 +42,11 @@ int main() { if (mode == 1) { x1.addElem(created, id); - ids1.insert(id); } else if (mode == 2) { x2.addElem(created, id); - ids2.insert(id); } else if (mode == 3) { x1.addElem(created, id); x2.addElem(created, id); - ids1.insert(id); - ids2.insert(id); } else { throw herr("unexpected mode"); } @@ -76,12 +69,10 @@ int main() { // q and have are returned to client for (auto &id : have) { - if (ids1.contains(id)) throw herr("redundant set"); - ids1.insert(id); + std::cout << "xor,2,HAVE," << to_hex(id) << "\n"; } for (auto &id : need) { - if (ids2.contains(id)) throw herr("redundant set"); - ids2.insert(id); + std::cout << "xor,2,NEED," << to_hex(id) << "\n"; } std::cerr << "HAVE " << (have.size() * idSize) << " bytes " << "NEED " << (need.size() * idSize) << " bytes " << std::endl; @@ -95,21 +86,13 @@ int main() { q = x1.handleQuery(q, have, need); for (auto &id : need) { - if (ids1.contains(id)) throw herr("redundant set"); - ids1.insert(id); + std::cout << "xor,1,NEED," << to_hex(id) << "\n"; } for (auto &id : have) { - if (ids2.contains(id)) throw herr("redundant set"); - ids2.insert(id); + std::cout << "xor,1,HAVE," << to_hex(id) << "\n"; } } } - 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; } diff --git a/test/xorTest.pl b/test/xorTest.pl index a4b6823..d5ec5ba 100644 --- a/test/xorTest.pl +++ b/test/xorTest.pl @@ -10,6 +10,9 @@ my $stgen = Session::Token->new(seed => "\x00" x 1024, alphabet => '0123456789ab while(1) { + my $ids1 = {}; + my $ids2 = {}; + my $pid = open2(my $outfile, my $infile, './test/xor'); my $num = rnd(10000) + 1; @@ -21,20 +24,43 @@ while(1) { } else { $mode = 3; } + my $created = 1677970534 + rnd($num); 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"; } close($infile); 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); 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"; }