]>
Commit | Line | Data |
---|---|---|
870a0fe4 | 1 | #include "config.h" |
8c0139b0 | 2 | #include <boost/format.hpp> |
3 | #include <boost/container/string.hpp> | |
34383528 BH |
4 | #include "dnsparser.hh" |
5 | #include "sstuff.hh" | |
6 | #include "misc.hh" | |
7 | #include "dnswriter.hh" | |
8 | #include "dnsrecords.hh" | |
5a6caecd | 9 | #include "iputils.hh" |
6b0ea82d | 10 | #include <fstream> |
8c0139b0 | 11 | |
34383528 BH |
12 | #ifndef RECURSOR |
13 | #include "statbag.hh" | |
88227be0 | 14 | #include "base64.hh" |
34383528 BH |
15 | StatBag S; |
16 | #endif | |
8c0139b0 | 17 | |
b00cab1d | 18 | volatile bool g_ret; // make sure the optimizer does not get too smart |
34383528 | 19 | uint64_t g_totalRuns; |
34383528 BH |
20 | volatile bool g_stop; |
21 | ||
22 | void alarmHandler(int) | |
23 | { | |
24 | g_stop=true; | |
25 | } | |
26 | ||
27 | template<typename C> void doRun(const C& cmd, int mseconds=100) | |
28 | { | |
29 | struct itimerval it; | |
30 | it.it_value.tv_sec=mseconds/1000; | |
31 | it.it_value.tv_usec = 1000* (mseconds%1000); | |
32 | it.it_interval.tv_sec=0; | |
33 | it.it_interval.tv_usec=0; | |
34 | ||
ecefa116 | 35 | signal(SIGVTALRM, alarmHandler); |
34383528 | 36 | setitimer(ITIMER_VIRTUAL, &it, 0); |
ecefa116 | 37 | |
34383528 BH |
38 | unsigned int runs=0; |
39 | g_stop=false; | |
ab570fc5 | 40 | CPUTime dt; |
41 | dt.start(); | |
34383528 BH |
42 | while(runs++, !g_stop) { |
43 | cmd(); | |
44 | } | |
ab570fc5 | 45 | double delta=dt.ndiff()/1000000000.0; |
34383528 BH |
46 | boost::format fmt("'%s' %.02f seconds: %.1f runs/s, %.02f usec/run"); |
47 | ||
48 | cerr<< (fmt % cmd.getName() % delta % (runs/delta) % (delta* 1000000.0/runs)) << endl; | |
49 | g_totalRuns += runs; | |
50 | } | |
51 | ||
52 | struct ARecordTest | |
53 | { | |
54 | explicit ARecordTest(int records) : d_records(records) {} | |
55 | ||
56 | string getName() const | |
57 | { | |
58 | return (boost::format("%d a records") % d_records).str(); | |
59 | } | |
60 | ||
61 | void operator()() const | |
62 | { | |
63 | vector<uint8_t> packet; | |
e325f20c | 64 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::A); |
34383528 | 65 | for(int records = 0; records < d_records; records++) { |
e325f20c | 66 | pw.startRecord(DNSName("outpost.ds9a.nl"), QType::A); |
34383528 BH |
67 | ARecordContent arc("1.2.3.4"); |
68 | arc.toPacket(pw); | |
69 | } | |
70 | pw.commit(); | |
71 | } | |
72 | int d_records; | |
73 | }; | |
74 | ||
75 | ||
76 | struct MakeStringFromCharStarTest | |
77 | { | |
78 | MakeStringFromCharStarTest() : d_size(0){} | |
79 | string getName() const | |
80 | { | |
81 | return (boost::format("make a std::string")).str(); | |
82 | } | |
83 | ||
84 | void operator()() const | |
85 | { | |
86 | string name("outpost.ds9a.nl"); | |
87 | d_size += name.length(); | |
88 | ||
89 | } | |
90 | mutable int d_size; | |
91 | }; | |
92 | ||
7519bae5 BH |
93 | |
94 | struct GetTimeTest | |
95 | { | |
96 | string getName() const | |
97 | { | |
98 | return "gettimeofday-test"; | |
99 | } | |
100 | ||
101 | void operator()() const | |
102 | { | |
103 | struct timeval tv; | |
104 | gettimeofday(&tv, 0); | |
105 | } | |
106 | }; | |
107 | ||
0ddde5fb | 108 | std::mutex s_testlock; |
1f9faf8b BH |
109 | |
110 | struct GetLockUncontendedTest | |
111 | { | |
112 | string getName() const | |
113 | { | |
114 | return "getlock-uncontended-test"; | |
115 | } | |
116 | ||
117 | void operator()() const | |
118 | { | |
0ddde5fb RG |
119 | s_testlock.lock(); |
120 | s_testlock.unlock(); | |
1f9faf8b BH |
121 | } |
122 | }; | |
123 | ||
124 | ||
125 | struct StaticMemberTest | |
126 | { | |
127 | string getName() const | |
128 | { | |
129 | return "static-member-test"; | |
130 | } | |
131 | ||
132 | void operator()() const | |
133 | { | |
134 | static string* s_ptr; | |
135 | if(!s_ptr) | |
136 | s_ptr = new string(); | |
137 | } | |
138 | }; | |
139 | ||
ab570fc5 | 140 | struct StringtokTest |
141 | { | |
142 | string getName() const | |
143 | { | |
144 | return "stringtok"; | |
145 | } | |
146 | ||
147 | void operator()() const | |
148 | { | |
149 | string str("the quick brown fox jumped"); | |
150 | vector<string> parts; | |
151 | stringtok(parts, str); | |
152 | } | |
153 | }; | |
154 | ||
155 | struct VStringtokTest | |
156 | { | |
157 | string getName() const | |
158 | { | |
159 | return "vstringtok"; | |
160 | } | |
161 | ||
162 | void operator()() const | |
163 | { | |
164 | string str("the quick brown fox jumped"); | |
165 | vector<pair<unsigned int, unsigned> > parts; | |
166 | vstringtok(parts, str); | |
167 | } | |
168 | }; | |
169 | ||
179dad39 | 170 | struct StringAppendTest |
171 | { | |
172 | string getName() const | |
173 | { | |
174 | return "stringappend"; | |
175 | } | |
176 | ||
177 | void operator()() const | |
178 | { | |
179 | string str; | |
180 | static char i; | |
181 | for(int n=0; n < 1000; ++n) | |
182 | str.append(1, i); | |
183 | i++; | |
184 | } | |
185 | }; | |
186 | ||
7519bae5 | 187 | |
6b0ea82d | 188 | struct BoostStringAppendTest |
189 | { | |
190 | string getName() const | |
191 | { | |
192 | return "booststringappend"; | |
193 | } | |
194 | ||
195 | void operator()() const | |
196 | { | |
197 | boost::container::string str; | |
198 | static char i; | |
199 | for(int n=0; n < 1000; ++n) | |
200 | str.append(1, i); | |
201 | i++; | |
202 | } | |
203 | }; | |
204 | ||
205 | ||
206 | ||
34383528 BH |
207 | struct MakeARecordTest |
208 | { | |
209 | string getName() const | |
210 | { | |
211 | return (boost::format("make a-record")).str(); | |
212 | } | |
213 | ||
214 | void operator()() const | |
215 | { | |
216 | static string src("1.2.3.4"); | |
217 | ARecordContent arc(src); | |
218 | //ARecordContent arc(0x01020304); | |
219 | ||
220 | } | |
221 | }; | |
222 | ||
6b0ea82d | 223 | vector<uint8_t> makeBigReferral() |
224 | { | |
225 | ||
226 | vector<uint8_t> packet; | |
227 | DNSPacketWriter pw(packet, DNSName("www.google.com"), QType::A); | |
228 | ||
229 | string gtld="x.gtld-servers.net"; | |
230 | for(char c='a'; c<= 'm';++c) { | |
231 | pw.startRecord(DNSName("com"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY); | |
232 | gtld[0]=c; | |
32122aab | 233 | auto drc = DNSRecordContent::mastermake(QType::NS, 1, gtld); |
6b0ea82d | 234 | drc->toPacket(pw); |
6b0ea82d | 235 | } |
236 | ||
237 | for(char c='a'; c<= 'k';++c) { | |
238 | gtld[0]=c; | |
239 | pw.startRecord(DNSName(gtld), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL); | |
32122aab | 240 | auto drc = DNSRecordContent::mastermake(QType::A, 1, "1.2.3.4"); |
6b0ea82d | 241 | drc->toPacket(pw); |
6b0ea82d | 242 | } |
243 | ||
244 | ||
245 | pw.startRecord(DNSName("a.gtld-servers.net"), QType::AAAA, 3600, 1, DNSResourceRecord::ADDITIONAL); | |
32122aab | 246 | auto aaaarc = DNSRecordContent::mastermake(QType::AAAA, 1, "2001:503:a83e::2:30"); |
6b0ea82d | 247 | aaaarc->toPacket(pw); |
6b0ea82d | 248 | |
249 | pw.startRecord(DNSName("b.gtld-servers.net"), QType::AAAA, 3600, 1, DNSResourceRecord::ADDITIONAL); | |
32122aab | 250 | aaaarc = DNSRecordContent::mastermake(QType::AAAA, 1, "2001:503:231d::2:30"); |
6b0ea82d | 251 | aaaarc->toPacket(pw); |
6b0ea82d | 252 | |
253 | ||
254 | pw.commit(); | |
255 | return packet; | |
256 | } | |
257 | ||
258 | vector<uint8_t> makeBigDNSPacketReferral() | |
259 | { | |
260 | vector<DNSResourceRecord> records; | |
261 | DNSResourceRecord rr; | |
262 | rr.qtype = QType::NS; | |
263 | rr.ttl=3600; | |
264 | rr.qname=DNSName("com"); | |
6b0ea82d | 265 | |
266 | string gtld="x.gtld-servers.net"; | |
267 | for(char c='a'; c<= 'm';++c) { | |
268 | gtld[0]=c; | |
269 | rr.content = gtld; | |
270 | records.push_back(rr); | |
271 | } | |
272 | ||
273 | rr.qtype = QType::A; | |
274 | for(char c='a'; c<= 'k';++c) { | |
275 | gtld[0]=c; | |
276 | rr.qname=DNSName(gtld); | |
277 | rr.content="1.2.3.4"; | |
278 | records.push_back(rr); | |
279 | } | |
280 | ||
281 | rr.qname=DNSName("a.gtld-servers.net"); | |
282 | rr.qtype=QType::AAAA; | |
283 | rr.content="2001:503:a83e::2:30"; | |
284 | records.push_back(rr); | |
285 | ||
286 | rr.qname=DNSName("b.gtld-servers.net"); | |
287 | rr.qtype=QType::AAAA; | |
288 | rr.content="2001:503:231d::2:30"; | |
289 | records.push_back(rr); | |
290 | ||
291 | ||
292 | vector<uint8_t> packet; | |
293 | DNSPacketWriter pw(packet, DNSName("www.google.com"), QType::A); | |
d190894c | 294 | // shuffle(records); |
6b0ea82d | 295 | for(const auto& rec : records) { |
8695de46 | 296 | pw.startRecord(rec.qname, rec.qtype.getCode(), rec.ttl, 1, DNSResourceRecord::ADDITIONAL); |
32122aab | 297 | auto drc = DNSRecordContent::mastermake(rec.qtype.getCode(), 1, rec.content); |
6b0ea82d | 298 | drc->toPacket(pw); |
6b0ea82d | 299 | } |
300 | ||
301 | pw.commit(); | |
302 | return packet; | |
303 | } | |
304 | ||
305 | ||
306 | ||
34383528 BH |
307 | struct MakeARecordTestMM |
308 | { | |
309 | string getName() const | |
310 | { | |
311 | return (boost::format("make a-record (mm)")).str(); | |
312 | } | |
313 | ||
314 | void operator()() const | |
315 | { | |
32122aab | 316 | auto drc = DNSRecordContent::mastermake(QType::A, 1, |
6177a176 | 317 | "1.2.3.4"); |
34383528 BH |
318 | } |
319 | }; | |
320 | ||
321 | ||
322 | struct A2RecordTest | |
323 | { | |
324 | explicit A2RecordTest(int records) : d_records(records) {} | |
325 | ||
326 | string getName() const | |
327 | { | |
328 | return (boost::format("%d a records") % d_records).str(); | |
329 | } | |
330 | ||
331 | void operator()() const | |
332 | { | |
333 | vector<uint8_t> packet; | |
e325f20c | 334 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::A); |
34383528 | 335 | ARecordContent arc("1.2.3.4"); |
e325f20c | 336 | DNSName name("outpost.ds9a.nl"); |
34383528 BH |
337 | for(int records = 0; records < d_records; records++) { |
338 | pw.startRecord(name, QType::A); | |
339 | ||
340 | arc.toPacket(pw); | |
341 | } | |
342 | pw.commit(); | |
343 | } | |
344 | int d_records; | |
345 | }; | |
346 | ||
347 | ||
348 | struct TXTRecordTest | |
349 | { | |
350 | explicit TXTRecordTest(int records) : d_records(records) {} | |
351 | ||
352 | string getName() const | |
353 | { | |
354 | return (boost::format("%d TXT records") % d_records).str(); | |
355 | } | |
356 | ||
357 | void operator()() const | |
358 | { | |
359 | vector<uint8_t> packet; | |
e325f20c | 360 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::TXT); |
34383528 | 361 | for(int records = 0; records < d_records; records++) { |
e325f20c | 362 | pw.startRecord(DNSName("outpost.ds9a.nl"), QType::TXT); |
34383528 BH |
363 | TXTRecordContent arc("\"een leuk verhaaltje in een TXT\""); |
364 | arc.toPacket(pw); | |
365 | } | |
366 | pw.commit(); | |
367 | } | |
368 | int d_records; | |
369 | }; | |
370 | ||
371 | ||
372 | struct GenericRecordTest | |
373 | { | |
374 | explicit GenericRecordTest(int records, uint16_t type, const std::string& content) | |
375 | : d_records(records), d_type(type), d_content(content) {} | |
376 | ||
377 | string getName() const | |
378 | { | |
379 | return (boost::format("%d %s records") % d_records % | |
b7821a82 | 380 | DNSRecordContent::NumberToType(d_type)).str(); |
34383528 BH |
381 | } |
382 | ||
383 | void operator()() const | |
384 | { | |
385 | vector<uint8_t> packet; | |
e325f20c | 386 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), d_type); |
34383528 | 387 | for(int records = 0; records < d_records; records++) { |
e325f20c | 388 | pw.startRecord(DNSName("outpost.ds9a.nl"), d_type); |
32122aab | 389 | auto drc = DNSRecordContent::mastermake(d_type, 1, |
6177a176 | 390 | d_content); |
34383528 | 391 | drc->toPacket(pw); |
34383528 BH |
392 | } |
393 | pw.commit(); | |
394 | } | |
395 | int d_records; | |
396 | uint16_t d_type; | |
397 | string d_content; | |
398 | }; | |
399 | ||
400 | ||
401 | struct AAAARecordTest | |
402 | { | |
403 | explicit AAAARecordTest(int records) : d_records(records) {} | |
404 | ||
405 | string getName() const | |
406 | { | |
407 | return (boost::format("%d aaaa records (mm)") % d_records).str(); | |
408 | } | |
409 | ||
410 | void operator()() const | |
411 | { | |
412 | vector<uint8_t> packet; | |
e325f20c | 413 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::AAAA); |
34383528 | 414 | for(int records = 0; records < d_records; records++) { |
e325f20c | 415 | pw.startRecord(DNSName("outpost.ds9a.nl"), QType::AAAA); |
32122aab | 416 | auto drc = DNSRecordContent::mastermake(QType::AAAA, 1, "fe80::21d:92ff:fe6d:8441"); |
34383528 | 417 | drc->toPacket(pw); |
34383528 BH |
418 | } |
419 | pw.commit(); | |
420 | } | |
421 | int d_records; | |
422 | }; | |
423 | ||
424 | struct SOARecordTest | |
425 | { | |
426 | explicit SOARecordTest(int records) : d_records(records) {} | |
427 | ||
428 | string getName() const | |
429 | { | |
430 | return (boost::format("%d soa records (mm)") % d_records).str(); | |
431 | } | |
432 | ||
433 | void operator()() const | |
434 | { | |
435 | vector<uint8_t> packet; | |
e325f20c | 436 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::SOA); |
34383528 BH |
437 | |
438 | for(int records = 0; records < d_records; records++) { | |
e325f20c | 439 | pw.startRecord(DNSName("outpost.ds9a.nl"), QType::SOA); |
32122aab | 440 | auto drc = DNSRecordContent::mastermake(QType::SOA, 1, "a0.org.afilias-nst.info. noc.afilias-nst.info. 2008758137 1800 900 604800 86400"); |
34383528 | 441 | drc->toPacket(pw); |
34383528 BH |
442 | } |
443 | pw.commit(); | |
444 | } | |
445 | int d_records; | |
446 | }; | |
447 | ||
448 | vector<uint8_t> makeEmptyQuery() | |
449 | { | |
450 | vector<uint8_t> packet; | |
e325f20c | 451 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::SOA); |
34383528 BH |
452 | return packet; |
453 | } | |
454 | ||
34383528 BH |
455 | vector<uint8_t> makeTypicalReferral() |
456 | { | |
457 | vector<uint8_t> packet; | |
e325f20c | 458 | DNSPacketWriter pw(packet, DNSName("outpost.ds9a.nl"), QType::A); |
34383528 | 459 | |
e693ff5a | 460 | pw.startRecord(DNSName("ds9a.nl"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY); |
32122aab | 461 | auto drc = DNSRecordContent::mastermake(QType::NS, 1, "ns1.ds9a.nl"); |
34383528 | 462 | drc->toPacket(pw); |
34383528 | 463 | |
e693ff5a | 464 | pw.startRecord(DNSName("ds9a.nl"), QType::NS, 3600, 1, DNSResourceRecord::AUTHORITY); |
32122aab | 465 | drc = DNSRecordContent::mastermake(QType::NS, 1, "ns2.ds9a.nl"); |
34383528 | 466 | drc->toPacket(pw); |
34383528 BH |
467 | |
468 | ||
e693ff5a | 469 | pw.startRecord(DNSName("ns1.ds9a.nl"), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL); |
32122aab | 470 | drc = DNSRecordContent::mastermake(QType::A, 1, "1.2.3.4"); |
34383528 | 471 | drc->toPacket(pw); |
34383528 | 472 | |
e693ff5a | 473 | pw.startRecord(DNSName("ns2.ds9a.nl"), QType::A, 3600, 1, DNSResourceRecord::ADDITIONAL); |
32122aab | 474 | drc = DNSRecordContent::mastermake(QType::A, 1, "4.3.2.1"); |
34383528 | 475 | drc->toPacket(pw); |
34383528 BH |
476 | |
477 | pw.commit(); | |
478 | return packet; | |
479 | } | |
480 | ||
b7821a82 BH |
481 | struct StackMallocTest |
482 | { | |
483 | string getName() const | |
484 | { | |
485 | return "stack allocation"; | |
486 | } | |
487 | ||
488 | void operator()() const | |
489 | { | |
490 | char *buffer= new char[200000]; | |
4da9585d | 491 | delete[] buffer; |
b7821a82 BH |
492 | } |
493 | ||
494 | }; | |
495 | ||
496 | ||
34383528 BH |
497 | struct EmptyQueryTest |
498 | { | |
499 | string getName() const | |
500 | { | |
501 | return "write empty query"; | |
502 | } | |
503 | ||
504 | void operator()() const | |
505 | { | |
506 | vector<uint8_t> packet=makeEmptyQuery(); | |
507 | } | |
508 | ||
509 | }; | |
510 | ||
511 | struct TypicalRefTest | |
512 | { | |
513 | string getName() const | |
514 | { | |
515 | return "write typical referral"; | |
516 | } | |
517 | ||
518 | void operator()() const | |
519 | { | |
520 | vector<uint8_t> packet=makeTypicalReferral(); | |
521 | } | |
522 | ||
523 | }; | |
524 | ||
6b0ea82d | 525 | struct BigRefTest |
526 | { | |
527 | string getName() const | |
528 | { | |
529 | return "write big referral"; | |
530 | } | |
531 | ||
532 | void operator()() const | |
533 | { | |
534 | vector<uint8_t> packet=makeBigReferral(); | |
535 | } | |
536 | ||
537 | }; | |
538 | ||
539 | struct BigDNSPacketRefTest | |
540 | { | |
541 | string getName() const | |
542 | { | |
543 | return "write big dnspacket referral"; | |
544 | } | |
545 | ||
546 | void operator()() const | |
547 | { | |
548 | vector<uint8_t> packet=makeBigDNSPacketReferral(); | |
549 | } | |
550 | ||
551 | }; | |
552 | ||
553 | ||
b7821a82 BH |
554 | struct TCacheComp |
555 | { | |
0c0fd241 | 556 | bool operator()(const pair<DNSName, QType>& a, const pair<DNSName, QType>& b) const |
b7821a82 | 557 | { |
0c0fd241 | 558 | if(a.first < b.first) |
b7821a82 | 559 | return true; |
0c0fd241 | 560 | if(b.first < a.first) |
b7821a82 BH |
561 | return false; |
562 | ||
563 | return a.second < b.second; | |
564 | } | |
565 | }; | |
566 | ||
567 | struct NegCacheEntry | |
568 | { | |
8171ab83 | 569 | DNSName d_name; |
b7821a82 | 570 | QType d_qtype; |
8171ab83 | 571 | DNSName d_qname; |
b7821a82 BH |
572 | uint32_t d_ttd; |
573 | }; | |
574 | ||
575 | struct timeval d_now; | |
576 | ||
b7821a82 | 577 | |
34383528 BH |
578 | |
579 | struct ParsePacketTest | |
580 | { | |
581 | explicit ParsePacketTest(const vector<uint8_t>& packet, const std::string& name) | |
582 | : d_packet(packet), d_name(name) | |
583 | {} | |
584 | ||
585 | string getName() const | |
586 | { | |
587 | return "parse '"+d_name+"'"; | |
588 | } | |
589 | ||
590 | void operator()() const | |
591 | { | |
27c0050c | 592 | MOADNSParser mdp(false, (const char*)&*d_packet.begin(), d_packet.size()); |
e8b23f3b | 593 | typedef map<pair<DNSName, QType>, set<DNSResourceRecord>, TCacheComp > tcache_t; |
b7821a82 BH |
594 | tcache_t tcache; |
595 | ||
596 | struct { | |
597 | vector<DNSResourceRecord> d_result; | |
598 | bool d_aabit; | |
599 | int d_rcode; | |
600 | } lwr; | |
b7821a82 BH |
601 | for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) { |
602 | DNSResourceRecord rr; | |
603 | rr.qtype=i->first.d_type; | |
e325f20c | 604 | rr.qname=i->first.d_name; |
b7821a82 BH |
605 | |
606 | rr.ttl=i->first.d_ttl; | |
607 | rr.content=i->first.d_content->getZoneRepresentation(); // this should be the serialised form | |
b7821a82 BH |
608 | lwr.d_result.push_back(rr); |
609 | } | |
610 | ||
8b77d409 | 611 | |
34383528 BH |
612 | } |
613 | const vector<uint8_t>& d_packet; | |
614 | std::string d_name; | |
615 | }; | |
616 | ||
b7821a82 BH |
617 | struct ParsePacketBareTest |
618 | { | |
619 | explicit ParsePacketBareTest(const vector<uint8_t>& packet, const std::string& name) | |
620 | : d_packet(packet), d_name(name) | |
621 | {} | |
622 | ||
623 | string getName() const | |
624 | { | |
625 | return "parse '"+d_name+"' bare"; | |
626 | } | |
627 | ||
628 | void operator()() const | |
629 | { | |
27c0050c | 630 | MOADNSParser mdp(false, (const char*)&*d_packet.begin(), d_packet.size()); |
b7821a82 BH |
631 | } |
632 | const vector<uint8_t>& d_packet; | |
633 | std::string d_name; | |
634 | }; | |
635 | ||
636 | ||
34383528 BH |
637 | struct SimpleCompressTest |
638 | { | |
639 | explicit SimpleCompressTest(const std::string& name) | |
640 | : d_name(name) | |
641 | {} | |
642 | ||
643 | string getName() const | |
644 | { | |
645 | return "compress '"+d_name+"'"; | |
646 | } | |
647 | ||
648 | void operator()() const | |
649 | { | |
650 | simpleCompress(d_name); | |
651 | } | |
652 | std::string d_name; | |
653 | }; | |
654 | ||
655 | struct VectorExpandTest | |
656 | { | |
657 | string getName() const | |
658 | { | |
659 | return "vector expand"; | |
660 | } | |
661 | ||
662 | void operator()() const | |
663 | { | |
664 | vector<uint8_t> d_record; | |
665 | d_record.resize(12); | |
666 | ||
667 | string out="\x03www\x04ds9a\x02nl"; | |
668 | string::size_type len = d_record.size(); | |
669 | d_record.resize(len + out.length()); | |
670 | memcpy(&d_record[len], out.c_str(), out.length()); | |
671 | } | |
672 | ||
673 | }; | |
674 | ||
b8a514bb | 675 | struct DNSNameParseTest |
676 | { | |
677 | string getName() const | |
678 | { | |
679 | return "DNSName parse"; | |
680 | } | |
681 | ||
682 | void operator()() const | |
683 | { | |
684 | DNSName name("www.powerdns.com"); | |
685 | } | |
686 | ||
687 | }; | |
688 | ||
689 | struct DNSNameRootTest | |
690 | { | |
691 | string getName() const | |
692 | { | |
693 | return "DNSName root"; | |
694 | } | |
695 | ||
696 | void operator()() const | |
697 | { | |
698 | DNSName name("."); | |
699 | } | |
700 | ||
701 | }; | |
702 | ||
b7821a82 BH |
703 | |
704 | ||
705 | struct IEqualsTest | |
706 | { | |
707 | string getName() const | |
708 | { | |
709 | return "iequals test"; | |
710 | } | |
711 | ||
712 | void operator()() const | |
713 | { | |
714 | static string a("www.ds9a.nl"), b("www.lwn.net"); | |
b00cab1d | 715 | g_ret = boost::iequals(a, b); |
b7821a82 BH |
716 | } |
717 | ||
718 | }; | |
719 | ||
720 | struct MyIEqualsTest | |
721 | { | |
722 | string getName() const | |
723 | { | |
724 | return "pdns_iequals test"; | |
725 | } | |
726 | ||
727 | void operator()() const | |
728 | { | |
729 | static string a("www.ds9a.nl"), b("www.lwn.net"); | |
b00cab1d | 730 | g_ret = pdns_iequals(a, b); |
b7821a82 BH |
731 | } |
732 | ||
733 | }; | |
734 | ||
735 | ||
736 | struct StrcasecmpTest | |
737 | { | |
738 | string getName() const | |
739 | { | |
740 | return "strcasecmp test"; | |
741 | } | |
742 | ||
743 | void operator()() const | |
744 | { | |
745 | static string a("www.ds9a.nl"), b("www.lwn.net"); | |
b00cab1d | 746 | g_ret = strcasecmp(a.c_str(), b.c_str()); |
b7821a82 BH |
747 | } |
748 | }; | |
749 | ||
750 | ||
88227be0 KM |
751 | struct Base64EncodeTest |
752 | { | |
753 | string getName() const | |
754 | { | |
755 | return "Bas64Encode test"; | |
756 | } | |
757 | ||
758 | void operator()() const | |
759 | { | |
760 | static string a("dq4KydZjmcoQQ45VYBP2EDR8FqKaMul0eSHBt7Xx5F7A4HFtabXEzDLD01bnSiGK"); | |
761 | Base64Encode(a); | |
762 | } | |
763 | }; | |
764 | ||
765 | ||
766 | struct B64DecodeTest | |
767 | { | |
768 | string getName() const | |
769 | { | |
770 | return "B64Decode test"; | |
771 | } | |
772 | ||
773 | void operator()() const | |
774 | { | |
775 | static string a("ZHE0S3lkWmptY29RUTQ1VllCUDJFRFI4RnFLYU11bDBlU0hCdDdYeDVGN0E0SEZ0YWJYRXpETEQwMWJuU2lHSw=="), b; | |
776 | g_ret = B64Decode(a,b); | |
777 | } | |
778 | }; | |
779 | ||
780 | ||
34383528 BH |
781 | struct NOPTest |
782 | { | |
783 | string getName() const | |
784 | { | |
785 | return "null test"; | |
786 | } | |
787 | ||
788 | void operator()() const | |
789 | { | |
790 | } | |
791 | ||
792 | }; | |
793 | ||
b756da67 PL |
794 | struct StatRingDNSNameQTypeToStringTest |
795 | { | |
796 | explicit StatRingDNSNameQTypeToStringTest(const DNSName &name, const QType type) : d_name(name), d_type(type) {} | |
797 | ||
798 | string getName() const { return "StatRing test with DNSName and QType to string"; } | |
799 | ||
800 | void operator()() const { | |
801 | S.ringAccount("testring", d_name.toLogString()+"/"+d_type.getName()); | |
802 | }; | |
803 | ||
804 | DNSName d_name; | |
805 | QType d_type; | |
806 | }; | |
807 | ||
c410bb1d PL |
808 | struct StatRingDNSNameQTypeTest |
809 | { | |
810 | explicit StatRingDNSNameQTypeTest(const DNSName &name, const QType type) : d_name(name), d_type(type) {} | |
811 | ||
812 | string getName() const { return "StatRing test with DNSName and QType"; } | |
813 | ||
814 | void operator()() const { | |
3b2aeba3 | 815 | S.ringAccount("testringdnsname", d_name, d_type); |
c410bb1d PL |
816 | }; |
817 | ||
818 | DNSName d_name; | |
819 | QType d_type; | |
820 | }; | |
821 | ||
34383528 | 822 | |
5a6caecd OM |
823 | struct NetmaskTreeTest |
824 | { | |
825 | string getName() const { return "NetmaskTreeTest"; } | |
826 | ||
827 | void operator()() const { | |
828 | Netmask nm("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/64"); | |
829 | NetmaskTree<bool> tree; | |
830 | ||
831 | for (int i = 0; i < 100; i++) | |
832 | tree.insert_or_assign(nm, true); | |
833 | } | |
834 | }; | |
34383528 BH |
835 | |
836 | int main(int argc, char** argv) | |
837 | try | |
838 | { | |
839 | reportAllTypes(); | |
e325f20c | 840 | |
b7821a82 | 841 | doRun(NOPTest()); |
ecefa116 | 842 | |
b7821a82 BH |
843 | doRun(IEqualsTest()); |
844 | doRun(MyIEqualsTest()); | |
845 | doRun(StrcasecmpTest()); | |
88227be0 KM |
846 | doRun(Base64EncodeTest()); |
847 | doRun(B64DecodeTest()); | |
b7821a82 BH |
848 | |
849 | doRun(StackMallocTest()); | |
34383528 | 850 | |
34383528 BH |
851 | doRun(EmptyQueryTest()); |
852 | doRun(TypicalRefTest()); | |
6b0ea82d | 853 | doRun(BigRefTest()); |
854 | doRun(BigDNSPacketRefTest()); | |
34383528 | 855 | |
69319910 | 856 | auto packet = makeEmptyQuery(); |
34383528 BH |
857 | doRun(ParsePacketTest(packet, "empty-query")); |
858 | ||
859 | packet = makeTypicalReferral(); | |
860 | cerr<<"typical referral size: "<<packet.size()<<endl; | |
b7821a82 | 861 | doRun(ParsePacketBareTest(packet, "typical-referral")); |
34383528 | 862 | |
b7821a82 | 863 | doRun(ParsePacketTest(packet, "typical-referral")); |
34383528 BH |
864 | |
865 | doRun(SimpleCompressTest("www.france.ds9a.nl")); | |
866 | ||
b7821a82 | 867 | |
34383528 | 868 | doRun(VectorExpandTest()); |
7519bae5 BH |
869 | |
870 | doRun(GetTimeTest()); | |
1f9faf8b BH |
871 | |
872 | doRun(GetLockUncontendedTest()); | |
873 | doRun(StaticMemberTest()); | |
874 | ||
34383528 BH |
875 | doRun(ARecordTest(1)); |
876 | doRun(ARecordTest(2)); | |
877 | doRun(ARecordTest(4)); | |
878 | doRun(ARecordTest(64)); | |
879 | ||
880 | doRun(A2RecordTest(1)); | |
881 | doRun(A2RecordTest(2)); | |
882 | doRun(A2RecordTest(4)); | |
883 | doRun(A2RecordTest(64)); | |
884 | ||
885 | doRun(MakeStringFromCharStarTest()); | |
886 | doRun(MakeARecordTest()); | |
887 | doRun(MakeARecordTestMM()); | |
888 | ||
889 | doRun(AAAARecordTest(1)); | |
890 | doRun(AAAARecordTest(2)); | |
891 | doRun(AAAARecordTest(4)); | |
892 | doRun(AAAARecordTest(64)); | |
893 | ||
894 | doRun(TXTRecordTest(1)); | |
895 | doRun(TXTRecordTest(2)); | |
896 | doRun(TXTRecordTest(4)); | |
897 | doRun(TXTRecordTest(64)); | |
898 | ||
899 | doRun(GenericRecordTest(1, QType::NS, "powerdnssec1.ds9a.nl")); | |
900 | doRun(GenericRecordTest(2, QType::NS, "powerdnssec1.ds9a.nl")); | |
901 | doRun(GenericRecordTest(4, QType::NS, "powerdnssec1.ds9a.nl")); | |
902 | doRun(GenericRecordTest(64, QType::NS, "powerdnssec1.ds9a.nl")); | |
903 | ||
ab570fc5 | 904 | |
34383528 BH |
905 | |
906 | doRun(SOARecordTest(1)); | |
907 | doRun(SOARecordTest(2)); | |
908 | doRun(SOARecordTest(4)); | |
909 | doRun(SOARecordTest(64)); | |
910 | ||
ab570fc5 | 911 | doRun(StringtokTest()); |
912 | doRun(VStringtokTest()); | |
179dad39 | 913 | doRun(StringAppendTest()); |
6b0ea82d | 914 | doRun(BoostStringAppendTest()); |
ab570fc5 | 915 | |
b8a514bb | 916 | doRun(DNSNameParseTest()); |
917 | doRun(DNSNameRootTest()); | |
918 | ||
5a6caecd OM |
919 | doRun(NetmaskTreeTest()); |
920 | ||
b756da67 PL |
921 | #ifndef RECURSOR |
922 | S.doRings(); | |
923 | ||
924 | S.declareRing("testring", "Just some ring where we'll account things"); | |
925 | doRun(StatRingDNSNameQTypeToStringTest(DNSName("example.com"), QType(1))); | |
c410bb1d | 926 | |
3b2aeba3 | 927 | S.declareDNSNameQTypeRing("testringdnsname", "Just some ring where we'll account things"); |
c410bb1d | 928 | doRun(StatRingDNSNameQTypeTest(DNSName("example.com"), QType(1))); |
b756da67 PL |
929 | #endif |
930 | ||
34383528 BH |
931 | cerr<<"Total runs: " << g_totalRuns<<endl; |
932 | ||
933 | } | |
934 | catch(std::exception &e) | |
935 | { | |
936 | cerr<<"Fatal: "<<e.what()<<endl; | |
937 | } | |
938 |