|
14 | 14 | #include "lock.hh" |
15 | 15 | #include "dns_random.hh" |
16 | 16 | #include "arguments.hh" |
| 17 | +#include "shuffle.hh" |
17 | 18 |
|
18 | 19 | #if defined(HAVE_LIBSODIUM) |
19 | 20 | #include <sodium.h> |
@@ -1181,6 +1182,37 @@ struct SipHashTest |
1181 | 1182 | }; |
1182 | 1183 | #endif |
1183 | 1184 |
|
| 1185 | +struct DedupRecordsTest |
| 1186 | +{ |
| 1187 | + explicit DedupRecordsTest(size_t howmany, bool dedup) : d_howmany(howmany), d_dedup(dedup) |
| 1188 | + { |
| 1189 | + } |
| 1190 | + |
| 1191 | + [[nodiscard]] string getName() const |
| 1192 | + { |
| 1193 | + return "DedupRecords " + std::to_string(d_howmany) + std::string(d_dedup ? "": " (generate only)"); |
| 1194 | + } |
| 1195 | + |
| 1196 | + void operator()() const |
| 1197 | + { |
| 1198 | + std::vector<DNSRecord> vec; |
| 1199 | + vec.reserve(d_howmany); |
| 1200 | + std::string name("some.name.in.some.domain"); |
| 1201 | + for (size_t i = 0; i < d_howmany; i++) { |
| 1202 | + auto content = DNSRecordContent::make(QType::TXT, QClass::IN, "\"a text " + std::to_string(i) + "\""); |
| 1203 | + DNSRecord rec(name, content, QType::TXT); |
| 1204 | + vec.emplace_back(std::move(rec)); |
| 1205 | + } |
| 1206 | + if (d_dedup) { |
| 1207 | + pdns::dedup(vec); |
| 1208 | + } |
| 1209 | + } |
| 1210 | + |
| 1211 | +private: |
| 1212 | + size_t d_howmany; |
| 1213 | + bool d_dedup; |
| 1214 | +}; |
| 1215 | + |
1184 | 1216 | int main() |
1185 | 1217 | { |
1186 | 1218 | try { |
@@ -1335,6 +1367,12 @@ int main() |
1335 | 1367 | #ifdef HAVE_LIBSODIUM |
1336 | 1368 | doRun(SipHashTest("a string of chars")); |
1337 | 1369 | #endif |
| 1370 | + doRun(DedupRecordsTest(2, false)); |
| 1371 | + doRun(DedupRecordsTest(2, true)); |
| 1372 | + doRun(DedupRecordsTest(256, false)); |
| 1373 | + doRun(DedupRecordsTest(256, true)); |
| 1374 | + doRun(DedupRecordsTest(4096, false)); |
| 1375 | + doRun(DedupRecordsTest(4096, true)); |
1338 | 1376 |
|
1339 | 1377 | cerr<<"Total runs: " << g_totalRuns<<endl; |
1340 | 1378 | } |
|
0 commit comments