]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/recursordist/testrunner.cc
updated KSK and ZSK Rollover procedures, small fixes in Algorithm Rollover procedure
[thirdparty/pdns.git] / pdns / recursordist / testrunner.cc
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #define BOOST_TEST_DYN_LINK
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 #include <boost/test/unit_test.hpp>
28
29 #include <iostream>
30 #include <dnsrecords.hh>
31 #include <iomanip>
32 #include "logger.hh"
33 #include "logging.hh"
34
35 static std::string s_timestampFormat = "%s";
36
37 static const char* toTimestampStringMilli(const struct timeval& tv, char* buf, size_t sz)
38
39 {
40 struct tm tm;
41 size_t len = strftime(buf, sz, s_timestampFormat.c_str(), localtime_r(&tv.tv_sec, &tm));
42 if (len == 0) {
43 len = snprintf(buf, sz, "%lld", static_cast<long long>(tv.tv_sec));
44 }
45
46 snprintf(buf + len, sz - len, ".%03ld", static_cast<long>(tv.tv_usec) / 1000);
47 return buf;
48 }
49
50 static void loggerBackend(const Logging::Entry& entry)
51 {
52 static thread_local std::stringstream buf;
53
54 buf.str("");
55 buf << "msg=" << std::quoted(entry.message);
56 if (entry.error) {
57 buf << " oserror=" << std::quoted(entry.error.get());
58 }
59
60 if (entry.name) {
61 buf << " subsystem=" << std::quoted(entry.name.get());
62 }
63 buf << " level=" << entry.level;
64 if (entry.d_priority) {
65 buf << " prio=" << static_cast<int>(entry.d_priority);
66 }
67 char timebuf[64];
68 buf << " ts=" << std::quoted(toTimestampStringMilli(entry.d_timestamp, timebuf, sizeof(timebuf)));
69 for (auto const& v : entry.values) {
70 buf << " ";
71 buf << v.first << "=" << std::quoted(v.second);
72 }
73 Logger::Urgency u = entry.d_priority ? Logger::Urgency(entry.d_priority) : Logger::Info;
74 g_log << u << buf.str() << endl;
75 }
76
77 static bool init_unit_test()
78 {
79 g_slog = Logging::Logger::create(loggerBackend);
80 reportAllTypes();
81 return true;
82 }
83
84 // entry point:
85 int main(int argc, char* argv[])
86 {
87 return boost::unit_test::unit_test_main(&init_unit_test, argc, argv);
88 }